mirror of
https://github.com/moparisthebest/Conversations
synced 2024-11-27 19:22:15 -05:00
reset messagesLoaded when changing retention settings
This commit is contained in:
parent
a86b2fefd9
commit
40ee1a0bfc
@ -22,6 +22,7 @@ import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.ListIterator;
|
||||
import java.util.Locale;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
import eu.siacs.conversations.Config;
|
||||
import eu.siacs.conversations.crypto.PgpDecryptionService;
|
||||
@ -91,6 +92,7 @@ public class Conversation extends AbstractEntity implements Blockable, Comparabl
|
||||
private String mLastReceivedOtrMessageId = null;
|
||||
private String mFirstMamReference = null;
|
||||
private Message correctingMessage;
|
||||
public AtomicBoolean messagesLoaded = new AtomicBoolean(true);
|
||||
|
||||
public boolean hasMessagesLeftOnServer() {
|
||||
return messagesLeftOnServer;
|
||||
|
@ -113,7 +113,6 @@ public class MessageArchiveService implements OnAdvancedStreamFeaturesLoaded {
|
||||
query.reference = conversation.getFirstMamReference();
|
||||
Log.d(Config.LOGTAG,"setting mam reference");
|
||||
}
|
||||
Log.d(Config.LOGTAG,"checking max of "+start+" end "+mXmppConnectionService.getAutomaticMessageDeletionDate());
|
||||
query.start = Math.max(start,mXmppConnectionService.getAutomaticMessageDeletionDate());
|
||||
if (start > end) {
|
||||
return null;
|
||||
|
@ -933,6 +933,10 @@ public class XmppConnectionService extends Service {
|
||||
}
|
||||
|
||||
private void expireOldMessages() {
|
||||
expireOldMessages(false);
|
||||
}
|
||||
|
||||
public void expireOldMessages(final boolean resetHasMessagesLeftOnServer) {
|
||||
mLastExpiryRun.set(SystemClock.elapsedRealtime());
|
||||
mDatabaseExecutor.execute(new Runnable() {
|
||||
@Override
|
||||
@ -943,6 +947,10 @@ public class XmppConnectionService extends Service {
|
||||
synchronized (XmppConnectionService.this.conversations) {
|
||||
for (Conversation conversation : XmppConnectionService.this.conversations) {
|
||||
conversation.expireOldMessages(timestamp);
|
||||
if (resetHasMessagesLeftOnServer) {
|
||||
conversation.messagesLoaded.set(true);
|
||||
conversation.setHasMessagesLeftOnServer(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
updateConversationUi();
|
||||
|
@ -1787,11 +1787,4 @@ public class ConversationActivity extends XmppActivity
|
||||
public boolean highlightSelectedConversations() {
|
||||
return !isConversationsOverviewHideable() || this.conversationWasSelectedByKeyboard;
|
||||
}
|
||||
|
||||
public void setMessagesLoaded() {
|
||||
if (mConversationFragment != null) {
|
||||
mConversationFragment.setMessagesLoaded();
|
||||
mConversationFragment.updateMessages();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -120,7 +120,6 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa
|
||||
private RelativeLayout snackbar;
|
||||
private TextView snackbarMessage;
|
||||
private TextView snackbarAction;
|
||||
private boolean messagesLoaded = true;
|
||||
private Toast messageLoaderToast;
|
||||
|
||||
private OnScrollListener mOnScrollListener = new OnScrollListener() {
|
||||
@ -135,14 +134,13 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa
|
||||
public void onScroll(AbsListView view, int firstVisibleItem,
|
||||
int visibleItemCount, int totalItemCount) {
|
||||
synchronized (ConversationFragment.this.messageList) {
|
||||
if (firstVisibleItem < 5 && messagesLoaded && messageList.size() > 0) {
|
||||
if (firstVisibleItem < 5 && conversation != null && conversation.messagesLoaded.compareAndSet(true,false) && messageList.size() > 0) {
|
||||
long timestamp;
|
||||
if (messageList.get(0).getType() == Message.TYPE_STATUS && messageList.size() >= 2) {
|
||||
timestamp = messageList.get(1).getTimeSent();
|
||||
} else {
|
||||
timestamp = messageList.get(0).getTimeSent();
|
||||
}
|
||||
messagesLoaded = false;
|
||||
activity.xmppConnectionService.loadMoreMessages(conversation, timestamp, new XmppConnectionService.OnMoreMessagesLoaded() {
|
||||
@Override
|
||||
public void onMoreMessagesLoaded(final int c, Conversation conversation) {
|
||||
@ -171,7 +169,6 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa
|
||||
messageListAdapter.notifyDataSetChanged();
|
||||
int pos = Math.max(getIndexOf(uuid,messageList),0);
|
||||
messagesView.setSelectionFromTop(pos, pxOffset);
|
||||
messagesLoaded = true;
|
||||
if (messageLoaderToast != null) {
|
||||
messageLoaderToast.cancel();
|
||||
}
|
||||
@ -376,10 +373,6 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa
|
||||
private ConversationActivity activity;
|
||||
private Message selectedMessage;
|
||||
|
||||
public void setMessagesLoaded() {
|
||||
this.messagesLoaded = true;
|
||||
}
|
||||
|
||||
private void sendMessage() {
|
||||
final String body = mEditMessage.getText().toString();
|
||||
if (body.length() == 0 || this.conversation == null) {
|
||||
@ -913,7 +906,7 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa
|
||||
messageListAdapter.updatePreferences();
|
||||
this.messagesView.setAdapter(messageListAdapter);
|
||||
updateMessages();
|
||||
this.messagesLoaded = true;
|
||||
this.conversation.messagesLoaded.set(true);
|
||||
synchronized (this.messageList) {
|
||||
final Message first = conversation.getFirstUnreadMessage();
|
||||
final int bottom = Math.max(0, this.messageList.size() - 1);
|
||||
|
@ -372,6 +372,8 @@ public class SettingsActivity extends XmppActivity implements
|
||||
reconnectAccounts();
|
||||
} else if (name.equals("use_tor")) {
|
||||
reconnectAccounts();
|
||||
} else if (name.equals(AUTOMATIC_MESSAGE_DELETION)) {
|
||||
xmppConnectionService.expireOldMessages(true);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -565,7 +565,7 @@ public class MessageAdapter extends ArrayAdapter<Message> implements CopyTextVie
|
||||
if (timestamp == 0) {
|
||||
timestamp = System.currentTimeMillis();
|
||||
}
|
||||
activity.setMessagesLoaded();
|
||||
conversation.messagesLoaded.set(true);
|
||||
MessageArchiveService.Query query = activity.xmppConnectionService.getMessageArchiveService().query(conversation, 0, timestamp);
|
||||
if (query != null) {
|
||||
Toast.makeText(activity, R.string.fetching_history_from_server, Toast.LENGTH_LONG).show();
|
||||
|
Loading…
Reference in New Issue
Block a user