Skip to content

Commit e1f8d7b

Browse files
Merge pull request #5928 from vector-im/steve/5903_lls_start
Location sharing: Support live location sharing start
2 parents 139316c + 446ca59 commit e1f8d7b

File tree

12 files changed

+213
-66
lines changed

12 files changed

+213
-66
lines changed

Riot/Modules/Common/Recents/Service/Mock/MockRoomSummary.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,10 @@ public class MockRoomSummary: NSObject, MXRoomSummaryProtocol {
9494

9595
public var parentSpaceIds: Set<String> = []
9696

97+
public var beaconInfoEvents: [MXBeaconInfo] = []
98+
99+
public var userIdsSharingLiveBeacon: Set<String> = []
100+
97101
public init(withRoomId roomId: String) {
98102
self.roomId = roomId
99103
super.init()

Riot/Modules/Room/DataSources/RoomDataSource.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@
6666
*/
6767
@property (nonatomic, nullable) NSString *highlightedEventId;
6868

69+
/// Is current user sharing is location in the room
70+
@property(nonatomic, readonly) BOOL isCurrentUserSharingIsLocation;
71+
6972
/**
7073
Check if there is an active jitsi widget in the room and return it.
7174
@@ -132,4 +135,7 @@
132135
- (void)roomDataSource:(RoomDataSource * _Nonnull)roomDataSource
133136
didTapThread:(id<MXThreadProtocol> _Nonnull)thread;
134137

138+
/// Called when current live location sharing status is changing (start or stop location sharing in the room)
139+
- (void)roomDataSourceDidUpdateCurrentUserSharingLocationStatus:(RoomDataSource * _Nonnull)roomDataSource;
140+
135141
@end

Riot/Modules/Room/DataSources/RoomDataSource.m

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ @interface RoomDataSource() <RoomReactionsViewModelDelegate, URLPreviewViewDeleg
5656

5757
@property (nonatomic) NSInteger typingCellIndex;
5858

59+
@property(nonatomic, readwrite) BOOL isCurrentUserSharingIsLocation;
60+
5961
@end
6062

6163
@implementation RoomDataSource
@@ -131,6 +133,8 @@ - (void)finalizeInitialization
131133
}
132134

133135
self.showTypingRow = YES;
136+
137+
[self updateCurrentUserLocationSharingStatus];
134138
}
135139

136140
- (id<RoomDataSourceDelegate>)roomDataSourceDelegate
@@ -225,6 +229,11 @@ - (void)registerTrustLevelDidChangeNotifications
225229

226230
- (void)roomSummaryDidChange:(NSNotification*)notification
227231
{
232+
if (BuildSettings.liveLocationSharingEnabled)
233+
{
234+
[self updateCurrentUserLocationSharingStatus];
235+
}
236+
228237
if (!self.room.summary.isEncrypted)
229238
{
230239
return;
@@ -1137,4 +1146,27 @@ - (void)threadSummaryViewTapped:(ThreadSummaryView *)summaryView
11371146
didTapThread:summaryView.thread];
11381147
}
11391148

1149+
#pragma mark - Location sharing
1150+
1151+
- (void)updateCurrentUserLocationSharingStatus
1152+
{
1153+
MXLocationService *locationService = self.mxSession.locationService;
1154+
1155+
if (!locationService || !self.roomId)
1156+
{
1157+
return;
1158+
}
1159+
1160+
BOOL isUserSharingIsLocation = [locationService isCurrentUserSharingIsLocationInRoomWithId:self.roomId];
1161+
1162+
if (isUserSharingIsLocation != self.isCurrentUserSharingIsLocation)
1163+
{
1164+
self.isCurrentUserSharingIsLocation = [locationService isCurrentUserSharingIsLocationInRoomWithId:self.roomId];
1165+
1166+
dispatch_async(dispatch_get_main_queue(), ^{
1167+
[self.roomDataSourceDelegate roomDataSourceDidUpdateCurrentUserSharingLocationStatus:self];
1168+
});
1169+
}
1170+
}
1171+
11401172
@end
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
//
2+
// Copyright 2022 New Vector Ltd
3+
//
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
//
8+
// http://www.apache.org/licenses/LICENSE-2.0
9+
//
10+
// Unless required by applicable law or agreed to in writing, software
11+
// distributed under the License is distributed on an "AS IS" BASIS,
12+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
// See the License for the specific language governing permissions and
14+
// limitations under the License.
15+
//
16+
17+
import Foundation
18+
19+
/// RoomViewController live location sharing handling
20+
@objc extension RoomViewController {
21+
22+
func updateLiveLocationBannerViewVisibility() {
23+
if self.shouldShowLiveLocationSharingBannerView {
24+
self.showLiveLocationBannerView()
25+
} else {
26+
self.hideLiveLocationBannerView()
27+
}
28+
}
29+
30+
func hideLiveLocationBannerView() {
31+
self.liveLocationSharingBannerView?.removeFromSuperview()
32+
}
33+
34+
func showLiveLocationBannerView() {
35+
guard liveLocationSharingBannerView == nil else {
36+
return
37+
}
38+
39+
let bannerView = LiveLocationSharingBannerView.instantiate()
40+
41+
bannerView.update(theme: ThemeService.shared().theme)
42+
43+
bannerView.didTapBackground = { [weak self] in
44+
guard let self = self else {
45+
return
46+
}
47+
48+
self.delegate?.roomViewControllerDidTapLiveLocationSharingBanner(self)
49+
}
50+
51+
bannerView.didTapStopButton = { [weak self] in
52+
53+
guard let self = self else {
54+
return
55+
}
56+
self.delegate?.roomViewControllerDidStopLiveLocationSharing(self)
57+
}
58+
59+
self.topBannersStackView?.addArrangedSubview(bannerView)
60+
61+
self.liveLocationSharingBannerView = bannerView
62+
}
63+
}

Riot/Modules/Room/RoomViewController.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
@protocol RoomViewControllerDelegate;
3333
@class RoomDisplayConfiguration;
3434
@class ThreadsCoordinatorBridgePresenter;
35+
@class LiveLocationSharingBannerView;
3536

3637
NS_ASSUME_NONNULL_BEGIN
3738

@@ -92,6 +93,15 @@ extern NSNotificationName const RoomGroupCallTileTappedNotification;
9293

9394
@property (nonatomic, getter=isContextPreview) BOOL contextPeview;
9495

96+
/// Handles all banners that should be displayed at the top of the timeline but that should not scroll with the timeline
97+
@property (weak, nonatomic, nullable) IBOutlet UIStackView *topBannersStackView;
98+
99+
/// Indicate YES to show live location sharing banner
100+
@property (nonatomic, readonly) BOOL shouldShowLiveLocationSharingBannerView;
101+
102+
/// Displayed live location sharing banner if any
103+
@property (nonatomic, weak) LiveLocationSharingBannerView *liveLocationSharingBannerView;
104+
95105
/**
96106
Display the preview of a room that is unknown for the user.
97107

Riot/Modules/Room/RoomViewController.m

Lines changed: 17 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -232,13 +232,6 @@ @interface RoomViewController () <UISearchBarDelegate, UIGestureRecognizerDelega
232232
// scroll state just before the layout change, and restore it after the layout.
233233
@property (nonatomic) BOOL wasScrollAtBottomBeforeLayout;
234234

235-
/// Handles all banners that should be displayed at the top of the timeline but that should not scroll with the timeline
236-
@property (weak, nonatomic, nullable) IBOutlet UIStackView *topBannersStackView;
237-
238-
@property (nonatomic) BOOL shouldShowLiveLocationSharingBannerView;
239-
240-
@property (nonatomic, weak) LiveLocationSharingBannerView *liveLocationSharingBannerView;
241-
242235
@end
243236

244237
@implementation RoomViewController
@@ -410,6 +403,8 @@ - (void)viewDidLoad
410403
[self setupActions];
411404

412405
[self setupUserSuggestionViewIfNeeded];
406+
407+
[self.topBannersStackView vc_removeAllSubviews];
413408
}
414409

415410
- (void)userInterfaceThemeDidChange
@@ -549,6 +544,8 @@ - (void)viewWillAppear:(BOOL)animated
549544

550545
notificationTaskProfile = [MXSDKOptions.sharedInstance.profiler startMeasuringTaskWithName:MXTaskProfileNameNotificationsOpenEvent];
551546
}
547+
548+
[self updateTopBanners];
552549
}
553550

554551
- (void)viewWillDisappear:(BOOL)animated
@@ -1055,6 +1052,8 @@ - (void)displayRoom:(MXKRoomDataSource *)dataSource
10551052
_userSuggestionCoordinator.delegate = self;
10561053

10571054
[self setupUserSuggestionViewIfNeeded];
1055+
1056+
[self updateTopBanners];
10581057
}
10591058

10601059
- (void)onRoomDataSourceReady
@@ -1525,6 +1524,11 @@ - (void)setMissedDiscussionsBadgeHidden:(BOOL)missedDiscussionsBadgeHidden{
15251524
missedDiscussionsDotView.hidden = missedDiscussionsBadgeHidden;
15261525
}
15271526

1527+
- (BOOL)shouldShowLiveLocationSharingBannerView
1528+
{
1529+
return customizedRoomDataSource.isCurrentUserSharingIsLocation;
1530+
}
1531+
15281532
#pragma mark - Internals
15291533

15301534
- (UIBarButtonItem *)videoCallBarButtonItem
@@ -2423,12 +2427,7 @@ - (void)updateTopBanners
24232427
{
24242428
[self.view bringSubviewToFront:self.topBannersStackView];
24252429

2426-
[self.topBannersStackView vc_removeAllSubviews];
2427-
2428-
if (self.shouldShowLiveLocationSharingBannerView)
2429-
{
2430-
[self showLiveLocationBannerView];
2431-
}
2430+
[self updateLiveLocationBannerViewVisibility];
24322431
}
24332432

24342433
#pragma mark - Jitsi
@@ -4419,6 +4418,11 @@ - (void)roomDataSource:(RoomDataSource *)roomDataSource didTapThread:(id<MXThrea
44194418
[Analytics.shared trackInteraction:AnalyticsUIElementRoomThreadSummaryItem];
44204419
}
44214420

4421+
- (void)roomDataSourceDidUpdateCurrentUserSharingLocationStatus:(RoomDataSource *)roomDataSource
4422+
{
4423+
[self updateLiveLocationBannerViewVisibility];
4424+
}
4425+
44224426
#pragma mark - Segues
44234427

44244428
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
@@ -7484,34 +7488,4 @@ - (void)roomParticipantsInviteCoordinatorBridgePresenterDidEndLoading:(RoomParti
74847488
[self stopActivityIndicator];
74857489
}
74867490

7487-
#pragma mark - Live location sharing
7488-
7489-
- (void)showLiveLocationBannerView
7490-
{
7491-
if (self.liveLocationSharingBannerView)
7492-
{
7493-
return;
7494-
}
7495-
7496-
LiveLocationSharingBannerView *bannerView = [LiveLocationSharingBannerView instantiate];
7497-
7498-
[bannerView updateWithTheme:ThemeService.shared.theme];
7499-
7500-
MXWeakify(self);
7501-
7502-
bannerView.didTapBackground = ^{
7503-
MXStrongifyAndReturnIfNil(self);
7504-
[self.delegate roomViewControllerDidTapLiveLocationSharingBanner:self];
7505-
};
7506-
7507-
bannerView.didTapStopButton = ^{
7508-
MXStrongifyAndReturnIfNil(self);
7509-
[self.delegate roomViewControllerDidStopLiveLocationSharing:self];
7510-
};
7511-
7512-
[self.topBannersStackView addArrangedSubview:bannerView];
7513-
7514-
self.liveLocationSharingBannerView = bannerView;
7515-
}
7516-
75177491
@end

0 commit comments

Comments
 (0)