mirror of
https://gitlab.opencode.de/bwi/bundesmessenger/clients/bundesmessenger-ios.git
synced 2026-04-19 08:03:50 +02:00
Widgets: Add "Remove for everyone" to the contextual menu
This commit is contained in:
@@ -86,6 +86,44 @@ NSString *const kJavascriptSendResponseToPostMessageAPI = @"riotIOS.sendResponse
|
||||
self.URL = self.widgetUrl;
|
||||
}
|
||||
|
||||
- (BOOL)hasUserEnoughPowerToManageCurrentWidget
|
||||
{
|
||||
BOOL hasUserEnoughPower = NO;
|
||||
|
||||
MXSession *session = widget.mxSession;
|
||||
MXRoom *room = [session roomWithRoomId:self.widget.roomId];
|
||||
MXRoomState *roomState = room.dangerousSyncState;
|
||||
if (roomState)
|
||||
{
|
||||
// Check user's power in the room
|
||||
MXRoomPowerLevels *powerLevels = roomState.powerLevels;
|
||||
NSInteger oneSelfPowerLevel = [powerLevels powerLevelOfUserWithUserID:session.myUser.userId];
|
||||
|
||||
// The user must be able to send state events to manage widgets
|
||||
if (oneSelfPowerLevel >= powerLevels.stateDefault)
|
||||
{
|
||||
hasUserEnoughPower = YES;
|
||||
}
|
||||
}
|
||||
|
||||
return hasUserEnoughPower;
|
||||
}
|
||||
|
||||
- (void)removeCurrentWidget
|
||||
{
|
||||
WidgetManager *widgetManager = [WidgetManager sharedManager];
|
||||
|
||||
MXRoom *room = [self.widget.mxSession roomWithRoomId:self.widget.roomId];
|
||||
NSString *widgetId = self.widget.widgetId;
|
||||
if (room && widgetId)
|
||||
{
|
||||
[widgetManager closeWidget:widgetId inRoom:room success:^{
|
||||
} failure:^(NSError *error) {
|
||||
NSLog(@"[WidgetVC] removeCurrentWidget failed. Error: %@", error);
|
||||
}];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)showErrorAsAlert:(NSError*)error
|
||||
{
|
||||
NSString *title = [error.userInfo valueForKey:NSLocalizedFailureReasonErrorKey];
|
||||
@@ -246,6 +284,17 @@ NSString *const kJavascriptSendResponseToPostMessageAPI = @"riotIOS.sendResponse
|
||||
}]];
|
||||
}
|
||||
|
||||
if ([self hasUserEnoughPowerToManageCurrentWidget])
|
||||
{
|
||||
[menu addAction:[UIAlertAction actionWithTitle:NSLocalizedStringFromTable(@"widget_menu_remove", @"Vector", nil)
|
||||
style:UIAlertActionStyleDefault
|
||||
handler:^(UIAlertAction * action)
|
||||
{
|
||||
[self removeCurrentWidget];
|
||||
[self withdrawViewControllerAnimated:YES completion:nil];
|
||||
}]];
|
||||
}
|
||||
|
||||
[menu addAction:[UIAlertAction actionWithTitle:[NSBundle mxk_localizedStringForKey:@"cancel"]
|
||||
style:UIAlertActionStyleCancel
|
||||
handler:^(UIAlertAction * action) {
|
||||
|
||||
Reference in New Issue
Block a user