A couple of message request fixes

Added an error state to the OpenGroupSuggestionGrid
Fixed a bug where the settings button wouldn't appear for the sender of a message request once approved
This commit is contained in:
Morgan Pretty 2022-03-10 14:33:20 +11:00
parent 57c1e8afbf
commit 3e380ede4e
28 changed files with 300 additions and 19 deletions

View File

@ -613,6 +613,10 @@ final class ConversationVC : BaseVC, ConversationViewModelDelegate, OWSConversat
let updateType = conversationUpdate.conversationUpdateType
guard updateType != .minor else { return } // No view items were affected
if updateType == .reload {
if threadStartedAsMessageRequest {
updateNavBarButtons() // In case the message request was approved
}
return messagesTableView.reloadData()
}
var shouldScrollToBottom = false
@ -633,6 +637,11 @@ final class ConversationVC : BaseVC, ConversationViewModelDelegate, OWSConversat
self.messagesTableView.reloadRows(at: [ IndexPath(row: Int(update.oldIndex), section: 0) ], with: .none)
default: preconditionFailure()
}
// Update the nav items if the message request was approved
if (update.viewItem?.interaction as? TSInfoMessage)?.messageType == .messageRequestAccepted {
self.updateNavBarButtons()
}
}
}
UIView.performWithoutAnimation {

View File

@ -0,0 +1,12 @@
{
"images" : [
{
"filename" : "warning.pdf",
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}

View File

@ -0,0 +1,125 @@
%PDF-1.7
1 0 obj
<< >>
endobj
2 0 obj
<< /Length 3 0 R >>
stream
/DeviceRGB CS
/DeviceRGB cs
q
1.000000 0.000000 -0.000000 1.000000 9.791016 13.111328 cm
0.000000 0.000000 0.000000 scn
13.476560 -0.000008 m
88.623062 -0.000008 l
91.389732 -0.000008 93.782394 0.602219 95.801064 1.806664 c
97.819061 3.011093 99.373398 4.630554 100.464066 6.665062 c
101.554733 8.699562 102.100060 10.970070 102.100060 13.476585 c
102.100060 14.583359 101.945396 15.706406 101.636063 16.845726 c
101.326729 17.985054 100.879059 19.075554 100.293060 20.117218 c
62.646458 85.693398 l
61.376923 87.939461 59.700493 89.640297 57.617161 90.795898 c
55.533829 91.951500 53.352856 92.529297 51.074257 92.529297 c
48.795589 92.529297 46.606461 91.951500 44.506859 90.795898 c
42.407257 89.640297 40.722694 87.939461 39.453159 85.693398 c
1.806660 20.068382 l
0.602220 17.985046 0.000000 15.787788 0.000000 13.476585 c
0.000000 10.970070 0.545253 8.699562 1.635759 6.665062 c
2.726226 4.630554 4.280593 3.011093 6.298860 1.806664 c
8.317060 0.602219 10.709626 -0.000008 13.476560 -0.000008 c
h
13.525359 7.666031 m
11.832692 7.666031 10.473660 8.260109 9.448260 9.448265 c
8.422860 10.636414 7.910159 11.979187 7.910159 13.476585 c
7.910159 13.932312 7.958992 14.412453 8.056659 14.917015 c
8.154325 15.421577 8.317092 15.917992 8.544959 16.406273 c
46.142559 81.982498 l
46.695957 82.926498 47.412125 83.618195 48.291058 84.057594 c
49.169926 84.497063 50.097656 84.716797 51.074257 84.716797 c
52.018257 84.716797 52.921558 84.497063 53.784157 84.057594 c
54.646824 83.618195 55.354828 82.926498 55.908161 81.982498 c
93.457062 16.357445 l
93.977730 15.445984 94.238060 14.485703 94.238060 13.476585 c
94.238060 11.979187 93.709061 10.636414 92.651062 9.448265 c
91.593063 8.260109 90.217827 7.666031 88.525360 7.666031 c
13.525359 7.666031 l
h
f
n
Q
q
1.000000 0.000000 -0.000000 1.000000 55.591797 30.201187 cm
0.000000 0.000000 0.000000 scn
5.273499 15.869133 m
7.714899 15.869133 8.951868 17.154930 8.984402 19.726532 c
9.716801 45.507832 l
9.749334 46.744831 9.334299 47.778366 8.471699 48.608433 c
7.609099 49.438499 6.526735 49.853531 5.224602 49.853531 c
3.890002 49.853531 2.807667 49.446632 1.977600 48.632832 c
1.147467 47.819031 0.748700 46.793633 0.781300 45.556633 c
1.416000 19.726532 l
1.481134 17.154930 2.766965 15.869133 5.273499 15.869133 c
h
5.273499 0.000000 m
6.673232 0.000000 7.902070 0.488285 8.960003 1.464851 c
10.017937 2.441410 10.546902 3.645840 10.546902 5.078133 c
10.546902 6.510399 10.026069 7.714832 8.984402 8.691433 c
7.942735 9.667965 6.705765 10.156235 5.273499 10.156235 c
3.841165 10.156235 2.604167 9.659832 1.562500 8.667030 c
0.520833 7.674164 0.000000 6.477867 0.000000 5.078133 c
0.000000 3.678394 0.520833 2.482101 1.562500 1.489262 c
2.604167 0.496422 3.841165 0.000000 5.273499 0.000000 c
h
f
n
Q
endstream
endobj
3 0 obj
2758
endobj
4 0 obj
<< /Annots []
/Type /Page
/MediaBox [ 0.000000 0.000000 122.000000 119.000000 ]
/Resources 1 0 R
/Contents 2 0 R
/Parent 5 0 R
>>
endobj
5 0 obj
<< /Kids [ 4 0 R ]
/Count 1
/Type /Pages
>>
endobj
6 0 obj
<< /Pages 5 0 R
/Type /Catalog
>>
endobj
xref
0 7
0000000000 65535 f
0000000010 00000 n
0000000034 00000 n
0000002848 00000 n
0000002871 00000 n
0000003046 00000 n
0000003120 00000 n
trailer
<< /ID [ (some) (id) ]
/Root 6 0 R
/Size 7
>>
startxref
3179
%%EOF

View File

@ -618,3 +618,5 @@
"NEW_CONVERSATION_MENU_OPEN_GROUP" = "Open Group";
"NEW_CONVERSATION_MENU_DIRECT_MESSAGE" = "Direct Message";
"NEW_CONVERSATION_MENU_CLOSED_GROUP" = "Closed Group";
"DEFAULT_OPEN_GROUP_LOAD_ERROR_TITLE" = "Oops, an error occurred";
"DEFAULT_OPEN_GROUP_LOAD_ERROR_SUBTITLE" = "Please try again later";

View File

@ -628,3 +628,5 @@
"NEW_CONVERSATION_MENU_OPEN_GROUP" = "Open Group";
"NEW_CONVERSATION_MENU_DIRECT_MESSAGE" = "Direct Message";
"NEW_CONVERSATION_MENU_CLOSED_GROUP" = "Closed Group";
"DEFAULT_OPEN_GROUP_LOAD_ERROR_TITLE" = "Oops, an error occurred";
"DEFAULT_OPEN_GROUP_LOAD_ERROR_SUBTITLE" = "Please try again later";

View File

@ -618,3 +618,5 @@
"NEW_CONVERSATION_MENU_OPEN_GROUP" = "Open Group";
"NEW_CONVERSATION_MENU_DIRECT_MESSAGE" = "Direct Message";
"NEW_CONVERSATION_MENU_CLOSED_GROUP" = "Closed Group";
"DEFAULT_OPEN_GROUP_LOAD_ERROR_TITLE" = "Oops, an error occurred";
"DEFAULT_OPEN_GROUP_LOAD_ERROR_SUBTITLE" = "Please try again later";

View File

@ -618,3 +618,5 @@
"NEW_CONVERSATION_MENU_OPEN_GROUP" = "Open Group";
"NEW_CONVERSATION_MENU_DIRECT_MESSAGE" = "Direct Message";
"NEW_CONVERSATION_MENU_CLOSED_GROUP" = "Closed Group";
"DEFAULT_OPEN_GROUP_LOAD_ERROR_TITLE" = "Oops, an error occurred";
"DEFAULT_OPEN_GROUP_LOAD_ERROR_SUBTITLE" = "Please try again later";

View File

@ -618,3 +618,5 @@
"NEW_CONVERSATION_MENU_OPEN_GROUP" = "Open Group";
"NEW_CONVERSATION_MENU_DIRECT_MESSAGE" = "Direct Message";
"NEW_CONVERSATION_MENU_CLOSED_GROUP" = "Closed Group";
"DEFAULT_OPEN_GROUP_LOAD_ERROR_TITLE" = "Oops, an error occurred";
"DEFAULT_OPEN_GROUP_LOAD_ERROR_SUBTITLE" = "Please try again later";

View File

@ -618,3 +618,5 @@
"NEW_CONVERSATION_MENU_OPEN_GROUP" = "Open Group";
"NEW_CONVERSATION_MENU_DIRECT_MESSAGE" = "Direct Message";
"NEW_CONVERSATION_MENU_CLOSED_GROUP" = "Closed Group";
"DEFAULT_OPEN_GROUP_LOAD_ERROR_TITLE" = "Oops, an error occurred";
"DEFAULT_OPEN_GROUP_LOAD_ERROR_SUBTITLE" = "Please try again later";

View File

@ -618,3 +618,5 @@
"NEW_CONVERSATION_MENU_OPEN_GROUP" = "Open Group";
"NEW_CONVERSATION_MENU_DIRECT_MESSAGE" = "Direct Message";
"NEW_CONVERSATION_MENU_CLOSED_GROUP" = "Closed Group";
"DEFAULT_OPEN_GROUP_LOAD_ERROR_TITLE" = "Oops, an error occurred";
"DEFAULT_OPEN_GROUP_LOAD_ERROR_SUBTITLE" = "Please try again later";

View File

@ -618,3 +618,5 @@
"NEW_CONVERSATION_MENU_OPEN_GROUP" = "Open Group";
"NEW_CONVERSATION_MENU_DIRECT_MESSAGE" = "Direct Message";
"NEW_CONVERSATION_MENU_CLOSED_GROUP" = "Closed Group";
"DEFAULT_OPEN_GROUP_LOAD_ERROR_TITLE" = "Oops, an error occurred";
"DEFAULT_OPEN_GROUP_LOAD_ERROR_SUBTITLE" = "Please try again later";

View File

@ -618,3 +618,5 @@
"NEW_CONVERSATION_MENU_OPEN_GROUP" = "Open Group";
"NEW_CONVERSATION_MENU_DIRECT_MESSAGE" = "Direct Message";
"NEW_CONVERSATION_MENU_CLOSED_GROUP" = "Closed Group";
"DEFAULT_OPEN_GROUP_LOAD_ERROR_TITLE" = "Oops, an error occurred";
"DEFAULT_OPEN_GROUP_LOAD_ERROR_SUBTITLE" = "Please try again later";

View File

@ -618,3 +618,5 @@
"NEW_CONVERSATION_MENU_OPEN_GROUP" = "Open Group";
"NEW_CONVERSATION_MENU_DIRECT_MESSAGE" = "Direct Message";
"NEW_CONVERSATION_MENU_CLOSED_GROUP" = "Closed Group";
"DEFAULT_OPEN_GROUP_LOAD_ERROR_TITLE" = "Oops, an error occurred";
"DEFAULT_OPEN_GROUP_LOAD_ERROR_SUBTITLE" = "Please try again later";

View File

@ -618,3 +618,5 @@
"NEW_CONVERSATION_MENU_OPEN_GROUP" = "Open Group";
"NEW_CONVERSATION_MENU_DIRECT_MESSAGE" = "Direct Message";
"NEW_CONVERSATION_MENU_CLOSED_GROUP" = "Closed Group";
"DEFAULT_OPEN_GROUP_LOAD_ERROR_TITLE" = "Oops, an error occurred";
"DEFAULT_OPEN_GROUP_LOAD_ERROR_SUBTITLE" = "Please try again later";

View File

@ -618,3 +618,5 @@
"NEW_CONVERSATION_MENU_OPEN_GROUP" = "Open Group";
"NEW_CONVERSATION_MENU_DIRECT_MESSAGE" = "Direct Message";
"NEW_CONVERSATION_MENU_CLOSED_GROUP" = "Closed Group";
"DEFAULT_OPEN_GROUP_LOAD_ERROR_TITLE" = "Oops, an error occurred";
"DEFAULT_OPEN_GROUP_LOAD_ERROR_SUBTITLE" = "Please try again later";

View File

@ -618,3 +618,5 @@
"NEW_CONVERSATION_MENU_OPEN_GROUP" = "Open Group";
"NEW_CONVERSATION_MENU_DIRECT_MESSAGE" = "Direct Message";
"NEW_CONVERSATION_MENU_CLOSED_GROUP" = "Closed Group";
"DEFAULT_OPEN_GROUP_LOAD_ERROR_TITLE" = "Oops, an error occurred";
"DEFAULT_OPEN_GROUP_LOAD_ERROR_SUBTITLE" = "Please try again later";

View File

@ -618,3 +618,5 @@
"NEW_CONVERSATION_MENU_OPEN_GROUP" = "Open Group";
"NEW_CONVERSATION_MENU_DIRECT_MESSAGE" = "Direct Message";
"NEW_CONVERSATION_MENU_CLOSED_GROUP" = "Closed Group";
"DEFAULT_OPEN_GROUP_LOAD_ERROR_TITLE" = "Oops, an error occurred";
"DEFAULT_OPEN_GROUP_LOAD_ERROR_SUBTITLE" = "Please try again later";

View File

@ -618,3 +618,5 @@
"NEW_CONVERSATION_MENU_OPEN_GROUP" = "Open Group";
"NEW_CONVERSATION_MENU_DIRECT_MESSAGE" = "Direct Message";
"NEW_CONVERSATION_MENU_CLOSED_GROUP" = "Closed Group";
"DEFAULT_OPEN_GROUP_LOAD_ERROR_TITLE" = "Oops, an error occurred";
"DEFAULT_OPEN_GROUP_LOAD_ERROR_SUBTITLE" = "Please try again later";

View File

@ -619,3 +619,5 @@
"NEW_CONVERSATION_MENU_OPEN_GROUP" = "Open Group";
"NEW_CONVERSATION_MENU_DIRECT_MESSAGE" = "Direct Message";
"NEW_CONVERSATION_MENU_CLOSED_GROUP" = "Closed Group";
"DEFAULT_OPEN_GROUP_LOAD_ERROR_TITLE" = "Oops, an error occurred";
"DEFAULT_OPEN_GROUP_LOAD_ERROR_SUBTITLE" = "Please try again later";

View File

@ -618,3 +618,5 @@
"NEW_CONVERSATION_MENU_OPEN_GROUP" = "Open Group";
"NEW_CONVERSATION_MENU_DIRECT_MESSAGE" = "Direct Message";
"NEW_CONVERSATION_MENU_CLOSED_GROUP" = "Closed Group";
"DEFAULT_OPEN_GROUP_LOAD_ERROR_TITLE" = "Oops, an error occurred";
"DEFAULT_OPEN_GROUP_LOAD_ERROR_SUBTITLE" = "Please try again later";

View File

@ -618,3 +618,5 @@
"NEW_CONVERSATION_MENU_OPEN_GROUP" = "Open Group";
"NEW_CONVERSATION_MENU_DIRECT_MESSAGE" = "Direct Message";
"NEW_CONVERSATION_MENU_CLOSED_GROUP" = "Closed Group";
"DEFAULT_OPEN_GROUP_LOAD_ERROR_TITLE" = "Oops, an error occurred";
"DEFAULT_OPEN_GROUP_LOAD_ERROR_SUBTITLE" = "Please try again later";

View File

@ -618,3 +618,5 @@
"NEW_CONVERSATION_MENU_OPEN_GROUP" = "Open Group";
"NEW_CONVERSATION_MENU_DIRECT_MESSAGE" = "Direct Message";
"NEW_CONVERSATION_MENU_CLOSED_GROUP" = "Closed Group";
"DEFAULT_OPEN_GROUP_LOAD_ERROR_TITLE" = "Oops, an error occurred";
"DEFAULT_OPEN_GROUP_LOAD_ERROR_SUBTITLE" = "Please try again later";

View File

@ -618,3 +618,5 @@
"NEW_CONVERSATION_MENU_OPEN_GROUP" = "Open Group";
"NEW_CONVERSATION_MENU_DIRECT_MESSAGE" = "Direct Message";
"NEW_CONVERSATION_MENU_CLOSED_GROUP" = "Closed Group";
"DEFAULT_OPEN_GROUP_LOAD_ERROR_TITLE" = "Oops, an error occurred";
"DEFAULT_OPEN_GROUP_LOAD_ERROR_SUBTITLE" = "Please try again later";

View File

@ -618,3 +618,5 @@
"NEW_CONVERSATION_MENU_OPEN_GROUP" = "Open Group";
"NEW_CONVERSATION_MENU_DIRECT_MESSAGE" = "Direct Message";
"NEW_CONVERSATION_MENU_CLOSED_GROUP" = "Closed Group";
"DEFAULT_OPEN_GROUP_LOAD_ERROR_TITLE" = "Oops, an error occurred";
"DEFAULT_OPEN_GROUP_LOAD_ERROR_SUBTITLE" = "Please try again later";

View File

@ -618,3 +618,5 @@
"NEW_CONVERSATION_MENU_OPEN_GROUP" = "Open Group";
"NEW_CONVERSATION_MENU_DIRECT_MESSAGE" = "Direct Message";
"NEW_CONVERSATION_MENU_CLOSED_GROUP" = "Closed Group";
"DEFAULT_OPEN_GROUP_LOAD_ERROR_TITLE" = "Oops, an error occurred";
"DEFAULT_OPEN_GROUP_LOAD_ERROR_SUBTITLE" = "Please try again later";

View File

@ -1,5 +1,6 @@
import PromiseKit
import NVActivityIndicatorView
import SessionUIKit
final class OpenGroupSuggestionGrid : UIView, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout {
private let maxWidth: CGFloat
@ -32,6 +33,42 @@ final class OpenGroupSuggestionGrid : UIView, UICollectionViewDataSource, UIColl
return result
}()
private lazy var errorView: UIView = {
let result: UIView = UIView()
result.isHidden = true
return result
}()
private lazy var errorImageView: UIImageView = {
let result: UIImageView = UIImageView(image: #imageLiteral(resourceName: "warning").withRenderingMode(.alwaysTemplate))
result.tintColor = Colors.destructive
return result
}()
private lazy var errorTitleLabel: UILabel = {
let result: UILabel = UILabel()
result.font = UIFont.systemFont(ofSize: Values.mediumFontSize, weight: .medium)
result.text = "DEFAULT_OPEN_GROUP_LOAD_ERROR_TITLE".localized()
result.textColor = Colors.text
result.textAlignment = .center
result.numberOfLines = 0
return result
}()
private lazy var errorSubtitleLabel: UILabel = {
let result: UILabel = UILabel()
result.font = UIFont.systemFont(ofSize: Values.smallFontSize, weight: .medium)
result.text = "DEFAULT_OPEN_GROUP_LOAD_ERROR_SUBTITLE".localized()
result.textColor = Colors.text
result.textAlignment = .center
result.numberOfLines = 0
return result
}()
// MARK: Settings
private static let cellHeight: CGFloat = 40
private static let separatorWidth = 1 / UIScreen.main.scale
@ -54,17 +91,40 @@ final class OpenGroupSuggestionGrid : UIView, UICollectionViewDataSource, UIColl
private func initialize() {
addSubview(collectionView)
collectionView.pin(to: self)
addSubview(spinner)
spinner.pin([ UIView.HorizontalEdge.left, UIView.VerticalEdge.top ], to: self)
spinner.pin(.top, to: .top, of: self)
spinner.center(.horizontal, in: self)
spinner.startAnimating()
addSubview(errorView)
errorView.pin(.top, to: .top, of: self, withInset: 10)
errorView.pin( [HorizontalEdge.leading, HorizontalEdge.trailing], to: self)
errorView.addSubview(errorImageView)
errorImageView.pin(.top, to: .top, of: errorView)
errorImageView.center(.horizontal, in: errorView)
errorImageView.set(.width, to: 60)
errorImageView.set(.height, to: 60)
errorView.addSubview(errorTitleLabel)
errorTitleLabel.pin(.top, to: .bottom, of: errorImageView, withInset: 10)
errorTitleLabel.center(.horizontal, in: errorView)
errorView.addSubview(errorSubtitleLabel)
errorSubtitleLabel.pin(.top, to: .bottom, of: errorTitleLabel, withInset: 20)
errorSubtitleLabel.center(.horizontal, in: errorView)
heightConstraint = set(.height, to: OpenGroupSuggestionGrid.cellHeight)
widthAnchor.constraint(greaterThanOrEqualToConstant: OpenGroupSuggestionGrid.cellHeight).isActive = true
if OpenGroupAPIV2.defaultRoomsPromise == nil {
OpenGroupAPIV2.getDefaultRoomsIfNeeded()
}
let _ = OpenGroupAPIV2.defaultRoomsPromise?.done { [weak self] rooms in
self?.rooms = rooms
}
OpenGroupAPIV2.getDefaultRoomsIfNeeded()
.done { [weak self] rooms in
self?.rooms = rooms
}
.catch { [weak self] _ in
self?.update()
}
}
// MARK: Updating
@ -75,6 +135,7 @@ final class OpenGroupSuggestionGrid : UIView, UICollectionViewDataSource, UIColl
let height = OpenGroupSuggestionGrid.cellHeight * ceil(CGFloat(roomCount) / 2)
heightConstraint.constant = height
collectionView.reloadData()
errorView.isHidden = (roomCount > 0)
}
// MARK: Layout
@ -173,8 +234,22 @@ 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)
if let imageData: Data = promise.value {
imageView.image = UIImage(data: imageData)
imageView.isHidden = (imageView.image == nil)
}
else {
imageView.isHidden = true
_ = promise.done { [weak self] imageData in
DispatchQueue.main.async {
self?.imageView.image = UIImage(data: imageData)
self?.imageView.isHidden = (self?.imageView.image == nil)
}
}
}
label.text = room.name
}
}

View File

@ -14,6 +14,6 @@ extension OpenGroupAPIV2 {
@objc(getDefaultRoomsIfNeeded)
public static func objc_getDefaultRoomsIfNeeded() {
return getDefaultRoomsIfNeeded()
getDefaultRoomsIfNeeded()
}
}

View File

@ -422,21 +422,37 @@ public final class OpenGroupAPIV2 : NSObject {
}
// MARK: General
public static func getDefaultRoomsIfNeeded() {
@discardableResult public static func getDefaultRoomsIfNeeded() -> Promise<[OpenGroupAPIV2.Info]> {
if let existingPromise: Promise<[OpenGroupAPIV2.Info]> = defaultRoomsPromise {
return existingPromise
}
let (promise, seal) = Promise<[OpenGroupAPIV2.Info]>.pending()
Storage.shared.write(with: { transaction in
Storage.shared.setOpenGroupPublicKey(for: defaultServer, to: defaultServerPublicKey, using: transaction)
}, completion: {
let promise = attempt(maxRetryCount: 8, recoveringOn: DispatchQueue.main) {
let internalPromise: Promise<[OpenGroupAPIV2.Info]> = attempt(maxRetryCount: 8, recoveringOn: DispatchQueue.main) {
OpenGroupAPIV2.getAllRooms(from: defaultServer)
}
let _ = promise.done(on: OpenGroupAPIV2.workQueue) { items in
items.forEach { getGroupImage(for: $0.id, on: defaultServer).retainUntilComplete() }
}
promise.catch(on: OpenGroupAPIV2.workQueue) { _ in
OpenGroupAPIV2.defaultRoomsPromise = nil
}
defaultRoomsPromise = promise
internalPromise
.done(on: OpenGroupAPIV2.workQueue) { items in
items.forEach { getGroupImage(for: $0.id, on: defaultServer).retainUntilComplete() }
seal.fulfill(items)
}
.retainUntilComplete()
internalPromise
.catch(on: OpenGroupAPIV2.workQueue) { error in
OpenGroupAPIV2.defaultRoomsPromise = nil
seal.reject(error)
}
})
defaultRoomsPromise = promise
return promise
}
public static func getInfo(for room: String, on server: String) -> Promise<Info> {