Changing incoming message states from unseen/seen to fresh/noticed/seen.

This commit is contained in:
B. Petersen
2017-07-03 23:35:16 +02:00
parent 54fe2accb6
commit 4a8749349f
12 changed files with 58 additions and 31 deletions
@@ -38,7 +38,7 @@ public class AutoMessageHeardReceiver extends BroadcastReceiver {
if (dialog_id == 0 || max_id == 0) {
return;
}
MrMailbox.markseenChat((int)dialog_id);
MrMailbox.marknoticedChat((int)dialog_id);
NotificationsController.getInstance().removeSeenMessages();
}
}
@@ -49,7 +49,7 @@ public class AutoMessageReplyReceiver extends BroadcastReceiver {
return;
}
SendMessagesHelper.getInstance().sendMessageText(text.toString(), dialog_id, null);
MrMailbox.markseenChat((int)dialog_id);
MrMailbox.marknoticedChat((int)dialog_id);
NotificationsController.getInstance().removeSeenMessages();
}
}
@@ -68,9 +68,7 @@ public class MrChat {
public int setDraft(String draft/*NULL=delete*/, long replyToMsgId) {
return MrChatSetDraft(m_hChat, draft, replyToMsgId);
}
public int getUnseenCount() {
return MrChatGetUnseenCount(m_hChat);
}
public native int getFreshMsgCount();
public int getTotalMsgCount() {
return MrChatGetTotalMsgCount(m_hChat);
@@ -86,7 +84,6 @@ public class MrChat {
private native static long MrChatGetDraftTimestamp (long hChat); // returns 0 for "no draft"
private native static int MrChatGetDraftReplyToMsgId (long hChat); // returns 0 for "no draft"
private native static int MrChatSetDraft (long hChat, String draft/*NULL=delete*/, long replyToMsgId);
private native static int MrChatGetUnseenCount (long hChat);
private native static int MrChatGetTotalMsgCount (long hChat);
@@ -123,8 +123,8 @@ public class MrMailbox {
return new MrChat(MrMailboxGetChat(m_hMailbox, chat_id));
}
public native static int markseenMsg (int msg_id);
public native static int markseenChat (int chat_id);
public native static int markseenMsgs (int msg_ids[]);
public native static int marknoticedChat (int chat_id);
public native static int getChatIdByContactId (int contact_id);
public native static int createChatByContactId(int contact_id); // returns chat_id
@@ -140,7 +140,7 @@ public class MrMailbox {
public native static int[] searchMsgs(int chat_id, String query);
public native static int[] getUnseenMsgs();
public native static int[] getFreshMsgs();
public native static int[] getChatMedia(int chat_id, int msg_type, int or_msg_type);
public native static int getNextMedia(int msg_id, int dir);
@@ -48,10 +48,9 @@ public class MrMsg {
public final static int MR_MSG_FILE = 60;
public final static int MR_STATE_UNDEFINED = 0;
public final static int MR_IN_UNREAD = 10;
public final static int MR_IN_READ = 16;
public final static int MR_IN_FRESH = 10;
public final static int MR_IN_NOTICED = 13;
public final static int MR_OUT_PENDING = 20;
public final static int MR_OUT_SENDING = 22;
public final static int MR_OUT_ERROR = 24;
public final static int MR_OUT_DELIVERED = 26;
public final static int MR_OUT_READ = 28;
@@ -502,7 +502,7 @@ public class NotificationsController {
}
// get all unread messages as a hash
int unseenArr[] = MrMailbox.getUnseenMsgs();
int unseenArr[] = MrMailbox.getFreshMsgs();
int unseenCnt = unseenArr.length;
HashMap<Integer, Boolean> unseenHash = new HashMap<>();
for( int i = 0; i < unseenCnt; i++ ) {
@@ -49,7 +49,7 @@ public class WearReplyReceiver extends BroadcastReceiver {
return;
}
SendMessagesHelper.getInstance().sendMessageText(text.toString(), dialog_id, null);
MrMailbox.markseenChat((int)dialog_id);
MrMailbox.marknoticedChat((int)dialog_id);
NotificationsController.getInstance().removeSeenMessages();
}
}
@@ -169,7 +169,7 @@ public class DialogsSearchAdapter extends RecyclerView.Adapter {
MrPoortext mrSummary = mrMsg.getSummary(mrChat);
cell.setDialog(mrChat, mrSummary, -1,
mrMsg.getState()==MrMsg.MR_IN_UNREAD /*show unread count only if the message itself is unread*/ );
mrMsg.getState()==MrMsg.MR_IN_FRESH /*show unread count only if the message itself is unread*/ );
}
}
break;
@@ -526,7 +526,7 @@ public class DialogCell extends BaseCell {
public void update(int mask) {
if( m_showUnreadCount ) {
unreadCount = m_mrChat.getUnseenCount();
unreadCount = m_mrChat.getFreshMsgCount();
}
if (mask != 0) {
@@ -47,6 +47,7 @@ import android.text.TextUtils;
import android.text.style.ClickableSpan;
import android.text.style.URLSpan;
import android.util.Log;
import android.util.SparseIntArray;
import android.util.TypedValue;
import android.view.Gravity;
import android.view.MotionEvent;
@@ -152,7 +153,7 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not
private boolean paused = true;
private boolean wasPaused = false;
private boolean readWhenResume = false;
private SparseIntArray markseenWhenResume = new SparseIntArray();
private boolean scrollToTopOnResume;
private boolean forceScrollToTop;
@@ -325,7 +326,7 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not
AndroidUtilities.runOnUIThread(new Runnable() {
@Override
public void run() {
MrMailbox.markseenChat((int)dialog_id);
MrMailbox.marknoticedChat((int)dialog_id);
NotificationsController.getInstance().removeSeenMessages();
}
}, 700);
@@ -1913,9 +1914,11 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not
if (markAsRead) {
if (paused) {
readWhenResume = true;
markseenWhenResume.put(evt_msg_id, 1);
} else {
MrMailbox.markseenMsg(evt_msg_id);
int msg_ids[] = new int[1];
msg_ids[0] = evt_msg_id;
MrMailbox.markseenMsgs(msg_ids);
NotificationsController.getInstance().removeSeenMessages();
}
}
@@ -2251,9 +2254,15 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not
scrollToMessage = null;
}
paused = false;
if (readWhenResume ) {
readWhenResume = false;
MrMailbox.markseenChat((int)dialog_id);
int markseenWhenResumeCnt = markseenWhenResume.size();
if (markseenWhenResumeCnt>0 ) {
int msg_ids[] = new int[markseenWhenResumeCnt];
for(int i=0; i<markseenWhenResumeCnt; i++) {
msg_ids[i] = markseenWhenResume.keyAt(i);
}
MrMailbox.markseenMsgs(msg_ids);
markseenWhenResume.clear();
NotificationsController.getInstance().removeSeenMessages();
}
@@ -2865,6 +2874,19 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not
} else {
messageCell.setHighlightedText(null);
}
// mark message as being read
int state = mrMsg.getState();
if( state == MrMsg.MR_IN_FRESH || state==MrMsg.MR_IN_NOTICED ) {
if(paused) {
markseenWhenResume.put(msg_id, 1);
}
else {
int msg_ids[] = new int[1];
msg_ids[0] = msg_id;
MrMailbox.markseenMsgs(msg_ids);
}
}
}
else if( view instanceof ChatActionCell )
{