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 SERVERNAME = "servername";
|
||||
public static final String PRESENCE_NAME = "presence_name";
|
||||
public static final String JID = "jid";
|
||||
public static final String OPTIONS = "options";
|
||||
public static final String SYSTEMACCOUNT = "systemaccount";
|
||||
|
@ -62,13 +63,14 @@ public class Contact implements ListItem, Blockable {
|
|||
private long mLastseen = 0;
|
||||
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 Uri systemAccount, final String keys, final String avatar, final long lastseen,
|
||||
final String presence, final String groups) {
|
||||
this.accountUuid = account;
|
||||
this.systemName = systemName;
|
||||
this.serverName = serverName;
|
||||
this.presenceName = presenceName;
|
||||
this.jid = jid;
|
||||
this.subscription = subscription;
|
||||
this.photoUri = photoUri;
|
||||
|
@ -116,6 +118,7 @@ public class Contact implements ListItem, Blockable {
|
|||
return new Contact(cursor.getString(cursor.getColumnIndex(ACCOUNT)),
|
||||
cursor.getString(cursor.getColumnIndex(SYSTEMNAME)),
|
||||
cursor.getString(cursor.getColumnIndex(SERVERNAME)),
|
||||
cursor.getString(cursor.getColumnIndex(PRESENCE_NAME)),
|
||||
jid,
|
||||
cursor.getInt(cursor.getColumnIndex(OPTIONS)),
|
||||
cursor.getString(cursor.getColumnIndex(PHOTOURI)),
|
||||
|
@ -213,6 +216,7 @@ public class Contact implements ListItem, Blockable {
|
|||
values.put(ACCOUNT, accountUuid);
|
||||
values.put(SYSTEMNAME, systemName);
|
||||
values.put(SERVERNAME, serverName);
|
||||
values.put(PRESENCE_NAME, presenceName);
|
||||
values.put(JID, jid.toString());
|
||||
values.put(OPTIONS, subscription);
|
||||
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());
|
||||
}
|
||||
|
||||
public boolean hasAvatarOrPresenceName() {
|
||||
return (avatar != null && avatar.getFilename() != null) || presenceName != null;
|
||||
}
|
||||
|
||||
public final class Options {
|
||||
public static final int TO = 0;
|
||||
public static final int FROM = 1;
|
||||
|
|
|
@ -300,6 +300,7 @@ public class MessageParser extends AbstractParser implements OnMessagePacketRece
|
|||
} else {
|
||||
Contact contact = account.getRoster().getContact(user);
|
||||
if (contact.setPresenceName(nick)) {
|
||||
mXmppConnectionService.syncRoster(account);
|
||||
mXmppConnectionService.getAvatarService().clear(contact);
|
||||
}
|
||||
}
|
||||
|
@ -1011,8 +1012,9 @@ public class MessageParser extends AbstractParser implements OnMessagePacketRece
|
|||
|
||||
final String nick = packet.findChildContent("nick", Namespace.NICK);
|
||||
if (nick != null && InvalidJid.hasValidFrom(original)) {
|
||||
Contact contact = account.getRoster().getContact(from);
|
||||
final Contact contact = account.getRoster().getContact(from);
|
||||
if (contact.setPresenceName(nick)) {
|
||||
mXmppConnectionService.syncRoster(account);
|
||||
mXmppConnectionService.getAvatarService().clear(contact);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -337,6 +337,7 @@ 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.syncRoster(account);
|
||||
mXmppConnectionService.getAvatarService().clear(contact);
|
||||
}
|
||||
if (contact.getOption(Contact.Options.PREEMPTIVE_GRANT)) {
|
||||
|
|
|
@ -63,11 +63,12 @@ import eu.siacs.conversations.xmpp.Jid;
|
|||
public class DatabaseBackend extends SQLiteOpenHelper {
|
||||
|
||||
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 String CREATE_CONTATCS_STATEMENT = "create table "
|
||||
+ Contact.TABLENAME + "(" + Contact.ACCOUNT + " TEXT, "
|
||||
+ Contact.SERVERNAME + " TEXT, " + Contact.SYSTEMNAME + " TEXT,"
|
||||
+ Contact.PRESENCE_NAME + " TEXT,"
|
||||
+ Contact.JID + " TEXT," + Contact.KEYS + " TEXT,"
|
||||
+ Contact.PHOTOURI + " TEXT," + Contact.OPTIONS + " NUMBER,"
|
||||
+ Contact.SYSTEMACCOUNT + " NUMBER, " + Contact.AVATAR + " TEXT, "
|
||||
|
@ -555,6 +556,9 @@ public class DatabaseBackend extends SQLiteOpenHelper {
|
|||
final long diff = SystemClock.elapsedRealtime() - start;
|
||||
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) {
|
||||
|
@ -573,7 +577,7 @@ public class DatabaseBackend extends SQLiteOpenHelper {
|
|||
continue;
|
||||
}
|
||||
|
||||
String updateArgs[] = {
|
||||
final String[] updateArgs = {
|
||||
newJid,
|
||||
cursor.getString(cursor.getColumnIndex(Conversation.UUID)),
|
||||
};
|
||||
|
@ -1011,7 +1015,7 @@ public class DatabaseBackend extends SQLiteOpenHelper {
|
|||
final SQLiteDatabase db = this.getWritableDatabase();
|
||||
db.beginTransaction();
|
||||
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());
|
||||
} else {
|
||||
String where = Contact.ACCOUNT + "=? AND " + Contact.JID + "=?";
|
||||
|
|
Loading…
Reference in New Issue