persist presence name (pep, nick in subscribe) to DB. fixes #3856
This commit is contained in:
parent
35af8894d2
commit
3dcb36a417
|
@ -33,6 +33,7 @@ public class Contact implements ListItem, Blockable {
|
||||||
|
|
||||||
public static final String SYSTEMNAME = "systemname";
|
public static final String SYSTEMNAME = "systemname";
|
||||||
public static final String SERVERNAME = "servername";
|
public static final String SERVERNAME = "servername";
|
||||||
|
public static final String PRESENCE_NAME = "presence_name";
|
||||||
public static final String JID = "jid";
|
public static final String JID = "jid";
|
||||||
public static final String OPTIONS = "options";
|
public static final String OPTIONS = "options";
|
||||||
public static final String SYSTEMACCOUNT = "systemaccount";
|
public static final String SYSTEMACCOUNT = "systemaccount";
|
||||||
|
@ -62,13 +63,14 @@ public class Contact implements ListItem, Blockable {
|
||||||
private long mLastseen = 0;
|
private long mLastseen = 0;
|
||||||
private String mLastPresence = null;
|
private String mLastPresence = null;
|
||||||
|
|
||||||
public Contact(final String account, final String systemName, final String serverName,
|
public Contact(final String account, final String systemName, final String serverName, final String presenceName,
|
||||||
final Jid jid, final int subscription, final String photoUri,
|
final Jid jid, final int subscription, final String photoUri,
|
||||||
final Uri systemAccount, final String keys, final String avatar, final long lastseen,
|
final Uri systemAccount, final String keys, final String avatar, final long lastseen,
|
||||||
final String presence, final String groups) {
|
final String presence, final String groups) {
|
||||||
this.accountUuid = account;
|
this.accountUuid = account;
|
||||||
this.systemName = systemName;
|
this.systemName = systemName;
|
||||||
this.serverName = serverName;
|
this.serverName = serverName;
|
||||||
|
this.presenceName = presenceName;
|
||||||
this.jid = jid;
|
this.jid = jid;
|
||||||
this.subscription = subscription;
|
this.subscription = subscription;
|
||||||
this.photoUri = photoUri;
|
this.photoUri = photoUri;
|
||||||
|
@ -116,6 +118,7 @@ public class Contact implements ListItem, Blockable {
|
||||||
return new Contact(cursor.getString(cursor.getColumnIndex(ACCOUNT)),
|
return new Contact(cursor.getString(cursor.getColumnIndex(ACCOUNT)),
|
||||||
cursor.getString(cursor.getColumnIndex(SYSTEMNAME)),
|
cursor.getString(cursor.getColumnIndex(SYSTEMNAME)),
|
||||||
cursor.getString(cursor.getColumnIndex(SERVERNAME)),
|
cursor.getString(cursor.getColumnIndex(SERVERNAME)),
|
||||||
|
cursor.getString(cursor.getColumnIndex(PRESENCE_NAME)),
|
||||||
jid,
|
jid,
|
||||||
cursor.getInt(cursor.getColumnIndex(OPTIONS)),
|
cursor.getInt(cursor.getColumnIndex(OPTIONS)),
|
||||||
cursor.getString(cursor.getColumnIndex(PHOTOURI)),
|
cursor.getString(cursor.getColumnIndex(PHOTOURI)),
|
||||||
|
@ -213,6 +216,7 @@ public class Contact implements ListItem, Blockable {
|
||||||
values.put(ACCOUNT, accountUuid);
|
values.put(ACCOUNT, accountUuid);
|
||||||
values.put(SYSTEMNAME, systemName);
|
values.put(SYSTEMNAME, systemName);
|
||||||
values.put(SERVERNAME, serverName);
|
values.put(SERVERNAME, serverName);
|
||||||
|
values.put(PRESENCE_NAME, presenceName);
|
||||||
values.put(JID, jid.toString());
|
values.put(JID, jid.toString());
|
||||||
values.put(OPTIONS, subscription);
|
values.put(OPTIONS, subscription);
|
||||||
values.put(SYSTEMACCOUNT, systemAccount != null ? systemAccount.toString() : null);
|
values.put(SYSTEMACCOUNT, systemAccount != null ? systemAccount.toString() : null);
|
||||||
|
@ -554,6 +558,10 @@ public class Contact implements ListItem, Blockable {
|
||||||
return UIHelper.getColorForName(jid != null ? jid.asBareJid().toString() : getDisplayName());
|
return UIHelper.getColorForName(jid != null ? jid.asBareJid().toString() : getDisplayName());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean hasAvatarOrPresenceName() {
|
||||||
|
return (avatar != null && avatar.getFilename() != null) || presenceName != null;
|
||||||
|
}
|
||||||
|
|
||||||
public final class Options {
|
public final class Options {
|
||||||
public static final int TO = 0;
|
public static final int TO = 0;
|
||||||
public static final int FROM = 1;
|
public static final int FROM = 1;
|
||||||
|
|
|
@ -300,6 +300,7 @@ public class MessageParser extends AbstractParser implements OnMessagePacketRece
|
||||||
} else {
|
} else {
|
||||||
Contact contact = account.getRoster().getContact(user);
|
Contact contact = account.getRoster().getContact(user);
|
||||||
if (contact.setPresenceName(nick)) {
|
if (contact.setPresenceName(nick)) {
|
||||||
|
mXmppConnectionService.syncRoster(account);
|
||||||
mXmppConnectionService.getAvatarService().clear(contact);
|
mXmppConnectionService.getAvatarService().clear(contact);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1011,8 +1012,9 @@ public class MessageParser extends AbstractParser implements OnMessagePacketRece
|
||||||
|
|
||||||
final String nick = packet.findChildContent("nick", Namespace.NICK);
|
final String nick = packet.findChildContent("nick", Namespace.NICK);
|
||||||
if (nick != null && InvalidJid.hasValidFrom(original)) {
|
if (nick != null && InvalidJid.hasValidFrom(original)) {
|
||||||
Contact contact = account.getRoster().getContact(from);
|
final Contact contact = account.getRoster().getContact(from);
|
||||||
if (contact.setPresenceName(nick)) {
|
if (contact.setPresenceName(nick)) {
|
||||||
|
mXmppConnectionService.syncRoster(account);
|
||||||
mXmppConnectionService.getAvatarService().clear(contact);
|
mXmppConnectionService.getAvatarService().clear(contact);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -337,6 +337,7 @@ public class PresenceParser extends AbstractParser implements
|
||||||
mXmppConnectionService.onContactStatusChanged.onContactStatusChanged(contact, false);
|
mXmppConnectionService.onContactStatusChanged.onContactStatusChanged(contact, false);
|
||||||
} else if (type.equals("subscribe")) {
|
} else if (type.equals("subscribe")) {
|
||||||
if (contact.setPresenceName(packet.findChildContent("nick", Namespace.NICK))) {
|
if (contact.setPresenceName(packet.findChildContent("nick", Namespace.NICK))) {
|
||||||
|
mXmppConnectionService.syncRoster(account);
|
||||||
mXmppConnectionService.getAvatarService().clear(contact);
|
mXmppConnectionService.getAvatarService().clear(contact);
|
||||||
}
|
}
|
||||||
if (contact.getOption(Contact.Options.PREEMPTIVE_GRANT)) {
|
if (contact.getOption(Contact.Options.PREEMPTIVE_GRANT)) {
|
||||||
|
|
|
@ -63,11 +63,12 @@ import eu.siacs.conversations.xmpp.Jid;
|
||||||
public class DatabaseBackend extends SQLiteOpenHelper {
|
public class DatabaseBackend extends SQLiteOpenHelper {
|
||||||
|
|
||||||
private static final String DATABASE_NAME = "history";
|
private static final String DATABASE_NAME = "history";
|
||||||
private static final int DATABASE_VERSION = 46;
|
private static final int DATABASE_VERSION = 47;
|
||||||
private static DatabaseBackend instance = null;
|
private static DatabaseBackend instance = null;
|
||||||
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, "
|
||||||
+ Contact.SERVERNAME + " TEXT, " + Contact.SYSTEMNAME + " TEXT,"
|
+ Contact.SERVERNAME + " TEXT, " + Contact.SYSTEMNAME + " TEXT,"
|
||||||
|
+ Contact.PRESENCE_NAME + " TEXT,"
|
||||||
+ Contact.JID + " TEXT," + Contact.KEYS + " TEXT,"
|
+ Contact.JID + " TEXT," + Contact.KEYS + " TEXT,"
|
||||||
+ Contact.PHOTOURI + " TEXT," + Contact.OPTIONS + " NUMBER,"
|
+ Contact.PHOTOURI + " TEXT," + Contact.OPTIONS + " NUMBER,"
|
||||||
+ Contact.SYSTEMACCOUNT + " NUMBER, " + Contact.AVATAR + " TEXT, "
|
+ Contact.SYSTEMACCOUNT + " NUMBER, " + Contact.AVATAR + " TEXT, "
|
||||||
|
@ -555,6 +556,9 @@ public class DatabaseBackend extends SQLiteOpenHelper {
|
||||||
final long diff = SystemClock.elapsedRealtime() - start;
|
final long diff = SystemClock.elapsedRealtime() - start;
|
||||||
Log.d(Config.LOGTAG,"deleted old edit information in "+diff+"ms");
|
Log.d(Config.LOGTAG,"deleted old edit information in "+diff+"ms");
|
||||||
}
|
}
|
||||||
|
if (oldVersion < 47 && newVersion >= 47) {
|
||||||
|
db.execSQL("ALTER TABLE " + Contact.TABLENAME + " ADD COLUMN " + Contact.PRESENCE_NAME + " TEXT");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void canonicalizeJids(SQLiteDatabase db) {
|
private void canonicalizeJids(SQLiteDatabase db) {
|
||||||
|
@ -573,7 +577,7 @@ public class DatabaseBackend extends SQLiteOpenHelper {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
String updateArgs[] = {
|
final String[] updateArgs = {
|
||||||
newJid,
|
newJid,
|
||||||
cursor.getString(cursor.getColumnIndex(Conversation.UUID)),
|
cursor.getString(cursor.getColumnIndex(Conversation.UUID)),
|
||||||
};
|
};
|
||||||
|
@ -1011,7 +1015,7 @@ public class DatabaseBackend extends SQLiteOpenHelper {
|
||||||
final SQLiteDatabase db = this.getWritableDatabase();
|
final SQLiteDatabase db = this.getWritableDatabase();
|
||||||
db.beginTransaction();
|
db.beginTransaction();
|
||||||
for (Contact contact : roster.getContacts()) {
|
for (Contact contact : roster.getContacts()) {
|
||||||
if (contact.getOption(Contact.Options.IN_ROSTER) || contact.getAvatarFilename() != null || contact.getOption(Contact.Options.SYNCED_VIA_OTHER)) {
|
if (contact.getOption(Contact.Options.IN_ROSTER) || contact.hasAvatarOrPresenceName() || contact.getOption(Contact.Options.SYNCED_VIA_OTHER)) {
|
||||||
db.insert(Contact.TABLENAME, null, contact.getContentValues());
|
db.insert(Contact.TABLENAME, null, contact.getContentValues());
|
||||||
} else {
|
} else {
|
||||||
String where = Contact.ACCOUNT + "=? AND " + Contact.JID + "=?";
|
String where = Contact.ACCOUNT + "=? AND " + Contact.JID + "=?";
|
||||||
|
|
Loading…
Reference in a new issue