Merge branch 'unread-metion-fix' into voice-calls-2
This commit is contained in:
commit
5f9bc4c55f
|
@ -144,7 +144,6 @@
|
|||
7B1581E827210ECC00848B49 /* RenderView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7B1581E727210ECC00848B49 /* RenderView.swift */; };
|
||||
7B1D74AA27BCC16E0030B423 /* NSENotificationPresenter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7B1D74A927BCC16E0030B423 /* NSENotificationPresenter.swift */; };
|
||||
7B1D74AC27BDE7510030B423 /* Promise+Timeout.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7B1D74AB27BDE7510030B423 /* Promise+Timeout.swift */; };
|
||||
7B1D74AE27C346220030B423 /* UnreadMentionMigtation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7B1D74AD27C346220030B423 /* UnreadMentionMigtation.swift */; };
|
||||
7B1D74B027C365960030B423 /* Timer+MainThread.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7B1D74AF27C365960030B423 /* Timer+MainThread.swift */; };
|
||||
7B251C3627D82D9E001A6284 /* SessionUtilitiesKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C3C2A679255388CC00C340D1 /* SessionUtilitiesKit.framework */; };
|
||||
7B4C75CB26B37E0F0000AC89 /* UnsendRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7B4C75CA26B37E0F0000AC89 /* UnsendRequest.swift */; };
|
||||
|
@ -1168,7 +1167,6 @@
|
|||
7B1581E727210ECC00848B49 /* RenderView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RenderView.swift; sourceTree = "<group>"; };
|
||||
7B1D74A927BCC16E0030B423 /* NSENotificationPresenter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NSENotificationPresenter.swift; sourceTree = "<group>"; };
|
||||
7B1D74AB27BDE7510030B423 /* Promise+Timeout.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Promise+Timeout.swift"; sourceTree = "<group>"; };
|
||||
7B1D74AD27C346220030B423 /* UnreadMentionMigtation.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UnreadMentionMigtation.swift; sourceTree = "<group>"; };
|
||||
7B1D74AF27C365960030B423 /* Timer+MainThread.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Timer+MainThread.swift"; sourceTree = "<group>"; };
|
||||
7B2DB2AD26F1B0FF0035B509 /* si */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = si; path = si.lproj/Localizable.strings; sourceTree = "<group>"; };
|
||||
7B4C75CA26B37E0F0000AC89 /* UnsendRequest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UnsendRequest.swift; sourceTree = "<group>"; };
|
||||
|
@ -3196,7 +3194,6 @@
|
|||
children = (
|
||||
7B93D07227CF19C800811CB6 /* MessageRequestsMigration.swift */,
|
||||
B8B32044258C117C0020074B /* ContactsMigration.swift */,
|
||||
7B1D74AD27C346220030B423 /* UnreadMentionMigtation.swift */,
|
||||
C38EF271255B6D79007E1867 /* OWSDatabaseMigration.h */,
|
||||
C38EF270255B6D79007E1867 /* OWSDatabaseMigration.m */,
|
||||
C38EF26F255B6D79007E1867 /* OWSDatabaseMigrationRunner.h */,
|
||||
|
@ -4728,7 +4725,6 @@
|
|||
C38EF40B255B6DF7007E1867 /* TappableStackView.swift in Sources */,
|
||||
C38EF31D255B6DBF007E1867 /* UIImage+OWS.swift in Sources */,
|
||||
C38EF359255B6DCC007E1867 /* SheetViewController.swift in Sources */,
|
||||
7B1D74AE27C346220030B423 /* UnreadMentionMigtation.swift in Sources */,
|
||||
B8F5F52925EC4F8A003BF8D4 /* BlockListUIUtils.m in Sources */,
|
||||
C38EF386255B6DD2007E1867 /* AttachmentApprovalInputAccessoryView.swift in Sources */,
|
||||
B8C2B2C82563685C00551B4D /* CircleView.swift in Sources */,
|
||||
|
|
|
@ -174,6 +174,7 @@ void VerifyRegistrationsForPrimaryStorage(OWSStorage *storage)
|
|||
withName:[TSDatabaseSecondaryIndexes registerTimeStampIndexExtensionName]];
|
||||
|
||||
[TSDatabaseView asyncRegisterUnseenDatabaseView:self];
|
||||
[TSDatabaseView asyncRegisterUnreadMentionDatabaseView:self];
|
||||
[TSDatabaseView asyncRegisterThreadOutgoingMessagesDatabaseView:self];
|
||||
|
||||
[FullTextSearchFinder asyncRegisterDatabaseExtensionWithStorage:self];
|
||||
|
|
|
@ -22,6 +22,7 @@ extern NSString *const TSMessageDatabaseViewExtensionName_Legacy;
|
|||
|
||||
extern NSString *const TSUnreadDatabaseViewExtensionName;
|
||||
extern NSString *const TSUnseenDatabaseViewExtensionName;
|
||||
extern NSString *const TSUnreadMentionDatabaseViewExtensionName;
|
||||
extern NSString *const TSThreadOutgoingMessageDatabaseViewExtensionName;
|
||||
extern NSString *const TSThreadSpecialMessagesDatabaseViewExtensionName;
|
||||
|
||||
|
@ -66,6 +67,11 @@ extern NSString *const TSLazyRestoreAttachmentsDatabaseViewExtensionName;
|
|||
// Instances of OWSReadTracking for wasRead is NO.
|
||||
+ (void)asyncRegisterUnseenDatabaseView:(OWSStorage *)storage;
|
||||
|
||||
// Should be used for "mention indicator".
|
||||
//
|
||||
// Instances of OWSReadTracking for wasRead is NO and isUserMentioned is YES.
|
||||
+ (void)asyncRegisterUnreadMentionDatabaseView:(OWSStorage *)storage;
|
||||
|
||||
+ (void)asyncRegisterLazyRestoreAttachmentsDatabaseView:(OWSStorage *)storage;
|
||||
|
||||
@end
|
||||
|
|
|
@ -47,6 +47,7 @@ NSString *const TSMessageDatabaseViewExtensionName_Legacy = @"TSMessageDatabaseV
|
|||
NSString *const TSThreadOutgoingMessageDatabaseViewExtensionName = @"TSThreadOutgoingMessageDatabaseViewExtensionName";
|
||||
NSString *const TSUnreadDatabaseViewExtensionName = @"TSUnreadDatabaseViewExtensionName";
|
||||
NSString *const TSUnseenDatabaseViewExtensionName = @"TSUnseenDatabaseViewExtensionName";
|
||||
NSString *const TSUnreadMentionDatabaseViewExtensionName = @"TSUnreadMentionDatabaseViewExtensionName";
|
||||
NSString *const TSThreadSpecialMessagesDatabaseViewExtensionName = @"TSThreadSpecialMessagesDatabaseViewExtensionName";
|
||||
NSString *const TSSecondaryDevicesDatabaseViewExtensionName = @"TSSecondaryDevicesDatabaseViewExtensionName";
|
||||
NSString *const TSLazyRestoreAttachmentsDatabaseViewExtensionName
|
||||
|
@ -134,6 +135,25 @@ NSString *const TSLazyRestoreAttachmentsGroup = @"TSLazyRestoreAttachmentsGroup"
|
|||
storage:storage];
|
||||
}
|
||||
|
||||
+ (void)asyncRegisterUnreadMentionDatabaseView:(OWSStorage *)storage
|
||||
{
|
||||
YapDatabaseViewGrouping *viewGrouping = [YapDatabaseViewGrouping withObjectBlock:^NSString *(
|
||||
YapDatabaseReadTransaction *transaction, NSString *collection, NSString *key, id object) {
|
||||
if ([object isKindOfClass:[TSIncomingMessage class]]) {
|
||||
TSIncomingMessage *message = (TSIncomingMessage *)object;
|
||||
if (!message.wasRead && message.isUserMentioned) {
|
||||
return message.uniqueThreadId;
|
||||
}
|
||||
}
|
||||
return nil;
|
||||
}];
|
||||
|
||||
[self registerMessageDatabaseViewWithName:TSUnreadMentionDatabaseViewExtensionName
|
||||
viewGrouping:viewGrouping
|
||||
version:@"2"
|
||||
storage:storage];
|
||||
}
|
||||
|
||||
+ (void)asyncRegisterLegacyThreadInteractionsDatabaseView:(OWSStorage *)storage
|
||||
{
|
||||
YapDatabaseView *existingView = [storage registeredExtension:TSMessageDatabaseViewExtensionName_Legacy];
|
||||
|
|
|
@ -287,10 +287,6 @@ NSString *const OWSReadReceiptManagerAreReadReceiptsEnabled = @"areReadReceiptsE
|
|||
for (id<OWSReadTracking> readItem in newlyReadList) {
|
||||
[readItem markAsReadAtTimestamp:readTimestamp trySendReadReceipt:trySendReadReceipt transaction:transaction];
|
||||
}
|
||||
|
||||
// Update unread mention.
|
||||
thread.hasUnreadMentionMessage = false;
|
||||
[thread saveWithTransaction:transaction];
|
||||
}
|
||||
|
||||
#pragma mark - Settings
|
||||
|
|
|
@ -16,7 +16,6 @@ BOOL IsNoteToSelfEnabled(void);
|
|||
*/
|
||||
@interface TSThread : TSYapDatabaseObject
|
||||
|
||||
@property (nonatomic) BOOL hasUnreadMentionMessage;
|
||||
@property (nonatomic) BOOL isPinned;
|
||||
@property (nonatomic) BOOL shouldBeVisible;
|
||||
@property (nonatomic, readonly) NSDate *creationDate;
|
||||
|
@ -79,6 +78,13 @@ BOOL IsNoteToSelfEnabled(void);
|
|||
- (NSUInteger)unreadMessageCountWithTransaction:(YapDatabaseReadTransaction *)transaction
|
||||
NS_SWIFT_NAME(unreadMessageCount(transaction:));
|
||||
|
||||
/**
|
||||
* @return If there is any message mentioning current user in this thread.
|
||||
*/
|
||||
- (NSUInteger)unreadMentionMessageCount;
|
||||
|
||||
- (NSUInteger)unreadMentionMessageCountWithTransaction:(YapDatabaseReadTransaction *)transaction;
|
||||
|
||||
- (void)markAllAsReadWithTransaction:(YapDatabaseReadWriteTransaction *)transaction;
|
||||
|
||||
/**
|
||||
|
|
|
@ -302,14 +302,27 @@ BOOL IsNoteToSelfEnabled(void)
|
|||
// return count;
|
||||
}
|
||||
|
||||
- (NSUInteger)unreadMentionMessageCount
|
||||
{
|
||||
__block NSUInteger unreadMentionMessageCount;
|
||||
[[self dbReadConnection] readWithBlock:^(YapDatabaseReadTransaction *transaction) {
|
||||
unreadMentionMessageCount = [self unreadMentionMessageCountWithTransaction:transaction];
|
||||
}];
|
||||
return unreadMentionMessageCount;
|
||||
}
|
||||
|
||||
- (NSUInteger)unreadMentionMessageCountWithTransaction:(YapDatabaseReadTransaction *)transaction
|
||||
{
|
||||
YapDatabaseViewTransaction *unreadMentions = [transaction ext:TSUnreadMentionDatabaseViewExtensionName];
|
||||
return [unreadMentions numberOfItemsInGroup:self.uniqueId];
|
||||
}
|
||||
|
||||
- (void)markAllAsReadWithTransaction:(YapDatabaseReadWriteTransaction *)transaction
|
||||
{
|
||||
for (id<OWSReadTracking> message in [self unseenMessagesWithTransaction:transaction]) {
|
||||
[message markAsReadAtTimestamp:[NSDate ows_millisecondTimeStamp] trySendReadReceipt:YES transaction:transaction];
|
||||
}
|
||||
|
||||
// Update unread mention.
|
||||
self.hasUnreadMentionMessage = false;
|
||||
[super saveWithTransaction:transaction];
|
||||
}
|
||||
|
||||
|
@ -376,12 +389,6 @@ BOOL IsNoteToSelfEnabled(void)
|
|||
_lastInteractionDate = lastMessage.receivedAtDate;
|
||||
[super saveWithTransaction:transaction];
|
||||
}
|
||||
|
||||
// Update unread mention if there is a new incoming message.
|
||||
if ([lastMessage isKindOfClass:[TSIncomingMessage class]] && ((TSIncomingMessage *)lastMessage).isUserMentioned) {
|
||||
self.hasUnreadMentionMessage = true;
|
||||
[super saveWithTransaction:transaction];
|
||||
}
|
||||
|
||||
if (!self.shouldBeVisible) {
|
||||
self.shouldBeVisible = YES;
|
||||
|
|
|
@ -26,7 +26,6 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
- (NSArray<OWSDatabaseMigration *> *)allMigrations
|
||||
{
|
||||
return @[
|
||||
[SNUnreadMentionMigration new],
|
||||
[SNMessageRequestsMigration new],
|
||||
[SNContactsMigration new]
|
||||
];
|
||||
|
|
|
@ -1,41 +0,0 @@
|
|||
// Copyright © 2022 Rangeproof Pty Ltd. All rights reserved.
|
||||
|
||||
@objc(SNUnreadMentionMigration)
|
||||
public class UnreadMentionMigration : OWSDatabaseMigration {
|
||||
|
||||
@objc
|
||||
class func migrationId() -> String {
|
||||
return "003" // leave "002" for message request migration
|
||||
}
|
||||
|
||||
override public func runUp(completion: @escaping OWSDatabaseMigrationCompletion) {
|
||||
self.doMigrationAsync(completion: completion)
|
||||
}
|
||||
|
||||
private func doMigrationAsync(completion: @escaping OWSDatabaseMigrationCompletion) {
|
||||
var threads: [TSThread] = []
|
||||
Storage.read { transaction in
|
||||
TSThread.enumerateCollectionObjects(with: transaction) { object, _ in
|
||||
guard let thread = object as? TSThread, let threadID = thread.uniqueId else { return }
|
||||
let unreadMessages = transaction.ext(TSUnreadDatabaseViewExtensionName) as! YapDatabaseViewTransaction
|
||||
unreadMessages.enumerateKeysAndObjects(inGroup: threadID) { collection, key, object, index, stop in
|
||||
guard let unreadMessage = object as? TSIncomingMessage else { return }
|
||||
if unreadMessage.wasRead { return }
|
||||
if unreadMessage.isUserMentioned {
|
||||
thread.hasUnreadMentionMessage = true
|
||||
stop.pointee = true
|
||||
}
|
||||
}
|
||||
threads.append(thread)
|
||||
}
|
||||
}
|
||||
Storage.write(with: { transaction in
|
||||
threads.forEach { thread in
|
||||
thread.save(with: transaction)
|
||||
}
|
||||
self.save(with: transaction) // Intentionally capture self
|
||||
}, completion: {
|
||||
completion()
|
||||
})
|
||||
}
|
||||
}
|
|
@ -81,25 +81,12 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
|
||||
BOOL isGroupThread = thread.isGroupThread;
|
||||
|
||||
[unreadMessages enumerateKeysAndObjectsInGroup:groupID
|
||||
usingBlock:^(NSString *collection, NSString *key, id object, NSUInteger index, BOOL *stop) {
|
||||
if (![object conformsToProtocol:@protocol(OWSReadTracking)]) {
|
||||
return;
|
||||
}
|
||||
id<OWSReadTracking> unread = (id<OWSReadTracking>)object;
|
||||
if (unread.read) {
|
||||
NSLog(@"Found an already read message in the * unread * messages list.");
|
||||
return;
|
||||
}
|
||||
// We have to filter those unread messages for groups that only notifiy for mentions
|
||||
if ([object isKindOfClass:TSIncomingMessage.class] && isGroupThread) {
|
||||
TSIncomingMessage *incomingMessage = (TSIncomingMessage *)object;
|
||||
if (((TSGroupThread *)thread).isOnlyNotifyingForMentions && !incomingMessage.isUserMentioned) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
count += 1;
|
||||
}];
|
||||
// For groups that only notifiy for mentions
|
||||
if (isGroupThread && ((TSGroupThread *)thread).isOnlyNotifyingForMentions) {
|
||||
count += [thread unreadMentionMessageCountWithTransaction:transaction];
|
||||
} else {
|
||||
count += [thread unreadMessageCountWithTransaction:transaction];
|
||||
}
|
||||
}
|
||||
}];
|
||||
|
||||
|
|
|
@ -52,7 +52,7 @@ public class ThreadViewModel: NSObject {
|
|||
|
||||
self.unreadCount = thread.unreadMessageCount(transaction: transaction)
|
||||
self.hasUnreadMessages = unreadCount > 0
|
||||
self.hasUnreadMentions = thread.hasUnreadMentionMessage
|
||||
self.hasUnreadMentions = thread.unreadMentionMessageCount(with: transaction) > 0
|
||||
}
|
||||
|
||||
@objc
|
||||
|
|
Loading…
Reference in New Issue