mark conversation as read when displayed marker from another client is received

This commit is contained in:
iNPUTmice 2014-10-02 21:07:11 +02:00
parent cc76e15b95
commit f671938e84
4 changed files with 27 additions and 7 deletions

View file

@ -1,6 +1,7 @@
package eu.siacs.conversations.parser; package eu.siacs.conversations.parser;
import android.os.SystemClock; import android.os.SystemClock;
import android.util.Log;
import net.java.otr4j.session.Session; import net.java.otr4j.session.Session;
import net.java.otr4j.session.SessionStatus; import net.java.otr4j.session.SessionStatus;
import eu.siacs.conversations.Config; import eu.siacs.conversations.Config;
@ -202,10 +203,24 @@ public class MessageParser extends AbstractParser implements
return null; return null;
} }
Element message = forwarded.findChild("message"); Element message = forwarded.findChild("message");
if ((message == null) || (!message.hasChild("body"))) { if (message == null) {
return null;
}
if (!message.hasChild("body")) {
if (status == Message.STATUS_RECEIVED if (status == Message.STATUS_RECEIVED
&& message.getAttribute("from") != null) { && message.getAttribute("from") != null) {
parseNonMessage(message, account); parseNonMessage(message, account);
} else if (status == Message.STATUS_SEND
&& message.hasChild("displayed", "urn:xmpp:chat-markers:0")) {
String to = message.getAttribute("to");
if (to != null) {
Conversation conversation = mXmppConnectionService.find(
mXmppConnectionService.getConversations(), account,
to.split("/")[0]);
if (conversation != null) {
mXmppConnectionService.markRead(conversation, false);
}
}
} }
return null; return null;
} }
@ -419,7 +434,8 @@ public class MessageParser extends AbstractParser implements
lastCarbonMessageReceived = SystemClock lastCarbonMessageReceived = SystemClock
.elapsedRealtime(); .elapsedRealtime();
notify = false; notify = false;
mXmppConnectionService.markRead(message.getConversation()); mXmppConnectionService.markRead(
message.getConversation(), false);
} else { } else {
message.markUnread(); message.markUnread();
} }
@ -436,7 +452,8 @@ public class MessageParser extends AbstractParser implements
|| NotificationService || NotificationService
.wasHighlightedOrPrivate(message); .wasHighlightedOrPrivate(message);
} else { } else {
mXmppConnectionService.markRead(message.getConversation()); mXmppConnectionService.markRead(message.getConversation(),
false);
lastCarbonMessageReceived = SystemClock.elapsedRealtime(); lastCarbonMessageReceived = SystemClock.elapsedRealtime();
notify = false; notify = false;
} }

View file

@ -1631,16 +1631,19 @@ public class XmppConnectionService extends Service {
return null; return null;
} }
public void markRead(Conversation conversation) { public void markRead(Conversation conversation, boolean calledByUi) {
conversation.markRead(); conversation.markRead();
mNotificationService.clear(conversation); mNotificationService.clear(conversation);
String id = conversation.popLatestMarkableMessageId(); String id = conversation.popLatestMarkableMessageId();
if (confirmMessages() && id != null) { if (confirmMessages() && id != null && calledByUi) {
Account account = conversation.getAccount(); Account account = conversation.getAccount();
String to = conversation.getContactJid(); String to = conversation.getContactJid();
this.sendMessagePacket(conversation.getAccount(), this.sendMessagePacket(conversation.getAccount(),
mMessageGenerator.confirm(account, to, id)); mMessageGenerator.confirm(account, to, id));
} }
if (!calledByUi) {
updateConversationUi();
}
} }
public void failWaitingOtrMessages(Conversation conversation) { public void failWaitingOtrMessages(Conversation conversation) {

View file

@ -156,7 +156,7 @@ public class ConversationActivity extends XmppActivity implements
openConversation(getSelectedConversation()); openConversation(getSelectedConversation());
if (!getSelectedConversation().isRead()) { if (!getSelectedConversation().isRead()) {
xmppConnectionService xmppConnectionService
.markRead(getSelectedConversation()); .markRead(getSelectedConversation(),true);
listView.invalidateViews(); listView.invalidateViews();
} }
} }

View file

@ -494,7 +494,7 @@ public class ConversationFragment extends Fragment {
getActivity().invalidateOptionsMenu(); getActivity().invalidateOptionsMenu();
updateChatMsgHint(); updateChatMsgHint();
if (!activity.shouldPaneBeOpen()) { if (!activity.shouldPaneBeOpen()) {
activity.xmppConnectionService.markRead(conversation); activity.xmppConnectionService.markRead(conversation,true);
activity.updateConversationList(); activity.updateConversationList();
} }
this.updateSendButton(); this.updateSendButton();