Show actual open group member count
This commit is contained in:
parent
7c72667ee6
commit
ccd48a9ae1
|
@ -187,11 +187,7 @@ final class ConversationTitleView : UIView {
|
|||
}
|
||||
}
|
||||
if let userCount = userCount {
|
||||
if userCount >= 200 {
|
||||
subtitle.append(NSAttributedString(string: "200+ members"))
|
||||
} else {
|
||||
subtitle.append(NSAttributedString(string: "\(userCount) members"))
|
||||
}
|
||||
subtitle.append(NSAttributedString(string: "\(userCount) members"))
|
||||
} else if let hexEncodedPublicKey = (self.thread as? TSContactThread)?.contactIdentifier(), ECKeyPair.isValidHexEncodedPublicKey(candidate: hexEncodedPublicKey) {
|
||||
subtitle.append(NSAttributedString(string: hexEncodedPublicKey))
|
||||
} else {
|
||||
|
|
|
@ -728,7 +728,7 @@ typedef enum : NSUInteger {
|
|||
[OWSPrimaryStorage.sharedManager.dbReadConnection readWithBlock:^(YapDatabaseReadTransaction *transaction) {
|
||||
publicChat = [LKDatabaseUtilities getPublicChatForThreadID:thread.uniqueId transaction:transaction];
|
||||
}];
|
||||
[LKPublicChatAPI getUserCountForGroup:publicChat.channel onServer:publicChat.server]
|
||||
[LKPublicChatAPI getInfoForChannelWithID:publicChat.channel onServer:publicChat.server]
|
||||
.thenOn(dispatch_get_main_queue(), ^(id userCount) {
|
||||
[self.headerView updateSubtitleForCurrentStatus];
|
||||
});
|
||||
|
|
|
@ -296,32 +296,6 @@ public final class LokiPublicChatAPI : LokiDotNetAPI {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
@objc(getUserCountForGroup:onServer:)
|
||||
public static func objc_getUserCount(for group: UInt64, on server: String) -> AnyPromise {
|
||||
return AnyPromise.from(getUserCount(for: group, on: server))
|
||||
}
|
||||
|
||||
public static func getUserCount(for channel: UInt64, on server: String) -> Promise<Int> {
|
||||
return getAuthToken(for: server).then { token -> Promise<Int> in
|
||||
let queryParameters = "count=200"
|
||||
let url = URL(string: "\(server)/channels/\(channel)/subscribers?\(queryParameters)")!
|
||||
let request = TSRequest(url: url)
|
||||
request.allHTTPHeaderFields = [ "Content-Type" : "application/json", "Authorization" : "Bearer \(token)" ]
|
||||
return LokiFileServerProxy(for: server).perform(request).map { rawResponse in
|
||||
guard let json = rawResponse as? JSON, let users = json["data"] as? [JSON] else {
|
||||
print("[Loki] Couldn't parse user count for public chat channel with ID: \(channel) on server: \(server) from: \(rawResponse).")
|
||||
throw LokiDotNetAPIError.parsingFailed
|
||||
}
|
||||
let userCount = users.count
|
||||
let storage = OWSPrimaryStorage.shared()
|
||||
storage.dbReadWriteConnection.readWrite { transaction in
|
||||
storage.setUserCount(userCount, forPublicChatWithID: "\(server).\(channel)", in: transaction)
|
||||
}
|
||||
return userCount
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static func getDisplayNames(for channel: UInt64, on server: String) -> Promise<Void> {
|
||||
let publicChatID = "\(server).\(channel)"
|
||||
|
@ -401,6 +375,11 @@ public final class LokiPublicChatAPI : LokiDotNetAPI {
|
|||
}
|
||||
}
|
||||
|
||||
@objc(getInfoForChannelWithID:onServer:)
|
||||
public static func objc_getInfo(for channel: UInt64, on server: String) -> AnyPromise {
|
||||
return AnyPromise.from(getInfo(for: channel, on: server))
|
||||
}
|
||||
|
||||
public static func getInfo(for channel: UInt64, on server: String) -> Promise<LokiPublicChatInfo> {
|
||||
let url = URL(string: "\(server)/channels/\(channel)?include_annotations=1")!
|
||||
let request = TSRequest(url: url)
|
||||
|
@ -410,11 +389,18 @@ public final class LokiPublicChatAPI : LokiDotNetAPI {
|
|||
let annotations = data["annotations"] as? [JSON],
|
||||
let annotation = annotations.first,
|
||||
let info = annotation["value"] as? JSON,
|
||||
let displayName = info["name"] as? String else {
|
||||
let displayName = info["name"] as? String,
|
||||
let countInfo = data["counts"] as? JSON,
|
||||
let memberCount = countInfo["subscribers"] as? Int else {
|
||||
print("[Loki] Couldn't parse info for public chat channel with ID: \(channel) on server: \(server) from: \(rawResponse).")
|
||||
throw LokiDotNetAPIError.parsingFailed
|
||||
}
|
||||
return LokiPublicChatInfo(displayName: displayName)
|
||||
let storage = OWSPrimaryStorage.shared()
|
||||
storage.dbReadWriteConnection.readWrite { transaction in
|
||||
storage.setUserCount(memberCount, forPublicChatWithID: "\(server).\(channel)", in: transaction)
|
||||
}
|
||||
// TODO: Use this to update open group names as needed
|
||||
return LokiPublicChatInfo(displayName: displayName, memberCount: memberCount)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
|
||||
public struct LokiPublicChatInfo {
|
||||
public let displayName: String
|
||||
public let memberCount: Int
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue