From 798b54124158bbb19e6083ab44fe4b5a157e61a7 Mon Sep 17 00:00:00 2001 From: ryanzhao Date: Mon, 26 Jul 2021 15:42:04 +1000 Subject: [PATCH 1/8] add UI in conversation settings --- .../OWSConversationSettingsViewController.m | 65 ++++++++++++++++++ .../NotifyMentions.imageset/Contents.json | 23 +++++++ .../ic_notification_mentions-1.png | Bin 0 -> 2527 bytes .../ic_notification_mentions-2.png | Bin 0 -> 2527 bytes .../ic_notification_mentions.png | Bin 0 -> 2527 bytes .../Translations/en.lproj/Localizable.strings | 2 + 6 files changed, 90 insertions(+) create mode 100644 Session/Meta/Images.xcassets/Session/NotifyMentions.imageset/Contents.json create mode 100644 Session/Meta/Images.xcassets/Session/NotifyMentions.imageset/ic_notification_mentions-1.png create mode 100644 Session/Meta/Images.xcassets/Session/NotifyMentions.imageset/ic_notification_mentions-2.png create mode 100644 Session/Meta/Images.xcassets/Session/NotifyMentions.imageset/ic_notification_mentions.png diff --git a/Session/Conversations/Settings/OWSConversationSettingsViewController.m b/Session/Conversations/Settings/OWSConversationSettingsViewController.m index 62f475e15..16f4fc84f 100644 --- a/Session/Conversations/Settings/OWSConversationSettingsViewController.m +++ b/Session/Conversations/Settings/OWSConversationSettingsViewController.m @@ -318,6 +318,55 @@ CGFloat kIconViewLength = 24; } actionBlock:^{ [weakSelf inviteUsersToOpenGroup]; }]]; + + // Notification Settings + [section addItem:[OWSTableItem itemWithCustomCellBlock:^{ + UITableViewCell *cell = [OWSTableItem newCell]; + OWSConversationSettingsViewController *strongSelf = weakSelf; + OWSCAssertDebug(strongSelf); + cell.preservesSuperviewLayoutMargins = YES; + cell.contentView.preservesSuperviewLayoutMargins = YES; + cell.selectionStyle = UITableViewCellSelectionStyleNone; + + UIImageView *iconView = [strongSelf viewForIconWithName:@"NotifyMentions"]; + + UILabel *rowLabel = [UILabel new]; + rowLabel.text = NSLocalizedString( + @"CONVERSATION_SETTINGS_NOTIFICATION", @""); + rowLabel.textColor = LKColors.text; + rowLabel.font = [UIFont systemFontOfSize:LKValues.mediumFontSize]; + rowLabel.lineBreakMode = NSLineBreakByTruncatingTail; + + UISwitch *switchView = [UISwitch new]; + switchView.on = ((TSGroupThread *)strongSelf.thread).isOnlyNotifyMentions; + [switchView addTarget:strongSelf action:@selector(notifyMentionsSwitchValueDidChange:) + forControlEvents:UIControlEventValueChanged]; + + UIStackView *topRow = + [[UIStackView alloc] initWithArrangedSubviews:@[ iconView, rowLabel, switchView ]]; + topRow.spacing = strongSelf.iconSpacing; + topRow.alignment = UIStackViewAlignmentCenter; + [cell.contentView addSubview:topRow]; + [topRow autoPinEdgesToSuperviewMarginsExcludingEdge:ALEdgeBottom]; + + UILabel *subtitleLabel = [UILabel new]; + subtitleLabel.text = NSLocalizedString(@"When enabled, only messages mentioned you will be notified.", @""); + subtitleLabel.textColor = LKColors.text; + subtitleLabel.font = [UIFont systemFontOfSize:LKValues.smallFontSize]; + subtitleLabel.numberOfLines = 0; + subtitleLabel.lineBreakMode = NSLineBreakByWordWrapping; + [cell.contentView addSubview:subtitleLabel]; + [subtitleLabel autoPinEdge:ALEdgeTop toEdge:ALEdgeBottom ofView:topRow withOffset:8]; + [subtitleLabel autoPinEdge:ALEdgeLeading toEdge:ALEdgeLeading ofView:rowLabel]; + [subtitleLabel autoPinTrailingToSuperviewMargin]; + [subtitleLabel autoPinBottomToSuperviewMargin]; + + cell.userInteractionEnabled = !strongSelf.hasLeftGroup; + + cell.accessibilityIdentifier = ACCESSIBILITY_IDENTIFIER_WITH_NAME(OWSConversationSettingsViewController, @"notify_mentions_only"); + + return cell; + } customRowHeight:UITableViewAutomaticDimension actionBlock:nil]]; } // Search @@ -947,6 +996,22 @@ CGFloat kIconViewLength = 24; [self.conversationSettingsViewDelegate conversationSettingsDidRequestConversationSearch:self]; } +- (void)notifyMentionsSwitchValueDidChange:(id)sender +{ + UISwitch *uiSwitch = (UISwitch *)sender; + if (uiSwitch.isOn) { + [LKStorage writeWithBlock:^(YapDatabaseReadWriteTransaction *transaction) { + ((TSGroupThread *)self.thread).isOnlyNotifyMentions = true; + [self.thread saveWithTransaction:transaction]; + }]; + } else { + [LKStorage writeWithBlock:^(YapDatabaseReadWriteTransaction *transaction) { + ((TSGroupThread *)self.thread).isOnlyNotifyMentions = false; + [self.thread saveWithTransaction:transaction]; + }]; + } +} + - (void)hideEditNameUI { self.isEditingDisplayName = NO; diff --git a/Session/Meta/Images.xcassets/Session/NotifyMentions.imageset/Contents.json b/Session/Meta/Images.xcassets/Session/NotifyMentions.imageset/Contents.json new file mode 100644 index 000000000..60527f39d --- /dev/null +++ b/Session/Meta/Images.xcassets/Session/NotifyMentions.imageset/Contents.json @@ -0,0 +1,23 @@ +{ + "images" : [ + { + "filename" : "ic_notification_mentions.png", + "idiom" : "universal", + "scale" : "1x" + }, + { + "filename" : "ic_notification_mentions-1.png", + "idiom" : "universal", + "scale" : "2x" + }, + { + "filename" : "ic_notification_mentions-2.png", + "idiom" : "universal", + "scale" : "3x" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/Session/Meta/Images.xcassets/Session/NotifyMentions.imageset/ic_notification_mentions-1.png b/Session/Meta/Images.xcassets/Session/NotifyMentions.imageset/ic_notification_mentions-1.png new file mode 100644 index 0000000000000000000000000000000000000000..fe39a8b3566e28a7e49d515e69bfe566a6311dc5 GIT binary patch literal 2527 zcmV<52_W`~P)EX>4Tx04R}tkvmAkP!xv$rb%@B6cQ)SShDfJi*c4AUmwAfDc| z4bJ<-5muB{;&b9rlP*a7$aTfzH_io@1)do()2Vsl2(egbW2KE*(bR~ih@+~eQ@)V# zSmnIMSu0mr^Pc>L;hes*%yn8rNMI35kRU=q6(y8mBSyPUiiH%N$9?>Ru3sXTLaq`R zITlcX2HEw4|H1FsTKUNdFDV=cI$s>;V;BhS0*#vEd>=bb;{*sk16O*>U#SB#pQP7X zTJ#9$-3BhMTbi;5Tk8{ps& z7%5Qpy3f12+UNFfPjh}hj&gFc8p;+|00006VoOIv00000008+zyMF)x010qNS#tmY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?SgdiK)QTB^ z6qst~%O2ET&{~CTAOPT5kLlmm5fDECAa*jU#@^}Urf>vULR0j+A5S1QWjF$2#$|YK zcU^|L``i%_5^a3k2UWlvM8a*pBOo3$LnK?7>?xiOJcbCZwg4`21lU0y@KOkuL739Y z5uit@hZoclkVf8Sh=1EOOg8}~ zh)l2!I9MaWbRE!93cr1bF&ZJxhfd%mBC!@k(rWUaujEt9&vK!+^$6#)jL#sVU2uMX zKqg3-g*f#k^l>zKhQeP??qr&s;(RJ$6&G$5O(wXK^LrPH3Ab?%ITIcvrZa(xG0Um1 z>t!w?r_>2QgJq6Q5}feUM1pRY;IG7U+H7q{7et!mqNrx5Gd07bBuHiFjLTtXoP#4E z_n}(}k9VR8jm=I34h{|u4kpOUqI+pVxZ@;s*b98-C^km}%+K>TDf4pSp|fcnP>I1g zn*p%f5fB^;v$U@|gMpUR&pzV+eO0Z6jlEn?J28ewCq$NVSm7_B7XJA<6RIf8517~E peF~yO0CY$E(>F*surSvi@;@hP47aC4Od Date: Mon, 26 Jul 2021 15:42:45 +1000 Subject: [PATCH 2/8] add thread flag for only notifying mentiongs --- SessionMessagingKit/Threads/TSGroupThread.h | 1 + SignalUtilitiesKit/Messaging/ThreadViewModel.swift | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/SessionMessagingKit/Threads/TSGroupThread.h b/SessionMessagingKit/Threads/TSGroupThread.h index 659ddd897..297ab5504 100644 --- a/SessionMessagingKit/Threads/TSGroupThread.h +++ b/SessionMessagingKit/Threads/TSGroupThread.h @@ -18,6 +18,7 @@ extern NSString *const TSGroupThread_NotificationKey_UniqueId; @property (nonatomic, strong) TSGroupModel *groupModel; @property (nonatomic, readonly) BOOL isOpenGroup; @property (nonatomic, readonly) BOOL isClosedGroup; +@property (nonatomic) BOOL isOnlyNotifyMentions; + (instancetype)getOrCreateThreadWithGroupModel:(TSGroupModel *)groupModel; + (instancetype)getOrCreateThreadWithGroupModel:(TSGroupModel *)groupModel diff --git a/SignalUtilitiesKit/Messaging/ThreadViewModel.swift b/SignalUtilitiesKit/Messaging/ThreadViewModel.swift index 98bbf91d5..6b1f0ef60 100644 --- a/SignalUtilitiesKit/Messaging/ThreadViewModel.swift +++ b/SignalUtilitiesKit/Messaging/ThreadViewModel.swift @@ -14,6 +14,7 @@ public class ThreadViewModel: NSObject { @objc public let contactSessionID: String? @objc public let name: String @objc public let isMuted: Bool + @objc public let isOnlyNotifyMentions: Bool var isContactThread: Bool { return !isGroupThread @@ -39,6 +40,12 @@ public class ThreadViewModel: NSObject { } else { self.contactSessionID = nil } + + if let groupThread = thread as? TSGroupThread { + self.isOnlyNotifyMentions = groupThread.isOnlyNotifyMentions + } else { + self.isOnlyNotifyMentions = false + } self.unreadCount = thread.unreadMessageCount(transaction: transaction) self.hasUnreadMessages = unreadCount > 0 From 354b7e0dc36cce4d3d0f73fcf2de60cb39a3570d Mon Sep 17 00:00:00 2001 From: ryanzhao Date: Mon, 26 Jul 2021 15:43:03 +1000 Subject: [PATCH 3/8] notify mentions as settings --- Session/Notifications/AppNotifications.swift | 7 +++++++ Session/Utilities/MentionUtilities.swift | 5 +++++ 2 files changed, 12 insertions(+) diff --git a/Session/Notifications/AppNotifications.swift b/Session/Notifications/AppNotifications.swift index 3ba8d5e62..42280c493 100644 --- a/Session/Notifications/AppNotifications.swift +++ b/Session/Notifications/AppNotifications.swift @@ -165,6 +165,13 @@ public class NotificationPresenter: NSObject, NotificationsProtocol { // see https://developer.apple.com/documentation/uikit/uilocalnotification/1616646-alertbody // for more details. let messageText = DisplayableText.filterNotificationText(rawMessageText) + + // Do not fire the notification wihtout mentioning current user, + // if current user sets isOnlyNotifyMentions on. + let isUserMentioned = MentionUtilities.isUserMentioned(in: messageText ?? "") + if let groupThread = thread as? TSGroupThread, groupThread.isOnlyNotifyMentions && !isUserMentioned { + return + } let context = Contact.context(for: thread) let senderName = Storage.shared.getContact(with: incomingMessage.authorId)?.displayName(for: context) ?? incomingMessage.authorId diff --git a/Session/Utilities/MentionUtilities.swift b/Session/Utilities/MentionUtilities.swift index 1a39cb1fa..5c888b09d 100644 --- a/Session/Utilities/MentionUtilities.swift +++ b/Session/Utilities/MentionUtilities.swift @@ -44,4 +44,9 @@ public final class MentionUtilities : NSObject { } return result } + + public static func isUserMentioned(in string: String) -> Bool { + let userPublicKey = getUserHexEncodedPublicKey() + return string.contains("@\(userPublicKey)") + } } From b5d1ccdbc3ed155ecc7d8ca98952d557225cf306 Mon Sep 17 00:00:00 2001 From: ryanzhao Date: Mon, 26 Jul 2021 15:43:33 +1000 Subject: [PATCH 4/8] add only notify mentions icon in home screen cells --- Session/Shared/ConversationCell.swift | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Session/Shared/ConversationCell.swift b/Session/Shared/ConversationCell.swift index d2f827a3b..e2e0f58d2 100644 --- a/Session/Shared/ConversationCell.swift +++ b/Session/Shared/ConversationCell.swift @@ -230,6 +230,13 @@ final class ConversationCell : UITableViewCell { let result = NSMutableAttributedString() if threadViewModel.isMuted { result.append(NSAttributedString(string: "\u{e067} ", attributes: [ .font : UIFont.ows_elegantIconsFont(10), .foregroundColor : Colors.unimportant ])) + } else if threadViewModel.isOnlyNotifyMentions { + let imageAttachment = NSTextAttachment() + imageAttachment.image = UIImage(named: "NotifyMentions.png")?.asTintedImage(color: Colors.unimportant) + imageAttachment.bounds = CGRect(x: 0, y: -2, width: Values.smallFontSize, height: Values.smallFontSize) + let imageString = NSAttributedString(attachment: imageAttachment) + result.append(imageString) + result.append(NSAttributedString(string: " ", attributes: [ .font : UIFont.ows_elegantIconsFont(10), .foregroundColor : Colors.unimportant ])) } if let rawSnippet = threadViewModel.lastMessageText { let snippet = MentionUtilities.highlightMentions(in: rawSnippet, threadID: threadViewModel.threadRecord.uniqueId!) From 0181b57f1a855feb2739d34368c625c4e3714d26 Mon Sep 17 00:00:00 2001 From: ryanzhao Date: Mon, 26 Jul 2021 16:15:47 +1000 Subject: [PATCH 5/8] add only notify mentions subtitle in conversation creen --- .../ConversationTitleView.swift | 32 ++++++++++++------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/Session/Conversations/Views & Modals/ConversationTitleView.swift b/Session/Conversations/Views & Modals/ConversationTitleView.swift index 1604490ad..da4680d5b 100644 --- a/Session/Conversations/Views & Modals/ConversationTitleView.swift +++ b/Session/Conversations/Views & Modals/ConversationTitleView.swift @@ -86,22 +86,32 @@ final class ConversationTitleView : UIView { } private func getSubtitle() -> NSAttributedString? { + let result = NSMutableAttributedString() if thread.isMuted { - let result = NSMutableAttributedString() result.append(NSAttributedString(string: "\u{e067} ", attributes: [ .font : UIFont.ows_elegantIconsFont(10), .foregroundColor : Colors.text ])) result.append(NSAttributedString(string: "Muted")) return result } else if let thread = self.thread as? TSGroupThread { - var userCount: UInt64? - switch thread.groupModel.groupType { - case .closedGroup: userCount = UInt64(thread.groupModel.groupMemberIds.count) - case .openGroup: - guard let openGroupV2 = Storage.shared.getV2OpenGroup(for: self.thread.uniqueId!) else { return nil } - userCount = Storage.shared.getUserCount(forV2OpenGroupWithID: openGroupV2.id) - default: break - } - if let userCount = userCount { - return NSAttributedString(string: "\(userCount) members") + if thread.isOnlyNotifyMentions { + let imageAttachment = NSTextAttachment() + imageAttachment.image = UIImage(named: "NotifyMentions.png")?.asTintedImage(color: Colors.text) + imageAttachment.bounds = CGRect(x: 0, y: -2, width: Values.smallFontSize, height: Values.smallFontSize) + let imageString = NSAttributedString(attachment: imageAttachment) + result.append(imageString) + result.append(NSAttributedString(string: " Only Notify Mentions")) + return result + } else { + var userCount: UInt64? + switch thread.groupModel.groupType { + case .closedGroup: userCount = UInt64(thread.groupModel.groupMemberIds.count) + case .openGroup: + guard let openGroupV2 = Storage.shared.getV2OpenGroup(for: self.thread.uniqueId!) else { return nil } + userCount = Storage.shared.getUserCount(forV2OpenGroupWithID: openGroupV2.id) + default: break + } + if let userCount = userCount { + return NSAttributedString(string: "\(userCount) members") + } } } return nil From b0e03f5dfd9ca71c0da4abf302882d3179d2f0e8 Mon Sep 17 00:00:00 2001 From: ryanzhao Date: Mon, 26 Jul 2021 16:16:14 +1000 Subject: [PATCH 6/8] update subtitle status in conversation screen instantly --- .../Settings/OWSConversationSettingsViewController.m | 6 ++---- SessionMessagingKit/Threads/TSGroupThread.h | 1 + SessionMessagingKit/Threads/TSGroupThread.m | 11 +++++++++++ 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/Session/Conversations/Settings/OWSConversationSettingsViewController.m b/Session/Conversations/Settings/OWSConversationSettingsViewController.m index 16f4fc84f..0e27958f8 100644 --- a/Session/Conversations/Settings/OWSConversationSettingsViewController.m +++ b/Session/Conversations/Settings/OWSConversationSettingsViewController.m @@ -1001,13 +1001,11 @@ CGFloat kIconViewLength = 24; UISwitch *uiSwitch = (UISwitch *)sender; if (uiSwitch.isOn) { [LKStorage writeWithBlock:^(YapDatabaseReadWriteTransaction *transaction) { - ((TSGroupThread *)self.thread).isOnlyNotifyMentions = true; - [self.thread saveWithTransaction:transaction]; + [(TSGroupThread *)self.thread setIsOnlyNotifyMentions:true withTransaction:transaction]; }]; } else { [LKStorage writeWithBlock:^(YapDatabaseReadWriteTransaction *transaction) { - ((TSGroupThread *)self.thread).isOnlyNotifyMentions = false; - [self.thread saveWithTransaction:transaction]; + [(TSGroupThread *)self.thread setIsOnlyNotifyMentions:false withTransaction:transaction]; }]; } } diff --git a/SessionMessagingKit/Threads/TSGroupThread.h b/SessionMessagingKit/Threads/TSGroupThread.h index 297ab5504..aa55f60f7 100644 --- a/SessionMessagingKit/Threads/TSGroupThread.h +++ b/SessionMessagingKit/Threads/TSGroupThread.h @@ -45,6 +45,7 @@ extern NSString *const TSGroupThread_NotificationKey_UniqueId; transaction:(YapDatabaseReadWriteTransaction *)transaction; - (void)setGroupModel:(TSGroupModel *)newGroupModel withTransaction:(YapDatabaseReadWriteTransaction *)transaction; +- (void)setIsOnlyNotifyMentions:(BOOL)isOnlyNotifyMentions withTransaction:(YapDatabaseReadWriteTransaction *)transaction; - (void)leaveGroupWithSneakyTransaction; - (void)leaveGroupWithTransaction:(YapDatabaseReadWriteTransaction *)transaction; diff --git a/SessionMessagingKit/Threads/TSGroupThread.m b/SessionMessagingKit/Threads/TSGroupThread.m index 542a2bb4e..e0a94401b 100644 --- a/SessionMessagingKit/Threads/TSGroupThread.m +++ b/SessionMessagingKit/Threads/TSGroupThread.m @@ -208,6 +208,17 @@ NSString *const TSGroupThread_NotificationKey_UniqueId = @"TSGroupThread_Notific }]; } +- (void)setIsOnlyNotifyMentions:(BOOL)isOnlyNotifyMentions withTransaction:(YapDatabaseReadWriteTransaction *)transaction +{ + self.isOnlyNotifyMentions = isOnlyNotifyMentions; + + [self saveWithTransaction:transaction]; + + [transaction addCompletionQueue:dispatch_get_main_queue() completionBlock:^{ + [NSNotificationCenter.defaultCenter postNotificationName:NSNotification.groupThreadUpdated object:self.uniqueId]; + }]; +} + - (void)leaveGroupWithSneakyTransaction { [LKStorage writeSyncWithBlock:^(YapDatabaseReadWriteTransaction *_Nonnull transaction) { From 25b9b0604434211b0a745633356c98137666202f Mon Sep 17 00:00:00 2001 From: ryanzhao Date: Tue, 27 Jul 2021 14:45:23 +1000 Subject: [PATCH 7/8] fix unread count not disappear after scrolling to bottom --- Session/Conversations/ConversationVC+Interaction.swift | 1 + 1 file changed, 1 insertion(+) diff --git a/Session/Conversations/ConversationVC+Interaction.swift b/Session/Conversations/ConversationVC+Interaction.swift index 61ac11d40..89ae4dc4e 100644 --- a/Session/Conversations/ConversationVC+Interaction.swift +++ b/Session/Conversations/ConversationVC+Interaction.swift @@ -22,6 +22,7 @@ extension ConversationVC : InputViewDelegate, MessageCellDelegate, ContextMenuAc // so the result may be inaccurate before all the cells are loaded. Use this // to scroll to the last row instead. let indexPath = IndexPath(row: viewItems.count - 1, section: 0) + unreadViewItems.removeAll() messagesTableView.scrollToRow(at: indexPath, at: .top, animated: true) } From 483ed4792f9dfbaf4234d61ff1220d6a98ee63ba Mon Sep 17 00:00:00 2001 From: Niels Andriesse Date: Thu, 29 Jul 2021 10:14:06 +1000 Subject: [PATCH 8/8] Fix localization & clean --- .../OWSConversationSettingsViewController.m | 114 +++++++++--------- .../ConversationTitleView.swift | 11 +- .../Translations/de.lproj/Localizable.strings | 3 + .../Translations/en.lproj/Localizable.strings | 5 +- .../Translations/es.lproj/Localizable.strings | 3 + .../Translations/fa.lproj/Localizable.strings | 3 + .../Translations/fi.lproj/Localizable.strings | 3 + .../Translations/fr.lproj/Localizable.strings | 3 + .../Translations/hi.lproj/Localizable.strings | 3 + .../Translations/hr.lproj/Localizable.strings | 3 + .../id-ID.lproj/Localizable.strings | 3 + .../Translations/it.lproj/Localizable.strings | 3 + .../Translations/ja.lproj/Localizable.strings | 3 + .../Translations/nl.lproj/Localizable.strings | 3 + .../Translations/pl.lproj/Localizable.strings | 3 + .../pt_BR.lproj/Localizable.strings | 3 + .../Translations/ru.lproj/Localizable.strings | 3 + .../Translations/sk.lproj/Localizable.strings | 3 + .../Translations/sv.lproj/Localizable.strings | 3 + .../Translations/th.lproj/Localizable.strings | 3 + .../vi-VN.lproj/Localizable.strings | 3 + .../zh-Hant.lproj/Localizable.strings | 3 + .../zh_CN.lproj/Localizable.strings | 3 + Session/Notifications/AppNotifications.swift | 6 +- Session/Shared/ConversationCell.swift | 2 +- SessionMessagingKit/Threads/TSGroupThread.h | 4 +- SessionMessagingKit/Threads/TSGroupThread.m | 4 +- .../Messaging/ThreadViewModel.swift | 6 +- 28 files changed, 135 insertions(+), 77 deletions(-) diff --git a/Session/Conversations/Settings/OWSConversationSettingsViewController.m b/Session/Conversations/Settings/OWSConversationSettingsViewController.m index 0e27958f8..4f54af7c5 100644 --- a/Session/Conversations/Settings/OWSConversationSettingsViewController.m +++ b/Session/Conversations/Settings/OWSConversationSettingsViewController.m @@ -318,55 +318,6 @@ CGFloat kIconViewLength = 24; } actionBlock:^{ [weakSelf inviteUsersToOpenGroup]; }]]; - - // Notification Settings - [section addItem:[OWSTableItem itemWithCustomCellBlock:^{ - UITableViewCell *cell = [OWSTableItem newCell]; - OWSConversationSettingsViewController *strongSelf = weakSelf; - OWSCAssertDebug(strongSelf); - cell.preservesSuperviewLayoutMargins = YES; - cell.contentView.preservesSuperviewLayoutMargins = YES; - cell.selectionStyle = UITableViewCellSelectionStyleNone; - - UIImageView *iconView = [strongSelf viewForIconWithName:@"NotifyMentions"]; - - UILabel *rowLabel = [UILabel new]; - rowLabel.text = NSLocalizedString( - @"CONVERSATION_SETTINGS_NOTIFICATION", @""); - rowLabel.textColor = LKColors.text; - rowLabel.font = [UIFont systemFontOfSize:LKValues.mediumFontSize]; - rowLabel.lineBreakMode = NSLineBreakByTruncatingTail; - - UISwitch *switchView = [UISwitch new]; - switchView.on = ((TSGroupThread *)strongSelf.thread).isOnlyNotifyMentions; - [switchView addTarget:strongSelf action:@selector(notifyMentionsSwitchValueDidChange:) - forControlEvents:UIControlEventValueChanged]; - - UIStackView *topRow = - [[UIStackView alloc] initWithArrangedSubviews:@[ iconView, rowLabel, switchView ]]; - topRow.spacing = strongSelf.iconSpacing; - topRow.alignment = UIStackViewAlignmentCenter; - [cell.contentView addSubview:topRow]; - [topRow autoPinEdgesToSuperviewMarginsExcludingEdge:ALEdgeBottom]; - - UILabel *subtitleLabel = [UILabel new]; - subtitleLabel.text = NSLocalizedString(@"When enabled, only messages mentioned you will be notified.", @""); - subtitleLabel.textColor = LKColors.text; - subtitleLabel.font = [UIFont systemFontOfSize:LKValues.smallFontSize]; - subtitleLabel.numberOfLines = 0; - subtitleLabel.lineBreakMode = NSLineBreakByWordWrapping; - [cell.contentView addSubview:subtitleLabel]; - [subtitleLabel autoPinEdge:ALEdgeTop toEdge:ALEdgeBottom ofView:topRow withOffset:8]; - [subtitleLabel autoPinEdge:ALEdgeLeading toEdge:ALEdgeLeading ofView:rowLabel]; - [subtitleLabel autoPinTrailingToSuperviewMargin]; - [subtitleLabel autoPinBottomToSuperviewMargin]; - - cell.userInteractionEnabled = !strongSelf.hasLeftGroup; - - cell.accessibilityIdentifier = ACCESSIBILITY_IDENTIFIER_WITH_NAME(OWSConversationSettingsViewController, @"notify_mentions_only"); - - return cell; - } customRowHeight:UITableViewAutomaticDimension actionBlock:nil]]; } // Search @@ -564,6 +515,56 @@ CGFloat kIconViewLength = 24; [weakSelf.navigationController pushViewController:vc animated:YES]; }]]; + if (self.isOpenGroup) { + // Notification Settings + [section addItem:[OWSTableItem itemWithCustomCellBlock:^{ + UITableViewCell *cell = [OWSTableItem newCell]; + OWSConversationSettingsViewController *strongSelf = weakSelf; + OWSCAssertDebug(strongSelf); + cell.preservesSuperviewLayoutMargins = YES; + cell.contentView.preservesSuperviewLayoutMargins = YES; + cell.selectionStyle = UITableViewCellSelectionStyleNone; + + UIImageView *iconView = [strongSelf viewForIconWithName:@"NotifyMentions"]; + + UILabel *rowLabel = [UILabel new]; + rowLabel.text = NSLocalizedString(@"vc_conversation_settings_notify_for_mentions_only_title", @""); + rowLabel.textColor = LKColors.text; + rowLabel.font = [UIFont systemFontOfSize:LKValues.mediumFontSize]; + rowLabel.lineBreakMode = NSLineBreakByTruncatingTail; + + UISwitch *switchView = [UISwitch new]; + switchView.on = ((TSGroupThread *)strongSelf.thread).isOnlyNotifyingForMentions; + [switchView addTarget:strongSelf action:@selector(notifyForMentionsOnlySwitchValueDidChange:) + forControlEvents:UIControlEventValueChanged]; + + UIStackView *topRow = + [[UIStackView alloc] initWithArrangedSubviews:@[ iconView, rowLabel, switchView ]]; + topRow.spacing = strongSelf.iconSpacing; + topRow.alignment = UIStackViewAlignmentCenter; + [cell.contentView addSubview:topRow]; + [topRow autoPinEdgesToSuperviewMarginsExcludingEdge:ALEdgeBottom]; + + UILabel *subtitleLabel = [UILabel new]; + subtitleLabel.text = NSLocalizedString(@"When enabled, only messages mentioned you will be notified.", @""); + subtitleLabel.textColor = LKColors.text; + subtitleLabel.font = [UIFont systemFontOfSize:LKValues.smallFontSize]; + subtitleLabel.numberOfLines = 0; + subtitleLabel.lineBreakMode = NSLineBreakByWordWrapping; + [cell.contentView addSubview:subtitleLabel]; + [subtitleLabel autoPinEdge:ALEdgeTop toEdge:ALEdgeBottom ofView:topRow withOffset:8]; + [subtitleLabel autoPinEdge:ALEdgeLeading toEdge:ALEdgeLeading ofView:rowLabel]; + [subtitleLabel autoPinTrailingToSuperviewMargin]; + [subtitleLabel autoPinBottomToSuperviewMargin]; + + cell.userInteractionEnabled = !strongSelf.hasLeftGroup; + + cell.accessibilityIdentifier = ACCESSIBILITY_IDENTIFIER_WITH_NAME(OWSConversationSettingsViewController, @"notify_for_mentions_only"); + + return cell; + } customRowHeight:UITableViewAutomaticDimension actionBlock:nil]]; + } + // Mute thread [section addItem:[OWSTableItem itemWithCustomCellBlock:^{ OWSConversationSettingsViewController *strongSelf = weakSelf; @@ -996,18 +997,13 @@ CGFloat kIconViewLength = 24; [self.conversationSettingsViewDelegate conversationSettingsDidRequestConversationSearch:self]; } -- (void)notifyMentionsSwitchValueDidChange:(id)sender +- (void)notifyForMentionsOnlySwitchValueDidChange:(id)sender { UISwitch *uiSwitch = (UISwitch *)sender; - if (uiSwitch.isOn) { - [LKStorage writeWithBlock:^(YapDatabaseReadWriteTransaction *transaction) { - [(TSGroupThread *)self.thread setIsOnlyNotifyMentions:true withTransaction:transaction]; - }]; - } else { - [LKStorage writeWithBlock:^(YapDatabaseReadWriteTransaction *transaction) { - [(TSGroupThread *)self.thread setIsOnlyNotifyMentions:false withTransaction:transaction]; - }]; - } + BOOL isEnabled = uiSwitch.isOn; + [LKStorage writeWithBlock:^(YapDatabaseReadWriteTransaction *transaction) { + [(TSGroupThread *)self.thread setisOnlyNotifyingForMentions:isEnabled withTransaction:transaction]; + }]; } - (void)hideEditNameUI diff --git a/Session/Conversations/Views & Modals/ConversationTitleView.swift b/Session/Conversations/Views & Modals/ConversationTitleView.swift index da4680d5b..d80912b29 100644 --- a/Session/Conversations/Views & Modals/ConversationTitleView.swift +++ b/Session/Conversations/Views & Modals/ConversationTitleView.swift @@ -92,13 +92,14 @@ final class ConversationTitleView : UIView { result.append(NSAttributedString(string: "Muted")) return result } else if let thread = self.thread as? TSGroupThread { - if thread.isOnlyNotifyMentions { + if thread.isOnlyNotifyingForMentions { let imageAttachment = NSTextAttachment() - imageAttachment.image = UIImage(named: "NotifyMentions.png")?.asTintedImage(color: Colors.text) + let color: UIColor = isDarkMode ? .white : .black + imageAttachment.image = UIImage(named: "NotifyMentions.png")?.asTintedImage(color: color) imageAttachment.bounds = CGRect(x: 0, y: -2, width: Values.smallFontSize, height: Values.smallFontSize) - let imageString = NSAttributedString(attachment: imageAttachment) - result.append(imageString) - result.append(NSAttributedString(string: " Only Notify Mentions")) + let imageAsString = NSAttributedString(attachment: imageAttachment) + result.append(imageAsString) + result.append(NSAttributedString(string: " " + NSLocalizedString("view_conversation_title_notify_for_mentions_only", comment: ""))) return result } else { var userCount: UInt64? diff --git a/Session/Meta/Translations/de.lproj/Localizable.strings b/Session/Meta/Translations/de.lproj/Localizable.strings index edbde38f7..6c0dca3f4 100644 --- a/Session/Meta/Translations/de.lproj/Localizable.strings +++ b/Session/Meta/Translations/de.lproj/Localizable.strings @@ -546,3 +546,6 @@ "modal_send_seed_title" = "Warning"; "modal_send_seed_explanation" = "This is your recovery phrase. If you send it to someone they'll have full access to your account."; "modal_send_seed_send_button_title" = "Send"; +"vc_conversation_settings_notify_for_mentions_only_title" = "Notify for Mentions Only"; +"vc_conversation_settings_notify_for_mentions_only_explanation" = "When enabled, you'll only be notified for messages mentioning you."; +"view_conversation_title_notify_for_mentions_only" = "Notifying for Mentions Only"; diff --git a/Session/Meta/Translations/en.lproj/Localizable.strings b/Session/Meta/Translations/en.lproj/Localizable.strings index 7d9603cd7..5ae81cb62 100644 --- a/Session/Meta/Translations/en.lproj/Localizable.strings +++ b/Session/Meta/Translations/en.lproj/Localizable.strings @@ -136,8 +136,6 @@ "CONVERSATION_SETTINGS_MUTED_UNTIL_FORMAT" = "until %@"; /* Table cell label in conversation settings which returns the user to the conversation with 'search mode' activated */ "CONVERSATION_SETTINGS_SEARCH" = "Search Conversation"; -/* Table cell label in conversation settings which returns the user to the conversation with 'notification settings' activated */ -"CONVERSATION_SETTINGS_NOTIFICATION" = "Notify Mentions Only"; /* Label for button to unmute a thread. */ "CONVERSATION_SETTINGS_UNMUTE_ACTION" = "Unmute"; /* Title for the 'crop/scale image' dialog. */ @@ -548,3 +546,6 @@ "modal_send_seed_title" = "Warning"; "modal_send_seed_explanation" = "This is your recovery phrase. If you send it to someone they'll have full access to your account."; "modal_send_seed_send_button_title" = "Send"; +"vc_conversation_settings_notify_for_mentions_only_title" = "Notify for Mentions Only"; +"vc_conversation_settings_notify_for_mentions_only_explanation" = "When enabled, you'll only be notified for messages mentioning you."; +"view_conversation_title_notify_for_mentions_only" = "Notifying for Mentions Only"; diff --git a/Session/Meta/Translations/es.lproj/Localizable.strings b/Session/Meta/Translations/es.lproj/Localizable.strings index 2c758a958..3c05898e9 100644 --- a/Session/Meta/Translations/es.lproj/Localizable.strings +++ b/Session/Meta/Translations/es.lproj/Localizable.strings @@ -546,3 +546,6 @@ "modal_send_seed_title" = "Warning"; "modal_send_seed_explanation" = "This is your recovery phrase. If you send it to someone they'll have full access to your account."; "modal_send_seed_send_button_title" = "Send"; +"vc_conversation_settings_notify_for_mentions_only_title" = "Notify for Mentions Only"; +"vc_conversation_settings_notify_for_mentions_only_explanation" = "When enabled, you'll only be notified for messages mentioning you."; +"view_conversation_title_notify_for_mentions_only" = "Notifying for Mentions Only"; diff --git a/Session/Meta/Translations/fa.lproj/Localizable.strings b/Session/Meta/Translations/fa.lproj/Localizable.strings index 8c7f27588..2f210126b 100644 --- a/Session/Meta/Translations/fa.lproj/Localizable.strings +++ b/Session/Meta/Translations/fa.lproj/Localizable.strings @@ -546,3 +546,6 @@ "modal_send_seed_title" = "Warning"; "modal_send_seed_explanation" = "This is your recovery phrase. If you send it to someone they'll have full access to your account."; "modal_send_seed_send_button_title" = "Send"; +"vc_conversation_settings_notify_for_mentions_only_title" = "Notify for Mentions Only"; +"vc_conversation_settings_notify_for_mentions_only_explanation" = "When enabled, you'll only be notified for messages mentioning you."; +"view_conversation_title_notify_for_mentions_only" = "Notifying for Mentions Only"; diff --git a/Session/Meta/Translations/fi.lproj/Localizable.strings b/Session/Meta/Translations/fi.lproj/Localizable.strings index 058f05a0d..ba0488b5c 100644 --- a/Session/Meta/Translations/fi.lproj/Localizable.strings +++ b/Session/Meta/Translations/fi.lproj/Localizable.strings @@ -546,3 +546,6 @@ "modal_send_seed_title" = "Warning"; "modal_send_seed_explanation" = "This is your recovery phrase. If you send it to someone they'll have full access to your account."; "modal_send_seed_send_button_title" = "Send"; +"vc_conversation_settings_notify_for_mentions_only_title" = "Notify for Mentions Only"; +"vc_conversation_settings_notify_for_mentions_only_explanation" = "When enabled, you'll only be notified for messages mentioning you."; +"view_conversation_title_notify_for_mentions_only" = "Notifying for Mentions Only"; diff --git a/Session/Meta/Translations/fr.lproj/Localizable.strings b/Session/Meta/Translations/fr.lproj/Localizable.strings index 116e66da9..3f3615722 100644 --- a/Session/Meta/Translations/fr.lproj/Localizable.strings +++ b/Session/Meta/Translations/fr.lproj/Localizable.strings @@ -546,3 +546,6 @@ "modal_send_seed_title" = "Warning"; "modal_send_seed_explanation" = "This is your recovery phrase. If you send it to someone they'll have full access to your account."; "modal_send_seed_send_button_title" = "Send"; +"vc_conversation_settings_notify_for_mentions_only_title" = "Notify for Mentions Only"; +"vc_conversation_settings_notify_for_mentions_only_explanation" = "When enabled, you'll only be notified for messages mentioning you."; +"view_conversation_title_notify_for_mentions_only" = "Notifying for Mentions Only"; diff --git a/Session/Meta/Translations/hi.lproj/Localizable.strings b/Session/Meta/Translations/hi.lproj/Localizable.strings index 62c69c9ab..4ac63066d 100644 --- a/Session/Meta/Translations/hi.lproj/Localizable.strings +++ b/Session/Meta/Translations/hi.lproj/Localizable.strings @@ -546,3 +546,6 @@ "modal_send_seed_title" = "Warning"; "modal_send_seed_explanation" = "This is your recovery phrase. If you send it to someone they'll have full access to your account."; "modal_send_seed_send_button_title" = "Send"; +"vc_conversation_settings_notify_for_mentions_only_title" = "Notify for Mentions Only"; +"vc_conversation_settings_notify_for_mentions_only_explanation" = "When enabled, you'll only be notified for messages mentioning you."; +"view_conversation_title_notify_for_mentions_only" = "Notifying for Mentions Only"; diff --git a/Session/Meta/Translations/hr.lproj/Localizable.strings b/Session/Meta/Translations/hr.lproj/Localizable.strings index a4f1ecec0..06175d3bd 100644 --- a/Session/Meta/Translations/hr.lproj/Localizable.strings +++ b/Session/Meta/Translations/hr.lproj/Localizable.strings @@ -546,3 +546,6 @@ "modal_send_seed_title" = "Warning"; "modal_send_seed_explanation" = "This is your recovery phrase. If you send it to someone they'll have full access to your account."; "modal_send_seed_send_button_title" = "Send"; +"vc_conversation_settings_notify_for_mentions_only_title" = "Notify for Mentions Only"; +"vc_conversation_settings_notify_for_mentions_only_explanation" = "When enabled, you'll only be notified for messages mentioning you."; +"view_conversation_title_notify_for_mentions_only" = "Notifying for Mentions Only"; diff --git a/Session/Meta/Translations/id-ID.lproj/Localizable.strings b/Session/Meta/Translations/id-ID.lproj/Localizable.strings index 4ea14eeb4..53f074e91 100644 --- a/Session/Meta/Translations/id-ID.lproj/Localizable.strings +++ b/Session/Meta/Translations/id-ID.lproj/Localizable.strings @@ -546,3 +546,6 @@ "modal_send_seed_title" = "Warning"; "modal_send_seed_explanation" = "This is your recovery phrase. If you send it to someone they'll have full access to your account."; "modal_send_seed_send_button_title" = "Send"; +"vc_conversation_settings_notify_for_mentions_only_title" = "Notify for Mentions Only"; +"vc_conversation_settings_notify_for_mentions_only_explanation" = "When enabled, you'll only be notified for messages mentioning you."; +"view_conversation_title_notify_for_mentions_only" = "Notifying for Mentions Only"; diff --git a/Session/Meta/Translations/it.lproj/Localizable.strings b/Session/Meta/Translations/it.lproj/Localizable.strings index d13c5ddb5..ba556afb2 100644 --- a/Session/Meta/Translations/it.lproj/Localizable.strings +++ b/Session/Meta/Translations/it.lproj/Localizable.strings @@ -546,3 +546,6 @@ "modal_send_seed_title" = "Warning"; "modal_send_seed_explanation" = "This is your recovery phrase. If you send it to someone they'll have full access to your account."; "modal_send_seed_send_button_title" = "Send"; +"vc_conversation_settings_notify_for_mentions_only_title" = "Notify for Mentions Only"; +"vc_conversation_settings_notify_for_mentions_only_explanation" = "When enabled, you'll only be notified for messages mentioning you."; +"view_conversation_title_notify_for_mentions_only" = "Notifying for Mentions Only"; diff --git a/Session/Meta/Translations/ja.lproj/Localizable.strings b/Session/Meta/Translations/ja.lproj/Localizable.strings index faf24bdc6..c7a4ddb46 100644 --- a/Session/Meta/Translations/ja.lproj/Localizable.strings +++ b/Session/Meta/Translations/ja.lproj/Localizable.strings @@ -546,3 +546,6 @@ "modal_send_seed_title" = "Warning"; "modal_send_seed_explanation" = "This is your recovery phrase. If you send it to someone they'll have full access to your account."; "modal_send_seed_send_button_title" = "Send"; +"vc_conversation_settings_notify_for_mentions_only_title" = "Notify for Mentions Only"; +"vc_conversation_settings_notify_for_mentions_only_explanation" = "When enabled, you'll only be notified for messages mentioning you."; +"view_conversation_title_notify_for_mentions_only" = "Notifying for Mentions Only"; diff --git a/Session/Meta/Translations/nl.lproj/Localizable.strings b/Session/Meta/Translations/nl.lproj/Localizable.strings index 8967ddfc9..f097fb431 100644 --- a/Session/Meta/Translations/nl.lproj/Localizable.strings +++ b/Session/Meta/Translations/nl.lproj/Localizable.strings @@ -546,3 +546,6 @@ "modal_send_seed_title" = "Warning"; "modal_send_seed_explanation" = "This is your recovery phrase. If you send it to someone they'll have full access to your account."; "modal_send_seed_send_button_title" = "Send"; +"vc_conversation_settings_notify_for_mentions_only_title" = "Notify for Mentions Only"; +"vc_conversation_settings_notify_for_mentions_only_explanation" = "When enabled, you'll only be notified for messages mentioning you."; +"view_conversation_title_notify_for_mentions_only" = "Notifying for Mentions Only"; diff --git a/Session/Meta/Translations/pl.lproj/Localizable.strings b/Session/Meta/Translations/pl.lproj/Localizable.strings index 59a6706ae..ebb5aa434 100644 --- a/Session/Meta/Translations/pl.lproj/Localizable.strings +++ b/Session/Meta/Translations/pl.lproj/Localizable.strings @@ -546,3 +546,6 @@ "modal_send_seed_title" = "Warning"; "modal_send_seed_explanation" = "This is your recovery phrase. If you send it to someone they'll have full access to your account."; "modal_send_seed_send_button_title" = "Send"; +"vc_conversation_settings_notify_for_mentions_only_title" = "Notify for Mentions Only"; +"vc_conversation_settings_notify_for_mentions_only_explanation" = "When enabled, you'll only be notified for messages mentioning you."; +"view_conversation_title_notify_for_mentions_only" = "Notifying for Mentions Only"; diff --git a/Session/Meta/Translations/pt_BR.lproj/Localizable.strings b/Session/Meta/Translations/pt_BR.lproj/Localizable.strings index 2555e945c..c5572ccc4 100644 --- a/Session/Meta/Translations/pt_BR.lproj/Localizable.strings +++ b/Session/Meta/Translations/pt_BR.lproj/Localizable.strings @@ -546,3 +546,6 @@ "modal_send_seed_title" = "Warning"; "modal_send_seed_explanation" = "This is your recovery phrase. If you send it to someone they'll have full access to your account."; "modal_send_seed_send_button_title" = "Send"; +"vc_conversation_settings_notify_for_mentions_only_title" = "Notify for Mentions Only"; +"vc_conversation_settings_notify_for_mentions_only_explanation" = "When enabled, you'll only be notified for messages mentioning you."; +"view_conversation_title_notify_for_mentions_only" = "Notifying for Mentions Only"; diff --git a/Session/Meta/Translations/ru.lproj/Localizable.strings b/Session/Meta/Translations/ru.lproj/Localizable.strings index 89119cb53..129b0b3d1 100644 --- a/Session/Meta/Translations/ru.lproj/Localizable.strings +++ b/Session/Meta/Translations/ru.lproj/Localizable.strings @@ -546,3 +546,6 @@ "modal_send_seed_title" = "Warning"; "modal_send_seed_explanation" = "This is your recovery phrase. If you send it to someone they'll have full access to your account."; "modal_send_seed_send_button_title" = "Send"; +"vc_conversation_settings_notify_for_mentions_only_title" = "Notify for Mentions Only"; +"vc_conversation_settings_notify_for_mentions_only_explanation" = "When enabled, you'll only be notified for messages mentioning you."; +"view_conversation_title_notify_for_mentions_only" = "Notifying for Mentions Only"; diff --git a/Session/Meta/Translations/sk.lproj/Localizable.strings b/Session/Meta/Translations/sk.lproj/Localizable.strings index 2ade1f164..495b874d0 100644 --- a/Session/Meta/Translations/sk.lproj/Localizable.strings +++ b/Session/Meta/Translations/sk.lproj/Localizable.strings @@ -546,3 +546,6 @@ "modal_send_seed_title" = "Warning"; "modal_send_seed_explanation" = "This is your recovery phrase. If you send it to someone they'll have full access to your account."; "modal_send_seed_send_button_title" = "Send"; +"vc_conversation_settings_notify_for_mentions_only_title" = "Notify for Mentions Only"; +"vc_conversation_settings_notify_for_mentions_only_explanation" = "When enabled, you'll only be notified for messages mentioning you."; +"view_conversation_title_notify_for_mentions_only" = "Notifying for Mentions Only"; diff --git a/Session/Meta/Translations/sv.lproj/Localizable.strings b/Session/Meta/Translations/sv.lproj/Localizable.strings index 81332a545..e6b1b4d59 100644 --- a/Session/Meta/Translations/sv.lproj/Localizable.strings +++ b/Session/Meta/Translations/sv.lproj/Localizable.strings @@ -546,3 +546,6 @@ "modal_send_seed_title" = "Warning"; "modal_send_seed_explanation" = "This is your recovery phrase. If you send it to someone they'll have full access to your account."; "modal_send_seed_send_button_title" = "Send"; +"vc_conversation_settings_notify_for_mentions_only_title" = "Notify for Mentions Only"; +"vc_conversation_settings_notify_for_mentions_only_explanation" = "When enabled, you'll only be notified for messages mentioning you."; +"view_conversation_title_notify_for_mentions_only" = "Notifying for Mentions Only"; diff --git a/Session/Meta/Translations/th.lproj/Localizable.strings b/Session/Meta/Translations/th.lproj/Localizable.strings index a92caaefa..5a99c82e0 100644 --- a/Session/Meta/Translations/th.lproj/Localizable.strings +++ b/Session/Meta/Translations/th.lproj/Localizable.strings @@ -546,3 +546,6 @@ "modal_send_seed_title" = "Warning"; "modal_send_seed_explanation" = "This is your recovery phrase. If you send it to someone they'll have full access to your account."; "modal_send_seed_send_button_title" = "Send"; +"vc_conversation_settings_notify_for_mentions_only_title" = "Notify for Mentions Only"; +"vc_conversation_settings_notify_for_mentions_only_explanation" = "When enabled, you'll only be notified for messages mentioning you."; +"view_conversation_title_notify_for_mentions_only" = "Notifying for Mentions Only"; diff --git a/Session/Meta/Translations/vi-VN.lproj/Localizable.strings b/Session/Meta/Translations/vi-VN.lproj/Localizable.strings index 9742ba586..0faba1ebe 100644 --- a/Session/Meta/Translations/vi-VN.lproj/Localizable.strings +++ b/Session/Meta/Translations/vi-VN.lproj/Localizable.strings @@ -546,3 +546,6 @@ "modal_send_seed_title" = "Warning"; "modal_send_seed_explanation" = "This is your recovery phrase. If you send it to someone they'll have full access to your account."; "modal_send_seed_send_button_title" = "Send"; +"vc_conversation_settings_notify_for_mentions_only_title" = "Notify for Mentions Only"; +"vc_conversation_settings_notify_for_mentions_only_explanation" = "When enabled, you'll only be notified for messages mentioning you."; +"view_conversation_title_notify_for_mentions_only" = "Notifying for Mentions Only"; diff --git a/Session/Meta/Translations/zh-Hant.lproj/Localizable.strings b/Session/Meta/Translations/zh-Hant.lproj/Localizable.strings index 0166c55c2..03fa38484 100644 --- a/Session/Meta/Translations/zh-Hant.lproj/Localizable.strings +++ b/Session/Meta/Translations/zh-Hant.lproj/Localizable.strings @@ -546,3 +546,6 @@ "modal_send_seed_title" = "Warning"; "modal_send_seed_explanation" = "This is your recovery phrase. If you send it to someone they'll have full access to your account."; "modal_send_seed_send_button_title" = "Send"; +"vc_conversation_settings_notify_for_mentions_only_title" = "Notify for Mentions Only"; +"vc_conversation_settings_notify_for_mentions_only_explanation" = "When enabled, you'll only be notified for messages mentioning you."; +"view_conversation_title_notify_for_mentions_only" = "Notifying for Mentions Only"; diff --git a/Session/Meta/Translations/zh_CN.lproj/Localizable.strings b/Session/Meta/Translations/zh_CN.lproj/Localizable.strings index 127219d84..764187588 100644 --- a/Session/Meta/Translations/zh_CN.lproj/Localizable.strings +++ b/Session/Meta/Translations/zh_CN.lproj/Localizable.strings @@ -546,3 +546,6 @@ "modal_send_seed_title" = "Warning"; "modal_send_seed_explanation" = "This is your recovery phrase. If you send it to someone they'll have full access to your account."; "modal_send_seed_send_button_title" = "Send"; +"vc_conversation_settings_notify_for_mentions_only_title" = "Notify for Mentions Only"; +"vc_conversation_settings_notify_for_mentions_only_explanation" = "When enabled, you'll only be notified for messages mentioning you."; +"view_conversation_title_notify_for_mentions_only" = "Notifying for Mentions Only"; diff --git a/Session/Notifications/AppNotifications.swift b/Session/Notifications/AppNotifications.swift index 42280c493..594430aeb 100644 --- a/Session/Notifications/AppNotifications.swift +++ b/Session/Notifications/AppNotifications.swift @@ -166,10 +166,10 @@ public class NotificationPresenter: NSObject, NotificationsProtocol { // for more details. let messageText = DisplayableText.filterNotificationText(rawMessageText) - // Do not fire the notification wihtout mentioning current user, - // if current user sets isOnlyNotifyMentions on. + // Don't fire the notification if the current user isn't mentioned + // and isOnlyNotifyingForMentions is on. let isUserMentioned = MentionUtilities.isUserMentioned(in: messageText ?? "") - if let groupThread = thread as? TSGroupThread, groupThread.isOnlyNotifyMentions && !isUserMentioned { + if let groupThread = thread as? TSGroupThread, groupThread.isOnlyNotifyingForMentions && !isUserMentioned { return } diff --git a/Session/Shared/ConversationCell.swift b/Session/Shared/ConversationCell.swift index e2e0f58d2..46074851b 100644 --- a/Session/Shared/ConversationCell.swift +++ b/Session/Shared/ConversationCell.swift @@ -230,7 +230,7 @@ final class ConversationCell : UITableViewCell { let result = NSMutableAttributedString() if threadViewModel.isMuted { result.append(NSAttributedString(string: "\u{e067} ", attributes: [ .font : UIFont.ows_elegantIconsFont(10), .foregroundColor : Colors.unimportant ])) - } else if threadViewModel.isOnlyNotifyMentions { + } else if threadViewModel.isOnlyNotifyingForMentions { let imageAttachment = NSTextAttachment() imageAttachment.image = UIImage(named: "NotifyMentions.png")?.asTintedImage(color: Colors.unimportant) imageAttachment.bounds = CGRect(x: 0, y: -2, width: Values.smallFontSize, height: Values.smallFontSize) diff --git a/SessionMessagingKit/Threads/TSGroupThread.h b/SessionMessagingKit/Threads/TSGroupThread.h index aa55f60f7..0599d0461 100644 --- a/SessionMessagingKit/Threads/TSGroupThread.h +++ b/SessionMessagingKit/Threads/TSGroupThread.h @@ -18,7 +18,7 @@ extern NSString *const TSGroupThread_NotificationKey_UniqueId; @property (nonatomic, strong) TSGroupModel *groupModel; @property (nonatomic, readonly) BOOL isOpenGroup; @property (nonatomic, readonly) BOOL isClosedGroup; -@property (nonatomic) BOOL isOnlyNotifyMentions; +@property (nonatomic) BOOL isOnlyNotifyingForMentions; + (instancetype)getOrCreateThreadWithGroupModel:(TSGroupModel *)groupModel; + (instancetype)getOrCreateThreadWithGroupModel:(TSGroupModel *)groupModel @@ -45,7 +45,7 @@ extern NSString *const TSGroupThread_NotificationKey_UniqueId; transaction:(YapDatabaseReadWriteTransaction *)transaction; - (void)setGroupModel:(TSGroupModel *)newGroupModel withTransaction:(YapDatabaseReadWriteTransaction *)transaction; -- (void)setIsOnlyNotifyMentions:(BOOL)isOnlyNotifyMentions withTransaction:(YapDatabaseReadWriteTransaction *)transaction; +- (void)setisOnlyNotifyingForMentions:(BOOL)isOnlyNotifyingForMentions withTransaction:(YapDatabaseReadWriteTransaction *)transaction; - (void)leaveGroupWithSneakyTransaction; - (void)leaveGroupWithTransaction:(YapDatabaseReadWriteTransaction *)transaction; diff --git a/SessionMessagingKit/Threads/TSGroupThread.m b/SessionMessagingKit/Threads/TSGroupThread.m index e0a94401b..f05d42732 100644 --- a/SessionMessagingKit/Threads/TSGroupThread.m +++ b/SessionMessagingKit/Threads/TSGroupThread.m @@ -208,9 +208,9 @@ NSString *const TSGroupThread_NotificationKey_UniqueId = @"TSGroupThread_Notific }]; } -- (void)setIsOnlyNotifyMentions:(BOOL)isOnlyNotifyMentions withTransaction:(YapDatabaseReadWriteTransaction *)transaction +- (void)setisOnlyNotifyingForMentions:(BOOL)isOnlyNotifyingForMentions withTransaction:(YapDatabaseReadWriteTransaction *)transaction { - self.isOnlyNotifyMentions = isOnlyNotifyMentions; + self.isOnlyNotifyingForMentions = isOnlyNotifyingForMentions; [self saveWithTransaction:transaction]; diff --git a/SignalUtilitiesKit/Messaging/ThreadViewModel.swift b/SignalUtilitiesKit/Messaging/ThreadViewModel.swift index 6b1f0ef60..30177ec11 100644 --- a/SignalUtilitiesKit/Messaging/ThreadViewModel.swift +++ b/SignalUtilitiesKit/Messaging/ThreadViewModel.swift @@ -14,7 +14,7 @@ public class ThreadViewModel: NSObject { @objc public let contactSessionID: String? @objc public let name: String @objc public let isMuted: Bool - @objc public let isOnlyNotifyMentions: Bool + @objc public let isOnlyNotifyingForMentions: Bool var isContactThread: Bool { return !isGroupThread @@ -42,9 +42,9 @@ public class ThreadViewModel: NSObject { } if let groupThread = thread as? TSGroupThread { - self.isOnlyNotifyMentions = groupThread.isOnlyNotifyMentions + self.isOnlyNotifyingForMentions = groupThread.isOnlyNotifyingForMentions } else { - self.isOnlyNotifyMentions = false + self.isOnlyNotifyingForMentions = false } self.unreadCount = thread.unreadMessageCount(transaction: transaction)