From 094886fab1f6e6c1f77e3b5b6d47bbe28c95c68d Mon Sep 17 00:00:00 2001 From: manuroe Date: Fri, 4 Aug 2017 13:47:50 +0200 Subject: [PATCH] Jitsi widget: RoomVC: Show it in the banner when there is an active jitsi conference in a room. --- Riot/Model/Room/RoomDataSource.h | 9 ++++ Riot/Model/Room/RoomDataSource.m | 17 +++++++ Riot/ViewController/RoomViewController.m | 25 +++++++++++ .../RoomActivitiesView/RoomActivitiesView.h | 7 +++ .../RoomActivitiesView/RoomActivitiesView.m | 44 +++++++++++++++++++ 5 files changed, 102 insertions(+) diff --git a/Riot/Model/Room/RoomDataSource.h b/Riot/Model/Room/RoomDataSource.h index bed1979e3..dc695ba7c 100644 --- a/Riot/Model/Room/RoomDataSource.h +++ b/Riot/Model/Room/RoomDataSource.h @@ -17,6 +17,8 @@ #import +#import "WidgetManager.h" + /** The data source for `RoomViewController` in Vector. */ @@ -32,4 +34,11 @@ */ @property(nonatomic) BOOL markTimelineInitialEvent; +/** + Check if there is an active jitsi widget in the room and return it. + + @return a widget representating the active jitsi conference in the room. Else, nil. + */ +- (Widget *)jitsiWidget; + @end diff --git a/Riot/Model/Room/RoomDataSource.m b/Riot/Model/Room/RoomDataSource.m index 66b52cfd9..1c548f0ac 100644 --- a/Riot/Model/Room/RoomDataSource.m +++ b/Riot/Model/Room/RoomDataSource.m @@ -390,4 +390,21 @@ _selectedEventId = selectedEventId; } +- (Widget *)jitsiWidget +{ + Widget *jitsiWidget; + + NSArray *widgets = [[WidgetManager sharedManager] widgetsInRoom:self.room]; + for (Widget *widget in widgets) + { + if ([widget.type isEqualToString:kWidgetTypeJitsi]) + { + jitsiWidget = widget; + break; + } + } + + return jitsiWidget; +} + @end diff --git a/Riot/ViewController/RoomViewController.m b/Riot/ViewController/RoomViewController.m index cd1c3fa0e..5d678ca7e 100644 --- a/Riot/ViewController/RoomViewController.m +++ b/Riot/ViewController/RoomViewController.m @@ -47,6 +47,8 @@ #import "ReadReceiptsViewController.h" +#import "JitsiViewController.h" + #import "RoomEmptyBubbleCell.h" #import "RoomIncomingTextMsgBubbleCell.h" @@ -96,6 +98,7 @@ #import "AvatarGenerator.h" #import "Tools.h" +#import "WidgetManager.h" #import "GBDeviceInfo_iOS.h" @@ -3275,6 +3278,8 @@ { [roomActivitiesView removeGestureRecognizer:roomActivitiesView.gestureRecognizers[0]]; } + + Widget *jitsiWidget = [customizedRoomDataSource jitsiWidget]; if ([AppDelegate theDelegate].isOffline) { @@ -3305,6 +3310,26 @@ }]; } } + else if (jitsiWidget) + { + // The room has an active jitsi widget, show it in the banner + [roomActivitiesView displayOngoingJitsiConference:^{ + + // Present the Jitsi view controller + AppDelegate *appDelegate = [AppDelegate theDelegate]; + JitsiViewController *jitsiViewController = [JitsiViewController jitsiViewControllerForWidget:jitsiWidget]; + + if (appDelegate.window.rootViewController.presentedViewController) + { + [appDelegate.window.rootViewController.presentedViewController presentViewController:jitsiViewController animated:YES completion:nil]; + } + else + { + [appDelegate.window.rootViewController presentViewController:jitsiViewController animated:YES completion:nil]; + } + + }]; + } else if ([self checkUnsentMessages] == NO) { // Show "scroll to bottom" icon when the most recent message is not visible, diff --git a/Riot/Views/RoomActivitiesView/RoomActivitiesView.h b/Riot/Views/RoomActivitiesView/RoomActivitiesView.h index de6cff48c..62af57992 100644 --- a/Riot/Views/RoomActivitiesView/RoomActivitiesView.h +++ b/Riot/Views/RoomActivitiesView/RoomActivitiesView.h @@ -66,6 +66,13 @@ */ - (void)displayOngoingConferenceCall:(void (^)(BOOL video))ongoingConferenceCallPressed; +/** + Display an ongoing jitsi conference call. + Replace the current notification if any. + + @param ongoingJitsiConferencePressed the block called when the user clicks on the banner. + */ +- (void)displayOngoingJitsiConference:(void (^)())ongoingJitsiConferencePressed; /** Display a "scroll to bottom" icon. diff --git a/Riot/Views/RoomActivitiesView/RoomActivitiesView.m b/Riot/Views/RoomActivitiesView/RoomActivitiesView.m index 5e5b45566..bab943a14 100644 --- a/Riot/Views/RoomActivitiesView/RoomActivitiesView.m +++ b/Riot/Views/RoomActivitiesView/RoomActivitiesView.m @@ -242,6 +242,50 @@ [self checkHeight:YES]; } +- (void)displayOngoingJitsiConference:(void (^)())ongoingJitsiConferencePressed +{ + [self reset]; + + // @TODO: use dedicated strings + objc_setAssociatedObject(self.messageTextView, "onOngoingConferenceCallPressed", [ongoingJitsiConferencePressed copy], OBJC_ASSOCIATION_RETAIN_NONATOMIC); + + // Build the string to display in the banner + NSString *onGoingConferenceCall = + [NSString stringWithFormat:NSLocalizedStringFromTable(@"room_ongoing_conference_call", @"Vector", nil), + NSLocalizedStringFromTable(@"voice", @"Vector", nil), + NSLocalizedStringFromTable(@"video", @"Vector", nil)]; + + NSMutableAttributedString *onGoingConferenceCallAttibutedString = [[NSMutableAttributedString alloc] initWithString:onGoingConferenceCall]; + + // Add a link on the "voice" string + NSRange voiceRange = [onGoingConferenceCall rangeOfString:NSLocalizedStringFromTable(@"voice", @"Vector", nil)]; + [onGoingConferenceCallAttibutedString addAttribute:NSUnderlineStyleAttributeName value:@(NSUnderlineStyleSingle) range:voiceRange]; + [onGoingConferenceCallAttibutedString addAttribute:NSLinkAttributeName value:@"onOngoingConferenceCallWithVoicePressed" range:voiceRange]; + + // Add a link on the "video" string + NSRange videoRange = [onGoingConferenceCall rangeOfString:NSLocalizedStringFromTable(@"video", @"Vector", nil)]; + [onGoingConferenceCallAttibutedString addAttribute:NSUnderlineStyleAttributeName value:@(NSUnderlineStyleSingle) range:videoRange]; + [onGoingConferenceCallAttibutedString addAttribute:NSLinkAttributeName value:@"onOngoingConferenceCallWithVideoPressed" range:videoRange]; + + // Display the string in white on pink red + NSRange wholeString = NSMakeRange(0, onGoingConferenceCallAttibutedString.length); + [onGoingConferenceCallAttibutedString addAttribute:NSForegroundColorAttributeName value:UIColor.whiteColor range:wholeString]; + [onGoingConferenceCallAttibutedString addAttribute:NSBackgroundColorAttributeName value:kRiotColorPinkRed range:wholeString]; + [onGoingConferenceCallAttibutedString addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:15] range:wholeString]; + + self.messageTextView.attributedText = onGoingConferenceCallAttibutedString; + self.messageTextView.tintColor = UIColor.whiteColor; + self.messageTextView.hidden = NO; + + self.backgroundColor = kRiotColorPinkRed; + self.messageTextView.backgroundColor = kRiotColorPinkRed; + + // Hide the separator to display correctly the red pink conf call banner + self.separatorView.hidden = YES; + + [self checkHeight:YES]; +} + - (void)displayScrollToBottomIcon:(NSUInteger)newMessagesCount onIconTapGesture:(void (^)(void))onIconTapGesture { if (newMessagesCount)