mirror of
https://github.com/oxen-io/session-ios.git
synced 2023-12-13 21:30:14 +01:00
Show group images
This commit is contained in:
parent
50ab253576
commit
c42a694ef6
2 changed files with 28 additions and 6 deletions
|
@ -110,6 +110,16 @@ extension OpenGroupSuggestionGrid {
|
|||
|
||||
static let identifier = "OpenGroupSuggestionGridCell"
|
||||
|
||||
private lazy var imageView: UIImageView = {
|
||||
let result = UIImageView()
|
||||
let size: CGFloat = 24
|
||||
result.set(.width, to: size)
|
||||
result.set(.height, to: size)
|
||||
result.layer.cornerRadius = size / 2
|
||||
result.clipsToBounds = true
|
||||
return result
|
||||
}()
|
||||
|
||||
private lazy var label: UILabel = {
|
||||
let result = UILabel()
|
||||
result.textColor = Colors.text
|
||||
|
@ -129,10 +139,13 @@ extension OpenGroupSuggestionGrid {
|
|||
}
|
||||
|
||||
private func setUpViewHierarchy() {
|
||||
addSubview(label)
|
||||
label.center(in: self)
|
||||
label.leadingAnchor.constraint(greaterThanOrEqualTo: leadingAnchor, constant: Values.smallSpacing).isActive = true
|
||||
trailingAnchor.constraint(greaterThanOrEqualTo: label.trailingAnchor, constant: Values.smallSpacing).isActive = true
|
||||
let stackView = UIStackView(arrangedSubviews: [ imageView, label ])
|
||||
stackView.axis = .horizontal
|
||||
stackView.spacing = Values.smallSpacing
|
||||
addSubview(stackView)
|
||||
stackView.center(in: self)
|
||||
stackView.leadingAnchor.constraint(greaterThanOrEqualTo: leadingAnchor, constant: Values.smallSpacing).isActive = true
|
||||
trailingAnchor.constraint(greaterThanOrEqualTo: stackView.trailingAnchor, constant: Values.smallSpacing).isActive = true
|
||||
setUpSeparators()
|
||||
}
|
||||
|
||||
|
@ -165,6 +178,9 @@ extension OpenGroupSuggestionGrid {
|
|||
|
||||
private func update() {
|
||||
guard let room = room else { return }
|
||||
let promise = OpenGroupAPIV2.getGroupImage(for: room.id, on: OpenGroupAPIV2.defaultServer)
|
||||
imageView.image = given(promise.value) { UIImage(data: $0)! }
|
||||
imageView.isHidden = (imageView.image == nil)
|
||||
label.text = room.name
|
||||
rightSeparator.alpha = showRightSeparator ? 1 :0
|
||||
bottomSeparator.alpha = showBottomSeparator ? 1 :0
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
import PromiseKit
|
||||
import SessionSnodeKit
|
||||
|
||||
// TODO: Cache group images
|
||||
|
||||
@objc(SNOpenGroupAPIV2)
|
||||
public final class OpenGroupAPIV2 : NSObject {
|
||||
private static var moderators: [String:[String:Set<String>]] = [:] // Server URL to room ID to set of moderator IDs
|
||||
|
@ -322,9 +324,13 @@ public final class OpenGroupAPIV2 : NSObject {
|
|||
Storage.shared.write(with: { transaction in
|
||||
Storage.shared.setOpenGroupPublicKey(for: defaultServer, to: defaultServerPublicKey, using: transaction)
|
||||
}, completion: {
|
||||
defaultRoomsPromise = attempt(maxRetryCount: 8, recoveringOn: DispatchQueue.main) {
|
||||
let promise = attempt(maxRetryCount: 8, recoveringOn: DispatchQueue.main) {
|
||||
OpenGroupAPIV2.getAllRooms(from: defaultServer)
|
||||
}
|
||||
let _ = promise.done(on: DispatchQueue.global(qos: .userInitiated)) { items in
|
||||
items.forEach { getGroupImage(for: $0.id, on: defaultServer).retainUntilComplete() }
|
||||
}
|
||||
defaultRoomsPromise = promise
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -370,7 +376,7 @@ public final class OpenGroupAPIV2 : NSObject {
|
|||
if let promise = groupImagePromises["\(server).\(room)"] {
|
||||
return promise
|
||||
} else {
|
||||
let request = Request(verb: .get, room: room, server: server, endpoint: "image")
|
||||
let request = Request(verb: .get, room: room, server: server, endpoint: "group_image")
|
||||
let promise: Promise<Data> = send(request).map(on: DispatchQueue.global(qos: .userInitiated)) { json in
|
||||
guard let base64EncodedFile = json["result"] as? String, let file = Data(base64Encoded: base64EncodedFile) else { throw Error.parsingFailed }
|
||||
return file
|
||||
|
|
Loading…
Reference in a new issue