Respond to CR.
This commit is contained in:
parent
91dab4e9cd
commit
5c5deae922
@ -75,7 +75,7 @@ class ThreadFinderPerformanceTest: PerformanceBaseTest {
|
||||
// Note that we enumerate _twice_ (archived & non-archived)
|
||||
let readCount = 10
|
||||
|
||||
write { transaction in
|
||||
read { transaction in
|
||||
self.startMeasuring()
|
||||
for _ in 0..<readCount {
|
||||
var observedCount = 0
|
||||
|
||||
@ -33,7 +33,7 @@ public struct ThreadRecord: SDSRecord {
|
||||
public let creationDate: Double?
|
||||
public let isArchived: Bool
|
||||
public let isArchivedByLegacyTimestampForSorting: Bool
|
||||
public let lastInteractionSortId: Int64
|
||||
public let lastInteractionRowId: Int64
|
||||
public let lastMessageDate: Double?
|
||||
public let messageDraft: String?
|
||||
public let mutedUntilDate: Double?
|
||||
@ -55,7 +55,7 @@ public struct ThreadRecord: SDSRecord {
|
||||
case creationDate
|
||||
case isArchived
|
||||
case isArchivedByLegacyTimestampForSorting
|
||||
case lastInteractionSortId
|
||||
case lastInteractionRowId
|
||||
case lastMessageDate
|
||||
case messageDraft
|
||||
case mutedUntilDate
|
||||
@ -96,7 +96,7 @@ public extension ThreadRecord {
|
||||
creationDate = row[5]
|
||||
isArchived = row[6]
|
||||
isArchivedByLegacyTimestampForSorting = row[7]
|
||||
lastInteractionSortId = row[8]
|
||||
lastInteractionRowId = row[8]
|
||||
lastMessageDate = row[9]
|
||||
messageDraft = row[10]
|
||||
mutedUntilDate = row[11]
|
||||
@ -144,7 +144,7 @@ extension TSThread {
|
||||
let creationDate: Date? = SDSDeserialization.optionalDoubleAsDate(creationDateInterval, name: "creationDate")
|
||||
let isArchived: Bool = record.isArchived
|
||||
let isArchivedByLegacyTimestampForSorting: Bool = record.isArchivedByLegacyTimestampForSorting
|
||||
let lastInteractionSortId: Int64 = record.lastInteractionSortId
|
||||
let lastInteractionRowId: Int64 = record.lastInteractionRowId
|
||||
let lastMessageDateInterval: Double? = record.lastMessageDate
|
||||
let lastMessageDate: Date? = SDSDeserialization.optionalDoubleAsDate(lastMessageDateInterval, name: "lastMessageDate")
|
||||
let messageDraft: String? = record.messageDraft
|
||||
@ -164,7 +164,7 @@ extension TSThread {
|
||||
creationDate: creationDate,
|
||||
isArchived: isArchived,
|
||||
isArchivedByLegacyTimestampForSorting: isArchivedByLegacyTimestampForSorting,
|
||||
lastInteractionSortId: lastInteractionSortId,
|
||||
lastInteractionRowId: lastInteractionRowId,
|
||||
lastMessageDate: lastMessageDate,
|
||||
messageDraft: messageDraft,
|
||||
mutedUntilDate: mutedUntilDate,
|
||||
@ -185,7 +185,7 @@ extension TSThread {
|
||||
let creationDate: Date? = SDSDeserialization.optionalDoubleAsDate(creationDateInterval, name: "creationDate")
|
||||
let isArchived: Bool = record.isArchived
|
||||
let isArchivedByLegacyTimestampForSorting: Bool = record.isArchivedByLegacyTimestampForSorting
|
||||
let lastInteractionSortId: Int64 = record.lastInteractionSortId
|
||||
let lastInteractionRowId: Int64 = record.lastInteractionRowId
|
||||
let lastMessageDateInterval: Double? = record.lastMessageDate
|
||||
let lastMessageDate: Date? = SDSDeserialization.optionalDoubleAsDate(lastMessageDateInterval, name: "lastMessageDate")
|
||||
let messageDraft: String? = record.messageDraft
|
||||
@ -203,7 +203,7 @@ extension TSThread {
|
||||
creationDate: creationDate,
|
||||
isArchived: isArchived,
|
||||
isArchivedByLegacyTimestampForSorting: isArchivedByLegacyTimestampForSorting,
|
||||
lastInteractionSortId: lastInteractionSortId,
|
||||
lastInteractionRowId: lastInteractionRowId,
|
||||
lastMessageDate: lastMessageDate,
|
||||
messageDraft: messageDraft,
|
||||
mutedUntilDate: mutedUntilDate,
|
||||
@ -221,7 +221,7 @@ extension TSThread {
|
||||
let creationDate: Date? = SDSDeserialization.optionalDoubleAsDate(creationDateInterval, name: "creationDate")
|
||||
let isArchived: Bool = record.isArchived
|
||||
let isArchivedByLegacyTimestampForSorting: Bool = record.isArchivedByLegacyTimestampForSorting
|
||||
let lastInteractionSortId: Int64 = record.lastInteractionSortId
|
||||
let lastInteractionRowId: Int64 = record.lastInteractionRowId
|
||||
let lastMessageDateInterval: Double? = record.lastMessageDate
|
||||
let lastMessageDate: Date? = SDSDeserialization.optionalDoubleAsDate(lastMessageDateInterval, name: "lastMessageDate")
|
||||
let messageDraft: String? = record.messageDraft
|
||||
@ -237,7 +237,7 @@ extension TSThread {
|
||||
creationDate: creationDate,
|
||||
isArchived: isArchived,
|
||||
isArchivedByLegacyTimestampForSorting: isArchivedByLegacyTimestampForSorting,
|
||||
lastInteractionSortId: lastInteractionSortId,
|
||||
lastInteractionRowId: lastInteractionRowId,
|
||||
lastMessageDate: lastMessageDate,
|
||||
messageDraft: messageDraft,
|
||||
mutedUntilDate: mutedUntilDate,
|
||||
@ -298,7 +298,7 @@ extension TSThreadSerializer {
|
||||
static let creationDateColumn = SDSColumnMetadata(columnName: "creationDate", columnType: .double, isOptional: true, columnIndex: 5)
|
||||
static let isArchivedColumn = SDSColumnMetadata(columnName: "isArchived", columnType: .int, columnIndex: 6)
|
||||
static let isArchivedByLegacyTimestampForSortingColumn = SDSColumnMetadata(columnName: "isArchivedByLegacyTimestampForSorting", columnType: .int, columnIndex: 7)
|
||||
static let lastInteractionSortIdColumn = SDSColumnMetadata(columnName: "lastInteractionSortId", columnType: .int64, columnIndex: 8)
|
||||
static let lastInteractionRowIdColumn = SDSColumnMetadata(columnName: "lastInteractionRowId", columnType: .int64, columnIndex: 8)
|
||||
static let lastMessageDateColumn = SDSColumnMetadata(columnName: "lastMessageDate", columnType: .double, isOptional: true, columnIndex: 9)
|
||||
static let messageDraftColumn = SDSColumnMetadata(columnName: "messageDraft", columnType: .unicodeString, isOptional: true, columnIndex: 10)
|
||||
static let mutedUntilDateColumn = SDSColumnMetadata(columnName: "mutedUntilDate", columnType: .double, isOptional: true, columnIndex: 11)
|
||||
@ -323,7 +323,7 @@ extension TSThreadSerializer {
|
||||
creationDateColumn,
|
||||
isArchivedColumn,
|
||||
isArchivedByLegacyTimestampForSortingColumn,
|
||||
lastInteractionSortIdColumn,
|
||||
lastInteractionRowIdColumn,
|
||||
lastMessageDateColumn,
|
||||
messageDraftColumn,
|
||||
mutedUntilDateColumn,
|
||||
@ -734,7 +734,7 @@ class TSThreadSerializer: SDSSerializer {
|
||||
let creationDate: Double? = archiveOptionalDate(model.creationDate)
|
||||
let isArchived: Bool = model.isArchived
|
||||
let isArchivedByLegacyTimestampForSorting: Bool = model.isArchivedByLegacyTimestampForSorting
|
||||
let lastInteractionSortId: Int64 = model.lastInteractionSortId
|
||||
let lastInteractionRowId: Int64 = model.lastInteractionRowId
|
||||
let lastMessageDate: Double? = archiveOptionalDate(model.lastMessageDate)
|
||||
let messageDraft: String? = model.messageDraft
|
||||
let mutedUntilDate: Double? = archiveOptionalDate(model.mutedUntilDate)
|
||||
@ -747,6 +747,6 @@ class TSThreadSerializer: SDSSerializer {
|
||||
let groupModel: Data? = nil
|
||||
let hasDismissedOffers: Bool? = nil
|
||||
|
||||
return ThreadRecord(delegate: model, id: id, recordType: recordType, uniqueId: uniqueId, archivalDate: archivalDate, conversationColorName: conversationColorName, creationDate: creationDate, isArchived: isArchived, isArchivedByLegacyTimestampForSorting: isArchivedByLegacyTimestampForSorting, lastInteractionSortId: lastInteractionSortId, lastMessageDate: lastMessageDate, messageDraft: messageDraft, mutedUntilDate: mutedUntilDate, shouldThreadBeVisible: shouldThreadBeVisible, contactPhoneNumber: contactPhoneNumber, contactThreadSchemaVersion: contactThreadSchemaVersion, contactUUID: contactUUID, groupModel: groupModel, hasDismissedOffers: hasDismissedOffers)
|
||||
return ThreadRecord(delegate: model, id: id, recordType: recordType, uniqueId: uniqueId, archivalDate: archivalDate, conversationColorName: conversationColorName, creationDate: creationDate, isArchived: isArchived, isArchivedByLegacyTimestampForSorting: isArchivedByLegacyTimestampForSorting, lastInteractionRowId: lastInteractionRowId, lastMessageDate: lastMessageDate, messageDraft: messageDraft, mutedUntilDate: mutedUntilDate, shouldThreadBeVisible: shouldThreadBeVisible, contactPhoneNumber: contactPhoneNumber, contactThreadSchemaVersion: contactThreadSchemaVersion, contactUUID: contactUUID, groupModel: groupModel, hasDismissedOffers: hasDismissedOffers)
|
||||
}
|
||||
}
|
||||
|
||||
@ -45,7 +45,7 @@ extern ConversationColorName const kConversationColorName_Default;
|
||||
|
||||
// zero if thread has never had an interaction.
|
||||
// The corresponding interaction may have been deleted.
|
||||
@property (nonatomic, readonly) int64_t lastInteractionSortId;
|
||||
@property (nonatomic, readonly) int64_t lastInteractionRowId;
|
||||
|
||||
// --- CODE GENERATION MARKER
|
||||
|
||||
@ -60,13 +60,13 @@ extern ConversationColorName const kConversationColorName_Default;
|
||||
creationDate:(nullable NSDate *)creationDate
|
||||
isArchived:(BOOL)isArchived
|
||||
isArchivedByLegacyTimestampForSorting:(BOOL)isArchivedByLegacyTimestampForSorting
|
||||
lastInteractionSortId:(int64_t)lastInteractionSortId
|
||||
lastInteractionRowId:(int64_t)lastInteractionRowId
|
||||
lastMessageDate:(nullable NSDate *)lastMessageDate
|
||||
messageDraft:(nullable NSString *)messageDraft
|
||||
mutedUntilDate:(nullable NSDate *)mutedUntilDate
|
||||
rowId:(int64_t)rowId
|
||||
shouldThreadBeVisible:(BOOL)shouldThreadBeVisible
|
||||
NS_SWIFT_NAME(init(grdbId:uniqueId:archivalDate:conversationColorName:creationDate:isArchived:isArchivedByLegacyTimestampForSorting:lastInteractionSortId:lastMessageDate:messageDraft:mutedUntilDate:rowId:shouldThreadBeVisible:));
|
||||
NS_SWIFT_NAME(init(grdbId:uniqueId:archivalDate:conversationColorName:creationDate:isArchived:isArchivedByLegacyTimestampForSorting:lastInteractionRowId:lastMessageDate:messageDraft:mutedUntilDate:rowId:shouldThreadBeVisible:));
|
||||
|
||||
// clang-format on
|
||||
|
||||
@ -126,12 +126,12 @@ NS_SWIFT_NAME(init(grdbId:uniqueId:archivalDate:conversationColorName:creationDa
|
||||
/**
|
||||
* Updates the thread's caches of the latest interaction.
|
||||
*
|
||||
* @param lastMessage Latest Interaction to take into consideration.
|
||||
* @param message Latest Interaction to take into consideration.
|
||||
* @param transaction Database transaction.
|
||||
*/
|
||||
- (void)updateWithLastMessage:(TSInteraction *)lastMessage
|
||||
wasMessageInserted:(BOOL)wasMessageInserted
|
||||
transaction:(SDSAnyWriteTransaction *)transaction;
|
||||
- (void)updateWithInsertedMessage:(TSInteraction *)message transaction:(SDSAnyWriteTransaction *)transaction;
|
||||
- (void)updateWithUpdatedMessage:(TSInteraction *)message transaction:(SDSAnyWriteTransaction *)transaction;
|
||||
- (void)updateWithRemovedMessage:(TSInteraction *)message transaction:(SDSAnyWriteTransaction *)transaction;
|
||||
|
||||
#pragma mark Archival
|
||||
|
||||
|
||||
@ -53,7 +53,7 @@ ConversationColorName const kConversationColorName_Default = ConversationColorNa
|
||||
@property (nonatomic, nullable) NSDate *lastMessageDate DEPRECATED_ATTRIBUTE;
|
||||
@property (nonatomic, nullable) NSDate *archivalDate DEPRECATED_ATTRIBUTE;
|
||||
|
||||
@property (nonatomic) int64_t lastInteractionSortId;
|
||||
@property (nonatomic) int64_t lastInteractionRowId;
|
||||
|
||||
@end
|
||||
|
||||
@ -111,7 +111,7 @@ ConversationColorName const kConversationColorName_Default = ConversationColorNa
|
||||
creationDate:(nullable NSDate *)creationDate
|
||||
isArchived:(BOOL)isArchived
|
||||
isArchivedByLegacyTimestampForSorting:(BOOL)isArchivedByLegacyTimestampForSorting
|
||||
lastInteractionSortId:(int64_t)lastInteractionSortId
|
||||
lastInteractionRowId:(int64_t)lastInteractionRowId
|
||||
lastMessageDate:(nullable NSDate *)lastMessageDate
|
||||
messageDraft:(nullable NSString *)messageDraft
|
||||
mutedUntilDate:(nullable NSDate *)mutedUntilDate
|
||||
@ -130,7 +130,7 @@ isArchivedByLegacyTimestampForSorting:(BOOL)isArchivedByLegacyTimestampForSortin
|
||||
_creationDate = creationDate;
|
||||
_isArchived = isArchived;
|
||||
_isArchivedByLegacyTimestampForSorting = isArchivedByLegacyTimestampForSorting;
|
||||
_lastInteractionSortId = lastInteractionSortId;
|
||||
_lastInteractionRowId = lastInteractionRowId;
|
||||
_lastMessageDate = lastMessageDate;
|
||||
_messageDraft = messageDraft;
|
||||
_mutedUntilDate = mutedUntilDate;
|
||||
@ -433,37 +433,47 @@ isArchivedByLegacyTimestampForSorting:(BOOL)isArchivedByLegacyTimestampForSortin
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (void)updateWithLastMessage:(TSInteraction *)lastMessage
|
||||
wasMessageInserted:(BOOL)wasMessageInserted
|
||||
transaction:(SDSAnyWriteTransaction *)transaction
|
||||
- (void)updateWithInsertedMessage:(TSInteraction *)message transaction:(SDSAnyWriteTransaction *)transaction
|
||||
{
|
||||
OWSAssertDebug(lastMessage);
|
||||
OWSAssertDebug(transaction);
|
||||
[self updateWithMessage:message wasMessageInserted:YES transaction:transaction];
|
||||
}
|
||||
|
||||
if (![self.class shouldInteractionAppearInInbox:lastMessage]) {
|
||||
- (void)updateWithUpdatedMessage:(TSInteraction *)message transaction:(SDSAnyWriteTransaction *)transaction
|
||||
{
|
||||
[self updateWithMessage:message wasMessageInserted:NO transaction:transaction];
|
||||
}
|
||||
|
||||
- (void)updateWithMessage:(TSInteraction *)message
|
||||
wasMessageInserted:(BOOL)wasMessageInserted
|
||||
transaction:(SDSAnyWriteTransaction *)transaction
|
||||
{
|
||||
OWSAssertDebug(message != nil);
|
||||
OWSAssertDebug(transaction != nil);
|
||||
|
||||
if (![self.class shouldInteractionAppearInInbox:message]) {
|
||||
return;
|
||||
}
|
||||
|
||||
int64_t messageSortId = 0;
|
||||
if (transaction.transitional_yapWriteTransaction) {
|
||||
messageSortId = lastMessage.sortId;
|
||||
messageSortId = message.sortId;
|
||||
} else {
|
||||
if (lastMessage.grdbId == nil) {
|
||||
if (message.grdbId == nil) {
|
||||
OWSFailDebug(@"Missing messageSortId.");
|
||||
} else if (lastMessage.grdbId.unsignedLongLongValue == 0) {
|
||||
} else if (message.grdbId.unsignedLongLongValue == 0) {
|
||||
OWSFailDebug(@"Invalid messageSortId.");
|
||||
} else {
|
||||
messageSortId = lastMessage.grdbId.longLongValue;
|
||||
messageSortId = message.grdbId.longLongValue;
|
||||
}
|
||||
}
|
||||
BOOL needsToMarkAsVisible = !self.shouldThreadBeVisible;
|
||||
BOOL needsToClearArchived = self.isArchived && wasMessageInserted;
|
||||
BOOL needsToUpdateLastInteractionSortId = messageSortId > self.lastInteractionSortId;
|
||||
if (needsToMarkAsVisible || needsToClearArchived || needsToUpdateLastInteractionSortId) {
|
||||
BOOL needsToUpdateLastInteractionRowId = messageSortId > self.lastInteractionRowId;
|
||||
if (needsToMarkAsVisible || needsToClearArchived || needsToUpdateLastInteractionRowId) {
|
||||
[self anyUpdateWithTransaction:transaction
|
||||
block:^(TSThread *thread) {
|
||||
thread.shouldThreadBeVisible = YES;
|
||||
thread.lastInteractionSortId = MAX(thread.lastInteractionSortId, messageSortId);
|
||||
thread.lastInteractionRowId = MAX(thread.lastInteractionRowId, messageSortId);
|
||||
if (thread.isArchived && wasMessageInserted) {
|
||||
// No longer archived.
|
||||
thread.isArchived = NO;
|
||||
@ -474,6 +484,40 @@ isArchivedByLegacyTimestampForSorting:(BOOL)isArchivedByLegacyTimestampForSortin
|
||||
}
|
||||
}
|
||||
|
||||
- (void)updateWithRemovedMessage:(TSInteraction *)message transaction:(SDSAnyWriteTransaction *)transaction
|
||||
{
|
||||
OWSAssertDebug(message != nil);
|
||||
OWSAssertDebug(transaction != nil);
|
||||
|
||||
if (![self.class shouldInteractionAppearInInbox:message]) {
|
||||
return;
|
||||
}
|
||||
|
||||
int64_t messageSortId = 0;
|
||||
if (transaction.transitional_yapWriteTransaction) {
|
||||
messageSortId = message.sortId;
|
||||
} else {
|
||||
if (message.grdbId == nil) {
|
||||
OWSFailDebug(@"Missing messageSortId.");
|
||||
} else if (message.grdbId.unsignedLongLongValue == 0) {
|
||||
OWSFailDebug(@"Invalid messageSortId.");
|
||||
} else {
|
||||
messageSortId = message.grdbId.longLongValue;
|
||||
}
|
||||
}
|
||||
BOOL needsToUpdateLastInteractionRowId = messageSortId == self.lastInteractionRowId;
|
||||
if (needsToUpdateLastInteractionRowId) {
|
||||
[self anyUpdateWithTransaction:transaction
|
||||
block:^(TSThread *thread) {
|
||||
TSInteraction *_Nullable latestInteraction =
|
||||
[thread lastInteractionForInboxWithTransaction:transaction];
|
||||
thread.lastInteractionRowId = latestInteraction ? latestInteraction.sortId : 0;
|
||||
}];
|
||||
} else {
|
||||
[self.databaseStorage touchThread:self transaction:transaction];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)softDeleteThreadWithTransaction:(SDSAnyWriteTransaction *)transaction
|
||||
{
|
||||
[self removeAllThreadInteractionsWithTransaction:transaction];
|
||||
|
||||
@ -66,7 +66,7 @@ class TSContactThreadSerializer: SDSSerializer {
|
||||
let creationDate: Double? = archiveOptionalDate(model.creationDate)
|
||||
let isArchived: Bool = model.isArchived
|
||||
let isArchivedByLegacyTimestampForSorting: Bool = model.isArchivedByLegacyTimestampForSorting
|
||||
let lastInteractionSortId: Int64 = model.lastInteractionSortId
|
||||
let lastInteractionRowId: Int64 = model.lastInteractionRowId
|
||||
let lastMessageDate: Double? = archiveOptionalDate(model.lastMessageDate)
|
||||
let messageDraft: String? = model.messageDraft
|
||||
let mutedUntilDate: Double? = archiveOptionalDate(model.mutedUntilDate)
|
||||
@ -79,6 +79,6 @@ class TSContactThreadSerializer: SDSSerializer {
|
||||
let groupModel: Data? = nil
|
||||
let hasDismissedOffers: Bool? = model.hasDismissedOffers
|
||||
|
||||
return ThreadRecord(delegate: model, id: id, recordType: recordType, uniqueId: uniqueId, archivalDate: archivalDate, conversationColorName: conversationColorName, creationDate: creationDate, isArchived: isArchived, isArchivedByLegacyTimestampForSorting: isArchivedByLegacyTimestampForSorting, lastInteractionSortId: lastInteractionSortId, lastMessageDate: lastMessageDate, messageDraft: messageDraft, mutedUntilDate: mutedUntilDate, shouldThreadBeVisible: shouldThreadBeVisible, contactPhoneNumber: contactPhoneNumber, contactThreadSchemaVersion: contactThreadSchemaVersion, contactUUID: contactUUID, groupModel: groupModel, hasDismissedOffers: hasDismissedOffers)
|
||||
return ThreadRecord(delegate: model, id: id, recordType: recordType, uniqueId: uniqueId, archivalDate: archivalDate, conversationColorName: conversationColorName, creationDate: creationDate, isArchived: isArchived, isArchivedByLegacyTimestampForSorting: isArchivedByLegacyTimestampForSorting, lastInteractionRowId: lastInteractionRowId, lastMessageDate: lastMessageDate, messageDraft: messageDraft, mutedUntilDate: mutedUntilDate, shouldThreadBeVisible: shouldThreadBeVisible, contactPhoneNumber: contactPhoneNumber, contactThreadSchemaVersion: contactThreadSchemaVersion, contactUUID: contactUUID, groupModel: groupModel, hasDismissedOffers: hasDismissedOffers)
|
||||
}
|
||||
}
|
||||
|
||||
@ -23,7 +23,7 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
creationDate:(nullable NSDate *)creationDate
|
||||
isArchived:(BOOL)isArchived
|
||||
isArchivedByLegacyTimestampForSorting:(BOOL)isArchivedByLegacyTimestampForSorting
|
||||
lastInteractionSortId:(int64_t)lastInteractionSortId
|
||||
lastInteractionRowId:(int64_t)lastInteractionRowId
|
||||
lastMessageDate:(nullable NSDate *)lastMessageDate
|
||||
messageDraft:(nullable NSString *)messageDraft
|
||||
mutedUntilDate:(nullable NSDate *)mutedUntilDate
|
||||
@ -33,7 +33,7 @@ isArchivedByLegacyTimestampForSorting:(BOOL)isArchivedByLegacyTimestampForSortin
|
||||
contactThreadSchemaVersion:(NSUInteger)contactThreadSchemaVersion
|
||||
contactUUID:(nullable NSString *)contactUUID
|
||||
hasDismissedOffers:(BOOL)hasDismissedOffers
|
||||
NS_SWIFT_NAME(init(grdbId:uniqueId:archivalDate:conversationColorName:creationDate:isArchived:isArchivedByLegacyTimestampForSorting:lastInteractionSortId:lastMessageDate:messageDraft:mutedUntilDate:rowId:shouldThreadBeVisible:contactPhoneNumber:contactThreadSchemaVersion:contactUUID:hasDismissedOffers:));
|
||||
NS_SWIFT_NAME(init(grdbId:uniqueId:archivalDate:conversationColorName:creationDate:isArchived:isArchivedByLegacyTimestampForSorting:lastInteractionRowId:lastMessageDate:messageDraft:mutedUntilDate:rowId:shouldThreadBeVisible:contactPhoneNumber:contactThreadSchemaVersion:contactUUID:hasDismissedOffers:));
|
||||
|
||||
// clang-format on
|
||||
|
||||
|
||||
@ -56,7 +56,7 @@ NSUInteger const TSContactThreadSchemaVersion = 1;
|
||||
creationDate:(nullable NSDate *)creationDate
|
||||
isArchived:(BOOL)isArchived
|
||||
isArchivedByLegacyTimestampForSorting:(BOOL)isArchivedByLegacyTimestampForSorting
|
||||
lastInteractionSortId:(int64_t)lastInteractionSortId
|
||||
lastInteractionRowId:(int64_t)lastInteractionRowId
|
||||
lastMessageDate:(nullable NSDate *)lastMessageDate
|
||||
messageDraft:(nullable NSString *)messageDraft
|
||||
mutedUntilDate:(nullable NSDate *)mutedUntilDate
|
||||
@ -74,7 +74,7 @@ isArchivedByLegacyTimestampForSorting:(BOOL)isArchivedByLegacyTimestampForSortin
|
||||
creationDate:creationDate
|
||||
isArchived:isArchived
|
||||
isArchivedByLegacyTimestampForSorting:isArchivedByLegacyTimestampForSorting
|
||||
lastInteractionSortId:lastInteractionSortId
|
||||
lastInteractionRowId:lastInteractionRowId
|
||||
lastMessageDate:lastMessageDate
|
||||
messageDraft:messageDraft
|
||||
mutedUntilDate:mutedUntilDate
|
||||
|
||||
@ -66,7 +66,7 @@ class TSGroupThreadSerializer: SDSSerializer {
|
||||
let creationDate: Double? = archiveOptionalDate(model.creationDate)
|
||||
let isArchived: Bool = model.isArchived
|
||||
let isArchivedByLegacyTimestampForSorting: Bool = model.isArchivedByLegacyTimestampForSorting
|
||||
let lastInteractionSortId: Int64 = model.lastInteractionSortId
|
||||
let lastInteractionRowId: Int64 = model.lastInteractionRowId
|
||||
let lastMessageDate: Double? = archiveOptionalDate(model.lastMessageDate)
|
||||
let messageDraft: String? = model.messageDraft
|
||||
let mutedUntilDate: Double? = archiveOptionalDate(model.mutedUntilDate)
|
||||
@ -79,6 +79,6 @@ class TSGroupThreadSerializer: SDSSerializer {
|
||||
let groupModel: Data? = optionalArchive(model.groupModel)
|
||||
let hasDismissedOffers: Bool? = nil
|
||||
|
||||
return ThreadRecord(delegate: model, id: id, recordType: recordType, uniqueId: uniqueId, archivalDate: archivalDate, conversationColorName: conversationColorName, creationDate: creationDate, isArchived: isArchived, isArchivedByLegacyTimestampForSorting: isArchivedByLegacyTimestampForSorting, lastInteractionSortId: lastInteractionSortId, lastMessageDate: lastMessageDate, messageDraft: messageDraft, mutedUntilDate: mutedUntilDate, shouldThreadBeVisible: shouldThreadBeVisible, contactPhoneNumber: contactPhoneNumber, contactThreadSchemaVersion: contactThreadSchemaVersion, contactUUID: contactUUID, groupModel: groupModel, hasDismissedOffers: hasDismissedOffers)
|
||||
return ThreadRecord(delegate: model, id: id, recordType: recordType, uniqueId: uniqueId, archivalDate: archivalDate, conversationColorName: conversationColorName, creationDate: creationDate, isArchived: isArchived, isArchivedByLegacyTimestampForSorting: isArchivedByLegacyTimestampForSorting, lastInteractionRowId: lastInteractionRowId, lastMessageDate: lastMessageDate, messageDraft: messageDraft, mutedUntilDate: mutedUntilDate, shouldThreadBeVisible: shouldThreadBeVisible, contactPhoneNumber: contactPhoneNumber, contactThreadSchemaVersion: contactThreadSchemaVersion, contactUUID: contactUUID, groupModel: groupModel, hasDismissedOffers: hasDismissedOffers)
|
||||
}
|
||||
}
|
||||
|
||||
@ -29,14 +29,14 @@ extern NSString *const TSGroupThread_NotificationKey_UniqueId;
|
||||
creationDate:(nullable NSDate *)creationDate
|
||||
isArchived:(BOOL)isArchived
|
||||
isArchivedByLegacyTimestampForSorting:(BOOL)isArchivedByLegacyTimestampForSorting
|
||||
lastInteractionSortId:(int64_t)lastInteractionSortId
|
||||
lastInteractionRowId:(int64_t)lastInteractionRowId
|
||||
lastMessageDate:(nullable NSDate *)lastMessageDate
|
||||
messageDraft:(nullable NSString *)messageDraft
|
||||
mutedUntilDate:(nullable NSDate *)mutedUntilDate
|
||||
rowId:(int64_t)rowId
|
||||
shouldThreadBeVisible:(BOOL)shouldThreadBeVisible
|
||||
groupModel:(TSGroupModel *)groupModel
|
||||
NS_SWIFT_NAME(init(grdbId:uniqueId:archivalDate:conversationColorName:creationDate:isArchived:isArchivedByLegacyTimestampForSorting:lastInteractionSortId:lastMessageDate:messageDraft:mutedUntilDate:rowId:shouldThreadBeVisible:groupModel:));
|
||||
NS_SWIFT_NAME(init(grdbId:uniqueId:archivalDate:conversationColorName:creationDate:isArchived:isArchivedByLegacyTimestampForSorting:lastInteractionRowId:lastMessageDate:messageDraft:mutedUntilDate:rowId:shouldThreadBeVisible:groupModel:));
|
||||
|
||||
// clang-format on
|
||||
|
||||
|
||||
@ -30,7 +30,7 @@ NSString *const TSGroupThread_NotificationKey_UniqueId = @"TSGroupThread_Notific
|
||||
creationDate:(nullable NSDate *)creationDate
|
||||
isArchived:(BOOL)isArchived
|
||||
isArchivedByLegacyTimestampForSorting:(BOOL)isArchivedByLegacyTimestampForSorting
|
||||
lastInteractionSortId:(int64_t)lastInteractionSortId
|
||||
lastInteractionRowId:(int64_t)lastInteractionRowId
|
||||
lastMessageDate:(nullable NSDate *)lastMessageDate
|
||||
messageDraft:(nullable NSString *)messageDraft
|
||||
mutedUntilDate:(nullable NSDate *)mutedUntilDate
|
||||
@ -45,7 +45,7 @@ isArchivedByLegacyTimestampForSorting:(BOOL)isArchivedByLegacyTimestampForSortin
|
||||
creationDate:creationDate
|
||||
isArchived:isArchived
|
||||
isArchivedByLegacyTimestampForSorting:isArchivedByLegacyTimestampForSorting
|
||||
lastInteractionSortId:lastInteractionSortId
|
||||
lastInteractionRowId:lastInteractionRowId
|
||||
lastMessageDate:lastMessageDate
|
||||
messageDraft:messageDraft
|
||||
mutedUntilDate:mutedUntilDate
|
||||
|
||||
@ -294,30 +294,24 @@ NSString *NSStringFromOWSInteractionType(OWSInteractionType value)
|
||||
{
|
||||
[super anyDidInsertWithTransaction:transaction];
|
||||
|
||||
[self updateLastMessageWithTransaction:transaction wasMessageInserted:YES];
|
||||
TSThread *fetchedThread = [self threadWithTransaction:transaction];
|
||||
[fetchedThread updateWithInsertedMessage:self transaction:transaction];
|
||||
}
|
||||
|
||||
- (void)anyDidUpdateWithTransaction:(SDSAnyWriteTransaction *)transaction
|
||||
{
|
||||
[super anyDidUpdateWithTransaction:transaction];
|
||||
|
||||
[self updateLastMessageWithTransaction:transaction wasMessageInserted:NO];
|
||||
}
|
||||
|
||||
- (void)updateLastMessageWithTransaction:(SDSAnyWriteTransaction *)transaction
|
||||
wasMessageInserted:(BOOL)wasMessageInserted
|
||||
{
|
||||
TSThread *fetchedThread = [self threadWithTransaction:transaction];
|
||||
|
||||
[fetchedThread updateWithLastMessage:self wasMessageInserted:wasMessageInserted transaction:transaction];
|
||||
[fetchedThread updateWithUpdatedMessage:self transaction:transaction];
|
||||
}
|
||||
|
||||
- (void)anyDidRemoveWithTransaction:(SDSAnyWriteTransaction *)transaction
|
||||
{
|
||||
[super anyDidRemoveWithTransaction:transaction];
|
||||
|
||||
TSThread *thread = [self threadWithTransaction:transaction];
|
||||
[self.databaseStorage touchThread:thread transaction:transaction];
|
||||
TSThread *fetchedThread = [self threadWithTransaction:transaction];
|
||||
[fetchedThread updateWithRemovedMessage:self transaction:transaction];
|
||||
}
|
||||
|
||||
#pragma mark -
|
||||
|
||||
@ -214,7 +214,7 @@ public class GRDBDatabaseStorageAdapter: NSObject {
|
||||
columns: [
|
||||
ThreadRecord.columnName(.shouldThreadBeVisible),
|
||||
ThreadRecord.columnName(.isArchived),
|
||||
ThreadRecord.columnName(.lastInteractionSortId)
|
||||
ThreadRecord.columnName(.lastInteractionRowId)
|
||||
]
|
||||
)
|
||||
|
||||
|
||||
@ -105,7 +105,7 @@ struct GRDBThreadFinder: ThreadFinder {
|
||||
FROM \(ThreadRecord.databaseTableName)
|
||||
WHERE \(threadColumn: .shouldThreadBeVisible) = 1
|
||||
AND \(threadColumn: .isArchived) = ?
|
||||
ORDER BY \(threadColumn: .lastInteractionSortId) DESC
|
||||
ORDER BY \(threadColumn: .lastInteractionRowId) DESC
|
||||
"""
|
||||
let arguments: StatementArguments = [isArchived]
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user