Merge branch 'charlesmchen/noteToSelf'

pull/1/head
Matthew Chen 6 years ago
commit de8abe269f

@ -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" #import "ConversationViewController.h"
@ -302,6 +302,13 @@ typedef enum : NSUInteger {
return SSKEnvironment.shared.attachmentDownloads; return SSKEnvironment.shared.attachmentDownloads;
} }
- (TSAccountManager *)tsAccountManager
{
OWSAssertDebug(SSKEnvironment.shared.tsAccountManager);
return SSKEnvironment.shared.tsAccountManager;
}
#pragma mark - #pragma mark -
- (void)addNotificationListeners - (void)addNotificationListeners
@ -490,7 +497,7 @@ typedef enum : NSUInteger {
} }
TSGroupThread *groupThread = (TSGroupThread *)self.thread; TSGroupThread *groupThread = (TSGroupThread *)self.thread;
return ![groupThread.groupModel.groupMemberIds containsObject:[TSAccountManager localNumber]]; return !groupThread.isLocalUserInGroup;
} }
- (void)hideInputIfNeeded - (void)hideInputIfNeeded
@ -1250,11 +1257,20 @@ typedef enum : NSUInteger {
} }
} else { } else {
OWSAssertDebug(self.thread.contactIdentifier); OWSAssertDebug(self.thread.contactIdentifier);
name =
[self.contactsManager attributedContactOrProfileNameForPhoneIdentifier:self.thread.contactIdentifier 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 primaryFont:self.headerView.titlePrimaryFont
secondaryFont:self.headerView.titleSecondaryFont]; secondaryFont:self.headerView.titleSecondaryFont];
} }
}
self.title = nil; self.title = nil;
if ([name isEqual:self.headerView.attributedTitle]) { if ([name isEqual:self.headerView.attributedTitle]) {
@ -1557,7 +1573,7 @@ typedef enum : NSUInteger {
- (BOOL)canCall - (BOOL)canCall
{ {
return !(self.isGroupConversation || return !(self.isGroupConversation ||
[((TSContactThread *)self.thread).contactIdentifier isEqualToString:[TSAccountManager localNumber]]); [((TSContactThread *)self.thread).contactIdentifier isEqualToString:self.tsAccountManager.localNumber]);
} }
#pragma mark - Dynamic Text #pragma mark - Dynamic Text
@ -3807,7 +3823,7 @@ typedef enum : NSUInteger {
OWSAssertDebug(groupModel); OWSAssertDebug(groupModel);
NSMutableSet *groupMemberIds = [NSMutableSet setWithArray:groupModel.groupMemberIds]; NSMutableSet *groupMemberIds = [NSMutableSet setWithArray:groupModel.groupMemberIds];
[groupMemberIds addObject:[TSAccountManager localNumber]]; [groupMemberIds addObject:self.tsAccountManager.localNumber];
groupModel.groupMemberIds = [NSMutableArray arrayWithArray:[groupMemberIds allObjects]]; groupModel.groupMemberIds = [NSMutableArray arrayWithArray:[groupMemberIds allObjects]];
[self updateGroupModelTo:groupModel successCompletion:nil]; [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" #import "HomeViewCell.h"
@ -53,6 +53,13 @@ NS_ASSUME_NONNULL_BEGIN
return SSKEnvironment.shared.typingIndicators; return SSKEnvironment.shared.typingIndicators;
} }
- (TSAccountManager *)tsAccountManager
{
OWSAssertDebug(SSKEnvironment.shared.tsAccountManager);
return SSKEnvironment.shared.tsAccountManager;
}
#pragma mark - #pragma mark -
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(nullable NSString *)reuseIdentifier - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(nullable NSString *)reuseIdentifier
@ -509,11 +516,19 @@ NS_ASSUME_NONNULL_BEGIN
} else { } else {
name = [[NSAttributedString alloc] initWithString:thread.name]; name = [[NSAttributedString alloc] initWithString:thread.name];
} }
} else {
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 { } else {
name = [self.contactsManager attributedContactOrProfileNameForPhoneIdentifier:thread.contactIdentifier name = [self.contactsManager attributedContactOrProfileNameForPhoneIdentifier:thread.contactIdentifier
primaryFont:self.nameFont primaryFont:self.nameFont
secondaryFont:self.nameSecondaryFont]; secondaryFont:self.nameSecondaryFont];
} }
}
self.nameLabel.attributedText = name; 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" #import "OWSConversationSettingsViewController.h"
@ -55,10 +55,6 @@ const CGFloat kIconViewLength = 24;
@property (nonatomic) NSArray<NSNumber *> *disappearingMessagesDurations; @property (nonatomic) NSArray<NSNumber *> *disappearingMessagesDurations;
@property (nonatomic) OWSDisappearingMessagesConfiguration *disappearingMessagesConfiguration; @property (nonatomic) OWSDisappearingMessagesConfiguration *disappearingMessagesConfiguration;
@property (nullable, nonatomic) MediaGallery *mediaGallery; @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) ContactsViewHelper *contactsViewHelper;
@property (nonatomic, readonly) UIImageView *avatarView; @property (nonatomic, readonly) UIImageView *avatarView;
@property (nonatomic, readonly) UILabel *disappearingMessagesDurationLabel; @property (nonatomic, readonly) UILabel *disappearingMessagesDurationLabel;
@ -110,10 +106,6 @@ const CGFloat kIconViewLength = 24;
- (void)commonInit - (void)commonInit
{ {
_accountManager = [TSAccountManager sharedInstance];
_contactsManager = Environment.shared.contactsManager;
_messageSender = SSKEnvironment.shared.messageSender;
_blockingManager = [OWSBlockingManager sharedManager];
_contactsViewHelper = [[ContactsViewHelper alloc] initWithDelegate:self]; _contactsViewHelper = [[ContactsViewHelper alloc] initWithDelegate:self];
[self observeNotifications]; [self observeNotifications];
@ -131,6 +123,33 @@ const CGFloat kIconViewLength = 24;
return SSKEnvironment.shared.messageSenderJobQueue; 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 #pragma mark
- (void)observeNotifications - (void)observeNotifications
@ -291,6 +310,8 @@ const CGFloat kIconViewLength = 24;
OWSTableContents *contents = [OWSTableContents new]; OWSTableContents *contents = [OWSTableContents new];
contents.title = NSLocalizedString(@"CONVERSATION_SETTINGS", @"title for conversation settings screen"); contents.title = NSLocalizedString(@"CONVERSATION_SETTINGS", @"title for conversation settings screen");
BOOL isNoteToSelf = self.thread.isNoteToSelf;
__weak OWSConversationSettingsViewController *weakSelf = self; __weak OWSConversationSettingsViewController *weakSelf = self;
// Main section. // 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:^{ [mainSection addItem:[OWSTableItem itemWithCustomCellBlock:^{
return [weakSelf return [weakSelf
disclosureCellWithName: 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 [mainSection
addItem:[OWSTableItem addItem:[OWSTableItem
itemWithCustomCellBlock:^{ itemWithCustomCellBlock:^{
@ -564,6 +587,7 @@ const CGFloat kIconViewLength = 24;
// Mute thread section. // Mute thread section.
if (!isNoteToSelf) {
OWSTableSection *notificationsSection = [OWSTableSection new]; OWSTableSection *notificationsSection = [OWSTableSection new];
// We need a section header to separate the notifications UI from the group settings UI. // We need a section header to separate the notifications UI from the group settings UI.
notificationsSection.headerTitle = NSLocalizedString( notificationsSection.headerTitle = NSLocalizedString(
@ -609,7 +633,8 @@ const CGFloat kIconViewLength = 24;
}]]; }]];
[notificationsSection [notificationsSection
addItem:[OWSTableItem addItem:
[OWSTableItem
itemWithCustomCellBlock:^{ itemWithCustomCellBlock:^{
UITableViewCell *cell = UITableViewCell *cell =
[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:nil]; [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:nil];
@ -672,12 +697,13 @@ const CGFloat kIconViewLength = 24;
actionBlock:^{ actionBlock:^{
[weakSelf showMuteUnmuteActionSheet]; [weakSelf showMuteUnmuteActionSheet];
}]]; }]];
notificationsSection.footerTitle notificationsSection.footerTitle = NSLocalizedString(
= NSLocalizedString(@"MUTE_BEHAVIOR_EXPLANATION", @"An explanation of the consequences of muting a thread."); @"MUTE_BEHAVIOR_EXPLANATION", @"An explanation of the consequences of muting a thread.");
[contents addSection:notificationsSection]; [contents addSection:notificationsSection];
}
// Block Conversation section. // Block Conversation section.
if (!isNoteToSelf) {
OWSTableSection *section = [OWSTableSection new]; OWSTableSection *section = [OWSTableSection new];
if (self.thread.isGroupThread) { if (self.thread.isGroupThread) {
section.footerTitle = NSLocalizedString( section.footerTitle = NSLocalizedString(
@ -718,6 +744,7 @@ const CGFloat kIconViewLength = 24;
} }
actionBlock:nil]]; actionBlock:nil]];
[contents addSection:section]; [contents addSection:section];
}
self.contents = contents; self.contents = contents;
} }
@ -961,7 +988,7 @@ const CGFloat kIconViewLength = 24;
- (void)showShareProfileAlert - (void)showShareProfileAlert
{ {
[OWSProfileManager.sharedManager presentAddThreadToProfileWhitelist:self.thread [self.profileManager presentAddThreadToProfileWhitelist:self.thread
fromViewController:self fromViewController:self
success:^{ success:^{
[self updateTableContents]; [self updateTableContents];
@ -1057,8 +1084,7 @@ const CGFloat kIconViewLength = 24;
{ {
if (self.isGroupThread) { if (self.isGroupThread) {
TSGroupThread *groupThread = (TSGroupThread *)self.thread; TSGroupThread *groupThread = (TSGroupThread *)self.thread;
BOOL inGroup = [groupThread.groupModel.groupMemberIds containsObject:TSAccountManager.localNumber]; return !groupThread.isLocalUserInGroup;
return !inGroup;
} }
return NO; return NO;
@ -1118,8 +1144,8 @@ const CGFloat kIconViewLength = 24;
} }
[BlockListUIUtils showUnblockThreadActionSheet:self.thread [BlockListUIUtils showUnblockThreadActionSheet:self.thread
fromViewController:self fromViewController:self
blockingManager:_blockingManager blockingManager:self.blockingManager
contactsManager:_contactsManager contactsManager:self.contactsManager
completionBlock:^(BOOL isBlocked) { completionBlock:^(BOOL isBlocked) {
// Update switch state if user cancels action. // Update switch state if user cancels action.
blockConversationSwitch.on = isBlocked; blockConversationSwitch.on = isBlocked;

@ -1466,6 +1466,9 @@
/* Label for a button that lets users search for contacts by phone number */ /* Label for a button that lets users search for contacts by phone number */
"NO_CONTACTS_SEARCH_BY_PHONE_NUMBER" = "Find 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') */ /* 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."; "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; return SSKEnvironment.shared.primaryStorage;
} }
- (TSAccountManager *)tsAccountManager
{
OWSAssertDebug(SSKEnvironment.shared.tsAccountManager);
return SSKEnvironment.shared.tsAccountManager;
}
#pragma mark - #pragma mark -
- (void)configure - (void)configure
@ -133,8 +140,17 @@ const CGFloat kContactCellAvatarTextMargin = 12;
self.thread = [TSContactThread getThreadWithContactId:recipientId transaction:transaction]; self.thread = [TSContactThread getThreadWithContactId:recipientId transaction:transaction];
}]; }];
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.nameLabel.attributedText =
[self.contactsManager formattedFullNameForRecipientId:recipientId font:self.nameLabel.font]; [self.contactsManager formattedFullNameForRecipientId:recipientId font:self.nameLabel.font];
}
[[NSNotificationCenter defaultCenter] addObserver:self [[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(otherUsersProfileDidChange:) selector:@selector(otherUsersProfileDidChange:)
@ -165,6 +181,12 @@ const CGFloat kContactCellAvatarTextMargin = 12;
threadName = [MessageStrings newGroupDefaultTitle]; 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 *attributedText =
[[NSAttributedString alloc] initWithString:threadName [[NSAttributedString alloc] initWithString:threadName
attributes:@{ 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" #import "TSConstants.h"
@ -14,6 +14,7 @@ extern NSString *const kNSNotificationName_LocalNumberDidChange;
@class AnyPromise; @class AnyPromise;
@class OWSPrimaryStorage; @class OWSPrimaryStorage;
@class TSNetworkManager; @class TSNetworkManager;
@class YapDatabaseReadTransaction;
@class YapDatabaseReadWriteTransaction; @class YapDatabaseReadWriteTransaction;
typedef NS_ENUM(NSUInteger, OWSRegistrationState) { typedef NS_ENUM(NSUInteger, OWSRegistrationState) {
@ -57,6 +58,9 @@ typedef NS_ENUM(NSUInteger, OWSRegistrationState) {
+ (nullable NSString *)localNumber; + (nullable NSString *)localNumber;
- (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, * 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" #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 - (void)storeLocalNumber:(NSString *)localNumber
{ {
@synchronized (self) { @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" #import "TSYapDatabaseObject.h"
@ -68,6 +68,8 @@ extern ConversationColorName const kConversationColorName_Default;
*/ */
@property (nonatomic, readonly) NSArray<NSString *> *recipientIdentifiers; @property (nonatomic, readonly) NSArray<NSString *> *recipientIdentifiers;
- (BOOL)isNoteToSelf;
#pragma mark Interactions #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" #import "TSThread.h"
@ -7,6 +7,8 @@
#import "OWSDisappearingMessagesConfiguration.h" #import "OWSDisappearingMessagesConfiguration.h"
#import "OWSPrimaryStorage.h" #import "OWSPrimaryStorage.h"
#import "OWSReadTracking.h" #import "OWSReadTracking.h"
#import "SSKEnvironment.h"
#import "TSAccountManager.h"
#import "TSDatabaseView.h" #import "TSDatabaseView.h"
#import "TSIncomingMessage.h" #import "TSIncomingMessage.h"
#import "TSInfoMessage.h" #import "TSInfoMessage.h"
@ -55,6 +57,17 @@ ConversationColorName const kConversationColorName_Default = ConversationColorNa
@implementation TSThread @implementation TSThread
#pragma mark - Dependencies
- (TSAccountManager *)tsAccountManager
{
OWSAssertDebug(SSKEnvironment.shared.tsAccountManager);
return SSKEnvironment.shared.tsAccountManager;
}
#pragma mark -
+ (NSString *)collection { + (NSString *)collection {
return @"TSThread"; 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 { - (BOOL)isGroupThread {
OWSAbstractMethod(); OWSAbstractMethod();
@ -211,7 +230,7 @@ ConversationColorName const kConversationColorName_Default = ConversationColorNa
return NO; return NO;
} }
#pragma mark Interactions #pragma mark - Interactions
/** /**
* Iterate over this thread's 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: - (OWSDisappearingMessagesConfiguration *)disappearingMessagesConfigurationWithTransaction:
(YapDatabaseReadTransaction *)transaction (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" #import "OWSMessageManager.h"
@ -511,7 +511,7 @@ NS_ASSUME_NONNULL_BEGIN
if (groupThread) { if (groupThread) {
if (dataMessage.group.type != SSKProtoGroupContextTypeUpdate) { if (dataMessage.group.type != SSKProtoGroupContextTypeUpdate) {
if (![groupThread.groupModel.groupMemberIds containsObject:self.tsAccountManager.localNumber]) { if (!groupThread.isLocalUserInGroup) {
OWSLogInfo(@"Ignoring messages for left group."); OWSLogInfo(@"Ignoring messages for left group.");
return; return;
} }
@ -705,7 +705,7 @@ NS_ASSUME_NONNULL_BEGIN
if (typingMessage.hasGroupID) { if (typingMessage.hasGroupID) {
TSGroupThread *groupThread = [TSGroupThread threadWithGroupId:typingMessage.groupID transaction:transaction]; 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."); OWSLogInfo(@"Ignoring messages for left group.");
return; return;
} }
@ -1135,8 +1135,7 @@ NS_ASSUME_NONNULL_BEGIN
} }
// Ensure we are in the group. // Ensure we are in the group.
NSString *localNumber = self.tsAccountManager.localNumber; if (!gThread.isLocalUserInGroup) {
if (![gThread.groupModel.groupMemberIds containsObject:localNumber]) {
OWSLogWarn(@"Ignoring 'Request Group Info' message for group we no longer belong to."); OWSLogWarn(@"Ignoring 'Request Group Info' message for group we no longer belong to.");
return; return;
} }

@ -524,7 +524,7 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException";
NSMutableSet<NSString *> *recipientIds = [NSMutableSet new]; NSMutableSet<NSString *> *recipientIds = [NSMutableSet new];
if ([message isKindOfClass:[OWSOutgoingSyncMessage class]]) { if ([message isKindOfClass:[OWSOutgoingSyncMessage class]]) {
[recipientIds addObject:[TSAccountManager localNumber]]; [recipientIds addObject:self.tsAccountManager.localNumber];
} else if (thread.isGroupThread) { } else if (thread.isGroupThread) {
TSGroupThread *groupThread = (TSGroupThread *)thread; TSGroupThread *groupThread = (TSGroupThread *)thread;
@ -543,7 +543,7 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException";
// Only send to members in the latest known group member list. // Only send to members in the latest known group member list.
[recipientIds intersectSet:[NSSet setWithArray:groupThread.groupModel.groupMemberIds]]; [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."); OWSFailDebug(@"Message send recipients should not include self.");
} }
} else if ([thread isKindOfClass:[TSContactThread class]]) { } else if ([thread isKindOfClass:[TSContactThread class]]) {
@ -565,7 +565,7 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException";
[recipientIds addObject:recipientContactId]; [recipientIds addObject:recipientContactId];
if ([recipientIds containsObject:TSAccountManager.localNumber]) { if ([recipientIds containsObject:self.tsAccountManager.localNumber]) {
OWSFailDebug(@"Message send recipients should not include self."); OWSFailDebug(@"Message send recipients should not include self.");
} }
} else { } 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. // In the "self-send" special case, we ony need to send a sync message with a delivery receipt.
if ([thread isKindOfClass:[TSContactThread class]] && if ([thread isKindOfClass:[TSContactThread class]] &&
[((TSContactThread *)thread).contactIdentifier isEqualToString:[TSAccountManager localNumber]]) { [((TSContactThread *)thread).contactIdentifier isEqualToString:self.tsAccountManager.localNumber]) {
// Send to self. // Send to self.
OWSAssertDebug(message.recipientIds.count == 1); OWSAssertDebug(message.recipientIds.count == 1);
[self.dbConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) { // Don't mark self-sent messages as read (or sent) until the sync transcript is sent.
for (NSString *recipientId in message.sendingRecipientIds) {
[message updateWithReadRecipientId:recipientId readTimestamp:message.timestamp transaction:transaction];
}
}];
successHandler(); successHandler();
return; return;
} }
@ -1349,7 +1345,7 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException";
NSArray *missingDevices = responseJson[@"missingDevices"]; NSArray *missingDevices = responseJson[@"missingDevices"];
if (missingDevices.count > 0) { if (missingDevices.count > 0) {
NSString *localNumber = [TSAccountManager localNumber]; NSString *localNumber = self.tsAccountManager.localNumber;
if ([localNumber isEqualToString:recipient.uniqueId]) { if ([localNumber isEqualToString:recipient.uniqueId]) {
[OWSDeviceManager.sharedManager setMayHaveLinkedDevices]; [OWSDeviceManager.sharedManager setMayHaveLinkedDevices];
} }
@ -1381,9 +1377,27 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException";
} }
- (void)handleMessageSentLocally:(TSOutgoingMessage *)message - (void)handleMessageSentLocally:(TSOutgoingMessage *)message
success:(void (^)(void))success success:(void (^)(void))successParam
failure:(RetryableFailureHandler)failure 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) { [self.dbConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
[[OWSDisappearingMessagesJob sharedJob] startAnyExpirationForMessage:message [[OWSDisappearingMessagesJob sharedJob] startAnyExpirationForMessage:message
expirationStartedAt:[NSDate ows_millisecondTimeStamp] 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 import Foundation
@ -25,6 +25,12 @@ public class SearchIndexer<T> {
@objc @objc
public class FullTextSearchFinder: NSObject { public class FullTextSearchFinder: NSObject {
// MARK: - Dependencies
private static var tsAccountManager: TSAccountManager {
return TSAccountManager.sharedInstance()
}
// MARK: - Querying // MARK: - Querying
// We want to match by prefix for "search as you type" functionality. // 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)) return String(String.UnicodeScalarView(digitScalars))
}(recipientId) }(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 private static let messageIndexer: SearchIndexer<TSMessage> = SearchIndexer { (message: TSMessage, transaction: YapDatabaseReadTransaction) in

Loading…
Cancel
Save