Skip to content

Commit

Permalink
Update mention data during recipient merge.
Browse files Browse the repository at this point in the history
  • Loading branch information
cody-signal authored and greyson-signal committed Aug 14, 2020
1 parent 0250851 commit 761de13
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@

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";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2288,6 +2288,7 @@ private boolean update(@NonNull SqlUtil.UpdateQuery updateQuery, @NonNull Conten
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) {
Expand Down Expand Up @@ -2351,6 +2352,16 @@ private boolean update(@NonNull SqlUtil.UpdateQuery updateQuery, @NonNull Conten
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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -875,18 +875,18 @@ public boolean update(long threadId, boolean unarchive, boolean allowDeletion) {

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.");

ContentValues values = new ContentValues();
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.");

Expand Down Expand Up @@ -918,7 +918,7 @@ public boolean update(long threadId, boolean unarchive, boolean allowDeletion) {

RemappedRecords.getInstance().addThread(context, secondary.getThreadId(), primary.getThreadId());

return new MergeResult(primary.getThreadId(), true);
return new MergeResult(primary.getThreadId(), secondary.getThreadId(), true);
}
}

Expand Down Expand Up @@ -1280,11 +1280,13 @@ public long getLastScrolled() {

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

0 comments on commit 761de13

Please sign in to comment.