mirror of https://github.com/oxen-io/session-ios
Send 'sent update' sync messages.
parent
6ce84e7f9b
commit
4f19d03bdc
@ -0,0 +1,25 @@
|
|||||||
|
//
|
||||||
|
// Copyright (c) 2019 Open Whisper Systems. All rights reserved.
|
||||||
|
//
|
||||||
|
|
||||||
|
#import "OWSOutgoingSyncMessage.h"
|
||||||
|
|
||||||
|
NS_ASSUME_NONNULL_BEGIN
|
||||||
|
|
||||||
|
@class TSOutgoingMessage;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Notifies your other registered devices (if you have any) that you've sent a message.
|
||||||
|
* This way the message you just sent can appear on all your devices.
|
||||||
|
*/
|
||||||
|
@interface OWSOutgoingSentUpdateMessageTranscript : OWSOutgoingSyncMessage
|
||||||
|
|
||||||
|
- (instancetype)init NS_UNAVAILABLE;
|
||||||
|
|
||||||
|
- (instancetype)initWithOutgoingMessage:(TSOutgoingMessage *)message
|
||||||
|
transaction:(YapDatabaseReadTransaction *)transaction NS_DESIGNATED_INITIALIZER;
|
||||||
|
- (nullable instancetype)initWithCoder:(NSCoder *)coder NS_DESIGNATED_INITIALIZER;
|
||||||
|
|
||||||
|
@end
|
||||||
|
|
||||||
|
NS_ASSUME_NONNULL_END
|
@ -0,0 +1,100 @@
|
|||||||
|
//
|
||||||
|
// Copyright (c) 2019 Open Whisper Systems. All rights reserved.
|
||||||
|
//
|
||||||
|
|
||||||
|
#import "OWSOutgoingSentUpdateMessageTranscript.h"
|
||||||
|
#import "TSGroupThread.h"
|
||||||
|
#import "TSOutgoingMessage.h"
|
||||||
|
#import "TSThread.h"
|
||||||
|
#import <SignalServiceKit/SignalServiceKit-Swift.h>
|
||||||
|
|
||||||
|
NS_ASSUME_NONNULL_BEGIN
|
||||||
|
|
||||||
|
@interface TSOutgoingMessage (OWSOutgoingSentMessageTranscript)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Normally this is private, but we need to embed this
|
||||||
|
* data structure within our own.
|
||||||
|
*
|
||||||
|
* recipientId is nil when building "sent" sync messages for messages
|
||||||
|
* sent to groups.
|
||||||
|
*/
|
||||||
|
- (nullable SSKProtoDataMessage *)buildDataMessage:(NSString *_Nullable)recipientId;
|
||||||
|
|
||||||
|
@end
|
||||||
|
|
||||||
|
@interface OWSOutgoingSentUpdateMessageTranscript ()
|
||||||
|
|
||||||
|
@property (nonatomic, readonly) TSOutgoingMessage *message;
|
||||||
|
@property (nonatomic, readonly) TSGroupThread *groupThread;
|
||||||
|
|
||||||
|
@end
|
||||||
|
|
||||||
|
@implementation OWSOutgoingSentUpdateMessageTranscript
|
||||||
|
|
||||||
|
- (instancetype)initWithOutgoingMessage:(TSOutgoingMessage *)message
|
||||||
|
transaction:(YapDatabaseReadTransaction *)transaction
|
||||||
|
{
|
||||||
|
self = [super init];
|
||||||
|
|
||||||
|
if (!self) {
|
||||||
|
return self;
|
||||||
|
}
|
||||||
|
|
||||||
|
_message = message;
|
||||||
|
_groupThread = (TSGroupThread *)[message threadWithTransaction:transaction];
|
||||||
|
|
||||||
|
return self;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (nullable instancetype)initWithCoder:(NSCoder *)coder
|
||||||
|
{
|
||||||
|
return [super initWithCoder:coder];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (nullable SSKProtoSyncMessageBuilder *)syncMessageBuilder
|
||||||
|
{
|
||||||
|
SSKProtoSyncMessageSentUpdateBuilder *sentBuilder =
|
||||||
|
[SSKProtoSyncMessageSentUpdate builderWithGroupID:self.groupThread.groupModel.groupId
|
||||||
|
timestamp:self.message.timestamp];
|
||||||
|
|
||||||
|
for (NSString *recipientId in self.message.sentRecipientIds) {
|
||||||
|
TSOutgoingMessageRecipientState *_Nullable recipientState =
|
||||||
|
[self.message recipientStateForRecipientId:recipientId];
|
||||||
|
if (!recipientState) {
|
||||||
|
OWSFailDebug(@"missing recipient state for: %@", recipientId);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (recipientState.state != OWSOutgoingMessageRecipientStateSent) {
|
||||||
|
OWSFailDebug(@"unexpected recipient state for: %@", recipientId);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
NSError *error;
|
||||||
|
SSKProtoSyncMessageSentUpdateUnidentifiedDeliveryStatusBuilder *statusBuilder =
|
||||||
|
[SSKProtoSyncMessageSentUpdateUnidentifiedDeliveryStatus builderWithDestination:recipientId];
|
||||||
|
[statusBuilder setUnidentified:recipientState.wasSentByUD];
|
||||||
|
SSKProtoSyncMessageSentUpdateUnidentifiedDeliveryStatus *_Nullable status =
|
||||||
|
[statusBuilder buildAndReturnError:&error];
|
||||||
|
if (error || !status) {
|
||||||
|
OWSFailDebug(@"Couldn't build UD status proto: %@", error);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
[sentBuilder addUnidentifiedStatus:status];
|
||||||
|
}
|
||||||
|
|
||||||
|
NSError *error;
|
||||||
|
SSKProtoSyncMessageSentUpdate *_Nullable sentUpdateProto = [sentBuilder buildAndReturnError:&error];
|
||||||
|
if (error || !sentUpdateProto) {
|
||||||
|
OWSFailDebug(@"could not build protobuf: %@", error);
|
||||||
|
return nil;
|
||||||
|
}
|
||||||
|
|
||||||
|
SSKProtoSyncMessageBuilder *syncMessageBuilder = [SSKProtoSyncMessage builder];
|
||||||
|
[syncMessageBuilder setSentUpdate:sentUpdateProto];
|
||||||
|
return syncMessageBuilder;
|
||||||
|
}
|
||||||
|
|
||||||
|
@end
|
||||||
|
|
||||||
|
NS_ASSUME_NONNULL_END
|
Loading…
Reference in New Issue