mirror of
https://github.com/vector-im/element-ios.git
synced 2024-09-29 07:42:40 +00:00
Jitsi widget: Add [WidgetManager closeWidget] and use it for jitsi conference
This commit is contained in:
parent
f13baec441
commit
9e02006abd
6 changed files with 156 additions and 9 deletions
|
@ -231,6 +231,8 @@
|
|||
"room_unsent_messages_notification" = "Messages not sent. %@ or %@ now?";
|
||||
"room_unsent_messages_unknown_devices_notification" = "Message not sent due to unknown devices being present. %@ or %@ now?";
|
||||
"room_ongoing_conference_call" = "Ongoing conference call. Join as %@ or %@.";
|
||||
"room_ongoing_conference_call_with_close" = "Ongoing conference call. Join as %@ or %@. %@ it.";
|
||||
"room_ongoing_conference_call_close" = "Close";
|
||||
"room_prompt_resend" = "Resend all";
|
||||
"room_prompt_cancel" = "cancel all";
|
||||
"room_resend_unsent_messages" = "Resend unsent messages";
|
||||
|
@ -493,3 +495,6 @@
|
|||
"bug_report_progress_uploading" = "Uploading report";
|
||||
"bug_report_send" = "Send";
|
||||
|
||||
// Widget
|
||||
"widget_no_power_to_manage" = "You need permission to manage widgets in this room";
|
||||
|
||||
|
|
|
@ -33,7 +33,17 @@ FOUNDATION_EXPORT NSString *const kWidgetTypeJitsi;
|
|||
/**
|
||||
Posted when a widget has been created, updated or removed.
|
||||
*/
|
||||
extern NSString *const kMXKWidgetManagerDidUpdateWidgetNotification;
|
||||
FOUNDATION_EXPORT NSString *const kMXKWidgetManagerDidUpdateWidgetNotification;
|
||||
|
||||
/**
|
||||
`WidgetManager` NSError domain and codes.
|
||||
*/
|
||||
FOUNDATION_EXPORT NSString *const WidgetManagerErrorDomain;
|
||||
|
||||
typedef enum : NSUInteger
|
||||
{
|
||||
WidgetManagerErrorCodeNotEnoughPower
|
||||
} WidgetManagerErrorCode;
|
||||
|
||||
|
||||
/**
|
||||
|
@ -65,6 +75,21 @@ extern NSString *const kMXKWidgetManagerDidUpdateWidgetNotification;
|
|||
*/
|
||||
- (NSArray<Widget*> *)widgetsOfTypes:(NSArray<NSString*>*)widgetTypes inRoom:(MXRoom*)room;
|
||||
|
||||
/**
|
||||
Close/Disable a widget in a room.
|
||||
|
||||
@param widgetId the id of the widget to close.
|
||||
@param room the room the widget is in.
|
||||
|
||||
@param success A block object called when the operation succeeds.
|
||||
@param failure A block object called when the operation fails.
|
||||
|
||||
@return a MXHTTPOperation instance.
|
||||
*/
|
||||
- (MXHTTPOperation *)closeWidget:(NSString*)widgetId inRoom:(MXRoom*)room
|
||||
success:(void (^)())success
|
||||
failure:(void (^)(NSError *error))failure;
|
||||
|
||||
/**
|
||||
Add/remove matrix session.
|
||||
|
||||
|
|
|
@ -23,6 +23,8 @@ NSString *const kWidgetTypeJitsi = @"jitsi";
|
|||
|
||||
NSString *const kMXKWidgetManagerDidUpdateWidgetNotification = @"kMXKWidgetManagerDidUpdateWidgetNotification";
|
||||
|
||||
NSString *const WidgetManagerErrorDomain = @"WidgetManagerErrorDomain";
|
||||
|
||||
@interface WidgetManager ()
|
||||
{
|
||||
// MXSession kind of hash -> Listener for matrix events for widgets.
|
||||
|
@ -127,6 +129,58 @@ NSString *const kMXKWidgetManagerDidUpdateWidgetNotification = @"kMXKWidgetManag
|
|||
return activeWidgets;
|
||||
}
|
||||
|
||||
- (MXHTTPOperation *)closeWidget:(NSString *)widgetId inRoom:(MXRoom *)room success:(void (^)())success failure:(void (^)(NSError *))failure
|
||||
{
|
||||
NSError *permissionError = [self checkWidgetPermissionInRoom:room];
|
||||
if (permissionError)
|
||||
{
|
||||
if (failure)
|
||||
{
|
||||
failure(permissionError);
|
||||
}
|
||||
return nil;
|
||||
}
|
||||
|
||||
// Send a state event with an empty content to disable the widget
|
||||
return [room sendStateEventOfType:kWidgetEventTypeString
|
||||
content:@{}
|
||||
stateKey:widgetId
|
||||
success:^(NSString *eventId)
|
||||
{
|
||||
if (success)
|
||||
{
|
||||
success();
|
||||
}
|
||||
} failure:failure];
|
||||
}
|
||||
|
||||
/**
|
||||
Check user's power for widgets management in a room.
|
||||
|
||||
@param room the room to check.
|
||||
@return an NSError if the user cannot act on widgets in this room. Else, nil.
|
||||
*/
|
||||
- (NSError *)checkWidgetPermissionInRoom:(MXRoom *)room
|
||||
{
|
||||
NSError *error;
|
||||
|
||||
// Check user's power in the room
|
||||
MXRoomPowerLevels *powerLevels = room.state.powerLevels;
|
||||
NSInteger oneSelfPowerLevel = [powerLevels powerLevelOfUserWithUserID:room.mxSession.myUser.userId];
|
||||
|
||||
// The user must be able to send state events to manage widgets
|
||||
if (oneSelfPowerLevel < powerLevels.stateDefault)
|
||||
{
|
||||
error = [NSError errorWithDomain:WidgetManagerErrorDomain
|
||||
code:WidgetManagerErrorCodeNotEnoughPower
|
||||
userInfo:@{
|
||||
NSLocalizedDescriptionKey: NSLocalizedStringFromTable(@"widget_no_power_to_manage", @"Vector", nil)
|
||||
}];
|
||||
}
|
||||
|
||||
return error;
|
||||
}
|
||||
|
||||
- (void)addMatrixSession:(MXSession *)mxSession
|
||||
{
|
||||
__weak __typeof__(self) weakSelf = self;
|
||||
|
|
|
@ -3412,7 +3412,7 @@
|
|||
{
|
||||
[customizedRoomDataSource.room placeCallWithVideo:video success:nil failure:nil];
|
||||
}
|
||||
}];
|
||||
} onClosePressed:nil];
|
||||
}
|
||||
}
|
||||
else if (jitsiWidget)
|
||||
|
@ -3435,6 +3435,36 @@
|
|||
|
||||
// Present the Jitsi view controller
|
||||
[appDelegate displayJitsiViewControllerWithWidget:jitsiWidget andVideo:video];
|
||||
} onClosePressed:^{
|
||||
|
||||
[self startActivityIndicator];
|
||||
|
||||
// TODO: hang up if we are in the conf
|
||||
|
||||
// Close the widget
|
||||
__weak __typeof(self) weakSelf = self;
|
||||
[[WidgetManager sharedManager] closeWidget:jitsiWidget.widgetId inRoom:self.roomDataSource.room success:^{
|
||||
|
||||
if (weakSelf)
|
||||
{
|
||||
typeof(self) self = weakSelf;
|
||||
[self stopActivityIndicator];
|
||||
|
||||
// The banner will automatically leave thanks to kMXKWidgetManagerDidUpdateWidgetNotification
|
||||
}
|
||||
|
||||
} failure:^(NSError *error) {
|
||||
if (weakSelf)
|
||||
{
|
||||
// TODO: Customise the alert for permission issues
|
||||
|
||||
//Alert user
|
||||
[[AppDelegate theDelegate] showErrorAsAlert:error];
|
||||
|
||||
typeof(self) self = weakSelf;
|
||||
[self stopActivityIndicator];
|
||||
}
|
||||
}];
|
||||
}];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -63,8 +63,10 @@
|
|||
|
||||
@param ongoingConferenceCallPressed the block called when the user clicks on the banner.
|
||||
video is YES if the user chose to join the conf in video mode.
|
||||
@param ongoingConferenceCallClosePressed the block called when the user clicks on the banner close button.
|
||||
nil means do not display a close button.
|
||||
*/
|
||||
- (void)displayOngoingConferenceCall:(void (^)(BOOL video))ongoingConferenceCallPressed;
|
||||
- (void)displayOngoingConferenceCall:(void (^)(BOOL video))ongoingConferenceCallPressed onClosePressed:(void (^)(void))ongoingConferenceCallClosePressed;
|
||||
|
||||
/**
|
||||
Display a "scroll to bottom" icon.
|
||||
|
|
|
@ -211,17 +211,31 @@
|
|||
[self checkHeight:YES];
|
||||
}
|
||||
|
||||
- (void)displayOngoingConferenceCall:(void (^)(BOOL))onOngoingConferenceCallPressed
|
||||
- (void)displayOngoingConferenceCall:(void (^)(BOOL))onOngoingConferenceCallPressed onClosePressed:(void (^)(void))onOngoingConferenceCallClosePressed
|
||||
{
|
||||
[self reset];
|
||||
|
||||
objc_setAssociatedObject(self.messageTextView, "onOngoingConferenceCallPressed", [onOngoingConferenceCallPressed copy], OBJC_ASSOCIATION_RETAIN_NONATOMIC);
|
||||
|
||||
// Build the string to display in the banner
|
||||
NSString *onGoingConferenceCall =
|
||||
[NSString stringWithFormat:NSLocalizedStringFromTable(@"room_ongoing_conference_call", @"Vector", nil),
|
||||
NSString *onGoingConferenceCall;
|
||||
|
||||
if (!onOngoingConferenceCallClosePressed)
|
||||
{
|
||||
onGoingConferenceCall = [NSString stringWithFormat:NSLocalizedStringFromTable(@"room_ongoing_conference_call", @"Vector", nil),
|
||||
NSLocalizedStringFromTable(@"voice", @"Vector", nil),
|
||||
NSLocalizedStringFromTable(@"video", @"Vector", nil)];
|
||||
}
|
||||
else
|
||||
{
|
||||
// Display the banner with a "Close it" string
|
||||
objc_setAssociatedObject(self.messageTextView, "onOngoingConferenceCallClosePressed", [onOngoingConferenceCallClosePressed copy], OBJC_ASSOCIATION_RETAIN_NONATOMIC);
|
||||
|
||||
onGoingConferenceCall = [NSString stringWithFormat:NSLocalizedStringFromTable(@"room_ongoing_conference_call_with_close", @"Vector", nil),
|
||||
NSLocalizedStringFromTable(@"voice", @"Vector", nil),
|
||||
NSLocalizedStringFromTable(@"video", @"Vector", nil),
|
||||
NSLocalizedStringFromTable(@"room_ongoing_conference_call_close", @"Vector", nil)];
|
||||
}
|
||||
|
||||
NSMutableAttributedString *onGoingConferenceCallAttibutedString = [[NSMutableAttributedString alloc] initWithString:onGoingConferenceCall];
|
||||
|
||||
|
@ -235,6 +249,14 @@
|
|||
[onGoingConferenceCallAttibutedString addAttribute:NSUnderlineStyleAttributeName value:@(NSUnderlineStyleSingle) range:videoRange];
|
||||
[onGoingConferenceCallAttibutedString addAttribute:NSLinkAttributeName value:@"onOngoingConferenceCallWithVideoPressed" range:videoRange];
|
||||
|
||||
// Add a link on the "Close" string
|
||||
if (onOngoingConferenceCallClosePressed)
|
||||
{
|
||||
NSRange closeRange = [onGoingConferenceCall rangeOfString:NSLocalizedStringFromTable(@"room_ongoing_conference_call_close", @"Vector", nil)];
|
||||
[onGoingConferenceCallAttibutedString addAttribute:NSUnderlineStyleAttributeName value:@(NSUnderlineStyleSingle) range:closeRange];
|
||||
[onGoingConferenceCallAttibutedString addAttribute:NSLinkAttributeName value:@"onOngoingConferenceCallClosePressed" range:closeRange];
|
||||
}
|
||||
|
||||
// Display the string in white on pink red
|
||||
NSRange wholeString = NSMakeRange(0, onGoingConferenceCallAttibutedString.length);
|
||||
[onGoingConferenceCallAttibutedString addAttribute:NSForegroundColorAttributeName value:kRiotPrimaryBgColor range:wholeString];
|
||||
|
@ -382,7 +404,16 @@
|
|||
|
||||
return NO;
|
||||
}
|
||||
return YES;
|
||||
else if ([[URL absoluteString] isEqualToString:@"onOngoingConferenceCallClosePressed"])
|
||||
{
|
||||
void (^onOngoingConferenceCallClosePressed)(BOOL) = objc_getAssociatedObject(self.messageTextView, "onOngoingConferenceCallClosePressed");
|
||||
if (onOngoingConferenceCallClosePressed)
|
||||
{
|
||||
onOngoingConferenceCallClosePressed(YES);
|
||||
}
|
||||
|
||||
return NO;
|
||||
} return YES;
|
||||
}
|
||||
|
||||
#pragma mark - UIGestureRecognizerDelegate
|
||||
|
|
Loading…
Reference in a new issue