diff options
Diffstat (limited to '')
3 files changed, 33 insertions, 8 deletions
diff --git a/src/main/java/de/pixart/messenger/ui/ConversationFragment.java b/src/main/java/de/pixart/messenger/ui/ConversationFragment.java index 332b62b7b..7bd20f3e5 100644 --- a/src/main/java/de/pixart/messenger/ui/ConversationFragment.java +++ b/src/main/java/de/pixart/messenger/ui/ConversationFragment.java @@ -239,8 +239,9 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke @Override public void onScrollStateChanged(AbsListView view, int scrollState) { - // TODO Auto-generated method stub - + if (AbsListView.OnScrollListener.SCROLL_STATE_IDLE == scrollState) { + fireReadEvent(); + } } @Override @@ -1825,9 +1826,33 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke getActivity().invalidateOptionsMenu(); }); super.onResume(); + binding.messagesView.post(this::fireReadEvent); + } + + private void fireReadEvent() { if (activity != null && this.conversation != null) { - activity.onConversationRead(this.conversation); + String uuid = getLastVisibleMessageUuid(); + if (uuid != null) { + activity.onConversationRead(this.conversation, uuid); + } + } + } + + private String getLastVisibleMessageUuid() { + if (binding == null) { + return null; } + int pos = binding.messagesView.getLastVisiblePosition(); + if (pos >= 0) { + Message message = (Message) binding.messagesView.getItemAtPosition(pos); + if (message != null) { + while (message.next() != null && message.next().wasMergedIntoPrevious()) { + message = message.next(); + } + return message.getUuid(); + } + } + return null; } private void showErrorMessage(final Message message) { @@ -2167,7 +2192,7 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke } } - activity.onConversationRead(this.conversation); + this.binding.messagesView.post(this::fireReadEvent); //TODO if we only do this when this fragment is running on main it won't *bing* in tablet layout which might be unnecessary since we can *see* it activity.xmppConnectionService.getNotificationService().setOpenConversation(this.conversation); @@ -2434,7 +2459,7 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke this.messageListAdapter.notifyDataSetChanged(); updateChatMsgHint(); if (notifyConversationRead && activity != null) { - activity.onConversationRead(this.conversation); + binding.messagesView.post(this::fireReadEvent); } updateSendButton(); updateEditablity(); diff --git a/src/main/java/de/pixart/messenger/ui/ConversationsActivity.java b/src/main/java/de/pixart/messenger/ui/ConversationsActivity.java index 89e003e9f..9fb4d26e8 100644 --- a/src/main/java/de/pixart/messenger/ui/ConversationsActivity.java +++ b/src/main/java/de/pixart/messenger/ui/ConversationsActivity.java @@ -863,9 +863,9 @@ public class ConversationsActivity extends XmppActivity implements OnConversatio } @Override - public void onConversationRead(Conversation conversation) { + public void onConversationRead(Conversation conversation, String upToUuid) { if (!mActivityPaused && pendingViewIntent.peek() == null) { - xmppConnectionService.sendReadMarker(conversation); + xmppConnectionService.sendReadMarker(conversation, upToUuid); } else { Log.d(Config.LOGTAG, "ignoring read callback. mActivityPaused=" + Boolean.toString(mActivityPaused)); } diff --git a/src/main/java/de/pixart/messenger/ui/interfaces/OnConversationRead.java b/src/main/java/de/pixart/messenger/ui/interfaces/OnConversationRead.java index ab5cc607d..763d139d3 100644 --- a/src/main/java/de/pixart/messenger/ui/interfaces/OnConversationRead.java +++ b/src/main/java/de/pixart/messenger/ui/interfaces/OnConversationRead.java @@ -32,5 +32,5 @@ package de.pixart.messenger.ui.interfaces; import de.pixart.messenger.entities.Conversation; public interface OnConversationRead { - void onConversationRead(Conversation conversation); + void onConversationRead(Conversation conversation, String upToUuid); }
\ No newline at end of file |