Set the server id on public chat messages.

This commit is contained in:
Mikunj 2019-08-28 11:09:28 +10:00
parent 17596d8bd3
commit 2392fed21a
5 changed files with 39 additions and 1 deletions

View File

@ -44,6 +44,14 @@ public final class LokiGroupChatPoller : NSObject {
x2.setTimestamp(message.timestamp)
x2.setGroup(try! x1.build())
x2.setBody(message.body)
// Pass down the message server id
if let messageServerID = message.serverID {
let publicChatInfo = SSKProtoPublicChatInfo.builder()
publicChatInfo.setServerID(messageServerID)
x2.setPublicChatInfo(try! publicChatInfo.build())
}
let x3 = SSKProtoContent.builder()
x3.setDataMessage(try! x2.build())
let x4 = SSKProtoEnvelope.builder(type: .ciphertext, timestamp: message.timestamp)

View File

@ -48,6 +48,12 @@ typedef NS_ENUM(NSInteger, LKMessageFriendRequestStatus) {
@property (nonatomic) BOOL isP2P;
// ========
// Public Chat
// ========
@property (nonatomic) uint64_t publicChatMessageID;
@property (nonatomic, readonly) BOOL isPublicChatMessage;
// ========
- (instancetype)initInteractionWithTimestamp:(uint64_t)timestamp inThread:(TSThread *)thread NS_UNAVAILABLE;
- (instancetype)initMessageWithTimestamp:(uint64_t)timestamp
@ -92,6 +98,10 @@ typedef NS_ENUM(NSInteger, LKMessageFriendRequestStatus) {
- (void)saveFriendRequestStatus:(LKMessageFriendRequestStatus)friendRequestStatus withTransaction:(YapDatabaseReadWriteTransaction *_Nullable)transaction;
- (void)saveFriendRequestExpiresAt:(u_int64_t)expiresAt withTransaction:(YapDatabaseReadWriteTransaction *_Nullable)transaction;
#pragma mark - Public Chat
- (void)savePublicChatMessageID:(uint64_t)serverMessageId withTransaction:(YapDatabaseReadWriteTransaction *_Nullable)transaction;
@end
NS_ASSUME_NONNULL_END

View File

@ -84,6 +84,7 @@ static const NSUInteger OWSMessageSchemaVersion = 4;
_linkPreview = linkPreview;
_friendRequestStatus = LKMessageFriendRequestStatusNone;
_friendRequestExpiresAt = 0;
_publicChatMessageID = -1;
return self;
}
@ -490,6 +491,23 @@ static const NSUInteger OWSMessageSchemaVersion = 4;
return self.isFriendRequest && self.friendRequestStatus != LKMessageFriendRequestStatusSendingOrFailed;
}
#pragma mark - Public chat handling
- (BOOL) isPublicChatMessage {
return self.publicChatMessageID > 0;
}
- (void)savePublicChatMessageID:(uint64_t)serverMessageId withTransaction:(YapDatabaseReadWriteTransaction *_Nullable)transaction {
self.publicChatMessageID = serverMessageId;
if (transaction == nil) {
[self save];
[self.dbReadWriteConnection flushTransactionsWithCompletionQueue:dispatch_get_main_queue() completionBlock:^{}];
} else {
[self saveWithTransaction:transaction];
[transaction.connection flushTransactionsWithCompletionQueue:dispatch_get_main_queue() completionBlock:^{}];
}
}
@end
NS_ASSUME_NONNULL_END

View File

@ -1360,7 +1360,7 @@ NS_ASSUME_NONNULL_BEGIN
envelopeAddress(envelope),
groupId,
(unsigned long)timestamp);
// Legit usage of senderTimestamp when creating an incoming group message record
TSIncomingMessage *incomingMessage =
[[TSIncomingMessage alloc] initIncomingMessageWithTimestamp:timestamp
@ -1377,6 +1377,7 @@ NS_ASSUME_NONNULL_BEGIN
wasReceivedByUD:wasReceivedByUD];
if (envelope.isPtpMessage) { incomingMessage.isP2P = YES; }
if (dataMessage.publicChatInfo && dataMessage.publicChatInfo.hasServerID) { incomingMessage.publicChatMessageID = dataMessage.publicChatInfo.serverID; }
NSArray<TSAttachmentPointer *> *attachmentPointers =
[TSAttachmentPointer attachmentPointersFromProtos:dataMessage.attachments

View File

@ -1117,6 +1117,7 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException";
[[LKGroupChatAPI sendMessage:groupMessage toGroup:LKGroupChatAPI.publicChatServerID onServer:LKGroupChatAPI.publicChatServer]
.thenOn(OWSDispatch.sendingQueue, ^(LKGroupMessage *groupMessage) {
[self.dbConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
[message savePublicChatMessageID:groupMessage.serverID withTransaction:transaction];
[OWSPrimaryStorage.sharedManager setIDForMessageWithServerID:groupMessage.serverID to:message.uniqueId in:transaction];
}];
[self messageSendDidSucceed:messageSend deviceMessages:deviceMessages wasSentByUD:false wasSentByWebsocket:false];