store server hash value for visible messages

This commit is contained in:
Ryan Zhao 2021-08-02 15:24:38 +10:00
parent f88c2b1708
commit 050a2ec534
10 changed files with 30 additions and 12 deletions

View File

@ -3,6 +3,7 @@ import PromiseKit
public final class MessageReceiveJob : NSObject, Job, NSCoding { // NSObject/NSCoding conformance is needed for YapDatabase compatibility public final class MessageReceiveJob : NSObject, Job, NSCoding { // NSObject/NSCoding conformance is needed for YapDatabase compatibility
public let data: Data public let data: Data
public let serverHash: String?
public let openGroupMessageServerID: UInt64? public let openGroupMessageServerID: UInt64?
public let openGroupID: String? public let openGroupID: String?
public let isBackgroundPoll: Bool public let isBackgroundPoll: Bool
@ -15,8 +16,9 @@ public final class MessageReceiveJob : NSObject, Job, NSCoding { // NSObject/NSC
public static let maxFailureCount: UInt = 10 public static let maxFailureCount: UInt = 10
// MARK: Initialization // MARK: Initialization
public init(data: Data, openGroupMessageServerID: UInt64? = nil, openGroupID: String? = nil, isBackgroundPoll: Bool) { public init(data: Data, serverHash: String? = nil, openGroupMessageServerID: UInt64? = nil, openGroupID: String? = nil, isBackgroundPoll: Bool) {
self.data = data self.data = data
self.serverHash = serverHash
self.openGroupMessageServerID = openGroupMessageServerID self.openGroupMessageServerID = openGroupMessageServerID
self.openGroupID = openGroupID self.openGroupID = openGroupID
self.isBackgroundPoll = isBackgroundPoll self.isBackgroundPoll = isBackgroundPoll
@ -32,6 +34,7 @@ public final class MessageReceiveJob : NSObject, Job, NSCoding { // NSObject/NSC
let id = coder.decodeObject(forKey: "id") as! String?, let id = coder.decodeObject(forKey: "id") as! String?,
let isBackgroundPoll = coder.decodeObject(forKey: "isBackgroundPoll") as! Bool? else { return nil } let isBackgroundPoll = coder.decodeObject(forKey: "isBackgroundPoll") as! Bool? else { return nil }
self.data = data self.data = data
self.serverHash = coder.decodeObject(forKey: "serverHash") as! String?
self.openGroupMessageServerID = coder.decodeObject(forKey: "openGroupMessageServerID") as! UInt64? self.openGroupMessageServerID = coder.decodeObject(forKey: "openGroupMessageServerID") as! UInt64?
self.openGroupID = coder.decodeObject(forKey: "openGroupID") as! String? self.openGroupID = coder.decodeObject(forKey: "openGroupID") as! String?
self.isBackgroundPoll = isBackgroundPoll self.isBackgroundPoll = isBackgroundPoll
@ -41,6 +44,7 @@ public final class MessageReceiveJob : NSObject, Job, NSCoding { // NSObject/NSC
public func encode(with coder: NSCoder) { public func encode(with coder: NSCoder) {
coder.encode(data, forKey: "data") coder.encode(data, forKey: "data")
coder.encode(serverHash, forKey: "serverHash")
coder.encode(openGroupMessageServerID, forKey: "openGroupMessageServerID") coder.encode(openGroupMessageServerID, forKey: "openGroupMessageServerID")
coder.encode(openGroupID, forKey: "openGroupID") coder.encode(openGroupID, forKey: "openGroupID")
coder.encode(isBackgroundPoll, forKey: "isBackgroundPoll") coder.encode(isBackgroundPoll, forKey: "isBackgroundPoll")
@ -62,6 +66,7 @@ public final class MessageReceiveJob : NSObject, Job, NSCoding { // NSObject/NSC
do { do {
let isRetry = (self.failureCount != 0) let isRetry = (self.failureCount != 0)
let (message, proto) = try MessageReceiver.parse(self.data, openGroupMessageServerID: self.openGroupMessageServerID, isRetry: isRetry, using: transaction) let (message, proto) = try MessageReceiver.parse(self.data, openGroupMessageServerID: self.openGroupMessageServerID, isRetry: isRetry, using: transaction)
message.serverHash = self.serverHash
try MessageReceiver.handle(message, associatedWithProto: proto, openGroupID: self.openGroupID, isBackgroundPoll: self.isBackgroundPoll, using: transaction) try MessageReceiver.handle(message, associatedWithProto: proto, openGroupID: self.openGroupID, isBackgroundPoll: self.isBackgroundPoll, using: transaction)
self.handleSuccess() self.handleSuccess()
seal.fulfill(()) seal.fulfill(())

View File

@ -22,7 +22,8 @@ public extension TSIncomingMessage {
serverTimestamp: visibleMessage.openGroupServerTimestamp as NSNumber?, serverTimestamp: visibleMessage.openGroupServerTimestamp as NSNumber?,
wasReceivedByUD: true, wasReceivedByUD: true,
openGroupInvitationName: visibleMessage.openGroupInvitation?.name, openGroupInvitationName: visibleMessage.openGroupInvitation?.name,
openGroupInvitationURL: visibleMessage.openGroupInvitation?.url openGroupInvitationURL: visibleMessage.openGroupInvitation?.url,
serverHash: visibleMessage.serverHash
) )
result.openGroupServerMessageID = openGroupServerMessageID result.openGroupServerMessageID = openGroupServerMessageID
return result return result

View File

@ -64,7 +64,8 @@ NS_ASSUME_NONNULL_BEGIN
serverTimestamp:(nullable NSNumber *)serverTimestamp serverTimestamp:(nullable NSNumber *)serverTimestamp
wasReceivedByUD:(BOOL)wasReceivedByUD wasReceivedByUD:(BOOL)wasReceivedByUD
openGroupInvitationName:(nullable NSString *)openGroupInvitationName openGroupInvitationName:(nullable NSString *)openGroupInvitationName
openGroupInvitationURL:(nullable NSString *)openGroupInvitationURL NS_DESIGNATED_INITIALIZER; openGroupInvitationURL:(nullable NSString *)openGroupInvitationURL
serverHash:(nullable NSString*)serverHash NS_DESIGNATED_INITIALIZER;
- (instancetype)initWithCoder:(NSCoder *)coder NS_DESIGNATED_INITIALIZER; - (instancetype)initWithCoder:(NSCoder *)coder NS_DESIGNATED_INITIALIZER;

View File

@ -56,6 +56,7 @@ NS_ASSUME_NONNULL_BEGIN
wasReceivedByUD:(BOOL)wasReceivedByUD wasReceivedByUD:(BOOL)wasReceivedByUD
openGroupInvitationName:(nullable NSString *)openGroupInvitationName openGroupInvitationName:(nullable NSString *)openGroupInvitationName
openGroupInvitationURL:(nullable NSString *)openGroupInvitationURL openGroupInvitationURL:(nullable NSString *)openGroupInvitationURL
serverHash:(nullable NSString *)serverHash
{ {
self = [super initMessageWithTimestamp:timestamp self = [super initMessageWithTimestamp:timestamp
inThread:thread inThread:thread
@ -66,7 +67,8 @@ NS_ASSUME_NONNULL_BEGIN
quotedMessage:quotedMessage quotedMessage:quotedMessage
linkPreview:linkPreview linkPreview:linkPreview
openGroupInvitationName:openGroupInvitationName openGroupInvitationName:openGroupInvitationName
openGroupInvitationURL:openGroupInvitationURL]; openGroupInvitationURL:openGroupInvitationURL
serverHash:serverHash];
if (!self) { if (!self) {
return self; return self;

View File

@ -57,7 +57,8 @@ NSUInteger TSInfoMessageSchemaVersion = 1;
quotedMessage:nil quotedMessage:nil
linkPreview:nil linkPreview:nil
openGroupInvitationName:nil openGroupInvitationName:nil
openGroupInvitationURL:nil]; openGroupInvitationURL:nil
serverHash:nil];
if (!self) { if (!self) {
return self; return self;

View File

@ -51,7 +51,8 @@ extern const NSUInteger kOversizeTextMessageSizeThreshold;
quotedMessage:(nullable TSQuotedMessage *)quotedMessage quotedMessage:(nullable TSQuotedMessage *)quotedMessage
linkPreview:(nullable OWSLinkPreview *)linkPreview linkPreview:(nullable OWSLinkPreview *)linkPreview
openGroupInvitationName:(nullable NSString *)openGroupInvitationName openGroupInvitationName:(nullable NSString *)openGroupInvitationName
openGroupInvitationURL:(nullable NSString *)openGroupInvitationURL NS_DESIGNATED_INITIALIZER; openGroupInvitationURL:(nullable NSString *)openGroupInvitationURL
serverHash:(nullable NSString *)serverHash NS_DESIGNATED_INITIALIZER;
- (nullable instancetype)initWithCoder:(NSCoder *)coder NS_DESIGNATED_INITIALIZER; - (nullable instancetype)initWithCoder:(NSCoder *)coder NS_DESIGNATED_INITIALIZER;

View File

@ -65,6 +65,7 @@ const NSUInteger kOversizeTextMessageSizeThreshold = 2 * 1024;
linkPreview:(nullable OWSLinkPreview *)linkPreview linkPreview:(nullable OWSLinkPreview *)linkPreview
openGroupInvitationName:(nullable NSString *)openGroupInvitationName openGroupInvitationName:(nullable NSString *)openGroupInvitationName
openGroupInvitationURL:(nullable NSString *)openGroupInvitationURL openGroupInvitationURL:(nullable NSString *)openGroupInvitationURL
serverHash:(nullable NSString *)serverHash
{ {
self = [super initInteractionWithTimestamp:timestamp inThread:thread]; self = [super initInteractionWithTimestamp:timestamp inThread:thread];
@ -84,7 +85,7 @@ const NSUInteger kOversizeTextMessageSizeThreshold = 2 * 1024;
_openGroupServerMessageID = 0; _openGroupServerMessageID = 0;
_openGroupInvitationName = openGroupInvitationName; _openGroupInvitationName = openGroupInvitationName;
_openGroupInvitationURL = openGroupInvitationURL; _openGroupInvitationURL = openGroupInvitationURL;
_serverHash = nil; _serverHash = serverHash;
return self; return self;
} }

View File

@ -30,7 +30,8 @@ import SessionUtilitiesKit
quotedMessage: TSQuotedMessage.from(visibleMessage.quote), quotedMessage: TSQuotedMessage.from(visibleMessage.quote),
linkPreview: OWSLinkPreview.from(visibleMessage.linkPreview), linkPreview: OWSLinkPreview.from(visibleMessage.linkPreview),
openGroupInvitationName: visibleMessage.openGroupInvitation?.name, openGroupInvitationName: visibleMessage.openGroupInvitation?.name,
openGroupInvitationURL: visibleMessage.openGroupInvitation?.url openGroupInvitationURL: visibleMessage.openGroupInvitation?.url,
serverHash: visibleMessage.serverHash
) )
} }
} }

View File

@ -94,7 +94,8 @@ typedef NS_ENUM(NSInteger, TSGroupMetaMessage) {
quotedMessage:(nullable TSQuotedMessage *)quotedMessage quotedMessage:(nullable TSQuotedMessage *)quotedMessage
linkPreview:(nullable OWSLinkPreview *)linkPreview linkPreview:(nullable OWSLinkPreview *)linkPreview
openGroupInvitationName:(nullable NSString *)openGroupInvitationName openGroupInvitationName:(nullable NSString *)openGroupInvitationName
openGroupInvitationURL:(nullable NSString *)openGroupInvitationURL NS_DESIGNATED_INITIALIZER; openGroupInvitationURL:(nullable NSString *)openGroupInvitationURL
serverHash:(nullable NSString *)serverHash NS_DESIGNATED_INITIALIZER;
- (nullable instancetype)initWithCoder:(NSCoder *)coder NS_DESIGNATED_INITIALIZER; - (nullable instancetype)initWithCoder:(NSCoder *)coder NS_DESIGNATED_INITIALIZER;

View File

@ -154,7 +154,8 @@ NSString *NSStringForOutgoingMessageRecipientState(OWSOutgoingMessageRecipientSt
quotedMessage:quotedMessage quotedMessage:quotedMessage
linkPreview:linkPreview linkPreview:linkPreview
openGroupInvitationName:nil openGroupInvitationName:nil
openGroupInvitationURL:nil]; openGroupInvitationURL:nil
serverHash:nil];
} }
+ (instancetype)outgoingMessageInThread:(nullable TSThread *)thread + (instancetype)outgoingMessageInThread:(nullable TSThread *)thread
@ -173,7 +174,8 @@ NSString *NSStringForOutgoingMessageRecipientState(OWSOutgoingMessageRecipientSt
quotedMessage:nil quotedMessage:nil
linkPreview:nil linkPreview:nil
openGroupInvitationName:nil openGroupInvitationName:nil
openGroupInvitationURL:nil]; openGroupInvitationURL:nil
serverHash:nil];
} }
- (instancetype)initOutgoingMessageWithTimestamp:(uint64_t)timestamp - (instancetype)initOutgoingMessageWithTimestamp:(uint64_t)timestamp
@ -188,6 +190,7 @@ NSString *NSStringForOutgoingMessageRecipientState(OWSOutgoingMessageRecipientSt
linkPreview:(nullable OWSLinkPreview *)linkPreview linkPreview:(nullable OWSLinkPreview *)linkPreview
openGroupInvitationName:(nullable NSString *)openGroupInvitationName openGroupInvitationName:(nullable NSString *)openGroupInvitationName
openGroupInvitationURL:(nullable NSString *)openGroupInvitationURL openGroupInvitationURL:(nullable NSString *)openGroupInvitationURL
serverHash:(nullable NSString *)serverHash
{ {
self = [super initMessageWithTimestamp:timestamp self = [super initMessageWithTimestamp:timestamp
inThread:thread inThread:thread
@ -198,7 +201,8 @@ NSString *NSStringForOutgoingMessageRecipientState(OWSOutgoingMessageRecipientSt
quotedMessage:quotedMessage quotedMessage:quotedMessage
linkPreview:linkPreview linkPreview:linkPreview
openGroupInvitationName:openGroupInvitationName openGroupInvitationName:openGroupInvitationName
openGroupInvitationURL:openGroupInvitationURL]; openGroupInvitationURL:openGroupInvitationURL
serverHash:serverHash];
if (!self) { if (!self) {
return self; return self;
} }