Don't use group name in message.

// FREEBIE
This commit is contained in:
Michael Kirk 2018-06-14 10:35:47 -04:00
parent 95b1dced18
commit 0a17246737
8 changed files with 51 additions and 49 deletions

View File

@ -3423,11 +3423,11 @@ typedef OWSContact * (^OWSContactBlock)(YapDatabaseReadWriteTransaction *transac
enabled:YES enabled:YES
durationSeconds:(uint32_t)[durationSeconds intValue]]; durationSeconds:(uint32_t)[durationSeconds intValue]];
[result addObject:[[OWSDisappearingConfigurationUpdateInfoMessage alloc] [result addObject:[[OWSDisappearingConfigurationUpdateInfoMessage alloc]
initWithTimestamp:[NSDate ows_millisecondTimeStamp] initWithTimestamp:[NSDate ows_millisecondTimeStamp]
thread:thread thread:thread
configuration:disappearingMessagesConfiguration configuration:disappearingMessagesConfiguration
createdByRemoteName:@"Alice" createdByRemoteName:@"Alice"
createdInExistingGroupName:nil]]; createdInExistingGroup:NO]];
} }
{ {
@ -3437,11 +3437,11 @@ typedef OWSContact * (^OWSContactBlock)(YapDatabaseReadWriteTransaction *transac
enabled:YES enabled:YES
durationSeconds:(uint32_t)[durationSeconds intValue]]; durationSeconds:(uint32_t)[durationSeconds intValue]];
[result addObject:[[OWSDisappearingConfigurationUpdateInfoMessage alloc] [result addObject:[[OWSDisappearingConfigurationUpdateInfoMessage alloc]
initWithTimestamp:[NSDate ows_millisecondTimeStamp] initWithTimestamp:[NSDate ows_millisecondTimeStamp]
thread:thread thread:thread
configuration:disappearingMessagesConfiguration configuration:disappearingMessagesConfiguration
createdByRemoteName:nil createdByRemoteName:nil
createdInExistingGroupName:@"Book Club"]]; createdInExistingGroup:YES]];
} }
{ {
@ -3451,11 +3451,11 @@ typedef OWSContact * (^OWSContactBlock)(YapDatabaseReadWriteTransaction *transac
enabled:YES enabled:YES
durationSeconds:(uint32_t)[durationSeconds intValue]]; durationSeconds:(uint32_t)[durationSeconds intValue]];
[result addObject:[[OWSDisappearingConfigurationUpdateInfoMessage alloc] [result addObject:[[OWSDisappearingConfigurationUpdateInfoMessage alloc]
initWithTimestamp:[NSDate ows_millisecondTimeStamp] initWithTimestamp:[NSDate ows_millisecondTimeStamp]
thread:thread thread:thread
configuration:disappearingMessagesConfiguration configuration:disappearingMessagesConfiguration
createdByRemoteName:@"Alice" createdByRemoteName:@"Alice"
createdInExistingGroupName:nil]]; createdInExistingGroup:NO]];
} }
{ {
OWSDisappearingMessagesConfiguration *disappearingMessagesConfiguration = OWSDisappearingMessagesConfiguration *disappearingMessagesConfiguration =
@ -3463,11 +3463,11 @@ typedef OWSContact * (^OWSContactBlock)(YapDatabaseReadWriteTransaction *transac
enabled:NO enabled:NO
durationSeconds:0]; durationSeconds:0];
[result addObject:[[OWSDisappearingConfigurationUpdateInfoMessage alloc] [result addObject:[[OWSDisappearingConfigurationUpdateInfoMessage alloc]
initWithTimestamp:[NSDate ows_millisecondTimeStamp] initWithTimestamp:[NSDate ows_millisecondTimeStamp]
thread:thread thread:thread
configuration:disappearingMessagesConfiguration configuration:disappearingMessagesConfiguration
createdByRemoteName:@"Alice" createdByRemoteName:@"Alice"
createdInExistingGroupName:nil]]; createdInExistingGroup:NO]];
} }
[result addObject:[TSInfoMessage userNotRegisteredMessageInThread:thread recipientId:@"+19174054215"]]; [result addObject:[TSInfoMessage userNotRegisteredMessageInThread:thread recipientId:@"+19174054215"]];

View File

@ -821,11 +821,11 @@ NS_ASSUME_NONNULL_BEGIN
[self.disappearingMessagesConfiguration save]; [self.disappearingMessagesConfiguration save];
OWSDisappearingConfigurationUpdateInfoMessage *infoMessage = OWSDisappearingConfigurationUpdateInfoMessage *infoMessage =
[[OWSDisappearingConfigurationUpdateInfoMessage alloc] [[OWSDisappearingConfigurationUpdateInfoMessage alloc]
initWithTimestamp:[NSDate ows_millisecondTimeStamp] initWithTimestamp:[NSDate ows_millisecondTimeStamp]
thread:self.thread thread:self.thread
configuration:self.disappearingMessagesConfiguration configuration:self.disappearingMessagesConfiguration
createdByRemoteName:nil createdByRemoteName:nil
createdInExistingGroupName:nil]; createdInExistingGroup:NO];
[infoMessage save]; [infoMessage save];
[OWSNotifyRemoteOfUpdatedDisappearingConfigurationJob [OWSNotifyRemoteOfUpdatedDisappearingConfigurationJob

View File

@ -660,7 +660,7 @@
"DISAPPEARING_MESSAGES" = "Disappearing Messages"; "DISAPPEARING_MESSAGES" = "Disappearing Messages";
/* Info Message when added to {{group name}} which has enabled message expiration after {{time amount}}, see the *_TIME_AMOUNT strings for context. */ /* Info Message when added to {{group name}} which has enabled message expiration after {{time amount}}, see the *_TIME_AMOUNT strings for context. */
"DISAPPEARING_MESSAGES_CONFIGURATION_GROUP_EXISTING_FORMAT" = "%@ has disappearing messages enabled for %@."; "DISAPPEARING_MESSAGES_CONFIGURATION_GROUP_EXISTING_FORMAT" = "Messages in this conversation will disappear after %@.";
/* subheading in conversation settings */ /* subheading in conversation settings */
"DISAPPEARING_MESSAGES_DESCRIPTION" = "When enabled, messages sent and received in this conversation will disappear after they have been seen."; "DISAPPEARING_MESSAGES_DESCRIPTION" = "When enabled, messages sent and received in this conversation will disappear after they have been seen.";

View File

@ -18,7 +18,7 @@ NS_ASSUME_NONNULL_BEGIN
thread:(TSThread *)thread thread:(TSThread *)thread
configuration:(OWSDisappearingMessagesConfiguration *)configuration configuration:(OWSDisappearingMessagesConfiguration *)configuration
createdByRemoteName:(nullable NSString *)remoteName createdByRemoteName:(nullable NSString *)remoteName
createdInExistingGroupName:(nullable NSString *)createdInExistingGroupName; createdInExistingGroup:(BOOL)createdInExistingGroup;
@end @end

View File

@ -11,7 +11,7 @@ NS_ASSUME_NONNULL_BEGIN
@interface OWSDisappearingConfigurationUpdateInfoMessage () @interface OWSDisappearingConfigurationUpdateInfoMessage ()
@property (nonatomic, readonly, nullable) NSString *createdByRemoteName; @property (nonatomic, readonly, nullable) NSString *createdByRemoteName;
@property (nonatomic, readonly, nullable) NSString *createdInExistingGroupName; @property (nonatomic, readonly) BOOL createdInExistingGroup;
@property (nonatomic, readonly) BOOL configurationIsEnabled; @property (nonatomic, readonly) BOOL configurationIsEnabled;
@property (nonatomic, readonly) uint32_t configurationDurationSeconds; @property (nonatomic, readonly) uint32_t configurationDurationSeconds;
@ -23,7 +23,7 @@ NS_ASSUME_NONNULL_BEGIN
thread:(TSThread *)thread thread:(TSThread *)thread
configuration:(OWSDisappearingMessagesConfiguration *)configuration configuration:(OWSDisappearingMessagesConfiguration *)configuration
createdByRemoteName:(nullable NSString *)remoteName createdByRemoteName:(nullable NSString *)remoteName
createdInExistingGroupName:(nullable NSString *)createdInExistingGroupName createdInExistingGroup:(BOOL)createdInExistingGroup
{ {
self = [super initWithTimestamp:timestamp inThread:thread messageType:TSInfoMessageTypeDisappearingMessagesUpdate]; self = [super initWithTimestamp:timestamp inThread:thread messageType:TSInfoMessageTypeDisappearingMessagesUpdate];
if (!self) { if (!self) {
@ -32,8 +32,12 @@ NS_ASSUME_NONNULL_BEGIN
_configurationIsEnabled = configuration.isEnabled; _configurationIsEnabled = configuration.isEnabled;
_configurationDurationSeconds = configuration.durationSeconds; _configurationDurationSeconds = configuration.durationSeconds;
// At most one should be set
OWSAssert(!remoteName || !createdInExistingGroup);
_createdByRemoteName = remoteName; _createdByRemoteName = remoteName;
_createdInExistingGroupName = createdInExistingGroupName; _createdInExistingGroup = createdInExistingGroup;
return self; return self;
} }
@ -47,7 +51,15 @@ NS_ASSUME_NONNULL_BEGIN
-(NSString *)previewTextWithTransaction:(YapDatabaseReadTransaction *)transaction -(NSString *)previewTextWithTransaction:(YapDatabaseReadTransaction *)transaction
{ {
if (self.createdByRemoteName) { if (self.createdInExistingGroup) {
OWSAssert(self.configurationIsEnabled && self.configurationDurationSeconds > 0);
NSString *infoFormat = NSLocalizedString(@"DISAPPEARING_MESSAGES_CONFIGURATION_GROUP_EXISTING_FORMAT",
@"Info Message when added to a group which has enabled disappearing messages. Embeds {{time amount}} "
@"before messages disappear, see the *_TIME_AMOUNT strings for context.");
NSString *durationString = [NSString formatDurationSeconds:self.configurationDurationSeconds useShortFormat:NO];
return [NSString stringWithFormat:infoFormat, durationString];
} else if (self.createdByRemoteName) {
if (self.configurationIsEnabled && self.configurationDurationSeconds > 0) { if (self.configurationIsEnabled && self.configurationDurationSeconds > 0) {
NSString *infoFormat = NSLocalizedString(@"OTHER_UPDATED_DISAPPEARING_MESSAGES_CONFIGURATION", NSString *infoFormat = NSLocalizedString(@"OTHER_UPDATED_DISAPPEARING_MESSAGES_CONFIGURATION",
@"Info Message when {{other user}} updates message expiration to {{time amount}}, see the " @"Info Message when {{other user}} updates message expiration to {{time amount}}, see the "
@ -62,14 +74,6 @@ NS_ASSUME_NONNULL_BEGIN
@"Info Message when {{other user}} disables or doesn't support disappearing messages"); @"Info Message when {{other user}} disables or doesn't support disappearing messages");
return [NSString stringWithFormat:infoFormat, self.createdByRemoteName]; return [NSString stringWithFormat:infoFormat, self.createdByRemoteName];
} }
} else if (self.createdInExistingGroupName) {
OWSAssert(self.configurationIsEnabled && self.configurationDurationSeconds > 0);
NSString *infoFormat = NSLocalizedString(@"DISAPPEARING_MESSAGES_CONFIGURATION_GROUP_EXISTING_FORMAT",
@"Info Message when added to {{group name}} which has enabled message expiration after {{time amount}}, "
@"see the *_TIME_AMOUNT strings for context.");
NSString *durationString = [NSString formatDurationSeconds:self.configurationDurationSeconds useShortFormat:NO];
return [NSString stringWithFormat:infoFormat, self.createdByRemoteName, durationString];
} else { } else {
// Changed by local request // Changed by local request
if (self.configurationIsEnabled && self.configurationDurationSeconds > 0) { if (self.configurationIsEnabled && self.configurationDurationSeconds > 0) {

View File

@ -49,14 +49,14 @@ NS_ASSUME_NONNULL_BEGIN
* *
* @param remoteContactName * @param remoteContactName
* nil for outgoing messages, otherwise the name of the sender * nil for outgoing messages, otherwise the name of the sender
* @param existingGroupName * @param createdInExistingGroup
* set when being added to a group which already has DM enabled, otherwise nil * YES when being added to a group which already has DM enabled, otherwise NO
*/ */
- (void)becomeConsistentWithDisappearingDuration:(uint32_t)duration - (void)becomeConsistentWithDisappearingDuration:(uint32_t)duration
thread:(TSThread *)thread thread:(TSThread *)thread
appearBeforeTimestamp:(uint64_t)timestampForSorting appearBeforeTimestamp:(uint64_t)timestampForSorting
createdByRemoteContactName:(nullable NSString *)remoteContactName createdByRemoteContactName:(nullable NSString *)remoteContactName
createdInExistingGroupName:(nullable NSString *)existingGroupName createdInExistingGroup:(BOOL)createdInExistingGroup
transaction:(YapDatabaseReadWriteTransaction *)transaction; transaction:(YapDatabaseReadWriteTransaction *)transaction;
// Clean up any messages that expired since last launch immediately // Clean up any messages that expired since last launch immediately

View File

@ -208,7 +208,7 @@ void AssertIsOnDisappearingMessagesQueue()
thread:thread thread:thread
appearBeforeTimestamp:message.timestampForSorting appearBeforeTimestamp:message.timestampForSorting
createdByRemoteContactName:remoteContactName createdByRemoteContactName:remoteContactName
createdInExistingGroupName:nil createdInExistingGroup:NO
transaction:transaction]; transaction:transaction];
} }
@ -216,7 +216,7 @@ void AssertIsOnDisappearingMessagesQueue()
thread:(TSThread *)thread thread:(TSThread *)thread
appearBeforeTimestamp:(uint64_t)timestampForSorting appearBeforeTimestamp:(uint64_t)timestampForSorting
createdByRemoteContactName:(nullable NSString *)remoteContactName createdByRemoteContactName:(nullable NSString *)remoteContactName
createdInExistingGroupName:(nullable NSString *)existingGroupName createdInExistingGroup:(BOOL)createdInExistingGroup
transaction:(YapDatabaseReadWriteTransaction *)transaction transaction:(YapDatabaseReadWriteTransaction *)transaction
{ {
OWSAssert(thread); OWSAssert(thread);
@ -253,7 +253,7 @@ void AssertIsOnDisappearingMessagesQueue()
thread:thread thread:thread
configuration:disappearingMessagesConfiguration configuration:disappearingMessagesConfiguration
createdByRemoteName:remoteContactName createdByRemoteName:remoteContactName
createdInExistingGroupName:existingGroupName]; createdInExistingGroup:createdInExistingGroup];
[infoMessage saveWithTransaction:transaction]; [infoMessage saveWithTransaction:transaction];
backgroundTask = nil; backgroundTask = nil;

View File

@ -776,7 +776,7 @@ NS_ASSUME_NONNULL_BEGIN
thread:thread thread:thread
configuration:disappearingMessagesConfiguration configuration:disappearingMessagesConfiguration
createdByRemoteName:name createdByRemoteName:name
createdInExistingGroupName:nil]; createdInExistingGroup:NO];
[message saveWithTransaction:transaction]; [message saveWithTransaction:transaction];
} }
@ -968,14 +968,12 @@ NS_ASSUME_NONNULL_BEGIN
customMessage:updateGroupInfo] saveWithTransaction:transaction]; customMessage:updateGroupInfo] saveWithTransaction:transaction];
if (dataMessage.hasExpireTimer && dataMessage.expireTimer > 0) { if (dataMessage.hasExpireTimer && dataMessage.expireTimer > 0) {
// We could use the sender name here, but maybe it makes more sense to attribute it to the group.
NSString *configUpdateName = dataMessage.group.name;
[[OWSDisappearingMessagesJob sharedJob] [[OWSDisappearingMessagesJob sharedJob]
becomeConsistentWithDisappearingDuration:dataMessage.expireTimer becomeConsistentWithDisappearingDuration:dataMessage.expireTimer
thread:newGroupThread thread:newGroupThread
appearBeforeTimestamp:now appearBeforeTimestamp:now
createdByRemoteContactName:nil createdByRemoteContactName:nil
createdInExistingGroupName:configUpdateName createdInExistingGroup:YES
transaction:transaction]; transaction:transaction];
} }