mirror of https://github.com/oxen-io/session-ios
parent
a99fde4d3b
commit
580781e3e4
@ -0,0 +1,16 @@
|
||||
// Copyright © 2016 Open Whisper Systems. All rights reserved.
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@interface OWSReadReceipt : NSObject
|
||||
|
||||
@property (nonatomic, readonly) NSString *senderId;
|
||||
@property (nonatomic, readonly) uint64_t timestamp;
|
||||
@property (nonatomic, readonly, getter=isValid) BOOL valid;
|
||||
@property (nonatomic, readonly) NSArray<NSString *> *validationErrorMessages;
|
||||
|
||||
- (instancetype)initWithSenderId:(NSString *)senderId timestamp:(uint64_t)timestamp;
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
@ -0,0 +1,35 @@
|
||||
// Copyright © 2016 Open Whisper Systems. All rights reserved.
|
||||
|
||||
#import "OWSReadReceipt.h"
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@implementation OWSReadReceipt
|
||||
|
||||
- (instancetype)initWithSenderId:(NSString *)senderId timestamp:(uint64_t)timestamp;
|
||||
{
|
||||
self = [super init];
|
||||
if (!self) {
|
||||
return self;
|
||||
}
|
||||
|
||||
NSMutableArray<NSString *> *validationErrorMessage = [NSMutableArray new];
|
||||
if (!senderId) {
|
||||
[validationErrorMessage addObject:@"Must specify sender id"];
|
||||
}
|
||||
_senderId = senderId;
|
||||
|
||||
if (!timestamp) {
|
||||
[validationErrorMessage addObject:@"Must specify timestamp"];
|
||||
}
|
||||
_timestamp = timestamp;
|
||||
|
||||
_valid = validationErrorMessage.count == 0;
|
||||
_validationErrorMessages = [validationErrorMessage copy];
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
@ -0,0 +1,15 @@
|
||||
// Copyright © 2016 Open Whisper Systems. All rights reserved.
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@class OWSSignalServiceProtosSyncMessageRead;
|
||||
|
||||
@interface OWSReadReceiptsProcessor : NSObject
|
||||
|
||||
- (instancetype)initWithReadReceiptProtos:(NSArray<OWSSignalServiceProtosSyncMessageRead *> *)readReceiptProtos
|
||||
NS_DESIGNATED_INITIALIZER;
|
||||
- (void)process;
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
@ -0,0 +1,62 @@
|
||||
// Copyright © 2016 Open Whisper Systems. All rights reserved.
|
||||
|
||||
#import "OWSReadReceiptsProcessor.h"
|
||||
#import "OWSReadReceipt.h"
|
||||
#import "OWSSignalServiceProtos.pb.h"
|
||||
#import "TSIncomingMessage.h"
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@interface OWSReadReceiptsProcessor ()
|
||||
|
||||
@property (nonatomic, readonly) NSArray<OWSReadReceipt *> *readReceipts;
|
||||
|
||||
@end
|
||||
|
||||
@implementation OWSReadReceiptsProcessor
|
||||
|
||||
- (instancetype)init
|
||||
{
|
||||
return [self initWithReadReceiptProtos:@[]];
|
||||
}
|
||||
|
||||
- (instancetype)initWithReadReceiptProtos:(NSArray<OWSSignalServiceProtosSyncMessageRead *> *)readReceiptProtos
|
||||
{
|
||||
self = [super init];
|
||||
if (!self) {
|
||||
return self;
|
||||
}
|
||||
|
||||
NSMutableArray<OWSReadReceipt *> *readReceipts = [NSMutableArray new];
|
||||
for (OWSSignalServiceProtosSyncMessageRead *readReceiptProto in readReceiptProtos) {
|
||||
OWSReadReceipt *readReceipt =
|
||||
[[OWSReadReceipt alloc] initWithSenderId:readReceiptProto.sender timestamp:readReceiptProto.timestamp];
|
||||
if (readReceipt.isValid) {
|
||||
[readReceipts addObject:readReceipt];
|
||||
} else {
|
||||
DDLogError(@"Received invalid read receipt: %@", readReceipt.validationErrorMessages);
|
||||
}
|
||||
}
|
||||
|
||||
_readReceipts = [readReceipts copy];
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)process
|
||||
{
|
||||
DDLogInfo(@"Processing %ld read receipts.", self.readReceipts.count);
|
||||
for (OWSReadReceipt *readReceipt in self.readReceipts) {
|
||||
TSIncomingMessage *message =
|
||||
[TSIncomingMessage findMessageWithAuthorId:readReceipt.senderId timestamp:readReceipt.timestamp];
|
||||
if (message) {
|
||||
[message markAsRead];
|
||||
} else {
|
||||
DDLogWarn(@"Couldn't find message for read receipt. Message not synced?");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
Loading…
Reference in New Issue