mirror of
https://github.com/oxen-io/session-ios.git
synced 2023-12-13 21:30:14 +01:00
Merge branch 'charlesmchen/noteToSelf'
This commit is contained in:
commit
de8abe269f
12 changed files with 289 additions and 142 deletions
|
@ -1,5 +1,5 @@
|
|||
//
|
||||
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
|
||||
// Copyright (c) 2019 Open Whisper Systems. All rights reserved.
|
||||
//
|
||||
|
||||
#import "ConversationViewController.h"
|
||||
|
@ -302,6 +302,13 @@ typedef enum : NSUInteger {
|
|||
return SSKEnvironment.shared.attachmentDownloads;
|
||||
}
|
||||
|
||||
- (TSAccountManager *)tsAccountManager
|
||||
{
|
||||
OWSAssertDebug(SSKEnvironment.shared.tsAccountManager);
|
||||
|
||||
return SSKEnvironment.shared.tsAccountManager;
|
||||
}
|
||||
|
||||
#pragma mark -
|
||||
|
||||
- (void)addNotificationListeners
|
||||
|
@ -490,7 +497,7 @@ typedef enum : NSUInteger {
|
|||
}
|
||||
|
||||
TSGroupThread *groupThread = (TSGroupThread *)self.thread;
|
||||
return ![groupThread.groupModel.groupMemberIds containsObject:[TSAccountManager localNumber]];
|
||||
return !groupThread.isLocalUserInGroup;
|
||||
}
|
||||
|
||||
- (void)hideInputIfNeeded
|
||||
|
@ -1250,10 +1257,19 @@ typedef enum : NSUInteger {
|
|||
}
|
||||
} else {
|
||||
OWSAssertDebug(self.thread.contactIdentifier);
|
||||
name =
|
||||
[self.contactsManager attributedContactOrProfileNameForPhoneIdentifier:self.thread.contactIdentifier
|
||||
primaryFont:self.headerView.titlePrimaryFont
|
||||
secondaryFont:self.headerView.titleSecondaryFont];
|
||||
|
||||
if (self.thread.isNoteToSelf) {
|
||||
name = [[NSAttributedString alloc]
|
||||
initWithString:NSLocalizedString(@"NOTE_TO_SELF", @"Label for 1:1 conversation with yourself.")
|
||||
attributes:@{
|
||||
NSFontAttributeName : self.headerView.titlePrimaryFont,
|
||||
}];
|
||||
} else {
|
||||
name = [self.contactsManager
|
||||
attributedContactOrProfileNameForPhoneIdentifier:self.thread.contactIdentifier
|
||||
primaryFont:self.headerView.titlePrimaryFont
|
||||
secondaryFont:self.headerView.titleSecondaryFont];
|
||||
}
|
||||
}
|
||||
self.title = nil;
|
||||
|
||||
|
@ -1557,7 +1573,7 @@ typedef enum : NSUInteger {
|
|||
- (BOOL)canCall
|
||||
{
|
||||
return !(self.isGroupConversation ||
|
||||
[((TSContactThread *)self.thread).contactIdentifier isEqualToString:[TSAccountManager localNumber]]);
|
||||
[((TSContactThread *)self.thread).contactIdentifier isEqualToString:self.tsAccountManager.localNumber]);
|
||||
}
|
||||
|
||||
#pragma mark - Dynamic Text
|
||||
|
@ -3807,7 +3823,7 @@ typedef enum : NSUInteger {
|
|||
OWSAssertDebug(groupModel);
|
||||
|
||||
NSMutableSet *groupMemberIds = [NSMutableSet setWithArray:groupModel.groupMemberIds];
|
||||
[groupMemberIds addObject:[TSAccountManager localNumber]];
|
||||
[groupMemberIds addObject:self.tsAccountManager.localNumber];
|
||||
groupModel.groupMemberIds = [NSMutableArray arrayWithArray:[groupMemberIds allObjects]];
|
||||
[self updateGroupModelTo:groupModel successCompletion:nil];
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
//
|
||||
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
|
||||
// Copyright (c) 2019 Open Whisper Systems. All rights reserved.
|
||||
//
|
||||
|
||||
#import "HomeViewCell.h"
|
||||
|
@ -53,6 +53,13 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
return SSKEnvironment.shared.typingIndicators;
|
||||
}
|
||||
|
||||
- (TSAccountManager *)tsAccountManager
|
||||
{
|
||||
OWSAssertDebug(SSKEnvironment.shared.tsAccountManager);
|
||||
|
||||
return SSKEnvironment.shared.tsAccountManager;
|
||||
}
|
||||
|
||||
#pragma mark -
|
||||
|
||||
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(nullable NSString *)reuseIdentifier
|
||||
|
@ -510,9 +517,17 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
name = [[NSAttributedString alloc] initWithString:thread.name];
|
||||
}
|
||||
} else {
|
||||
name = [self.contactsManager attributedContactOrProfileNameForPhoneIdentifier:thread.contactIdentifier
|
||||
primaryFont:self.nameFont
|
||||
secondaryFont:self.nameSecondaryFont];
|
||||
if (self.thread.threadRecord.isNoteToSelf) {
|
||||
name = [[NSAttributedString alloc]
|
||||
initWithString:NSLocalizedString(@"NOTE_TO_SELF", @"Label for 1:1 conversation with yourself.")
|
||||
attributes:@{
|
||||
NSFontAttributeName : self.nameFont,
|
||||
}];
|
||||
} else {
|
||||
name = [self.contactsManager attributedContactOrProfileNameForPhoneIdentifier:thread.contactIdentifier
|
||||
primaryFont:self.nameFont
|
||||
secondaryFont:self.nameSecondaryFont];
|
||||
}
|
||||
}
|
||||
|
||||
self.nameLabel.attributedText = name;
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
//
|
||||
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
|
||||
// Copyright (c) 2019 Open Whisper Systems. All rights reserved.
|
||||
//
|
||||
|
||||
#import "OWSConversationSettingsViewController.h"
|
||||
|
@ -55,10 +55,6 @@ const CGFloat kIconViewLength = 24;
|
|||
@property (nonatomic) NSArray<NSNumber *> *disappearingMessagesDurations;
|
||||
@property (nonatomic) OWSDisappearingMessagesConfiguration *disappearingMessagesConfiguration;
|
||||
@property (nullable, nonatomic) MediaGallery *mediaGallery;
|
||||
@property (nonatomic, readonly) TSAccountManager *accountManager;
|
||||
@property (nonatomic, readonly) OWSContactsManager *contactsManager;
|
||||
@property (nonatomic, readonly) OWSMessageSender *messageSender;
|
||||
@property (nonatomic, readonly) OWSBlockingManager *blockingManager;
|
||||
@property (nonatomic, readonly) ContactsViewHelper *contactsViewHelper;
|
||||
@property (nonatomic, readonly) UIImageView *avatarView;
|
||||
@property (nonatomic, readonly) UILabel *disappearingMessagesDurationLabel;
|
||||
|
@ -110,10 +106,6 @@ const CGFloat kIconViewLength = 24;
|
|||
|
||||
- (void)commonInit
|
||||
{
|
||||
_accountManager = [TSAccountManager sharedInstance];
|
||||
_contactsManager = Environment.shared.contactsManager;
|
||||
_messageSender = SSKEnvironment.shared.messageSender;
|
||||
_blockingManager = [OWSBlockingManager sharedManager];
|
||||
_contactsViewHelper = [[ContactsViewHelper alloc] initWithDelegate:self];
|
||||
|
||||
[self observeNotifications];
|
||||
|
@ -131,6 +123,33 @@ const CGFloat kIconViewLength = 24;
|
|||
return SSKEnvironment.shared.messageSenderJobQueue;
|
||||
}
|
||||
|
||||
- (TSAccountManager *)tsAccountManager
|
||||
{
|
||||
OWSAssertDebug(SSKEnvironment.shared.tsAccountManager);
|
||||
|
||||
return SSKEnvironment.shared.tsAccountManager;
|
||||
}
|
||||
|
||||
- (OWSContactsManager *)contactsManager
|
||||
{
|
||||
return Environment.shared.contactsManager;
|
||||
}
|
||||
|
||||
- (OWSMessageSender *)messageSender
|
||||
{
|
||||
return SSKEnvironment.shared.messageSender;
|
||||
}
|
||||
|
||||
- (OWSBlockingManager *)blockingManager
|
||||
{
|
||||
return [OWSBlockingManager sharedManager];
|
||||
}
|
||||
|
||||
- (OWSProfileManager *)profileManager
|
||||
{
|
||||
return [OWSProfileManager sharedManager];
|
||||
}
|
||||
|
||||
#pragma mark
|
||||
|
||||
- (void)observeNotifications
|
||||
|
@ -291,6 +310,8 @@ const CGFloat kIconViewLength = 24;
|
|||
OWSTableContents *contents = [OWSTableContents new];
|
||||
contents.title = NSLocalizedString(@"CONVERSATION_SETTINGS", @"title for conversation settings screen");
|
||||
|
||||
BOOL isNoteToSelf = self.thread.isNoteToSelf;
|
||||
|
||||
__weak OWSConversationSettingsViewController *weakSelf = self;
|
||||
|
||||
// Main section.
|
||||
|
@ -333,7 +354,7 @@ const CGFloat kIconViewLength = 24;
|
|||
}]];
|
||||
}
|
||||
|
||||
if (!self.isGroupThread && self.thread.hasSafetyNumbers) {
|
||||
if (!isNoteToSelf && !self.isGroupThread && self.thread.hasSafetyNumbers) {
|
||||
[mainSection addItem:[OWSTableItem itemWithCustomCellBlock:^{
|
||||
return [weakSelf
|
||||
disclosureCellWithName:
|
||||
|
@ -346,7 +367,9 @@ const CGFloat kIconViewLength = 24;
|
|||
}]];
|
||||
}
|
||||
|
||||
if ([OWSProfileManager.sharedManager isThreadInProfileWhitelist:self.thread]) {
|
||||
if (isNoteToSelf) {
|
||||
// Skip the profile whitelist.
|
||||
} else if ([self.profileManager isThreadInProfileWhitelist:self.thread]) {
|
||||
[mainSection
|
||||
addItem:[OWSTableItem
|
||||
itemWithCustomCellBlock:^{
|
||||
|
@ -564,52 +587,54 @@ const CGFloat kIconViewLength = 24;
|
|||
|
||||
// Mute thread section.
|
||||
|
||||
OWSTableSection *notificationsSection = [OWSTableSection new];
|
||||
// We need a section header to separate the notifications UI from the group settings UI.
|
||||
notificationsSection.headerTitle = NSLocalizedString(
|
||||
@"SETTINGS_SECTION_NOTIFICATIONS", @"Label for the notifications section of conversation settings view.");
|
||||
if (!isNoteToSelf) {
|
||||
OWSTableSection *notificationsSection = [OWSTableSection new];
|
||||
// We need a section header to separate the notifications UI from the group settings UI.
|
||||
notificationsSection.headerTitle = NSLocalizedString(
|
||||
@"SETTINGS_SECTION_NOTIFICATIONS", @"Label for the notifications section of conversation settings view.");
|
||||
|
||||
[notificationsSection
|
||||
addItem:[OWSTableItem
|
||||
itemWithCustomCellBlock:^{
|
||||
UITableViewCell *cell =
|
||||
[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:nil];
|
||||
[OWSTableItem configureCell:cell];
|
||||
OWSConversationSettingsViewController *strongSelf = weakSelf;
|
||||
OWSCAssertDebug(strongSelf);
|
||||
cell.preservesSuperviewLayoutMargins = YES;
|
||||
cell.contentView.preservesSuperviewLayoutMargins = YES;
|
||||
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
|
||||
[notificationsSection
|
||||
addItem:[OWSTableItem
|
||||
itemWithCustomCellBlock:^{
|
||||
UITableViewCell *cell =
|
||||
[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:nil];
|
||||
[OWSTableItem configureCell:cell];
|
||||
OWSConversationSettingsViewController *strongSelf = weakSelf;
|
||||
OWSCAssertDebug(strongSelf);
|
||||
cell.preservesSuperviewLayoutMargins = YES;
|
||||
cell.contentView.preservesSuperviewLayoutMargins = YES;
|
||||
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
|
||||
|
||||
UIImageView *iconView = [strongSelf viewForIconWithName:@"table_ic_notification_sound"];
|
||||
UIImageView *iconView = [strongSelf viewForIconWithName:@"table_ic_notification_sound"];
|
||||
|
||||
UILabel *rowLabel = [UILabel new];
|
||||
rowLabel.text = NSLocalizedString(@"SETTINGS_ITEM_NOTIFICATION_SOUND",
|
||||
@"Label for settings view that allows user to change the notification sound.");
|
||||
rowLabel.textColor = [Theme primaryColor];
|
||||
rowLabel.font = [UIFont ows_dynamicTypeBodyFont];
|
||||
rowLabel.lineBreakMode = NSLineBreakByTruncatingTail;
|
||||
UILabel *rowLabel = [UILabel new];
|
||||
rowLabel.text = NSLocalizedString(@"SETTINGS_ITEM_NOTIFICATION_SOUND",
|
||||
@"Label for settings view that allows user to change the notification sound.");
|
||||
rowLabel.textColor = [Theme primaryColor];
|
||||
rowLabel.font = [UIFont ows_dynamicTypeBodyFont];
|
||||
rowLabel.lineBreakMode = NSLineBreakByTruncatingTail;
|
||||
|
||||
UIStackView *contentRow =
|
||||
[[UIStackView alloc] initWithArrangedSubviews:@[ iconView, rowLabel ]];
|
||||
contentRow.spacing = strongSelf.iconSpacing;
|
||||
contentRow.alignment = UIStackViewAlignmentCenter;
|
||||
[cell.contentView addSubview:contentRow];
|
||||
[contentRow autoPinEdgesToSuperviewMargins];
|
||||
UIStackView *contentRow =
|
||||
[[UIStackView alloc] initWithArrangedSubviews:@[ iconView, rowLabel ]];
|
||||
contentRow.spacing = strongSelf.iconSpacing;
|
||||
contentRow.alignment = UIStackViewAlignmentCenter;
|
||||
[cell.contentView addSubview:contentRow];
|
||||
[contentRow autoPinEdgesToSuperviewMargins];
|
||||
|
||||
OWSSound sound = [OWSSounds notificationSoundForThread:strongSelf.thread];
|
||||
cell.detailTextLabel.text = [OWSSounds displayNameForSound:sound];
|
||||
return cell;
|
||||
}
|
||||
customRowHeight:UITableViewAutomaticDimension
|
||||
actionBlock:^{
|
||||
OWSSoundSettingsViewController *vc = [OWSSoundSettingsViewController new];
|
||||
vc.thread = weakSelf.thread;
|
||||
[weakSelf.navigationController pushViewController:vc animated:YES];
|
||||
}]];
|
||||
OWSSound sound = [OWSSounds notificationSoundForThread:strongSelf.thread];
|
||||
cell.detailTextLabel.text = [OWSSounds displayNameForSound:sound];
|
||||
return cell;
|
||||
}
|
||||
customRowHeight:UITableViewAutomaticDimension
|
||||
actionBlock:^{
|
||||
OWSSoundSettingsViewController *vc = [OWSSoundSettingsViewController new];
|
||||
vc.thread = weakSelf.thread;
|
||||
[weakSelf.navigationController pushViewController:vc animated:YES];
|
||||
}]];
|
||||
|
||||
[notificationsSection
|
||||
addItem:[OWSTableItem
|
||||
[notificationsSection
|
||||
addItem:
|
||||
[OWSTableItem
|
||||
itemWithCustomCellBlock:^{
|
||||
UITableViewCell *cell =
|
||||
[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:nil];
|
||||
|
@ -672,53 +697,55 @@ const CGFloat kIconViewLength = 24;
|
|||
actionBlock:^{
|
||||
[weakSelf showMuteUnmuteActionSheet];
|
||||
}]];
|
||||
notificationsSection.footerTitle
|
||||
= NSLocalizedString(@"MUTE_BEHAVIOR_EXPLANATION", @"An explanation of the consequences of muting a thread.");
|
||||
[contents addSection:notificationsSection];
|
||||
|
||||
notificationsSection.footerTitle = NSLocalizedString(
|
||||
@"MUTE_BEHAVIOR_EXPLANATION", @"An explanation of the consequences of muting a thread.");
|
||||
[contents addSection:notificationsSection];
|
||||
}
|
||||
// Block Conversation section.
|
||||
|
||||
OWSTableSection *section = [OWSTableSection new];
|
||||
if (self.thread.isGroupThread) {
|
||||
section.footerTitle = NSLocalizedString(
|
||||
@"BLOCK_GROUP_BEHAVIOR_EXPLANATION", @"An explanation of the consequences of blocking a group.");
|
||||
} else {
|
||||
section.footerTitle = NSLocalizedString(
|
||||
@"BLOCK_USER_BEHAVIOR_EXPLANATION", @"An explanation of the consequences of blocking another user.");
|
||||
if (!isNoteToSelf) {
|
||||
OWSTableSection *section = [OWSTableSection new];
|
||||
if (self.thread.isGroupThread) {
|
||||
section.footerTitle = NSLocalizedString(
|
||||
@"BLOCK_GROUP_BEHAVIOR_EXPLANATION", @"An explanation of the consequences of blocking a group.");
|
||||
} else {
|
||||
section.footerTitle = NSLocalizedString(
|
||||
@"BLOCK_USER_BEHAVIOR_EXPLANATION", @"An explanation of the consequences of blocking another user.");
|
||||
}
|
||||
|
||||
[section addItem:[OWSTableItem
|
||||
itemWithCustomCellBlock:^{
|
||||
OWSConversationSettingsViewController *strongSelf = weakSelf;
|
||||
if (!strongSelf) {
|
||||
return [UITableViewCell new];
|
||||
}
|
||||
|
||||
NSString *cellTitle;
|
||||
if (strongSelf.thread.isGroupThread) {
|
||||
cellTitle = NSLocalizedString(@"CONVERSATION_SETTINGS_BLOCK_THIS_GROUP",
|
||||
@"table cell label in conversation settings");
|
||||
} else {
|
||||
cellTitle = NSLocalizedString(@"CONVERSATION_SETTINGS_BLOCK_THIS_USER",
|
||||
@"table cell label in conversation settings");
|
||||
}
|
||||
UITableViewCell *cell =
|
||||
[strongSelf disclosureCellWithName:cellTitle iconName:@"table_ic_block"];
|
||||
|
||||
cell.selectionStyle = UITableViewCellSelectionStyleNone;
|
||||
|
||||
UISwitch *blockConversationSwitch = [UISwitch new];
|
||||
blockConversationSwitch.on =
|
||||
[strongSelf.blockingManager isThreadBlocked:strongSelf.thread];
|
||||
[blockConversationSwitch addTarget:strongSelf
|
||||
action:@selector(blockConversationSwitchDidChange:)
|
||||
forControlEvents:UIControlEventValueChanged];
|
||||
cell.accessoryView = blockConversationSwitch;
|
||||
return cell;
|
||||
}
|
||||
actionBlock:nil]];
|
||||
[contents addSection:section];
|
||||
}
|
||||
|
||||
[section addItem:[OWSTableItem
|
||||
itemWithCustomCellBlock:^{
|
||||
OWSConversationSettingsViewController *strongSelf = weakSelf;
|
||||
if (!strongSelf) {
|
||||
return [UITableViewCell new];
|
||||
}
|
||||
|
||||
NSString *cellTitle;
|
||||
if (strongSelf.thread.isGroupThread) {
|
||||
cellTitle = NSLocalizedString(@"CONVERSATION_SETTINGS_BLOCK_THIS_GROUP",
|
||||
@"table cell label in conversation settings");
|
||||
} else {
|
||||
cellTitle = NSLocalizedString(@"CONVERSATION_SETTINGS_BLOCK_THIS_USER",
|
||||
@"table cell label in conversation settings");
|
||||
}
|
||||
UITableViewCell *cell =
|
||||
[strongSelf disclosureCellWithName:cellTitle iconName:@"table_ic_block"];
|
||||
|
||||
cell.selectionStyle = UITableViewCellSelectionStyleNone;
|
||||
|
||||
UISwitch *blockConversationSwitch = [UISwitch new];
|
||||
blockConversationSwitch.on =
|
||||
[strongSelf.blockingManager isThreadBlocked:strongSelf.thread];
|
||||
[blockConversationSwitch addTarget:strongSelf
|
||||
action:@selector(blockConversationSwitchDidChange:)
|
||||
forControlEvents:UIControlEventValueChanged];
|
||||
cell.accessoryView = blockConversationSwitch;
|
||||
return cell;
|
||||
}
|
||||
actionBlock:nil]];
|
||||
[contents addSection:section];
|
||||
|
||||
self.contents = contents;
|
||||
}
|
||||
|
||||
|
@ -961,11 +988,11 @@ const CGFloat kIconViewLength = 24;
|
|||
|
||||
- (void)showShareProfileAlert
|
||||
{
|
||||
[OWSProfileManager.sharedManager presentAddThreadToProfileWhitelist:self.thread
|
||||
fromViewController:self
|
||||
success:^{
|
||||
[self updateTableContents];
|
||||
}];
|
||||
[self.profileManager presentAddThreadToProfileWhitelist:self.thread
|
||||
fromViewController:self
|
||||
success:^{
|
||||
[self updateTableContents];
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)showVerificationView
|
||||
|
@ -1057,8 +1084,7 @@ const CGFloat kIconViewLength = 24;
|
|||
{
|
||||
if (self.isGroupThread) {
|
||||
TSGroupThread *groupThread = (TSGroupThread *)self.thread;
|
||||
BOOL inGroup = [groupThread.groupModel.groupMemberIds containsObject:TSAccountManager.localNumber];
|
||||
return !inGroup;
|
||||
return !groupThread.isLocalUserInGroup;
|
||||
}
|
||||
|
||||
return NO;
|
||||
|
@ -1118,8 +1144,8 @@ const CGFloat kIconViewLength = 24;
|
|||
}
|
||||
[BlockListUIUtils showUnblockThreadActionSheet:self.thread
|
||||
fromViewController:self
|
||||
blockingManager:_blockingManager
|
||||
contactsManager:_contactsManager
|
||||
blockingManager:self.blockingManager
|
||||
contactsManager:self.contactsManager
|
||||
completionBlock:^(BOOL isBlocked) {
|
||||
// Update switch state if user cancels action.
|
||||
blockConversationSwitch.on = isBlocked;
|
||||
|
|
|
@ -1466,6 +1466,9 @@
|
|||
/* Label for a button that lets users search for contacts by phone number */
|
||||
"NO_CONTACTS_SEARCH_BY_PHONE_NUMBER" = "Find Contacts by Phone Number";
|
||||
|
||||
/* Label for 1:1 conversation with yourself. */
|
||||
"NOTE_TO_SELF" = "Note to Self";
|
||||
|
||||
/* Lock screen notification text presented after user powers on their device without unlocking. Embeds {{device model}} (either 'iPad' or 'iPhone') */
|
||||
"NOTIFICATION_BODY_PHONE_LOCKED_FORMAT" = "You may have received messages while your %@ was restarting.";
|
||||
|
||||
|
|
|
@ -61,6 +61,13 @@ const CGFloat kContactCellAvatarTextMargin = 12;
|
|||
return SSKEnvironment.shared.primaryStorage;
|
||||
}
|
||||
|
||||
- (TSAccountManager *)tsAccountManager
|
||||
{
|
||||
OWSAssertDebug(SSKEnvironment.shared.tsAccountManager);
|
||||
|
||||
return SSKEnvironment.shared.tsAccountManager;
|
||||
}
|
||||
|
||||
#pragma mark -
|
||||
|
||||
- (void)configure
|
||||
|
@ -133,8 +140,17 @@ const CGFloat kContactCellAvatarTextMargin = 12;
|
|||
self.thread = [TSContactThread getThreadWithContactId:recipientId transaction:transaction];
|
||||
}];
|
||||
|
||||
self.nameLabel.attributedText =
|
||||
[self.contactsManager formattedFullNameForRecipientId:recipientId font:self.nameLabel.font];
|
||||
BOOL isNoteToSelf = [recipientId isEqualToString:self.tsAccountManager.localNumber];
|
||||
if (isNoteToSelf) {
|
||||
self.nameLabel.attributedText = [[NSAttributedString alloc]
|
||||
initWithString:NSLocalizedString(@"NOTE_TO_SELF", @"Label for 1:1 conversation with yourself.")
|
||||
attributes:@{
|
||||
NSFontAttributeName : self.nameLabel.font,
|
||||
}];
|
||||
} else {
|
||||
self.nameLabel.attributedText =
|
||||
[self.contactsManager formattedFullNameForRecipientId:recipientId font:self.nameLabel.font];
|
||||
}
|
||||
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self
|
||||
selector:@selector(otherUsersProfileDidChange:)
|
||||
|
@ -165,6 +181,12 @@ const CGFloat kContactCellAvatarTextMargin = 12;
|
|||
threadName = [MessageStrings newGroupDefaultTitle];
|
||||
}
|
||||
|
||||
BOOL isNoteToSelf
|
||||
= (!thread.isGroupThread && [thread.contactIdentifier isEqualToString:self.tsAccountManager.localNumber]);
|
||||
if (isNoteToSelf) {
|
||||
threadName = NSLocalizedString(@"NOTE_TO_SELF", @"Label for 1:1 conversation with yourself.");
|
||||
}
|
||||
|
||||
NSAttributedString *attributedText =
|
||||
[[NSAttributedString alloc] initWithString:threadName
|
||||
attributes:@{
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
//
|
||||
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
|
||||
// Copyright (c) 2019 Open Whisper Systems. All rights reserved.
|
||||
//
|
||||
|
||||
#import "TSConstants.h"
|
||||
|
@ -14,6 +14,7 @@ extern NSString *const kNSNotificationName_LocalNumberDidChange;
|
|||
@class AnyPromise;
|
||||
@class OWSPrimaryStorage;
|
||||
@class TSNetworkManager;
|
||||
@class YapDatabaseReadTransaction;
|
||||
@class YapDatabaseReadWriteTransaction;
|
||||
|
||||
typedef NS_ENUM(NSUInteger, OWSRegistrationState) {
|
||||
|
@ -57,6 +58,9 @@ typedef NS_ENUM(NSUInteger, OWSRegistrationState) {
|
|||
+ (nullable NSString *)localNumber;
|
||||
- (nullable NSString *)localNumber;
|
||||
|
||||
// A variant of localNumber that never opens a "sneaky" transaction.
|
||||
- (nullable NSString *)storedOrCachedLocalNumber:(YapDatabaseReadTransaction *)transaction;
|
||||
|
||||
/**
|
||||
* Symmetric key that's used to encrypt message payloads from the server,
|
||||
*
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
//
|
||||
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
|
||||
// Copyright (c) 2019 Open Whisper Systems. All rights reserved.
|
||||
//
|
||||
|
||||
#import "TSAccountManager.h"
|
||||
|
@ -220,6 +220,18 @@ NSString *const TSAccountManager_NeedsAccountAttributesUpdateKey = @"TSAccountMa
|
|||
}
|
||||
}
|
||||
|
||||
- (nullable NSString *)storedOrCachedLocalNumber:(YapDatabaseReadTransaction *)transaction
|
||||
{
|
||||
@synchronized(self) {
|
||||
if (self.cachedLocalNumber) {
|
||||
return self.cachedLocalNumber;
|
||||
}
|
||||
}
|
||||
|
||||
return [transaction stringForKey:TSAccountManager_RegisteredNumberKey
|
||||
inCollection:TSAccountManager_UserAccountCollection];
|
||||
}
|
||||
|
||||
- (void)storeLocalNumber:(NSString *)localNumber
|
||||
{
|
||||
@synchronized (self) {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
//
|
||||
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
|
||||
// Copyright (c) 2019 Open Whisper Systems. All rights reserved.
|
||||
//
|
||||
|
||||
#import "TSYapDatabaseObject.h"
|
||||
|
@ -68,6 +68,8 @@ extern ConversationColorName const kConversationColorName_Default;
|
|||
*/
|
||||
@property (nonatomic, readonly) NSArray<NSString *> *recipientIdentifiers;
|
||||
|
||||
- (BOOL)isNoteToSelf;
|
||||
|
||||
#pragma mark Interactions
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
//
|
||||
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
|
||||
// Copyright (c) 2019 Open Whisper Systems. All rights reserved.
|
||||
//
|
||||
|
||||
#import "TSThread.h"
|
||||
|
@ -7,6 +7,8 @@
|
|||
#import "OWSDisappearingMessagesConfiguration.h"
|
||||
#import "OWSPrimaryStorage.h"
|
||||
#import "OWSReadTracking.h"
|
||||
#import "SSKEnvironment.h"
|
||||
#import "TSAccountManager.h"
|
||||
#import "TSDatabaseView.h"
|
||||
#import "TSIncomingMessage.h"
|
||||
#import "TSInfoMessage.h"
|
||||
|
@ -55,6 +57,17 @@ ConversationColorName const kConversationColorName_Default = ConversationColorNa
|
|||
|
||||
@implementation TSThread
|
||||
|
||||
#pragma mark - Dependencies
|
||||
|
||||
- (TSAccountManager *)tsAccountManager
|
||||
{
|
||||
OWSAssertDebug(SSKEnvironment.shared.tsAccountManager);
|
||||
|
||||
return SSKEnvironment.shared.tsAccountManager;
|
||||
}
|
||||
|
||||
#pragma mark -
|
||||
|
||||
+ (NSString *)collection {
|
||||
return @"TSThread";
|
||||
}
|
||||
|
@ -179,7 +192,13 @@ ConversationColorName const kConversationColorName_Default = ConversationColorNa
|
|||
}
|
||||
}
|
||||
|
||||
#pragma mark To be subclassed.
|
||||
- (BOOL)isNoteToSelf
|
||||
{
|
||||
return (!self.isGroupThread && self.contactIdentifier != nil &&
|
||||
[self.contactIdentifier isEqualToString:self.tsAccountManager.localNumber]);
|
||||
}
|
||||
|
||||
#pragma mark - To be subclassed.
|
||||
|
||||
- (BOOL)isGroupThread {
|
||||
OWSAbstractMethod();
|
||||
|
@ -211,7 +230,7 @@ ConversationColorName const kConversationColorName_Default = ConversationColorNa
|
|||
return NO;
|
||||
}
|
||||
|
||||
#pragma mark Interactions
|
||||
#pragma mark - Interactions
|
||||
|
||||
/**
|
||||
* Iterate over this thread's interactions
|
||||
|
@ -405,7 +424,7 @@ ConversationColorName const kConversationColorName_Default = ConversationColorNa
|
|||
}
|
||||
}
|
||||
|
||||
#pragma mark Disappearing Messages
|
||||
#pragma mark - Disappearing Messages
|
||||
|
||||
- (OWSDisappearingMessagesConfiguration *)disappearingMessagesConfigurationWithTransaction:
|
||||
(YapDatabaseReadTransaction *)transaction
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
//
|
||||
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
|
||||
// Copyright (c) 2019 Open Whisper Systems. All rights reserved.
|
||||
//
|
||||
|
||||
#import "OWSMessageManager.h"
|
||||
|
@ -511,7 +511,7 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
|
||||
if (groupThread) {
|
||||
if (dataMessage.group.type != SSKProtoGroupContextTypeUpdate) {
|
||||
if (![groupThread.groupModel.groupMemberIds containsObject:self.tsAccountManager.localNumber]) {
|
||||
if (!groupThread.isLocalUserInGroup) {
|
||||
OWSLogInfo(@"Ignoring messages for left group.");
|
||||
return;
|
||||
}
|
||||
|
@ -705,7 +705,7 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
if (typingMessage.hasGroupID) {
|
||||
TSGroupThread *groupThread = [TSGroupThread threadWithGroupId:typingMessage.groupID transaction:transaction];
|
||||
|
||||
if (![groupThread.groupModel.groupMemberIds containsObject:self.tsAccountManager.localNumber]) {
|
||||
if (!groupThread.isLocalUserInGroup) {
|
||||
OWSLogInfo(@"Ignoring messages for left group.");
|
||||
return;
|
||||
}
|
||||
|
@ -1135,8 +1135,7 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
}
|
||||
|
||||
// Ensure we are in the group.
|
||||
NSString *localNumber = self.tsAccountManager.localNumber;
|
||||
if (![gThread.groupModel.groupMemberIds containsObject:localNumber]) {
|
||||
if (!gThread.isLocalUserInGroup) {
|
||||
OWSLogWarn(@"Ignoring 'Request Group Info' message for group we no longer belong to.");
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -524,7 +524,7 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException";
|
|||
|
||||
NSMutableSet<NSString *> *recipientIds = [NSMutableSet new];
|
||||
if ([message isKindOfClass:[OWSOutgoingSyncMessage class]]) {
|
||||
[recipientIds addObject:[TSAccountManager localNumber]];
|
||||
[recipientIds addObject:self.tsAccountManager.localNumber];
|
||||
} else if (thread.isGroupThread) {
|
||||
TSGroupThread *groupThread = (TSGroupThread *)thread;
|
||||
|
||||
|
@ -543,7 +543,7 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException";
|
|||
// Only send to members in the latest known group member list.
|
||||
[recipientIds intersectSet:[NSSet setWithArray:groupThread.groupModel.groupMemberIds]];
|
||||
|
||||
if ([recipientIds containsObject:TSAccountManager.localNumber]) {
|
||||
if ([recipientIds containsObject:self.tsAccountManager.localNumber]) {
|
||||
OWSFailDebug(@"Message send recipients should not include self.");
|
||||
}
|
||||
} else if ([thread isKindOfClass:[TSContactThread class]]) {
|
||||
|
@ -565,7 +565,7 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException";
|
|||
|
||||
[recipientIds addObject:recipientContactId];
|
||||
|
||||
if ([recipientIds containsObject:TSAccountManager.localNumber]) {
|
||||
if ([recipientIds containsObject:self.tsAccountManager.localNumber]) {
|
||||
OWSFailDebug(@"Message send recipients should not include self.");
|
||||
}
|
||||
} else {
|
||||
|
@ -706,14 +706,10 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException";
|
|||
|
||||
// In the "self-send" special case, we ony need to send a sync message with a delivery receipt.
|
||||
if ([thread isKindOfClass:[TSContactThread class]] &&
|
||||
[((TSContactThread *)thread).contactIdentifier isEqualToString:[TSAccountManager localNumber]]) {
|
||||
[((TSContactThread *)thread).contactIdentifier isEqualToString:self.tsAccountManager.localNumber]) {
|
||||
// Send to self.
|
||||
OWSAssertDebug(message.recipientIds.count == 1);
|
||||
[self.dbConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||||
for (NSString *recipientId in message.sendingRecipientIds) {
|
||||
[message updateWithReadRecipientId:recipientId readTimestamp:message.timestamp transaction:transaction];
|
||||
}
|
||||
}];
|
||||
// Don't mark self-sent messages as read (or sent) until the sync transcript is sent.
|
||||
successHandler();
|
||||
return;
|
||||
}
|
||||
|
@ -1349,7 +1345,7 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException";
|
|||
NSArray *missingDevices = responseJson[@"missingDevices"];
|
||||
|
||||
if (missingDevices.count > 0) {
|
||||
NSString *localNumber = [TSAccountManager localNumber];
|
||||
NSString *localNumber = self.tsAccountManager.localNumber;
|
||||
if ([localNumber isEqualToString:recipient.uniqueId]) {
|
||||
[OWSDeviceManager.sharedManager setMayHaveLinkedDevices];
|
||||
}
|
||||
|
@ -1381,9 +1377,27 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException";
|
|||
}
|
||||
|
||||
- (void)handleMessageSentLocally:(TSOutgoingMessage *)message
|
||||
success:(void (^)(void))success
|
||||
success:(void (^)(void))successParam
|
||||
failure:(RetryableFailureHandler)failure
|
||||
{
|
||||
dispatch_block_t success = ^{
|
||||
TSThread *_Nullable thread = message.thread;
|
||||
if (thread && [thread isKindOfClass:[TSContactThread class]] &&
|
||||
[thread.contactIdentifier isEqualToString:self.tsAccountManager.localNumber]) {
|
||||
OWSAssertDebug(message.recipientIds.count == 1);
|
||||
// Don't mark self-sent messages as read (or sent) until the sync transcript is sent.
|
||||
[self.dbConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||||
for (NSString *recipientId in message.sendingRecipientIds) {
|
||||
[message updateWithReadRecipientId:recipientId
|
||||
readTimestamp:message.timestamp
|
||||
transaction:transaction];
|
||||
}
|
||||
}];
|
||||
}
|
||||
|
||||
successParam();
|
||||
};
|
||||
|
||||
[self.dbConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||||
[[OWSDisappearingMessagesJob sharedJob] startAnyExpirationForMessage:message
|
||||
expirationStartedAt:[NSDate ows_millisecondTimeStamp]
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
//
|
||||
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
|
||||
// Copyright (c) 2019 Open Whisper Systems. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
@ -25,6 +25,12 @@ public class SearchIndexer<T> {
|
|||
@objc
|
||||
public class FullTextSearchFinder: NSObject {
|
||||
|
||||
// MARK: - Dependencies
|
||||
|
||||
private static var tsAccountManager: TSAccountManager {
|
||||
return TSAccountManager.sharedInstance()
|
||||
}
|
||||
|
||||
// MARK: - Querying
|
||||
|
||||
// We want to match by prefix for "search as you type" functionality.
|
||||
|
@ -184,7 +190,16 @@ public class FullTextSearchFinder: NSObject {
|
|||
return String(String.UnicodeScalarView(digitScalars))
|
||||
}(recipientId)
|
||||
|
||||
return "\(recipientId) \(nationalNumber) \(displayName)"
|
||||
var result = "\(recipientId) \(nationalNumber) \(displayName)"
|
||||
|
||||
if let localNumber = tsAccountManager.storedOrCachedLocalNumber(transaction) {
|
||||
if localNumber == recipientId {
|
||||
let noteToSelfLabel = NSLocalizedString("NOTE_TO_SELF", comment: "Label for 1:1 conversation with yourself.")
|
||||
result += " \(noteToSelfLabel)"
|
||||
}
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
private static let messageIndexer: SearchIndexer<TSMessage> = SearchIndexer { (message: TSMessage, transaction: YapDatabaseReadTransaction) in
|
||||
|
|
Loading…
Reference in a new issue