mirror of
https://github.com/oxen-io/session-ios.git
synced 2023-12-13 21:30:14 +01:00
Implement receiving quotes in group chats
This commit is contained in:
parent
c780023d63
commit
5569e87485
|
@ -56,6 +56,11 @@ public final class LokiGroupChatPoller : NSObject {
|
|||
let x2 = SSKProtoDataMessage.builder()
|
||||
x2.setTimestamp(message.timestamp)
|
||||
x2.setGroup(try! x1.build())
|
||||
if let quote = message.quote {
|
||||
let x5 = SSKProtoDataMessageQuote.builder(id: quote.quotedMessageTimestamp, author: quote.quoteeHexEncodedPublicKey)
|
||||
x5.setText(quote.quotedMessageBody)
|
||||
x2.setQuote(try! x5.build())
|
||||
}
|
||||
x2.setBody(message.body)
|
||||
if let messageServerID = message.serverID {
|
||||
let publicChatInfo = SSKProtoPublicChatInfo.builder()
|
||||
|
@ -68,7 +73,6 @@ public final class LokiGroupChatPoller : NSObject {
|
|||
x4.setSource(senderHexEncodedPublicKey)
|
||||
x4.setSourceDevice(OWSDevicePrimaryDeviceId)
|
||||
x4.setContent(try! x3.build().serializedData())
|
||||
|
||||
let storage = OWSPrimaryStorage.shared()
|
||||
storage.dbReadWriteConnection.readWrite { transaction in
|
||||
transaction.setObject(senderDisplayName, forKey: senderHexEncodedPublicKey, inCollection: group.id)
|
||||
|
|
|
@ -139,6 +139,8 @@ public final class LokiGroupChatAPI : NSObject {
|
|||
throw Error.parsingFailed
|
||||
}
|
||||
return rawMessages.flatMap { message in
|
||||
let isDeleted = (message["is_deleted"] as? Int == 1)
|
||||
guard !isDeleted else { return nil }
|
||||
guard let annotations = message["annotations"] as? [JSON], let annotation = annotations.first, let value = annotation["value"] as? JSON,
|
||||
let serverID = message["id"] as? UInt64, let body = message["text"] as? String, let hexEncodedPublicKey = value["source"] as? String, let displayName = value["from"] as? String,
|
||||
let timestamp = value["timestamp"] as? UInt64 else {
|
||||
|
@ -147,7 +149,13 @@ public final class LokiGroupChatAPI : NSObject {
|
|||
}
|
||||
let lastMessageServerID = getLastMessageServerID(for: group, on: server)
|
||||
if serverID > (lastMessageServerID ?? 0) { setLastMessageServerID(for: group, on: server, to: serverID) }
|
||||
return LokiGroupMessage(serverID: serverID, hexEncodedPublicKey: hexEncodedPublicKey, displayName: displayName, body: body, type: publicChatMessageType, timestamp: timestamp)
|
||||
let quote: LokiGroupMessage.Quote?
|
||||
if let quoteAsJSON = value["quote"] as? JSON, let quotedMessageTimestamp = quoteAsJSON["id"] as? UInt64, let quoteeHexEncodedPublicKey = quoteAsJSON["author"] as? String, let quotedMessageBody = quoteAsJSON["text"] as? String {
|
||||
quote = LokiGroupMessage.Quote(quotedMessageTimestamp: quotedMessageTimestamp, quoteeHexEncodedPublicKey: quoteeHexEncodedPublicKey, quotedMessageBody: quotedMessageBody)
|
||||
} else {
|
||||
quote = nil
|
||||
}
|
||||
return LokiGroupMessage(serverID: serverID, hexEncodedPublicKey: hexEncodedPublicKey, displayName: displayName, body: body, type: publicChatMessageType, timestamp: timestamp, quote: quote)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -170,7 +178,8 @@ public final class LokiGroupChatAPI : NSObject {
|
|||
throw Error.parsingFailed
|
||||
}
|
||||
let timestamp = UInt64(date.timeIntervalSince1970) * 1000
|
||||
return LokiGroupMessage(serverID: serverID, hexEncodedPublicKey: userHexEncodedPublicKey, displayName: displayName, body: body, type: publicChatMessageType, timestamp: timestamp)
|
||||
let quote: LokiGroupMessage.Quote?
|
||||
return LokiGroupMessage(serverID: serverID, hexEncodedPublicKey: userHexEncodedPublicKey, displayName: displayName, body: body, type: publicChatMessageType, timestamp: timestamp, quote: nil)
|
||||
}
|
||||
}.recover { error -> Promise<LokiGroupMessage> in
|
||||
if let error = error as? NetworkManagerError, error.statusCode == 401 {
|
||||
|
|
|
@ -9,22 +9,30 @@ public final class LokiGroupMessage : NSObject {
|
|||
/// - Note: Expressed as milliseconds since 00:00:00 UTC on 1 January 1970.
|
||||
public let timestamp: UInt64
|
||||
public let type: String
|
||||
public let quote: Quote?
|
||||
|
||||
@objc(serverID)
|
||||
public var objc_serverID: UInt64 { return serverID ?? 0 }
|
||||
|
||||
public init(serverID: UInt64?, hexEncodedPublicKey: String, displayName: String, body: String, type: String, timestamp: UInt64) {
|
||||
public struct Quote {
|
||||
public let quotedMessageTimestamp: UInt64
|
||||
public let quoteeHexEncodedPublicKey: String
|
||||
public let quotedMessageBody: String
|
||||
}
|
||||
|
||||
public init(serverID: UInt64?, hexEncodedPublicKey: String, displayName: String, body: String, type: String, timestamp: UInt64, quote: Quote?) {
|
||||
self.serverID = serverID
|
||||
self.hexEncodedPublicKey = hexEncodedPublicKey
|
||||
self.displayName = displayName
|
||||
self.body = body
|
||||
self.type = type
|
||||
self.timestamp = timestamp
|
||||
self.quote = quote
|
||||
super.init()
|
||||
}
|
||||
|
||||
@objc public convenience init(hexEncodedPublicKey: String, displayName: String, body: String, type: String, timestamp: UInt64) {
|
||||
self.init(serverID: nil, hexEncodedPublicKey: hexEncodedPublicKey, displayName: displayName, body: body, type: type, timestamp: timestamp)
|
||||
self.init(serverID: nil, hexEncodedPublicKey: hexEncodedPublicKey, displayName: displayName, body: body, type: type, timestamp: timestamp, quote: nil)
|
||||
}
|
||||
|
||||
internal func toJSON() -> JSON {
|
||||
|
|
|
@ -157,7 +157,7 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
}
|
||||
}
|
||||
|
||||
OWSAssertDebug(bodySource != TSQuotedMessageContentSourceUnknown);
|
||||
// OWSAssertDebug(bodySource != TSQuotedMessageContentSourceUnknown);
|
||||
|
||||
NSMutableArray<OWSAttachmentInfo *> *attachmentInfos = [NSMutableArray new];
|
||||
for (SSKProtoDataMessageQuoteQuotedAttachment *quotedAttachment in quoteProto.attachments) {
|
||||
|
|
Loading…
Reference in a new issue