push CN into nick pep node when uploading certificate. subscribe to nick node
This commit is contained in:
		
							parent
							
								
									7410e2023a
								
							
						
					
					
						commit
						c7ff196f58
					
				|  | @ -515,6 +515,7 @@ public class AxolotlService implements OnAdvancedStreamFeaturesLoaded { | ||||||
| 
 | 
 | ||||||
| 					if (changed) { | 					if (changed) { | ||||||
| 						if (account.getPrivateKeyAlias() != null && Config.X509_VERIFICATION) { | 						if (account.getPrivateKeyAlias() != null && Config.X509_VERIFICATION) { | ||||||
|  | 							mXmppConnectionService.publishDisplayName(account); | ||||||
| 							publishDeviceVerificationAndBundle(signedPreKeyRecord, preKeyRecords, announce, wipe); | 							publishDeviceVerificationAndBundle(signedPreKeyRecord, preKeyRecords, announce, wipe); | ||||||
| 						} else { | 						} else { | ||||||
| 							publishDeviceBundle(signedPreKeyRecord, preKeyRecords, announce, wipe); | 							publishDeviceBundle(signedPreKeyRecord, preKeyRecords, announce, wipe); | ||||||
|  |  | ||||||
|  | @ -37,6 +37,7 @@ public class Account extends AbstractEntity { | ||||||
| 	public static final String ROSTERVERSION = "rosterversion"; | 	public static final String ROSTERVERSION = "rosterversion"; | ||||||
| 	public static final String KEYS = "keys"; | 	public static final String KEYS = "keys"; | ||||||
| 	public static final String AVATAR = "avatar"; | 	public static final String AVATAR = "avatar"; | ||||||
|  | 	public static final String DISPLAY_NAME = "display_name"; | ||||||
| 
 | 
 | ||||||
| 	public static final String PINNED_MECHANISM_KEY = "pinned_mechanism"; | 	public static final String PINNED_MECHANISM_KEY = "pinned_mechanism"; | ||||||
| 
 | 
 | ||||||
|  | @ -49,6 +50,14 @@ public class Account extends AbstractEntity { | ||||||
| 		return xmppConnection != null && xmppConnection.getFeatures().httpUpload(); | 		return xmppConnection != null && xmppConnection.getFeatures().httpUpload(); | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
|  | 	public void setDisplayName(String displayName) { | ||||||
|  | 		this.displayName = displayName; | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
|  | 	public String getDisplayName() { | ||||||
|  | 		return displayName; | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
| 	public static enum State { | 	public static enum State { | ||||||
| 		DISABLED, | 		DISABLED, | ||||||
| 		OFFLINE, | 		OFFLINE, | ||||||
|  | @ -124,6 +133,7 @@ public class Account extends AbstractEntity { | ||||||
| 	protected State status = State.OFFLINE; | 	protected State status = State.OFFLINE; | ||||||
| 	protected JSONObject keys = new JSONObject(); | 	protected JSONObject keys = new JSONObject(); | ||||||
| 	protected String avatar; | 	protected String avatar; | ||||||
|  | 	protected String displayName = null; | ||||||
| 	protected boolean online = false; | 	protected boolean online = false; | ||||||
| 	private OtrService mOtrService = null; | 	private OtrService mOtrService = null; | ||||||
| 	private AxolotlService axolotlService = null; | 	private AxolotlService axolotlService = null; | ||||||
|  | @ -140,12 +150,12 @@ public class Account extends AbstractEntity { | ||||||
| 
 | 
 | ||||||
| 	public Account(final Jid jid, final String password) { | 	public Account(final Jid jid, final String password) { | ||||||
| 		this(java.util.UUID.randomUUID().toString(), jid, | 		this(java.util.UUID.randomUUID().toString(), jid, | ||||||
| 				password, 0, null, "", null); | 				password, 0, null, "", null, null); | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	public Account(final String uuid, final Jid jid, | 	public Account(final String uuid, final Jid jid, | ||||||
| 			final String password, final int options, final String rosterVersion, final String keys, | 			final String password, final int options, final String rosterVersion, final String keys, | ||||||
| 			final String avatar) { | 			final String avatar, String displayName) { | ||||||
| 		this.uuid = uuid; | 		this.uuid = uuid; | ||||||
| 		this.jid = jid; | 		this.jid = jid; | ||||||
| 		if (jid.isBareJid()) { | 		if (jid.isBareJid()) { | ||||||
|  | @ -160,6 +170,7 @@ public class Account extends AbstractEntity { | ||||||
| 			this.keys = new JSONObject(); | 			this.keys = new JSONObject(); | ||||||
| 		} | 		} | ||||||
| 		this.avatar = avatar; | 		this.avatar = avatar; | ||||||
|  | 		this.displayName = displayName; | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	public static Account fromCursor(final Cursor cursor) { | 	public static Account fromCursor(final Cursor cursor) { | ||||||
|  | @ -175,7 +186,8 @@ public class Account extends AbstractEntity { | ||||||
| 				cursor.getInt(cursor.getColumnIndex(OPTIONS)), | 				cursor.getInt(cursor.getColumnIndex(OPTIONS)), | ||||||
| 				cursor.getString(cursor.getColumnIndex(ROSTERVERSION)), | 				cursor.getString(cursor.getColumnIndex(ROSTERVERSION)), | ||||||
| 				cursor.getString(cursor.getColumnIndex(KEYS)), | 				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) { | 	public boolean isOptionSet(final int option) { | ||||||
|  | @ -287,6 +299,7 @@ public class Account extends AbstractEntity { | ||||||
| 		values.put(KEYS, this.keys.toString()); | 		values.put(KEYS, this.keys.toString()); | ||||||
| 		values.put(ROSTERVERSION, rosterVersion); | 		values.put(ROSTERVERSION, rosterVersion); | ||||||
| 		values.put(AVATAR, avatar); | 		values.put(AVATAR, avatar); | ||||||
|  | 		values.put(DISPLAY_NAME, displayName); | ||||||
| 		return values; | 		return values; | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -27,6 +27,7 @@ public abstract class AbstractGenerator { | ||||||
| 			"http://jabber.org/protocol/caps", | 			"http://jabber.org/protocol/caps", | ||||||
| 			"http://jabber.org/protocol/disco#info", | 			"http://jabber.org/protocol/disco#info", | ||||||
| 			"urn:xmpp:avatar:metadata+notify", | 			"urn:xmpp:avatar:metadata+notify", | ||||||
|  | 			"http://jabber.org/protocol/nick+notify", | ||||||
| 			"urn:xmpp:ping", | 			"urn:xmpp:ping", | ||||||
| 			"jabber:iq:version", | 			"jabber:iq:version", | ||||||
| 			"http://jabber.org/protocol/chatstates", | 			"http://jabber.org/protocol/chatstates", | ||||||
|  |  | ||||||
|  | @ -82,6 +82,12 @@ public class IqGenerator extends AbstractGenerator { | ||||||
| 		return packet; | 		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) { | 	public IqPacket publishAvatar(Avatar avatar) { | ||||||
| 		final Element item = new Element("item"); | 		final Element item = new Element("item"); | ||||||
| 		item.setAttribute("id", avatar.sha1sum); | 		item.setAttribute("id", avatar.sha1sum); | ||||||
|  |  | ||||||
|  | @ -183,7 +183,7 @@ public class MessageParser extends AbstractParser implements | ||||||
| 		} else if ("http://jabber.org/protocol/nick".equals(node)) { | 		} else if ("http://jabber.org/protocol/nick".equals(node)) { | ||||||
| 			Element i = items.findChild("item"); | 			Element i = items.findChild("item"); | ||||||
| 			Element nick = i == null ? null : i.findChild("nick", "http://jabber.org/protocol/nick"); | 			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 contact = account.getRoster().getContact(from); | ||||||
| 				contact.setPresenceName(nick.getContent()); | 				contact.setPresenceName(nick.getContent()); | ||||||
| 				mXmppConnectionService.getAvatarService().clear(account); | 				mXmppConnectionService.getAvatarService().clear(account); | ||||||
|  |  | ||||||
|  | @ -43,7 +43,7 @@ public class DatabaseBackend extends SQLiteOpenHelper { | ||||||
| 	private static DatabaseBackend instance = null; | 	private static DatabaseBackend instance = null; | ||||||
| 
 | 
 | ||||||
| 	private static final String DATABASE_NAME = "history"; | 	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 " | 	private static String CREATE_CONTATCS_STATEMENT = "create table " | ||||||
| 			+ Contact.TABLENAME + "(" + Contact.ACCOUNT + " TEXT, " | 			+ Contact.TABLENAME + "(" + Contact.ACCOUNT + " TEXT, " | ||||||
|  | @ -121,6 +121,7 @@ public class DatabaseBackend extends SQLiteOpenHelper { | ||||||
| 		db.execSQL("create table " + Account.TABLENAME + "(" + Account.UUID | 		db.execSQL("create table " + Account.TABLENAME + "(" + Account.UUID | ||||||
| 				+ " TEXT PRIMARY KEY," + Account.USERNAME + " TEXT," | 				+ " TEXT PRIMARY KEY," + Account.USERNAME + " TEXT," | ||||||
| 				+ Account.SERVER + " TEXT," + Account.PASSWORD + " TEXT," | 				+ Account.SERVER + " TEXT," + Account.PASSWORD + " TEXT," | ||||||
|  | 				+ Account.DISPLAY_NAME + " TEXT, " | ||||||
| 				+ Account.ROSTERVERSION + " TEXT," + Account.OPTIONS | 				+ Account.ROSTERVERSION + " TEXT," + Account.OPTIONS | ||||||
| 				+ " NUMBER, " + Account.AVATAR + " TEXT, " + Account.KEYS | 				+ " NUMBER, " + Account.AVATAR + " TEXT, " + Account.KEYS | ||||||
| 				+ " TEXT)"); | 				+ " TEXT)"); | ||||||
|  | @ -324,6 +325,9 @@ public class DatabaseBackend extends SQLiteOpenHelper { | ||||||
| 		if (oldVersion < 18 && newVersion >= 18) { | 		if (oldVersion < 18 && newVersion >= 18) { | ||||||
| 			db.execSQL("ALTER TABLE " + Message.TABLENAME + " ADD COLUMN "+ Message.READ+ " NUMBER DEFAULT 1"); | 			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) { | 	public static synchronized DatabaseBackend getInstance(Context context) { | ||||||
|  |  | ||||||
|  | @ -1331,6 +1331,7 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa | ||||||
| 						Account account = new Account(info.first, ""); | 						Account account = new Account(info.first, ""); | ||||||
| 						account.setPrivateKeyAlias(alias); | 						account.setPrivateKeyAlias(alias); | ||||||
| 						account.setOption(Account.OPTION_DISABLED, true); | 						account.setOption(Account.OPTION_DISABLED, true); | ||||||
|  | 						account.setDisplayName(info.second); | ||||||
| 						createAccount(account); | 						createAccount(account); | ||||||
| 						callback.onAccountCreated(account); | 						callback.onAccountCreated(account); | ||||||
| 						if (Config.X509_VERIFICATION) { | 						if (Config.X509_VERIFICATION) { | ||||||
|  | @ -1359,6 +1360,7 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa | ||||||
| 			Pair<Jid, String> info = CryptoHelper.extractJidAndName(chain[0]); | 			Pair<Jid, String> info = CryptoHelper.extractJidAndName(chain[0]); | ||||||
| 			if (account.getJid().toBareJid().equals(info.first)) { | 			if (account.getJid().toBareJid().equals(info.first)) { | ||||||
| 				account.setPrivateKeyAlias(alias); | 				account.setPrivateKeyAlias(alias); | ||||||
|  | 				account.setDisplayName(info.second); | ||||||
| 				databaseBackend.updateAccount(account); | 				databaseBackend.updateAccount(account); | ||||||
| 				if (Config.X509_VERIFICATION) { | 				if (Config.X509_VERIFICATION) { | ||||||
| 					try { | 					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 { | 	public interface OnAccountCreated { | ||||||
| 		void onAccountCreated(Account account); | 		void onAccountCreated(Account account); | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue
	
	 Daniel Gultsch
						Daniel Gultsch