mirror of https://github.com/oxen-io/session-ios
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
102 lines
3.7 KiB
Objective-C
102 lines
3.7 KiB
Objective-C
//
|
|
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
|
|
//
|
|
|
|
#import "ThreadUtil.h"
|
|
#import "Signal-Swift.h"
|
|
#import <SignalServiceKit/NSDate+millisecondTimeStamp.h>
|
|
#import <SignalServiceKit/OWSDisappearingMessagesConfiguration.h>
|
|
#import <SignalServiceKit/OWSMessageSender.h>
|
|
#import <SignalServiceKit/TSOutgoingMessage.h>
|
|
#import <SignalServiceKit/TSThread.h>
|
|
|
|
NS_ASSUME_NONNULL_BEGIN
|
|
|
|
@implementation ThreadUtil
|
|
|
|
+ (void)sendMessageWithText:(NSString *)text inThread:(TSThread *)thread messageSender:(OWSMessageSender *)messageSender
|
|
{
|
|
OWSAssert([NSThread isMainThread]);
|
|
OWSAssert(text.length > 0);
|
|
OWSAssert(thread);
|
|
OWSAssert(messageSender);
|
|
|
|
TSOutgoingMessage *message;
|
|
OWSDisappearingMessagesConfiguration *configuration =
|
|
[OWSDisappearingMessagesConfiguration fetchObjectWithUniqueID:thread.uniqueId];
|
|
if (configuration.isEnabled) {
|
|
message = [[TSOutgoingMessage alloc] initWithTimestamp:[NSDate ows_millisecondTimeStamp]
|
|
inThread:thread
|
|
messageBody:text
|
|
attachmentIds:[NSMutableArray new]
|
|
expiresInSeconds:configuration.durationSeconds];
|
|
} else {
|
|
message = [[TSOutgoingMessage alloc] initWithTimestamp:[NSDate ows_millisecondTimeStamp]
|
|
inThread:thread
|
|
messageBody:text];
|
|
}
|
|
|
|
[messageSender sendMessage:message
|
|
success:^{
|
|
DDLogInfo(@"%@ Successfully sent message.", self.tag);
|
|
}
|
|
failure:^(NSError *error) {
|
|
DDLogWarn(@"%@ Failed to deliver message with error: %@", self.tag, error);
|
|
}];
|
|
}
|
|
|
|
|
|
+ (void)sendMessageWithAttachment:(SignalAttachment *)attachment
|
|
inThread:(TSThread *)thread
|
|
messageSender:(OWSMessageSender *)messageSender
|
|
{
|
|
OWSAssert([NSThread isMainThread]);
|
|
OWSAssert(attachment);
|
|
OWSAssert(![attachment hasError]);
|
|
OWSAssert([attachment mimeType].length > 0);
|
|
OWSAssert(thread);
|
|
OWSAssert(messageSender);
|
|
|
|
TSOutgoingMessage *message;
|
|
OWSDisappearingMessagesConfiguration *configuration =
|
|
[OWSDisappearingMessagesConfiguration fetchObjectWithUniqueID:thread.uniqueId];
|
|
if (configuration.isEnabled) {
|
|
message = [[TSOutgoingMessage alloc] initWithTimestamp:[NSDate ows_millisecondTimeStamp]
|
|
inThread:thread
|
|
messageBody:nil
|
|
attachmentIds:[NSMutableArray new]
|
|
expiresInSeconds:configuration.durationSeconds];
|
|
} else {
|
|
message = [[TSOutgoingMessage alloc] initWithTimestamp:[NSDate ows_millisecondTimeStamp]
|
|
inThread:thread
|
|
messageBody:nil
|
|
attachmentIds:[NSMutableArray new]];
|
|
}
|
|
|
|
[messageSender sendAttachmentData:attachment.data
|
|
contentType:[attachment mimeType]
|
|
inMessage:message
|
|
success:^{
|
|
DDLogDebug(@"%@ Successfully sent message attachment.", self.tag);
|
|
}
|
|
failure:^(NSError *error) {
|
|
DDLogError(@"%@ Failed to send message attachment with error: %@", self.tag, error);
|
|
}];
|
|
}
|
|
|
|
#pragma mark - Logging
|
|
|
|
+ (NSString *)tag
|
|
{
|
|
return [NSString stringWithFormat:@"[%@]", self.class];
|
|
}
|
|
|
|
- (NSString *)tag
|
|
{
|
|
return self.class.tag;
|
|
}
|
|
|
|
@end
|
|
|
|
NS_ASSUME_NONNULL_END
|