2016-10-05 17:42:44 +02:00
|
|
|
// Created by Michael Kirk on 9/25/16.
|
|
|
|
// Copyright © 2016 Open Whisper Systems. All rights reserved.
|
|
|
|
|
|
|
|
#import "OWSNotifyRemoteOfUpdatedDisappearingConfigurationJob.h"
|
|
|
|
#import "OWSDisappearingMessagesConfigurationMessage.h"
|
2016-10-14 23:00:29 +02:00
|
|
|
#import "OWSMessageSender.h"
|
2016-10-05 17:42:44 +02:00
|
|
|
|
|
|
|
NS_ASSUME_NONNULL_BEGIN
|
|
|
|
|
|
|
|
@interface OWSNotifyRemoteOfUpdatedDisappearingConfigurationJob ()
|
|
|
|
|
|
|
|
@property (nonatomic, readonly) OWSDisappearingMessagesConfiguration *configuration;
|
2016-10-14 23:00:29 +02:00
|
|
|
@property (nonatomic, readonly) OWSMessageSender *messageSender;
|
2016-10-05 17:42:44 +02:00
|
|
|
@property (nonatomic, readonly) TSThread *thread;
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation OWSNotifyRemoteOfUpdatedDisappearingConfigurationJob
|
|
|
|
|
|
|
|
- (instancetype)initWithConfiguration:(OWSDisappearingMessagesConfiguration *)configuration
|
|
|
|
thread:(TSThread *)thread
|
2016-10-14 23:00:29 +02:00
|
|
|
messageSender:(OWSMessageSender *)messageSender
|
2016-10-05 17:42:44 +02:00
|
|
|
{
|
|
|
|
self = [super init];
|
|
|
|
if (!self) {
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
_thread = thread;
|
|
|
|
_configuration = configuration;
|
2016-10-14 23:00:29 +02:00
|
|
|
_messageSender = messageSender;
|
2016-10-05 17:42:44 +02:00
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
+ (void)runWithConfiguration:(OWSDisappearingMessagesConfiguration *)configuration
|
|
|
|
thread:(TSThread *)thread
|
2016-10-14 23:00:29 +02:00
|
|
|
messageSender:(OWSMessageSender *)messageSender
|
2016-10-05 17:42:44 +02:00
|
|
|
{
|
|
|
|
OWSNotifyRemoteOfUpdatedDisappearingConfigurationJob *job =
|
2016-10-14 23:00:29 +02:00
|
|
|
[[self alloc] initWithConfiguration:configuration thread:thread messageSender:messageSender];
|
2016-10-05 17:42:44 +02:00
|
|
|
[job run];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)run
|
|
|
|
{
|
|
|
|
OWSDisappearingMessagesConfigurationMessage *message =
|
|
|
|
[[OWSDisappearingMessagesConfigurationMessage alloc] initWithConfiguration:self.configuration
|
|
|
|
thread:self.thread];
|
|
|
|
|
2016-10-14 23:00:29 +02:00
|
|
|
[self.messageSender sendMessage:message
|
2016-10-05 17:42:44 +02:00
|
|
|
success:^{
|
|
|
|
DDLogDebug(
|
|
|
|
@"%@ Successfully notified %@ of new disappearing messages configuration", self.tag, self.thread);
|
|
|
|
}
|
2016-10-14 23:00:29 +02:00
|
|
|
failure:^(NSError *error) {
|
|
|
|
DDLogError(@"%@ Failed to notify %@ of new disappearing messages configuration with error: %@",
|
|
|
|
self.tag,
|
|
|
|
self.thread,
|
|
|
|
error);
|
2016-10-05 17:42:44 +02:00
|
|
|
}];
|
|
|
|
}
|
|
|
|
|
|
|
|
#pragma mark - Logging
|
|
|
|
|
|
|
|
+ (NSString *)tag
|
|
|
|
{
|
|
|
|
return [NSString stringWithFormat:@"[%@]", self.class];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *)tag
|
|
|
|
{
|
|
|
|
return self.class.tag;
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
NS_ASSUME_NONNULL_END
|