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 let data: Data
public let serverHash: String?
public let openGroupMessageServerID: UInt64?
public let openGroupID: String?
public let isBackgroundPoll: Bool
@ -15,8 +16,9 @@ public final class MessageReceiveJob : NSObject, Job, NSCoding { // NSObject/NSC
public static let maxFailureCount: UInt = 10
// 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.serverHash = serverHash
self.openGroupMessageServerID = openGroupMessageServerID
self.openGroupID = openGroupID
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 isBackgroundPoll = coder.decodeObject(forKey: "isBackgroundPoll") as! Bool? else { return nil }
self.data = data
self.serverHash = coder.decodeObject(forKey: "serverHash") as! String?
self.openGroupMessageServerID = coder.decodeObject(forKey: "openGroupMessageServerID") as! UInt64?
self.openGroupID = coder.decodeObject(forKey: "openGroupID") as! String?
self.isBackgroundPoll = isBackgroundPoll
@ -41,6 +44,7 @@ public final class MessageReceiveJob : NSObject, Job, NSCoding { // NSObject/NSC
public func encode(with coder: NSCoder) {
coder.encode(data, forKey: "data")
coder.encode(serverHash, forKey: "serverHash")
coder.encode(openGroupMessageServerID, forKey: "openGroupMessageServerID")
coder.encode(openGroupID, forKey: "openGroupID")
coder.encode(isBackgroundPoll, forKey: "isBackgroundPoll")
@ -62,6 +66,7 @@ public final class MessageReceiveJob : NSObject, Job, NSCoding { // NSObject/NSC
do {
let isRetry = (self.failureCount != 0)
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)
self.handleSuccess()
seal.fulfill(())

View File

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

View File

@ -64,7 +64,8 @@ NS_ASSUME_NONNULL_BEGIN
serverTimestamp:(nullable NSNumber *)serverTimestamp
wasReceivedByUD:(BOOL)wasReceivedByUD
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;

View File

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

View File

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

View File

@ -51,7 +51,8 @@ extern const NSUInteger kOversizeTextMessageSizeThreshold;
quotedMessage:(nullable TSQuotedMessage *)quotedMessage
linkPreview:(nullable OWSLinkPreview *)linkPreview
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;

View File

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

View File

@ -30,7 +30,8 @@ import SessionUtilitiesKit
quotedMessage: TSQuotedMessage.from(visibleMessage.quote),
linkPreview: OWSLinkPreview.from(visibleMessage.linkPreview),
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
linkPreview:(nullable OWSLinkPreview *)linkPreview
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;

View File

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