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 000000000..fe39a8b35 Binary files /dev/null and b/Session/Meta/Images.xcassets/Session/NotifyMentions.imageset/ic_notification_mentions-1.png differ diff --git a/Session/Meta/Images.xcassets/Session/NotifyMentions.imageset/ic_notification_mentions-2.png b/Session/Meta/Images.xcassets/Session/NotifyMentions.imageset/ic_notification_mentions-2.png new file mode 100644 index 000000000..fe39a8b35 Binary files /dev/null and b/Session/Meta/Images.xcassets/Session/NotifyMentions.imageset/ic_notification_mentions-2.png differ diff --git a/Session/Meta/Images.xcassets/Session/NotifyMentions.imageset/ic_notification_mentions.png b/Session/Meta/Images.xcassets/Session/NotifyMentions.imageset/ic_notification_mentions.png new file mode 100644 index 000000000..fe39a8b35 Binary files /dev/null and b/Session/Meta/Images.xcassets/Session/NotifyMentions.imageset/ic_notification_mentions.png differ diff --git a/Session/Meta/Translations/en.lproj/Localizable.strings b/Session/Meta/Translations/en.lproj/Localizable.strings index c1f7a7f76..7d9603cd7 100644 --- a/Session/Meta/Translations/en.lproj/Localizable.strings +++ b/Session/Meta/Translations/en.lproj/Localizable.strings @@ -136,6 +136,8 @@ "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. */