Update mention data during recipient merge.
This commit is contained in:
parent
02508512d5
commit
761de1318e
3 changed files with 23 additions and 10 deletions
|
@ -26,12 +26,12 @@ import java.util.Map;
|
|||
|
||||
public class MentionDatabase extends Database {
|
||||
|
||||
private static final String TABLE_NAME = "mention";
|
||||
static final String TABLE_NAME = "mention";
|
||||
|
||||
private static final String ID = "_id";
|
||||
private static final String THREAD_ID = "thread_id";
|
||||
static final String THREAD_ID = "thread_id";
|
||||
private static final String MESSAGE_ID = "message_id";
|
||||
private static final String RECIPIENT_ID = "recipient_id";
|
||||
static final String RECIPIENT_ID = "recipient_id";
|
||||
private static final String RANGE_START = "range_start";
|
||||
private static final String RANGE_LENGTH = "range_length";
|
||||
|
||||
|
|
|
@ -2288,6 +2288,7 @@ public class RecipientDatabase extends Database {
|
|||
uuidValues.put(SYSTEM_CONTACT_URI, e164Settings.getSystemContactUri());
|
||||
uuidValues.put(PROFILE_SHARING, uuidSettings.isProfileSharing() || e164Settings.isProfileSharing());
|
||||
uuidValues.put(GROUPS_V2_CAPABILITY, uuidSettings.getGroupsV2Capability() != Recipient.Capability.UNKNOWN ? uuidSettings.getGroupsV2Capability().serialize() : e164Settings.getGroupsV2Capability().serialize());
|
||||
uuidValues.put(MENTION_SETTING, uuidSettings.getMentionSetting() != MentionSetting.GLOBAL ? uuidSettings.getMentionSetting().getId() : e164Settings.getMentionSetting().getId());
|
||||
if (uuidSettings.getProfileKey() != null) {
|
||||
updateProfileValuesForMerge(uuidValues, uuidSettings);
|
||||
} else if (e164Settings.getProfileKey() != null) {
|
||||
|
@ -2351,6 +2352,16 @@ public class RecipientDatabase extends Database {
|
|||
Log.w(TAG, "Had no sessions. No action necessary.");
|
||||
}
|
||||
|
||||
// Mentions
|
||||
ContentValues mentionRecipientValues = new ContentValues();
|
||||
mentionRecipientValues.put(MentionDatabase.RECIPIENT_ID, byUuid.serialize());
|
||||
db.update(MentionDatabase.TABLE_NAME, mentionRecipientValues, MentionDatabase.RECIPIENT_ID + " = ?", SqlUtil.buildArgs(byE164));
|
||||
if (threadMerge.neededMerge) {
|
||||
ContentValues mentionThreadValues = new ContentValues();
|
||||
mentionThreadValues.put(MentionDatabase.THREAD_ID, threadMerge.threadId);
|
||||
db.update(MentionDatabase.TABLE_NAME, mentionThreadValues, MentionDatabase.THREAD_ID + " = ?", SqlUtil.buildArgs(threadMerge.previousThreadId));
|
||||
}
|
||||
|
||||
DatabaseFactory.getThreadDatabase(context).update(threadMerge.threadId, false, false);
|
||||
|
||||
return byUuid;
|
||||
|
|
|
@ -875,7 +875,7 @@ public class ThreadDatabase extends Database {
|
|||
|
||||
if (primary != null && secondary == null) {
|
||||
Log.w(TAG, "[merge] Only had a thread for primary. Returning that.");
|
||||
return new MergeResult(primary.getThreadId(), false);
|
||||
return new MergeResult(primary.getThreadId(), -1, false);
|
||||
} else if (primary == null && secondary != null) {
|
||||
Log.w(TAG, "[merge] Only had a thread for secondary. Updating it to have the recipientId of the primary.");
|
||||
|
||||
|
@ -883,10 +883,10 @@ public class ThreadDatabase extends Database {
|
|||
values.put(RECIPIENT_ID, primaryRecipientId.serialize());
|
||||
|
||||
databaseHelper.getWritableDatabase().update(TABLE_NAME, values, ID_WHERE, SqlUtil.buildArgs(secondary.getThreadId()));
|
||||
return new MergeResult(secondary.getThreadId(), false);
|
||||
return new MergeResult(secondary.getThreadId(), -1, false);
|
||||
} else if (primary == null && secondary == null) {
|
||||
Log.w(TAG, "[merge] No thread for either.");
|
||||
return new MergeResult(-1, false);
|
||||
return new MergeResult(-1, -1, false);
|
||||
} else {
|
||||
Log.w(TAG, "[merge] Had a thread for both. Deleting the secondary and merging the attributes together.");
|
||||
|
||||
|
@ -918,7 +918,7 @@ public class ThreadDatabase extends Database {
|
|||
|
||||
RemappedRecords.getInstance().addThread(context, secondary.getThreadId(), primary.getThreadId());
|
||||
|
||||
return new MergeResult(primary.getThreadId(), true);
|
||||
return new MergeResult(primary.getThreadId(), secondary.getThreadId(), true);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1280,11 +1280,13 @@ public class ThreadDatabase extends Database {
|
|||
|
||||
static final class MergeResult {
|
||||
final long threadId;
|
||||
final long previousThreadId;
|
||||
final boolean neededMerge;
|
||||
|
||||
private MergeResult(long threadId, boolean neededMerge) {
|
||||
this.threadId = threadId;
|
||||
this.neededMerge = neededMerge;
|
||||
private MergeResult(long threadId, long previousThreadId, boolean neededMerge) {
|
||||
this.threadId = threadId;
|
||||
this.previousThreadId = previousThreadId;
|
||||
this.neededMerge = neededMerge;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue