mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-04-22 18:00:02 +01:00
NotificationThread migration.
This commit is contained in:
@@ -21,6 +21,7 @@ import org.thoughtcrime.securesms.database.documents.IdentityKeyMismatchSet;
|
||||
import org.thoughtcrime.securesms.database.documents.NetworkFailure;
|
||||
import org.thoughtcrime.securesms.database.model.MessageId;
|
||||
import org.thoughtcrime.securesms.database.model.MessageRecord;
|
||||
import org.thoughtcrime.securesms.database.model.ParentStoryId;
|
||||
import org.thoughtcrime.securesms.database.model.SmsMessageRecord;
|
||||
import org.thoughtcrime.securesms.database.model.StoryResult;
|
||||
import org.thoughtcrime.securesms.database.model.StoryViewState;
|
||||
@@ -200,6 +201,7 @@ public abstract class MessageDatabase extends Database implements MmsSmsColumns
|
||||
public abstract @Nullable Long getOldestStorySendTimestamp();
|
||||
public abstract int deleteStoriesOlderThan(long timestamp);
|
||||
public abstract @NonNull MessageDatabase.Reader getUnreadStories(@NonNull RecipientId recipientId, int limit);
|
||||
public abstract @Nullable ParentStoryId.GroupReply getParentStoryIdForGroupReply(long messageId);
|
||||
|
||||
public abstract @NonNull StoryViewState getStoryViewState(@NonNull RecipientId recipientId);
|
||||
public abstract void updateViewedStories(@NonNull Set<SyncMessageId> syncMessageIds);
|
||||
|
||||
@@ -614,6 +614,25 @@ public class MmsDatabase extends MessageDatabase {
|
||||
return new Reader(rawQuery(query, args, false, limit));
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable ParentStoryId.GroupReply getParentStoryIdForGroupReply(long messageId) {
|
||||
String[] projection = SqlUtil.buildArgs(PARENT_STORY_ID);
|
||||
String[] args = SqlUtil.buildArgs(messageId);
|
||||
|
||||
try (Cursor cursor = getReadableDatabase().query(TABLE_NAME, projection, ID_WHERE, args, null, null, null)) {
|
||||
if (cursor != null && cursor.moveToFirst()) {
|
||||
ParentStoryId parentStoryId = ParentStoryId.deserialize(CursorUtil.requireLong(cursor, PARENT_STORY_ID));
|
||||
if (parentStoryId != null && parentStoryId.isGroupReply()) {
|
||||
return (ParentStoryId.GroupReply) parentStoryId;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NonNull StoryViewState getStoryViewState(@NonNull RecipientId recipientId) {
|
||||
if (!Stories.isFeatureEnabled()) {
|
||||
|
||||
@@ -259,20 +259,29 @@ public class MmsSmsDatabase extends Database {
|
||||
}
|
||||
stickyQuery.append("(")
|
||||
.append(MmsSmsColumns.THREAD_ID + " = ")
|
||||
.append(stickyThread.getThreadId())
|
||||
.append(stickyThread.getNotificationThread().getThreadId())
|
||||
.append(" AND ")
|
||||
.append(MmsSmsColumns.NORMALIZED_DATE_RECEIVED)
|
||||
.append(" >= ")
|
||||
.append(stickyThread.getEarliestTimestamp())
|
||||
.append(getStickyWherePartForParentStoryId(stickyThread.getNotificationThread().getGroupStoryId()))
|
||||
.append(")");
|
||||
}
|
||||
|
||||
String order = MmsSmsColumns.NORMALIZED_DATE_RECEIVED + " ASC";
|
||||
String selection = MmsSmsColumns.NOTIFIED + " = 0 AND " + MmsDatabase.STORY_TYPE + " = 0 AND " + MmsDatabase.PARENT_STORY_ID + " <= 0 AND (" + MmsSmsColumns.READ + " = 0 OR " + MmsSmsColumns.REACTIONS_UNREAD + " = 1" + (stickyQuery.length() > 0 ? " OR (" + stickyQuery.toString() + ")" : "") + ")";
|
||||
String selection = MmsSmsColumns.NOTIFIED + " = 0 AND " + MmsDatabase.STORY_TYPE + " = 0 AND (" + MmsSmsColumns.READ + " = 0 OR " + MmsSmsColumns.REACTIONS_UNREAD + " = 1" + (stickyQuery.length() > 0 ? " OR (" + stickyQuery + ")" : "") + ")";
|
||||
|
||||
return queryTables(PROJECTION, selection, order, null, true);
|
||||
}
|
||||
|
||||
private @NonNull String getStickyWherePartForParentStoryId(@Nullable Long parentStoryId) {
|
||||
if (parentStoryId == null) {
|
||||
return " AND " + MmsDatabase.PARENT_STORY_ID + " <= 0";
|
||||
}
|
||||
|
||||
return " AND " + MmsDatabase.PARENT_STORY_ID + " = " + parentStoryId;
|
||||
}
|
||||
|
||||
public int getUnreadCount(long threadId) {
|
||||
String selection = MmsSmsColumns.READ + " = 0 AND " + MmsDatabase.STORY_TYPE + " = 0 AND " + MmsSmsColumns.THREAD_ID + " = " + threadId + " AND " + MmsDatabase.PARENT_STORY_ID + " <= 0";
|
||||
|
||||
|
||||
@@ -42,6 +42,7 @@ import org.thoughtcrime.securesms.database.documents.NetworkFailure;
|
||||
import org.thoughtcrime.securesms.database.model.GroupCallUpdateDetailsUtil;
|
||||
import org.thoughtcrime.securesms.database.model.MessageId;
|
||||
import org.thoughtcrime.securesms.database.model.MessageRecord;
|
||||
import org.thoughtcrime.securesms.database.model.ParentStoryId;
|
||||
import org.thoughtcrime.securesms.database.model.SmsMessageRecord;
|
||||
import org.thoughtcrime.securesms.database.model.StoryResult;
|
||||
import org.thoughtcrime.securesms.database.model.StoryViewState;
|
||||
@@ -1471,6 +1472,11 @@ public class SmsDatabase extends MessageDatabase {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable ParentStoryId.GroupReply getParentStoryIdForGroupReply(long messageId) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public MessageRecord getMessageRecord(long messageId) throws NoSuchMessageException {
|
||||
return getSmsMessage(messageId);
|
||||
|
||||
@@ -197,8 +197,9 @@ object SignalDatabaseMigrations {
|
||||
private const val GROUP_SERVICE_ID = 141
|
||||
private const val QUOTE_TYPE = 142
|
||||
private const val STORY_SYNCS = 143
|
||||
private const val GROUP_STORY_NOTIFICATIONS = 144
|
||||
|
||||
const val DATABASE_VERSION = 143
|
||||
const val DATABASE_VERSION = 144
|
||||
|
||||
@JvmStatic
|
||||
fun migrate(context: Application, db: SQLiteDatabase, oldVersion: Int, newVersion: Int) {
|
||||
@@ -2567,6 +2568,10 @@ object SignalDatabaseMigrations {
|
||||
db.execSQL("ALTER TABLE story_sends_tmp RENAME TO story_sends")
|
||||
db.execSQL("CREATE INDEX story_sends_recipient_id_sent_timestamp_allows_replies_index ON story_sends (recipient_id, sent_timestamp, allows_replies)")
|
||||
}
|
||||
|
||||
if (oldVersion < GROUP_STORY_NOTIFICATIONS) {
|
||||
db.execSQL("UPDATE mms SET read = 1 WHERE parent_story_id > 0")
|
||||
}
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
|
||||
Reference in New Issue
Block a user