Skip to content

Commit 77c5a62

Browse files
Merge pull request #1421 from matrix-org/steve/5903_lls_start
[Location sharing] Live location sharing start event
2 parents ece2e8f + 4e8c95b commit 77c5a62

32 files changed

+972
-18
lines changed

MatrixSDK.xcodeproj/project.pbxproj

Lines changed: 58 additions & 0 deletions
Large diffs are not rendered by default.

MatrixSDK/Contrib/Swift/JSONModels/MXEvent.swift

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ public enum MXEventType: Equatable, Hashable {
7878
case pollStart
7979
case pollResponse
8080
case pollEnd
81+
82+
case beaconInfo
8183

8284
case custom(String)
8385

@@ -132,7 +134,8 @@ public enum MXEventType: Equatable, Hashable {
132134
case .pollStart: return kMXEventTypeStringPollStartMSC3381
133135
case .pollResponse: return kMXEventTypeStringPollResponseMSC3381
134136
case .pollEnd: return kMXEventTypeStringPollEndMSC3381
135-
137+
case .beaconInfo: return kMXEventTypeStringBeaconInfoMSC3672
138+
136139
// Swift converts any constant with the suffix "Notification" as the type `Notification.Name`
137140
// The original value can be reached using the `rawValue` property.
138141
case .typing: return NSNotification.Name.mxEventTypeStringTyping.rawValue
@@ -142,7 +145,7 @@ public enum MXEventType: Equatable, Hashable {
142145
}
143146

144147
public init(identifier: String) {
145-
let events: [MXEventType] = [.roomName, .roomTopic, .roomAvatar, .roomMember, .roomCreate, .roomJoinRules, .roomPowerLevels, .roomAliases, .roomCanonicalAlias, .roomEncrypted, .roomEncryption, .roomGuestAccess, .roomHistoryVisibility, .roomKey, .roomForwardedKey, .roomKeyRequest, .roomMessage, .roomMessageFeedback, .roomRedaction, .roomThirdPartyInvite, .roomTag, .presence, .typing, .callInvite, .callCandidates, .callAnswer, .callSelectAnswer, .callHangup, .callReject, .callNegotiate, .callReplaces, .callRejectReplacement, .callAssertedIdentity, .callAssertedIdentityUnstable, .reaction, .receipt, .roomTombStone, .keyVerificationStart, .keyVerificationAccept, .keyVerificationKey, .keyVerificationMac, .keyVerificationCancel, .keyVerificationDone, .taggedEvents, .spaceChild, .spaceOrder, .pollStart, .pollResponse, .pollEnd]
148+
let events: [MXEventType] = [.roomName, .roomTopic, .roomAvatar, .roomMember, .roomCreate, .roomJoinRules, .roomPowerLevels, .roomAliases, .roomCanonicalAlias, .roomEncrypted, .roomEncryption, .roomGuestAccess, .roomHistoryVisibility, .roomKey, .roomForwardedKey, .roomKeyRequest, .roomMessage, .roomMessageFeedback, .roomRedaction, .roomThirdPartyInvite, .roomTag, .presence, .typing, .callInvite, .callCandidates, .callAnswer, .callSelectAnswer, .callHangup, .callReject, .callNegotiate, .callReplaces, .callRejectReplacement, .callAssertedIdentity, .callAssertedIdentityUnstable, .reaction, .receipt, .roomTombStone, .keyVerificationStart, .keyVerificationAccept, .keyVerificationKey, .keyVerificationMac, .keyVerificationCancel, .keyVerificationDone, .taggedEvents, .spaceChild, .spaceOrder, .pollStart, .pollResponse, .pollEnd, .beaconInfo]
146149

147150
if let type = events.first(where: { $0.identifier == identifier }) {
148151
self = type

MatrixSDK/Data/MXRoomState.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#import "MXStore.h"
2828
#import "MXRoomTombStoneContent.h"
2929
#import "MXRoomCreateContent.h"
30+
#import "MXBeaconInfo.h"
3031

3132
@class MXSession;
3233

@@ -172,6 +173,9 @@ Use MXRoomSummary.displayname to get a computed room display name.
172173
*/
173174
@property (nonatomic, strong, readonly) MXRoomTombStoneContent *tombStoneContent;
174175

176+
/// Beacon info events
177+
@property (nonatomic, readonly) NSArray<MXBeaconInfo*> *beaconInfos;
178+
175179
/**
176180
Create a `MXRoomState` instance.
177181

MatrixSDK/Data/MXRoomState.m

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,25 @@ - (MXRoomTombStoneContent*)tombStoneContent
399399
return roomTombStoneContent;
400400
}
401401

402+
- (NSArray<MXBeaconInfo*>*)beaconInfoEvents
403+
{
404+
NSMutableArray *beaconInfoEvents = [NSMutableArray new];
405+
406+
NSArray *stateEvents = [self stateEventsWithType:kMXEventTypeStringBeaconInfoMSC3672];
407+
408+
for (MXEvent *event in stateEvents)
409+
{
410+
MXBeaconInfo *beaconInfo = [[MXBeaconInfo alloc] initWithMXEvent:event];
411+
412+
if (beaconInfo)
413+
{
414+
[beaconInfoEvents addObject:beaconInfo];
415+
}
416+
}
417+
418+
return beaconInfoEvents;
419+
}
420+
402421
#pragma mark - State events handling
403422
- (void)handleStateEvents:(NSArray<MXEvent *> *)events;
404423
{

MatrixSDK/Data/MXRoomSummary.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,9 @@ FOUNDATION_EXPORT NSUInteger const MXRoomSummaryPaginationChunkSize;
345345
*/
346346
@property (nonatomic) NSSet<NSString*> *parentSpaceIds;
347347

348+
/// User ids of users sharing active beacon in the room
349+
@property (nonatomic) NSSet<NSString*> *userIdsSharingLiveBeacon;
350+
348351
/**
349352
Mark all messages as read.
350353
*/

MatrixSDK/Data/MXRoomSummary.m

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,7 @@ - (void)updateWith:(id<MXRoomSummaryProtocol>)summary
251251
_dataTypes = summary.dataTypes;
252252
_sentStatus = summary.sentStatus;
253253
_parentSpaceIds = summary.parentSpaceIds;
254+
_userIdsSharingLiveBeacon = summary.userIdsSharingLiveBeacon;
254255

255256
if (!_others)
256257
{
@@ -968,6 +969,7 @@ - (instancetype)initWithCoder:(NSCoder *)aDecoder
968969
_sentStatus = (MXRoomSummarySentStatus)[aDecoder decodeIntegerForKey:@"sentStatus"];
969970
_favoriteTagOrder = [aDecoder decodeObjectForKey:@"favoriteTagOrder"];
970971
_parentSpaceIds = [aDecoder decodeObjectForKey:@"parentSpaceIds"];
972+
_userIdsSharingLiveBeacon = [aDecoder decodeObjectForKey:@"userIdsSharingLiveBeacon"];
971973

972974
// Compute the trust if asked to do it automatically
973975
// or maintain its computation it has been already calcutated
@@ -1022,6 +1024,7 @@ - (void)encodeWithCoder:(NSCoder *)aCoder
10221024
[aCoder encodeInteger:_sentStatus forKey:@"sentStatus"];
10231025
[aCoder encodeObject:_favoriteTagOrder forKey:@"favoriteTagOrder"];
10241026
[aCoder encodeObject:_parentSpaceIds forKey:@"parentSpaceIds"];
1027+
[aCoder encodeObject:_userIdsSharingLiveBeacon forKey:@"userIdsSharingLiveBeacon"];
10251028
}
10261029

10271030
- (NSString *)description

MatrixSDK/Data/MXRoomSummaryProtocol.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,9 @@ NS_ASSUME_NONNULL_BEGIN
143143
/// Parent space identifiers of whom the room is a descendant
144144
@property (nonatomic, readonly) NSSet<NSString*> *parentSpaceIds;
145145

146+
/// User ids of users sharing active beacon in the room
147+
@property (nonatomic, readonly) NSSet<NSString*> *userIdsSharingLiveBeacon;
148+
146149
#pragma mark - Optional
147150

148151
@optional

MatrixSDK/Data/MXRoomSummaryUpdater.m

Lines changed: 54 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#import "MXRoom.h"
2424
#import "MXSession.h"
2525
#import "MXRoomNameDefaultStringLocalizer.h"
26+
#import "MXBeaconInfo.h"
2627

2728
#import "NSArray+MatrixSDK.h"
2829

@@ -144,7 +145,9 @@ - (BOOL)session:(MXSession *)session updateRoomSummary:(MXRoomSummary *)summary
144145
{
145146
BOOL hasRoomMembersChange = NO;
146147
BOOL updated = NO;
147-
148+
149+
NSMutableSet<NSString*>* userIdsSharingLiveBeacon = [summary.userIdsSharingLiveBeacon mutableCopy] ?: [NSMutableSet new] ;
150+
148151
for (MXEvent *event in stateEvents)
149152
{
150153
switch (event.eventType)
@@ -236,13 +239,25 @@ - (BOOL)session:(MXSession *)session updateRoomSummary:(MXRoomSummary *)summary
236239
updated = YES;
237240
[self checkRoomCreateStateEventPredecessorAndUpdateObsoleteRoomSummaryIfNeededWithCreateContent:createContent summary:summary session:session roomState:roomState];
238241
[self checkRoomIsVirtualWithCreateEvent:event summary:summary session:session];
242+
243+
break;
239244
}
245+
246+
case MXEventTypeBeaconInfo:
247+
{
248+
[self updateUserIdsSharingLiveBeacon:userIdsSharingLiveBeacon withStateEvent:event];
240249
break;
241-
250+
}
242251
default:
243252
break;
244253
}
245254
}
255+
256+
if (![userIdsSharingLiveBeacon isEqualToSet:summary.userIdsSharingLiveBeacon])
257+
{
258+
summary.userIdsSharingLiveBeacon = userIdsSharingLiveBeacon;
259+
updated = YES;
260+
}
246261

247262
if (hasRoomMembersChange)
248263
{
@@ -793,4 +808,41 @@ - (BOOL)isMembershipEventAllowedAsLastMessage:(MXEvent*)event forUserId:(NSStrin
793808
return [self isMembershipEventJoinOrInvite:event forUserId:userId];
794809
}
795810

811+
#pragma mark Beacon info
812+
813+
- (BOOL)updateUserIdsSharingLiveBeacon:(NSMutableSet<NSString*>*)userIdsSharingLiveBeacon withStateEvent:(MXEvent*)stateEvent
814+
{
815+
MXBeaconInfo *beaconInfo = [[MXBeaconInfo alloc] initWithMXEvent:stateEvent];
816+
817+
NSString *userId = beaconInfo.userId;
818+
819+
if (!beaconInfo || !userId)
820+
{
821+
return NO;
822+
}
823+
824+
BOOL updated = NO;
825+
826+
BOOL isUserExist = [userIdsSharingLiveBeacon containsObject:userId];
827+
828+
if (beaconInfo.isLive)
829+
{
830+
if (!isUserExist)
831+
{
832+
[userIdsSharingLiveBeacon addObject:userId];
833+
updated = YES;
834+
}
835+
}
836+
else
837+
{
838+
if (isUserExist)
839+
{
840+
[userIdsSharingLiveBeacon removeObject:userId];
841+
updated = YES;
842+
}
843+
}
844+
845+
return updated;
846+
}
847+
796848
@end

MatrixSDK/Data/RoomList/CoreData/MXCoreDataRoomListDataFetcher.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,8 @@ private class RoomSummaryForTotalCounts: NSObject, MXRoomSummaryProtocol {
447447
var sentStatus: MXRoomSummarySentStatus
448448
var spaceChildInfo: MXSpaceChildInfo?
449449
var parentSpaceIds: Set<String> = []
450-
450+
var userIdsSharingLiveBeacon: Set<String> = []
451+
451452
/// Initializer with a dictionary obtained by a fetch request, with result type `.dictionaryResultType`. Only parses some properties.
452453
/// - Parameter dictionary: Dictionary object representing an `MXRoomSummaryMO` instance
453454
init(withDictionary dictionary: [String: Any]) {

MatrixSDK/Data/RoomSummaryStore/CoreData/MXCoreDataRoomSummaryStore.swift

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,17 @@ public class MXCoreDataRoomSummaryStore: NSObject {
3030

3131
private lazy var persistenceCoordinator: NSPersistentStoreCoordinator = {
3232
let result = NSPersistentStoreCoordinator(managedObjectModel: Self.managedObjectModel)
33+
34+
let options: [AnyHashable : Any] = [
35+
NSMigratePersistentStoresAutomaticallyOption: true,
36+
NSInferMappingModelAutomaticallyOption: true
37+
]
38+
3339
do {
3440
try result.addPersistentStore(ofType: NSSQLiteStoreType,
3541
configurationName: nil,
3642
at: storeURL,
37-
options: nil)
43+
options: options)
3844
} catch {
3945
fatalError(error.localizedDescription)
4046
}

0 commit comments

Comments
 (0)