Show V2 open group member count

This commit is contained in:
Niels Andriesse 2021-03-26 16:31:15 +11:00
parent 46fb792c96
commit 5504f74659
4 changed files with 18 additions and 4 deletions

View File

@ -195,6 +195,10 @@ final class ConversationVC : BaseVC, ConversationViewModelDelegate, OWSConversat
if !draft.isEmpty {
snInputView.text = draft
}
// Update member count if this is a V2 open group
if let v2OpenGroup = Storage.shared.getV2OpenGroup(for: thread.uniqueId!) {
OpenGroupAPIV2.getMemberCount(for: v2OpenGroup.room, on: v2OpenGroup.server).retainUntilComplete()
}
}
override func viewDidLayoutSubviews() {

View File

@ -241,7 +241,11 @@ extension Storage {
}
public func setUserCount(to newValue: Int, forOpenGroupWithID openGroupID: String, using transaction: Any) {
(transaction as! YapDatabaseReadWriteTransaction).setObject(newValue, forKey: openGroupID, inCollection: Storage.oldOpenGroupUserCountCollection)
let transaction = transaction as! YapDatabaseReadWriteTransaction
transaction.setObject(newValue, forKey: openGroupID, inCollection: Storage.oldOpenGroupUserCountCollection)
transaction.addCompletionQueue(.main) {
NotificationCenter.default.post(name: .groupThreadUpdated, object: nil)
}
}
private static let oldOpenGroupCollection = "LokiPublicChatCollection"

View File

@ -343,10 +343,14 @@ public final class OpenGroupAPIV2 : NSObject {
}
}
public static func getMemberCount(for room: String, on server: String) -> Promise<UInt> {
public static func getMemberCount(for room: String, on server: String) -> Promise<UInt64> {
let request = Request(verb: .get, room: room, server: server, endpoint: "member_count")
return send(request).map(on: DispatchQueue.global(qos: .userInitiated)) { json in
guard let memberCount = json["member_count"] as? UInt else { throw Error.parsingFailed }
guard let memberCount = json["member_count"] as? UInt64 else { throw Error.parsingFailed }
let storage = SNMessagingKitConfiguration.shared.storage
storage.write { transaction in
storage.setUserCount(to: memberCount, forV2OpenGroupWithID: "\(server).\(room)", using: transaction)
}
return memberCount
}
}

View File

@ -67,7 +67,7 @@ public protocol SessionMessagingKitStorageProtocol {
// MARK: - Open Group Metadata
func setUserCount(to newValue: Int, forOpenGroupWithID openGroupID: String, using transaction: Any)
func setUserCount(to newValue: UInt64, forV2OpenGroupWithID openGroupID: String, using transaction: Any)
func getIDForMessage(withServerID serverID: UInt64) -> String?
func setIDForMessage(withServerID serverID: UInt64, to messageID: String, using transaction: Any)
func setOpenGroupDisplayName(to displayName: String, for publicKey: String, inOpenGroupWithID openGroupID: String, using transaction: Any)
@ -104,4 +104,6 @@ public protocol SessionMessagingKitStorageProtocol {
func getAllUserOpenGroups() -> [String:OpenGroup]
func getOpenGroup(for threadID: String) -> OpenGroup?
func setUserCount(to newValue: Int, forOpenGroupWithID openGroupID: String, using transaction: Any)
}