diff options
author | Daniel Gultsch <daniel@gultsch.de> | 2015-10-29 13:41:08 +0100 |
---|---|---|
committer | Daniel Gultsch <daniel@gultsch.de> | 2015-10-29 13:41:08 +0100 |
commit | c7ff196f58b5576ca1aeb5fd6d51bbe500754f06 (patch) | |
tree | 281e1c922d70d6a85a098f403448965a861f8ab1 /src/main/java/eu/siacs | |
parent | 7410e2023adb2c4535e3301637fa0ecc61e7187c (diff) |
push CN into nick pep node when uploading certificate. subscribe to nick node
Diffstat (limited to 'src/main/java/eu/siacs')
7 files changed, 47 insertions, 5 deletions
diff --git a/src/main/java/eu/siacs/conversations/crypto/axolotl/AxolotlService.java b/src/main/java/eu/siacs/conversations/crypto/axolotl/AxolotlService.java index ab3aefac..e15a73ba 100644 --- a/src/main/java/eu/siacs/conversations/crypto/axolotl/AxolotlService.java +++ b/src/main/java/eu/siacs/conversations/crypto/axolotl/AxolotlService.java @@ -515,6 +515,7 @@ public class AxolotlService implements OnAdvancedStreamFeaturesLoaded { if (changed) { if (account.getPrivateKeyAlias() != null && Config.X509_VERIFICATION) { + mXmppConnectionService.publishDisplayName(account); publishDeviceVerificationAndBundle(signedPreKeyRecord, preKeyRecords, announce, wipe); } else { publishDeviceBundle(signedPreKeyRecord, preKeyRecords, announce, wipe); diff --git a/src/main/java/eu/siacs/conversations/entities/Account.java b/src/main/java/eu/siacs/conversations/entities/Account.java index ebfd9805..c5791625 100644 --- a/src/main/java/eu/siacs/conversations/entities/Account.java +++ b/src/main/java/eu/siacs/conversations/entities/Account.java @@ -37,6 +37,7 @@ public class Account extends AbstractEntity { public static final String ROSTERVERSION = "rosterversion"; public static final String KEYS = "keys"; public static final String AVATAR = "avatar"; + public static final String DISPLAY_NAME = "display_name"; public static final String PINNED_MECHANISM_KEY = "pinned_mechanism"; @@ -49,6 +50,14 @@ public class Account extends AbstractEntity { return xmppConnection != null && xmppConnection.getFeatures().httpUpload(); } + public void setDisplayName(String displayName) { + this.displayName = displayName; + } + + public String getDisplayName() { + return displayName; + } + public static enum State { DISABLED, OFFLINE, @@ -124,6 +133,7 @@ public class Account extends AbstractEntity { protected State status = State.OFFLINE; protected JSONObject keys = new JSONObject(); protected String avatar; + protected String displayName = null; protected boolean online = false; private OtrService mOtrService = null; private AxolotlService axolotlService = null; @@ -140,12 +150,12 @@ public class Account extends AbstractEntity { public Account(final Jid jid, final String password) { this(java.util.UUID.randomUUID().toString(), jid, - password, 0, null, "", null); + password, 0, null, "", null, null); } public Account(final String uuid, final Jid jid, final String password, final int options, final String rosterVersion, final String keys, - final String avatar) { + final String avatar, String displayName) { this.uuid = uuid; this.jid = jid; if (jid.isBareJid()) { @@ -160,6 +170,7 @@ public class Account extends AbstractEntity { this.keys = new JSONObject(); } this.avatar = avatar; + this.displayName = displayName; } public static Account fromCursor(final Cursor cursor) { @@ -175,7 +186,8 @@ public class Account extends AbstractEntity { cursor.getInt(cursor.getColumnIndex(OPTIONS)), cursor.getString(cursor.getColumnIndex(ROSTERVERSION)), cursor.getString(cursor.getColumnIndex(KEYS)), - cursor.getString(cursor.getColumnIndex(AVATAR))); + cursor.getString(cursor.getColumnIndex(AVATAR)), + cursor.getString(cursor.getColumnIndex(DISPLAY_NAME))); } public boolean isOptionSet(final int option) { @@ -287,6 +299,7 @@ public class Account extends AbstractEntity { values.put(KEYS, this.keys.toString()); values.put(ROSTERVERSION, rosterVersion); values.put(AVATAR, avatar); + values.put(DISPLAY_NAME, displayName); return values; } diff --git a/src/main/java/eu/siacs/conversations/generator/AbstractGenerator.java b/src/main/java/eu/siacs/conversations/generator/AbstractGenerator.java index 879a5680..5741af53 100644 --- a/src/main/java/eu/siacs/conversations/generator/AbstractGenerator.java +++ b/src/main/java/eu/siacs/conversations/generator/AbstractGenerator.java @@ -27,6 +27,7 @@ public abstract class AbstractGenerator { "http://jabber.org/protocol/caps", "http://jabber.org/protocol/disco#info", "urn:xmpp:avatar:metadata+notify", + "http://jabber.org/protocol/nick+notify", "urn:xmpp:ping", "jabber:iq:version", "http://jabber.org/protocol/chatstates", diff --git a/src/main/java/eu/siacs/conversations/generator/IqGenerator.java b/src/main/java/eu/siacs/conversations/generator/IqGenerator.java index 7457cad8..345f68ae 100644 --- a/src/main/java/eu/siacs/conversations/generator/IqGenerator.java +++ b/src/main/java/eu/siacs/conversations/generator/IqGenerator.java @@ -82,6 +82,12 @@ public class IqGenerator extends AbstractGenerator { return packet; } + public IqPacket publishNick(String nick) { + final Element item = new Element("item"); + item.addChild("nick","http://jabber.org/protocol/nick").setContent(nick); + return publish("http://jabber.org/protocol/nick", item); + } + public IqPacket publishAvatar(Avatar avatar) { final Element item = new Element("item"); item.setAttribute("id", avatar.sha1sum); diff --git a/src/main/java/eu/siacs/conversations/parser/MessageParser.java b/src/main/java/eu/siacs/conversations/parser/MessageParser.java index e39df085..05c23593 100644 --- a/src/main/java/eu/siacs/conversations/parser/MessageParser.java +++ b/src/main/java/eu/siacs/conversations/parser/MessageParser.java @@ -183,7 +183,7 @@ public class MessageParser extends AbstractParser implements } else if ("http://jabber.org/protocol/nick".equals(node)) { Element i = items.findChild("item"); Element nick = i == null ? null : i.findChild("nick", "http://jabber.org/protocol/nick"); - if (nick != null) { + if (nick != null && nick.getContent() != null) { Contact contact = account.getRoster().getContact(from); contact.setPresenceName(nick.getContent()); mXmppConnectionService.getAvatarService().clear(account); diff --git a/src/main/java/eu/siacs/conversations/persistance/DatabaseBackend.java b/src/main/java/eu/siacs/conversations/persistance/DatabaseBackend.java index 07071323..707237a1 100644 --- a/src/main/java/eu/siacs/conversations/persistance/DatabaseBackend.java +++ b/src/main/java/eu/siacs/conversations/persistance/DatabaseBackend.java @@ -43,7 +43,7 @@ public class DatabaseBackend extends SQLiteOpenHelper { private static DatabaseBackend instance = null; private static final String DATABASE_NAME = "history"; - private static final int DATABASE_VERSION = 18; + private static final int DATABASE_VERSION = 19; private static String CREATE_CONTATCS_STATEMENT = "create table " + Contact.TABLENAME + "(" + Contact.ACCOUNT + " TEXT, " @@ -121,6 +121,7 @@ public class DatabaseBackend extends SQLiteOpenHelper { db.execSQL("create table " + Account.TABLENAME + "(" + Account.UUID + " TEXT PRIMARY KEY," + Account.USERNAME + " TEXT," + Account.SERVER + " TEXT," + Account.PASSWORD + " TEXT," + + Account.DISPLAY_NAME + " TEXT, " + Account.ROSTERVERSION + " TEXT," + Account.OPTIONS + " NUMBER, " + Account.AVATAR + " TEXT, " + Account.KEYS + " TEXT)"); @@ -324,6 +325,9 @@ public class DatabaseBackend extends SQLiteOpenHelper { if (oldVersion < 18 && newVersion >= 18) { db.execSQL("ALTER TABLE " + Message.TABLENAME + " ADD COLUMN "+ Message.READ+ " NUMBER DEFAULT 1"); } + if (oldVersion < 19 && newVersion >= 19) { + db.execSQL("ALTER TABLE " + Account.TABLENAME + " ADD COLUMN "+ Account.DISPLAY_NAME+ " TEXT"); + } } public static synchronized DatabaseBackend getInstance(Context context) { diff --git a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java index cc8f4784..ba235a38 100644 --- a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java +++ b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java @@ -1331,6 +1331,7 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa Account account = new Account(info.first, ""); account.setPrivateKeyAlias(alias); account.setOption(Account.OPTION_DISABLED, true); + account.setDisplayName(info.second); createAccount(account); callback.onAccountCreated(account); if (Config.X509_VERIFICATION) { @@ -1359,6 +1360,7 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa Pair<Jid, String> info = CryptoHelper.extractJidAndName(chain[0]); if (account.getJid().toBareJid().equals(info.first)) { account.setPrivateKeyAlias(alias); + account.setDisplayName(info.second); databaseBackend.updateAccount(account); if (Config.X509_VERIFICATION) { try { @@ -2871,6 +2873,21 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa } } + public void publishDisplayName(Account account) { + String displayName = account.getDisplayName(); + if (displayName != null && !displayName.isEmpty()) { + IqPacket publish = mIqGenerator.publishNick(displayName); + sendIqPacket(account, publish, new OnIqPacketReceived() { + @Override + public void onIqPacketReceived(Account account, IqPacket packet) { + if (packet.getType() == IqPacket.TYPE.ERROR) { + Log.d(Config.LOGTAG,account.getJid().toBareJid()+": could not publish nick"); + } + } + }); + } + } + public interface OnAccountCreated { void onAccountCreated(Account account); |