From ce5dffdbfbd347d54dbd18e3d1076b91dd31fb67 Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Mon, 26 Nov 2018 12:56:30 +0100 Subject: [PATCH] transmit display name (nick) in subscription requests and display them on Quicksy --- .../java/eu/siacs/conversations/entities/Contact.java | 3 ++- .../eu/siacs/conversations/entities/Conversation.java | 3 ++- .../conversations/generator/PresenceGenerator.java | 10 +++++++++- .../eu/siacs/conversations/parser/PresenceParser.java | 6 +++--- 4 files changed, 16 insertions(+), 6 deletions(-) diff --git a/src/main/java/eu/siacs/conversations/entities/Contact.java b/src/main/java/eu/siacs/conversations/entities/Contact.java index f1f3b58c0..5ea714cd6 100644 --- a/src/main/java/eu/siacs/conversations/entities/Contact.java +++ b/src/main/java/eu/siacs/conversations/entities/Contact.java @@ -21,6 +21,7 @@ import eu.siacs.conversations.Config; import eu.siacs.conversations.R; import eu.siacs.conversations.android.AbstractPhoneContact; import eu.siacs.conversations.android.JabberIdContact; +import eu.siacs.conversations.services.QuickConversationsService; import eu.siacs.conversations.utils.JidHelper; import eu.siacs.conversations.utils.UIHelper; import eu.siacs.conversations.xml.Element; @@ -133,7 +134,7 @@ public class Contact implements ListItem, Blockable { return this.systemName; } else if (!TextUtils.isEmpty(this.serverName)) { return this.serverName; - } else if (!TextUtils.isEmpty(this.presenceName) && mutualPresenceSubscription()) { + } else if (!TextUtils.isEmpty(this.presenceName) && ((QuickConversationsService.isQuicksy() && Config.QUICKSY_DOMAIN.equals(jid.getDomain())) ||mutualPresenceSubscription())) { return this.presenceName; } else if (jid.getLocal() != null) { return JidHelper.localPartOrFallback(jid); diff --git a/src/main/java/eu/siacs/conversations/entities/Conversation.java b/src/main/java/eu/siacs/conversations/entities/Conversation.java index e12627e24..393893b32 100644 --- a/src/main/java/eu/siacs/conversations/entities/Conversation.java +++ b/src/main/java/eu/siacs/conversations/entities/Conversation.java @@ -23,6 +23,7 @@ import eu.siacs.conversations.Config; import eu.siacs.conversations.crypto.OmemoSetting; import eu.siacs.conversations.crypto.PgpDecryptionService; import eu.siacs.conversations.crypto.axolotl.AxolotlService; +import eu.siacs.conversations.services.QuickConversationsService; import eu.siacs.conversations.utils.JidHelper; import eu.siacs.conversations.xmpp.InvalidJid; import eu.siacs.conversations.xmpp.chatstate.ChatState; @@ -498,7 +499,7 @@ public class Conversation extends AbstractEntity implements Blockable, Comparabl return contactJid.getLocal() != null ? contactJid.getLocal() : contactJid; } } - } else if (isWithStranger()) { + } else if ((QuickConversationsService.isConversations() || !Config.QUICKSY_DOMAIN.equals(contactJid.getDomain())) && isWithStranger()) { return contactJid; } else { return this.getContact().getDisplayName(); diff --git a/src/main/java/eu/siacs/conversations/generator/PresenceGenerator.java b/src/main/java/eu/siacs/conversations/generator/PresenceGenerator.java index b44c79315..df6b9eaca 100644 --- a/src/main/java/eu/siacs/conversations/generator/PresenceGenerator.java +++ b/src/main/java/eu/siacs/conversations/generator/PresenceGenerator.java @@ -1,11 +1,14 @@ package eu.siacs.conversations.generator; +import android.text.TextUtils; + import eu.siacs.conversations.entities.Account; import eu.siacs.conversations.entities.Contact; import eu.siacs.conversations.entities.MucOptions; import eu.siacs.conversations.entities.Presence; import eu.siacs.conversations.services.XmppConnectionService; import eu.siacs.conversations.xml.Element; +import eu.siacs.conversations.xml.Namespace; import eu.siacs.conversations.xmpp.stanzas.PresencePacket; public class PresenceGenerator extends AbstractGenerator { @@ -23,7 +26,12 @@ public class PresenceGenerator extends AbstractGenerator { } public PresencePacket requestPresenceUpdatesFrom(Contact contact) { - return subscription("subscribe", contact); + PresencePacket packet = subscription("subscribe", contact); + String displayName = contact.getAccount().getDisplayName(); + if (!TextUtils.isEmpty(displayName)) { + packet.addChild("nick",Namespace.NICK).setContent(displayName); + } + return packet; } public PresencePacket stopPresenceUpdatesFrom(Contact contact) { diff --git a/src/main/java/eu/siacs/conversations/parser/PresenceParser.java b/src/main/java/eu/siacs/conversations/parser/PresenceParser.java index 201ea1c94..3ae3179d5 100644 --- a/src/main/java/eu/siacs/conversations/parser/PresenceParser.java +++ b/src/main/java/eu/siacs/conversations/parser/PresenceParser.java @@ -260,9 +260,6 @@ public class PresenceParser extends AbstractParser implements final Contact contact = account.getRoster().getContact(from); if (type == null) { final String resource = from.isBareJid() ? "" : from.getResource(); - if (contact.setPresenceName(packet.findChildContent("nick", Namespace.NICK))) { - mXmppConnectionService.getAvatarService().clear(contact); - } Avatar avatar = Avatar.parsePresence(packet.findChild("x", "vcard-temp:x:update")); if (avatar != null && (!contact.isSelf() || account.getAvatar() == null)) { avatar.owner = from.asBareJid(); @@ -341,6 +338,9 @@ public class PresenceParser extends AbstractParser implements } mXmppConnectionService.onContactStatusChanged.onContactStatusChanged(contact, false); } else if (type.equals("subscribe")) { + if (contact.setPresenceName(packet.findChildContent("nick", Namespace.NICK))) { + mXmppConnectionService.getAvatarService().clear(contact); + } if (contact.getOption(Contact.Options.PREEMPTIVE_GRANT)) { mXmppConnectionService.sendPresencePacket(account, mPresenceGenerator.sendPresenceUpdatesTo(contact));