Merge commit '653554e759f81eb0d18852ac8a46b462c514b245' into feature/refactoring_federation

* commit '653554e759f81eb0d18852ac8a46b462c514b245':
  reset versions
  MESSENGER-5304 refactoring
  MESSENGER-5304 add condition
  MESSENGER-5386 change alert appearance
  MESSENGER-5381 disable federated admins
  MESSENGER-5386 us17  invite federated users only if room is federated
  MESSENGER-5304 refactoring and english translation
  MESSENGER-5304 add text styling and spacing
  MESSENGER-5304 add room federation decision sheet
This commit is contained in:
JanNiklas Grabowski
2024-01-26 11:56:58 +01:00
8 changed files with 438 additions and 20 deletions

View File

@@ -59,8 +59,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/matrix-org/matrix-wysiwyg-composer-swift",
"state" : {
"revision" : "dfb74c89bf54b41ea000d564d6435ac6444ba6b4",
"version" : "2.18.0"
"revision" : "0aa1308c43451fd077e332f72d6a32135f258834",
"version" : "2.19.0"
}
},
{

View File

@@ -673,7 +673,7 @@
"bwi_room_settings_federation_alert_title" = "Achtung!";
"bwi_room_settings_federation_alert_message" = "Durch das Aufheben der Föderation werden alle Mitglieder der anderen Organisation unwiderruflich entfernt.\n\nFöderation trotzdem aufheben?";
"bwi_room_settings_federation_alert_withdraw_button" = "Ja, aufheben";
"room_details_failed_to_update_room_server_acl_rule" = "Aktualisierung der Föderations Einstellung fehlgeschlagen";
"room_details_failed_to_update_room_server_acl_rule" = "Aktualisierung der Föderations-Einstellung fehlgeschlagen";
"room_details_failed_to_change_federation_for_room_error_title" = "Föderation aktiv";
"room_details_failed_to_change_federation_for_room_error_text" = "Die Föderation konnte nicht geändert werden, bitte versuche es später erneut.";
"room_details_failed_to_change_federation_alert_dismiss_button" = "Ok";
@@ -683,3 +683,20 @@
"create_room_failed_to_deactivate_federation_for_room_error_title" = "Föderation aktiv";
"create_room_failed_to_deactivate_federation_for_room_error_text" = "Die Föderation konnte nicht deaktiviert werden, bitte versuche es später erneut.";
"create_room_failed_to_deactivate_federation_alert_dismiss_button" = "Ok";
"room_member_details_change_federated_member_power_lvl_to_admin_error_text" = "Diese Person kann keine Adminrechte erhalten, da sie nicht aus deiner Organisation stammt. Föderierte Personen können nur Mitglieder oder Moderatoren sein.";
"room_member_details_change_federated_member_power_lvl_to_admin_error_button" = "Verstanden";
"room_admin_federation_decision_sheet_title" = "\"%@\" für eine Föderation zulassen?";
"room_admin_federation_decision_sheet_text" = "Hierdurch kann der Raum von externen Organisationen mitgenutzt werden. Dies kann nachträglich in den Einstellungen geändert werden.";
"room_admin_federation_decision_sheet_remind_later_button" = "Später erinnern";
"room_admin_federation_decision_sheet_activate_federation_button" = "Raum föderieren";
"room_admin_federation_decision_sheet_deactivate_federation_button" = "Raum intern behalten";
"room_admin_federation_decision_set_federation_error_alert_title" = "Aktualisierung fehlgeschlagen";
"room_admin_federation_decision_set_federation_error_alert_text" = "Aktualisierung der Föderations-Einstellung fehlgeschlagen, bitte versuche es später erneut.";
"room_participants_invite_prompt_federation_for_room_not_allowed_text" = "Du kannst diese Person nicht einladen, da die Föderation für diesen Raum durch den Admin nicht gewünscht ist.";
"room_participants_invite_prompt_server_acl_for_room_not_configured_text" = "Du kannst noch keine Personen aus einer föderierten Organisation einladen, da die Freigabe hierfür noch nicht erteilt wurde. Gib dem Admin Bescheid, dass die Einstellung getroffen werden muss.";
"room_participants_invite_prompt_server_acl_loading_error_text" = "Die Person kann aktuell nicht eingeladen werden, bitte versuche es später erneut.";

View File

@@ -592,3 +592,20 @@
"create_room_failed_to_deactivate_federation_for_room_error_title" = "Federation active";
"create_room_failed_to_deactivate_federation_for_room_error_text" = "The federation could not be disabled, please try again later.";
"create_room_failed_to_deactivate_federation_alert_dismiss_button" = "Ok";
"room_member_details_change_federated_member_power_lvl_to_admin_error_text" = "This user cannot be granted admin rights as they do not come from your organization. Federated users can only be members or moderators.";
"room_member_details_change_federated_member_power_lvl_to_admin_error_button" = "Ok";
"room_admin_federation_decision_sheet_title" = "Approve \"%@\" for federation?";
"room_admin_federation_decision_sheet_text" = "This will enable external organizations to access the room. It can be reversed in the room settings afterwards.";
"room_admin_federation_decision_sheet_remind_later_button" = "Remind later";
"room_admin_federation_decision_sheet_activate_federation_button" = "Federrate room";
"room_admin_federation_decision_sheet_deactivate_federation_button" = "Keep room internal";
"room_admin_federation_decision_set_federation_error_alert_title" = "Fail to update";
"room_admin_federation_decision_set_federation_error_alert_text" = "Fail to update the federation settings, please try again later.";
"room_participants_invite_prompt_federation_for_room_not_allowed_text" = "You cannot invite this user because the federation for this room is not desired by the admin";
"room_participants_invite_prompt_server_acl_for_room_not_configured_text" = "You cannot yet invite people from a federated organization, as this has not yet been approved. Let the admin know that the setting needs to be made.";
"room_participants_invite_prompt_server_acl_loading_error_text" = "You cannot invite this user at the moment, please try again later.";

View File

@@ -1127,6 +1127,34 @@ public class BWIL10n: NSObject {
public static var retry: String {
return BWIL10n.tr("Bwi", "retry")
}
/// Aktualisierung der Föderations-Einstellung fehlgeschlagen, bitte versuche es später erneut.
public static var roomAdminFederationDecisionSetFederationErrorAlertText: String {
return BWIL10n.tr("Bwi", "room_admin_federation_decision_set_federation_error_alert_text")
}
/// Aktualisierung fehlgeschlagen
public static var roomAdminFederationDecisionSetFederationErrorAlertTitle: String {
return BWIL10n.tr("Bwi", "room_admin_federation_decision_set_federation_error_alert_title")
}
/// Raum föderieren
public static var roomAdminFederationDecisionSheetActivateFederationButton: String {
return BWIL10n.tr("Bwi", "room_admin_federation_decision_sheet_activate_federation_button")
}
/// Raum intern behalten
public static var roomAdminFederationDecisionSheetDeactivateFederationButton: String {
return BWIL10n.tr("Bwi", "room_admin_federation_decision_sheet_deactivate_federation_button")
}
/// Später erinnern
public static var roomAdminFederationDecisionSheetRemindLaterButton: String {
return BWIL10n.tr("Bwi", "room_admin_federation_decision_sheet_remind_later_button")
}
/// Hierdurch kann der Raum von externen Organisationen mitgenutzt werden. Dies kann nachträglich in den Einstellungen geändert werden.
public static var roomAdminFederationDecisionSheetText: String {
return BWIL10n.tr("Bwi", "room_admin_federation_decision_sheet_text")
}
/// "%@" für eine Föderation zulassen?
public static func roomAdminFederationDecisionSheetTitle(_ p1: String) -> String {
return BWIL10n.tr("Bwi", "room_admin_federation_decision_sheet_title", p1)
}
/// Raumbild ändern
public static var roomAvatarViewAccessibilityHint: String {
return BWIL10n.tr("Bwi", "room_avatar_view_accessibility_hint")
@@ -1187,7 +1215,7 @@ public class BWIL10n: NSObject {
public static var roomDetailsFailedToChangeFederationForRoomErrorTitle: String {
return BWIL10n.tr("Bwi", "room_details_failed_to_change_federation_for_room_error_title")
}
/// Aktualisierung der Föderations Einstellung fehlgeschlagen
/// Aktualisierung der Föderations-Einstellung fehlgeschlagen
public static var roomDetailsFailedToUpdateRoomServerAclRule: String {
return BWIL10n.tr("Bwi", "room_details_failed_to_update_room_server_acl_rule")
}

View File

@@ -1270,7 +1270,22 @@
}
case MXKRoomMemberDetailsActionSetAdmin:
{
[self setPowerLevel:RoomPowerLevelAdmin promptUser:YES];
// bwi: #5381 federated admins are not allowed
if (BWIBuildSettings.shared.isFederationEnabled)
{
if ([self.mxRoom isRoomMemberFederated:self.mxRoomMember.userId])
{
[self showAlertFederatedAdminsNotAllowed];
}
else
{
[self setPowerLevel:RoomPowerLevelAdmin promptUser:YES];
}
}
else
{
[self setPowerLevel:RoomPowerLevelAdmin promptUser:YES];
}
break;
}
case MXKRoomMemberDetailsActionBan:
@@ -1690,6 +1705,29 @@
[bwiUserLabelButton setTitle:title forState:UIControlStateHighlighted];
}
// bwi: #5381 federated admins are not allowed
- (void)showAlertFederatedAdminsNotAllowed {
__weak typeof(self) weakSelf = self;
currentAlert = [UIAlertController alertControllerWithTitle:BWIL10n.roomMemberDetailsChangeFederatedMemberPowerLvlToAdminErrorText
message:nil
preferredStyle:UIAlertControllerStyleAlert];
[currentAlert addAction:[UIAlertAction actionWithTitle:BWIL10n.roomMemberDetailsChangeFederatedMemberPowerLvlToAdminErrorButton
style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action) {
if (weakSelf)
{
typeof(self) self = weakSelf;
self->currentAlert = nil;
}
}]];
[self presentViewController:currentAlert animated:YES completion:nil];
}
#pragma mark - bwi textfield delegate
-(void) textFieldDidChangeSelection:(UITextField *)textField {

View File

@@ -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: "", title: BWIL10n.roomParticipantsInvitePromptFederationForRoomNotAllowedText, actions: [
UIAlertAction(title: VectorL10n.ok, style: .cancel)
])
}
} else {
// ServerACL not configured
self.coordinatorDelegate?.contactsPickerViewModel(self, display: "", title: BWIL10n.roomParticipantsInvitePromptServerAclForRoomNotConfiguredText, actions: [
UIAlertAction(title: VectorL10n.ok, style: .cancel)
])
}
}
} else {
canInvite = true
}
} else {
// Show error if federation cannot be determined
coordinatorDelegate?.contactsPickerViewModel(self, display: "", title: BWIL10n.roomParticipantsInvitePromptServerAclLoadingErrorText, actions: [
UIAlertAction(title: VectorL10n.ok, style: .cancel)
])
}
} else {
// Show error if federation cannot be determined
coordinatorDelegate?.contactsPickerViewModel(self, display: "", title: BWIL10n.roomParticipantsInvitePromptServerAclLoadingErrorText, actions: [
UIAlertAction(title: VectorL10n.ok, style: .cancel)
])
}
} else {
canInvite = true
}
return canInvite
}
}

View File

@@ -242,6 +242,9 @@ static CGSize kThreadListBarButtonItemImageSize;
// Check if we should wait for other participants
@property (nonatomic, readonly) BOOL shouldWaitForOtherParticipants;
// bwi: #5304 show federation decision sheet
@property (nonatomic) BOOL wasFederationDecisionSheetShownBefore;
@end
@implementation RoomViewController
@@ -434,6 +437,9 @@ static CGSize kThreadListBarButtonItemImageSize;
[self setupCompletionSuggestionViewIfNeeded];
[self.topBannersStackView vc_removeAllSubviews];
// bwi: #5304 show federation decision sheet
self.wasFederationDecisionSheetShownBefore = false;
}
- (void)userInterfaceThemeDidChange
@@ -717,6 +723,10 @@ static CGSize kThreadListBarButtonItemImageSize;
}
[self setMaximisedToolbarIsHiddenIfNeeded: NO];
// bwi: #5304 show federation decision sheet only for admins and only in rooms / not in DMs
[self showFederationDecisionSheet];
}
- (void)viewDidDisappear:(BOOL)animated
@@ -8231,6 +8241,57 @@ static CGSize kThreadListBarButtonItemImageSize;
}
}
#pragma mark - BWI Federation
// bwi: #5304 show federation decision sheet only for admins and only in rooms / not in DMs
- (void)showFederationDecisionSheet {
if (BWIBuildSettings.shared.isFederationEnabled)
{
// Show sheet only when opening room
if (!self.wasFederationDecisionSheetShownBefore)
{
// Do not show sheet if room DM
if (!self.roomDataSource.room.isDirect)
{
// Do not show sheet if room is personal notes room
if (!self.roomDataSource.room.isPersonalNotesRoom)
{
// Do not show sheet if isFederated room flag is false (default == true)
if (self.roomDataSource.room.isRoomFederated)
{
// Do not show sheet if users power level is lower than admin
MXRoomPowerLevels *powerLevels = self.roomDataSource.roomState.powerLevels;
if ([powerLevels powerLevelOfUserWithUserID:self.mainSession.myUser.userId] >= RoomPowerLevelAdmin)
{
// Show sheet if no serverACL have been configured
[self.roomDataSource.room getCurrentRoomServerACLSettingsWithCompletion:^(NSString *serverACL)
{
if (serverACL == nil) {
self.wasFederationDecisionSheetShownBefore = true;
RoomFederationDecisionSheet *federationDecisionView = [[RoomFederationDecisionSheet alloc] init];
UIImage *roomAvatarImage;
MXKImageView *roomAvatarImageView = ((RoomTitleView*)self.titleView).pictureView;
if (roomAvatarImageView && roomAvatarImageView.image)
{
roomAvatarImage = roomAvatarImageView.image;
}
else
{
roomAvatarImage = [AvatarGenerator generateAvatarForMatrixItem:self.roomDataSource.roomId withDisplayName:self.roomDataSource.room.summary.displayName];
}
UIViewController *sheetViewController = [federationDecisionView makeViewControllerWithRoom:self.roomDataSource.room roomAvatarImage: roomAvatarImage];
sheetViewController.modalPresentationStyle = UIModalPresentationFormSheet;
[self presentViewController:sheetViewController animated:YES completion:nil];
}
}];
}
}
}
}
}
}
}
#pragma mark - UserSuggestionCoordinatorBridgeDelegate
- (void)completionSuggestionCoordinatorBridge:(CompletionSuggestionCoordinatorBridge *)coordinator

View File

@@ -0,0 +1,200 @@
//
/*
* Copyright (c) 2024 BWI GmbH
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import SwiftUI
/// Helper class for making our SwiftUI view available to ObjectiveC
@objcMembers class RoomFederationDecisionSheet: NSObject {
private var decisionView: RoomFederationDecisionView?
@Published var theme: Theme
override init() {
theme = ThemeService.shared().theme
}
func makeViewController(room: MXRoom, roomAvatarImage: UIImage) -> UIViewController {
registerThemeServiceDidChangeThemeNotification()
self.decisionView = RoomFederationDecisionView(theme: Binding(get: {
return self.theme
}, set: { newTheme in
self.theme = newTheme
}), room: room, roomAvatarImage: roomAvatarImage)
return UIHostingController(rootView: decisionView)
}
private func registerThemeServiceDidChangeThemeNotification() {
NotificationCenter.default.addObserver(self, selector: #selector(themeDidChange), name: .themeServiceDidChangeTheme, object: nil)
}
@objc private func themeDidChange() {
self.theme = ThemeService.shared().theme
}
}
// bwi: #5304
struct RoomFederationDecisionView: View {
@Environment(\.dismiss) var dismissView
@State var isUpdatingServerACLs: Bool = false
@Binding var theme: Theme
@State var showSetServerACLErrorAlert: Bool = false
var room: MXRoom
@State var pendingRequest: MXHTTPOperation?
var roomAvatarImage: UIImage
let imageStackScale = 0.30
let imageStackShift = 5.0
let lineWith = 7.0
let spacing = 16.0
var body: some View {
GeometryReader { geo in
ScrollView(.vertical) {
VStack(spacing: spacing) {
VStack(spacing: spacing) {
Spacer()
// Federation image with room avatar
ZStack(alignment: .center) {
Circle()
.fill(Color(theme.colors.quinaryContent))
.overlay(Circle()
.stroke(Color(theme.colors.background), lineWidth: lineWith))
.offset(x:((getImageSize(width: geo.size.width, height: geo.size.height) * imageStackScale) / imageStackShift))
Image(uiImage: roomAvatarImage)
.resizable()
.clipShape(Circle())
.overlay(Circle()
.stroke(Color(theme.colors.background), lineWidth: lineWith))
.offset(x:-((getImageSize(width: geo.size.width, height: geo.size.height) * imageStackScale) / imageStackShift))
}
.frame(width: getImageSize(width: geo.size.width, height: geo.size.height) * imageStackScale, height: getImageSize(width: geo.size.width, height: geo.size.height) * imageStackScale)
// Federation info text
textStack
}
if isUpdatingServerACLs {
ProgressView()
}
// Federation actions
buttonStack
}
.frame(minHeight: geo.size.height)
}
.interactiveDismissDisabled()
.frame(width: geo.size.width, height: geo.size.height)
.background(Color(theme.colors.background))
.alert(isPresented: $showSetServerACLErrorAlert) {
Alert(title: Text(BWIL10n.roomAdminFederationDecisionSetFederationErrorAlertTitle), message: Text(BWIL10n.roomAdminFederationDecisionSetFederationErrorAlertText), dismissButton: .default(Text("Ok")))
}
}
}
func getImageSize(width: CGFloat, height: CGFloat) -> CGFloat {
return (width > height ? height : width)
}
var textStack: some View {
VStack(spacing: spacing) {
Text(BWIL10n.roomAdminFederationDecisionSheetTitle(room.displayName ?? ""))
.font(.system(size: 24).bold())
.multilineTextAlignment(.center)
.lineLimit(nil)
.foregroundColor(Color(theme.colors.primaryContent))
Text(BWIL10n.roomAdminFederationDecisionSheetText)
.font(.system(size: 12))
.multilineTextAlignment(.center)
.lineLimit(nil)
.foregroundColor(Color(theme.colors.secondaryContent))
}
.padding(spacing)
}
var buttonStack: some View {
VStack(spacing: spacing) {
Spacer()
Button {
closeView()
} label: {
Text(BWIL10n.roomAdminFederationDecisionSheetRemindLaterButton)
}
.buttonStyle(SecondaryActionButtonStyle())
.accessibilityIdentifier("federationDecisionSheetRemindLaterButton")
Button {
setServerACL(isFederated: true)
} label: {
Text(BWIL10n.roomAdminFederationDecisionSheetActivateFederationButton)
}
.buttonStyle(SecondaryActionButtonStyle())
.accessibilityIdentifier("federationDecisionSheetActivateFederationButton")
.disabled(isUpdatingServerACLs)
Button {
setServerACL(isFederated: false)
} label: {
Text(BWIL10n.roomAdminFederationDecisionSheetDeactivateFederationButton)
}
.buttonStyle(PrimaryActionButtonStyle())
.accessibilityIdentifier("federationDecisionSheetDeactivateFederationButton")
.disabled(isUpdatingServerACLs)
}
.padding(spacing)
}
func setServerACL(isFederated: Bool) {
var serverACL: [String] = [String]()
if isFederated {
serverACL.append("*")
} else {
if let myUserIDComponents = room.mxSession.myUserId?.components(separatedBy: ":")
{
if myUserIDComponents.count == 2 {
serverACL.append(myUserIDComponents[1])
}
}
}
var content: [String:Any] = [String:Any]()
content.updateValue(serverACL, forKey: "allow")
content.updateValue(false, forKey: "allowIPLiterals")
isUpdatingServerACLs = true
pendingRequest = room.sendStateEvent(MXEventType.roomServerACL, content: content, stateKey: "") { response in
isUpdatingServerACLs = false
if response.isSuccess {
closeView()
}
else {
showSetServerACLErrorAlert = true
}
}
}
func closeView() {
if let pendingRequest = pendingRequest {
pendingRequest.cancel()
}
dismissView()
}
}