transmit display name (nick) in subscription requests and display them on Quicksy

This commit is contained in:
Daniel Gultsch 2018-11-26 12:56:30 +01:00
parent 1de385dcb9
commit ce5dffdbfb
4 changed files with 16 additions and 6 deletions

View File

@ -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);

View File

@ -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();

View File

@ -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) {

View File

@ -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));