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