MESSENGER-5386 us17 invite federated users only if room is federated

This commit is contained in:
JanNiklas Grabowski
2024-01-24 16:07:26 +01:00
parent f20b1660d3
commit 81a6a1cd73
3 changed files with 82 additions and 15 deletions
@@ -201,21 +201,24 @@ extension ContactsPickerViewModel: ContactsTableViewControllerDelegate {
return
}
// Check for user
if MXTools.isMatrixUserIdentifier(contact.displayName) {
let user = MXUser(userId: contact.displayName)
coordinatorDelegate?.contactsPickerViewModelDidStartValidatingUser(self)
user?.update(fromHomeserverOfMatrixSession: self.room.mxSession, success: { [weak self] in
guard let self = self else { return }
self.coordinatorDelegate?.contactsPickerViewModelDidEndValidatingUser(self)
self.displayInvitePrompt(contact: contact)
}, failure: { [weak self] error in
guard let self = self else { return }
self.coordinatorDelegate?.contactsPickerViewModelDidEndValidatingUser(self)
self.displayInvitePrompt(contact: contact, isUnknownUser: true)
})
} else {
displayInvitePrompt(contact: contact)
// bwi: #5386
if checkRoomFederationStatusForInvite(contact: contact) {
// Check for user
if MXTools.isMatrixUserIdentifier(contact.displayName) {
let user = MXUser(userId: contact.displayName)
coordinatorDelegate?.contactsPickerViewModelDidStartValidatingUser(self)
user?.update(fromHomeserverOfMatrixSession: self.room.mxSession, success: { [weak self] in
guard let self = self else { return }
self.coordinatorDelegate?.contactsPickerViewModelDidEndValidatingUser(self)
self.displayInvitePrompt(contact: contact)
}, failure: { [weak self] error in
guard let self = self else { return }
self.coordinatorDelegate?.contactsPickerViewModelDidEndValidatingUser(self)
self.displayInvitePrompt(contact: contact, isUnknownUser: true)
})
} else {
displayInvitePrompt(contact: contact)
}
}
}
@@ -300,4 +303,58 @@ extension ContactsPickerViewModel: ContactsTableViewControllerDelegate {
}
}
/*
bwi: #5386 show error msg if federation is not configured or deactivated for this room
- if user is not federated -> display invite prompt
- if user federated -> Check:
- if server acl is configured and room is federated / serverACL = "*" -> display invite prompt
- if server acl is configured and room is not federated -> show error prompt
- if server acl is not configured -> show error prompt
*/
private func checkRoomFederationStatusForInvite(contact: MXKContact) -> Bool {
var canInvite: Bool = false
if BWIBuildSettings.shared.isFederationEnabled {
if let identifieres = contact.matrixIdentifiers {
if let identifiere = identifieres.first as? String {
// Check if user is federated
if room.isRoomMemberFederated(identifiere) {
// Get current serverACL settings for room
room.getCurrentRoomServerACLSettings { serverACL in
if let serverACL = serverACL {
if serverACL.elementsEqual("*") {
// Federation is active
canInvite = true
} else {
// Federation is deactivated
self.coordinatorDelegate?.contactsPickerViewModel(self, display: BWIL10n.roomParticipantsInvitePromptFederationForRoomNotAllowedText, title: "", actions: [
UIAlertAction(title: VectorL10n.ok, style: .cancel)
])
}
} else {
// ServerACL not configured
self.coordinatorDelegate?.contactsPickerViewModel(self, display: BWIL10n.roomParticipantsInvitePromptServerAclForRoomNotConfiguredText, title: "", actions: [
UIAlertAction(title: VectorL10n.ok, style: .cancel)
])
}
}
} else {
canInvite = true
}
} else {
// Show error if federation cannot be determined
coordinatorDelegate?.contactsPickerViewModel(self, display: BWIL10n.roomParticipantsInvitePromptServerAclLoadingErrorText, title: "", actions: [
UIAlertAction(title: VectorL10n.ok, style: .cancel)
])
}
} else {
// Show error if federation cannot be determined
coordinatorDelegate?.contactsPickerViewModel(self, display: BWIL10n.roomParticipantsInvitePromptServerAclLoadingErrorText, title: "", actions: [
UIAlertAction(title: VectorL10n.ok, style: .cancel)
])
}
} else {
canInvite = true
}
return canInvite
}
}