improvements for self messages

* fix omemo in group chats w/o participants
* don't create two axolotl messages when messaging self
* fix read marker for self messages
This commit is contained in:
Daniel Gultsch 2018-01-27 10:45:02 +01:00
parent 3e111e7f58
commit be70eb5650
5 changed files with 25 additions and 10 deletions

View file

@ -335,6 +335,10 @@ public class AxolotlService implements OnAdvancedStreamFeaturesLoaded {
} }
private Set<XmppAxolotlSession> findSessionsForConversation(Conversation conversation) { private Set<XmppAxolotlSession> findSessionsForConversation(Conversation conversation) {
if (conversation.getContact().isSelf()) {
//will be added in findOwnSessions()
return Collections.emptySet();
}
HashSet<XmppAxolotlSession> sessions = new HashSet<>(); HashSet<XmppAxolotlSession> sessions = new HashSet<>();
for (Jid jid : conversation.getAcceptedCryptoTargets()) { for (Jid jid : conversation.getAcceptedCryptoTargets()) {
sessions.addAll(this.sessions.getAll(getAddressForJid(jid).getName()).values()); sessions.addAll(this.sessions.getAll(getAddressForJid(jid).getName()).values());
@ -1180,7 +1184,8 @@ public class AxolotlService implements OnAdvancedStreamFeaturesLoaded {
} }
public boolean trustedSessionVerified(final Conversation conversation) { public boolean trustedSessionVerified(final Conversation conversation) {
Set<XmppAxolotlSession> sessions = findSessionsForConversation(conversation); final Set<XmppAxolotlSession> sessions = new HashSet<>();
sessions.addAll(findSessionsForConversation(conversation));
sessions.addAll(findOwnSessions()); sessions.addAll(findOwnSessions());
boolean verified = false; boolean verified = false;
for (XmppAxolotlSession session : sessions) { for (XmppAxolotlSession session : sessions) {
@ -1214,7 +1219,7 @@ public class AxolotlService implements OnAdvancedStreamFeaturesLoaded {
@Nullable @Nullable
private boolean buildHeader(XmppAxolotlMessage axolotlMessage, Conversation c) { private boolean buildHeader(XmppAxolotlMessage axolotlMessage, Conversation c) {
Set<XmppAxolotlSession> remoteSessions = findSessionsForConversation(c); Set<XmppAxolotlSession> remoteSessions = findSessionsForConversation(c);
final boolean acceptEmpty = c.getMode() == Conversation.MODE_MULTI && c.getMucOptions().getUserCount() == 0; final boolean acceptEmpty = (c.getMode() == Conversation.MODE_MULTI && c.getMucOptions().getUserCount() == 0) || c.getContact().isSelf();
Collection<XmppAxolotlSession> ownSessions = findOwnSessions(); Collection<XmppAxolotlSession> ownSessions = findOwnSessions();
if (remoteSessions.isEmpty() && !acceptEmpty) { if (remoteSessions.isEmpty() && !acceptEmpty) {
return false; return false;

View file

@ -194,7 +194,7 @@ public class Conversation extends AbstractEntity implements Blockable, Comparabl
} }
public boolean setOutgoingChatState(ChatState state) { public boolean setOutgoingChatState(ChatState state) {
if (mode == MODE_SINGLE || (isPrivateAndNonAnonymous() && getNextCounterpart() == null)) { if (mode == MODE_SINGLE && !getContact().isSelf() || (isPrivateAndNonAnonymous() && getNextCounterpart() == null)) {
if (this.mOutgoingChatState != state) { if (this.mOutgoingChatState != state) {
this.mOutgoingChatState = state; this.mOutgoingChatState = state;
return true; return true;

View file

@ -645,7 +645,7 @@ public class Message extends AbstractEntity {
public boolean trusted() { public boolean trusted() {
Contact contact = this.getContact(); Contact contact = this.getContact();
return (status > STATUS_RECEIVED || (contact != null && contact.mutualPresenceSubscription())); return status > STATUS_RECEIVED || (contact != null && (contact.mutualPresenceSubscription() || contact.isSelf()));
} }
public boolean fixCounterpart() { public boolean fixCounterpart() {

View file

@ -36,10 +36,11 @@ public class MessageGenerator extends AbstractGenerator {
Conversation conversation = message.getConversation(); Conversation conversation = message.getConversation();
Account account = conversation.getAccount(); Account account = conversation.getAccount();
MessagePacket packet = new MessagePacket(); MessagePacket packet = new MessagePacket();
final boolean isWithSelf = conversation.getContact().isSelf();
if (conversation.getMode() == Conversation.MODE_SINGLE) { if (conversation.getMode() == Conversation.MODE_SINGLE) {
packet.setTo(message.getCounterpart()); packet.setTo(message.getCounterpart());
packet.setType(MessagePacket.TYPE_CHAT); packet.setType(MessagePacket.TYPE_CHAT);
if (this.mXmppConnectionService.indicateReceived()) { if (this.mXmppConnectionService.indicateReceived() && !isWithSelf) {
packet.addChild("request", "urn:xmpp:receipts"); packet.addChild("request", "urn:xmpp:receipts");
} }
} else if (message.getType() == Message.TYPE_PRIVATE) { } else if (message.getType() == Message.TYPE_PRIVATE) {

View file

@ -586,6 +586,7 @@ public class MessageParser extends AbstractParser implements OnMessagePacketRece
&& replacedMessage.getStatus() == Message.STATUS_RECEIVED && replacedMessage.getStatus() == Message.STATUS_RECEIVED
&& (replacedMessage.trusted() || replacedMessage.getType() == Message.TYPE_PRIVATE) && (replacedMessage.trusted() || replacedMessage.getType() == Message.TYPE_PRIVATE)
&& remoteMsgId != null && remoteMsgId != null
&& !selfAddressed
&& !isTypeGroupChat) { && !isTypeGroupChat) {
processMessageReceipts(account, packet, query); processMessageReceipts(account, packet, query);
} }
@ -663,6 +664,7 @@ public class MessageParser extends AbstractParser implements OnMessagePacketRece
&& message.getStatus() == Message.STATUS_RECEIVED && message.getStatus() == Message.STATUS_RECEIVED
&& (message.trusted() || message.getType() == Message.TYPE_PRIVATE) && (message.trusted() || message.getType() == Message.TYPE_PRIVATE)
&& remoteMsgId != null && remoteMsgId != null
&& !selfAddressed
&& !isTypeGroupChat) { && !isTypeGroupChat) {
processMessageReceipts(account, packet, query); processMessageReceipts(account, packet, query);
} }
@ -792,11 +794,8 @@ public class MessageParser extends AbstractParser implements OnMessagePacketRece
if (displayed != null) { if (displayed != null) {
final String id = displayed.getAttribute("id"); final String id = displayed.getAttribute("id");
final Jid sender = displayed.getAttributeAsJid("sender"); final Jid sender = displayed.getAttributeAsJid("sender");
if (packet.fromAccount(account)) { if (packet.fromAccount(account) && !selfAddressed) {
Conversation conversation = mXmppConnectionService.find(account, counterpart.toBareJid()); dismissNotification(account, counterpart, query);
if (conversation != null && (query == null || query.isCatchup())) {
mXmppConnectionService.markRead(conversation); //TODO only mark messages read that are older than timestamp
}
} else if (isTypeGroupChat) { } else if (isTypeGroupChat) {
Conversation conversation = mXmppConnectionService.find(account, counterpart.toBareJid()); Conversation conversation = mXmppConnectionService.find(account, counterpart.toBareJid());
if (conversation != null && id != null && sender != null) { if (conversation != null && id != null && sender != null) {
@ -827,6 +826,9 @@ public class MessageParser extends AbstractParser implements OnMessagePacketRece
mXmppConnectionService.markMessage(message, Message.STATUS_SEND_DISPLAYED); mXmppConnectionService.markMessage(message, Message.STATUS_SEND_DISPLAYED);
message = message.prev(); message = message.prev();
} }
if (displayedMessage != null && selfAddressed) {
dismissNotification(account, counterpart, query);
}
} }
} }
@ -844,6 +846,13 @@ public class MessageParser extends AbstractParser implements OnMessagePacketRece
} }
} }
private void dismissNotification(Account account, Jid counterpart, MessageArchiveService.Query query) {
Conversation conversation = mXmppConnectionService.find(account, counterpart.toBareJid());
if (conversation != null && (query == null || query.isCatchup())) {
mXmppConnectionService.markRead(conversation); //TODO only mark messages read that are older than timestamp
}
}
private static Jid getTrueCounterpart(Element mucUserElement, Jid fallback) { private static Jid getTrueCounterpart(Element mucUserElement, Jid fallback) {
final Element item = mucUserElement == null ? null : mucUserElement.findChild("item"); final Element item = mucUserElement == null ? null : mucUserElement.findChild("item");
Jid result = item == null ? null : item.getAttributeAsJid("jid"); Jid result = item == null ? null : item.getAttributeAsJid("jid");