protected void onConversationSeen() { LogUtils.d(LOG_TAG, "AbstractConversationViewFragment#onConversationSeen()"); // Ignore unsafe calls made after a fragment is detached from an activity final ControllableActivity activity = (ControllableActivity) getActivity(); if (activity == null) { LogUtils.w(LOG_TAG, "ignoring onConversationSeen for conv=%s", mConversation.id); return; } mViewState.setInfoForConversation(mConversation); LogUtils.d( LOG_TAG, "onConversationSeen() - mSuppressMarkingViewed = %b", mSuppressMarkingViewed); // In most circumstances we want to mark the conversation as viewed and read, since the // user has read it. However, if the user has already marked the conversation unread, we // do not want a later mark-read operation to undo this. So we check this variable which // is set in #markUnread() which suppresses automatic mark-read. if (!mSuppressMarkingViewed) { // mark viewed/read if not previously marked viewed by this conversation view, // or if unread messages still exist in the message list cursor // we don't want to keep marking viewed on rotation or restore // but we do want future re-renders to mark read (e.g. "New message from X" case) final MessageCursor cursor = getMessageCursor(); LogUtils.d( LOG_TAG, "onConversationSeen() - mConversation.isViewed() = %b, " + "cursor null = %b, cursor.isConversationRead() = %b", mConversation.isViewed(), cursor == null, cursor != null && cursor.isConversationRead()); if (!mConversation.isViewed() || (cursor != null && !cursor.isConversationRead())) { // Mark the conversation viewed and read. activity .getConversationUpdater() .markConversationsRead(Arrays.asList(mConversation), true, true); // and update the Message objects in the cursor so the next time a cursor update // happens with these messages marked read, we know to ignore it if (cursor != null && !cursor.isClosed()) { cursor.markMessagesRead(); } } } activity.getListHandler().onConversationSeen(); }
@Override public ConversationUpdater getListController() { final ControllableActivity activity = (ControllableActivity) getActivity(); return activity != null ? activity.getConversationUpdater() : null; }