push CN into nick pep node when uploading certificate. subscribe to nick node

This commit is contained in:
Daniel Gultsch 2015-10-29 13:41:08 +01:00
parent 7410e2023a
commit c7ff196f58
7 changed files with 47 additions and 5 deletions

View File

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

View File

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

View File

@ -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",

View File

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

View File

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

View File

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

View File

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