store hash value for outgoing messages

This commit is contained in:
Ryan Zhao 2021-08-02 14:49:34 +10:00
parent e2a0578770
commit c68350f3d8
5 changed files with 12 additions and 1 deletions

View file

@ -11,6 +11,7 @@ public class Message : NSObject, NSCoding { // NSObject/NSCoding conformance is
public var groupPublicKey: String?
public var openGroupServerMessageID: UInt64?
public var openGroupServerTimestamp: UInt64?
public var serverHash: String?
public var ttl: UInt64 { 14 * 24 * 60 * 60 * 1000 }
public var isSelfSendValid: Bool { false }
@ -35,6 +36,7 @@ public class Message : NSObject, NSCoding { // NSObject/NSCoding conformance is
if let groupPublicKey = coder.decodeObject(forKey: "groupPublicKey") as! String? { self.groupPublicKey = groupPublicKey }
if let openGroupServerMessageID = coder.decodeObject(forKey: "openGroupServerMessageID") as! UInt64? { self.openGroupServerMessageID = openGroupServerMessageID }
if let openGroupServerTimestamp = coder.decodeObject(forKey: "openGroupServerTimestamp") as! UInt64? { self.openGroupServerTimestamp = openGroupServerTimestamp }
if let serverHash = coder.decodeObject(forKey: "serverHash") as! String? { self.serverHash = serverHash }
}
public func encode(with coder: NSCoder) {
@ -47,6 +49,7 @@ public class Message : NSObject, NSCoding { // NSObject/NSCoding conformance is
coder.encode(groupPublicKey, forKey: "groupPublicKey")
coder.encode(openGroupServerMessageID, forKey: "openGroupServerMessageID")
coder.encode(openGroupServerTimestamp, forKey: "openGroupServerTimestamp")
coder.encode(serverHash, forKey: "serverHash")
}
// MARK: Proto Conversion

View file

@ -38,6 +38,7 @@ extern const NSUInteger kOversizeTextMessageSizeThreshold;
@property (nonatomic, readonly) BOOL isOpenGroupMessage;
@property (nonatomic, readonly, nullable) NSString *openGroupInvitationName;
@property (nonatomic, readonly, nullable) NSString *openGroupInvitationURL;
@property (nonatomic, nullable) NSString *serverHash;
- (instancetype)initInteractionWithTimestamp:(uint64_t)timestamp inThread:(TSThread *)thread NS_UNAVAILABLE;

View file

@ -84,6 +84,7 @@ const NSUInteger kOversizeTextMessageSizeThreshold = 2 * 1024;
_openGroupServerMessageID = 0;
_openGroupInvitationName = openGroupInvitationName;
_openGroupInvitationURL = openGroupInvitationURL;
_serverHash = nil;
return self;
}

View file

@ -208,10 +208,13 @@ public final class MessageSender : NSObject {
let promiseCount = promises.count
var errorCount = 0
promises.forEach {
let _ = $0.done(on: DispatchQueue.global(qos: .userInitiated)) { _ in
let _ = $0.done(on: DispatchQueue.global(qos: .userInitiated)) { rawResponse in
guard !isSuccess else { return } // Succeed as soon as the first promise succeeds
isSuccess = true
storage.write(with: { transaction in
let json = rawResponse as? JSON
let hash = json?["hash"] as? String
message.serverHash = hash
MessageSender.handleSuccessfulMessageSend(message, to: destination, isSyncMessage: isSyncMessage, using: transaction)
var shouldNotify = ((message is VisibleMessage || message is UnsendRequest) && !isSyncMessage)
/*
@ -329,6 +332,7 @@ public final class MessageSender : NSObject {
Storage.shared.addReceivedMessageTimestamp(message.sentTimestamp!, using: transaction)
// Get the visible message if possible
if let tsMessage = TSOutgoingMessage.find(withTimestamp: message.sentTimestamp!) {
tsMessage.serverHash = message.serverHash
// Track the open group server message ID
tsMessage.openGroupServerMessageID = message.openGroupServerMessageID ?? 0
tsMessage.save(with: transaction)

View file

@ -454,6 +454,8 @@ public final class SnodeAPI : NSObject {
return promise
}
// public static func deleteMessage() -> Promise
/// Clears all the user's data from their swarm. Returns a dictionary of snode public key to deletion confirmation.
public static func clearAllData() -> Promise<[String:Bool]> {
let storage = SNSnodeKitConfiguration.shared.storage