Skip to content

Commit 8568c45

Browse files
committed
Merge branch 'release/0.22.5/master'
2 parents 9f5477e + e012260 commit 8568c45

16 files changed

+161
-36
lines changed

CHANGES.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
## Changes in 0.22.5 (2022-03-08)
2+
3+
🙌 Improvements
4+
5+
- Room data filters: strict matches support ([#1379](https://github.com/matrix-org/matrix-ios-sdk/pull/1379))
6+
- Analytics: Add event composition tracking and isSpace for joined room events. ([#5365](https://github.com/vector-im/element-ios/issues/5365))
7+
- MXEvent+Extensions: Do not highlight any event that the current user sent. ([#5552](https://github.com/vector-im/element-ios/issues/5552))
8+
9+
🐛 Bugfixes
10+
11+
- Room: fix crash on members count not being always properly set ([#4949](https://github.com/vector-im/element-ios/issues/4949))
12+
- MXSuggestedRoomListDataFetcher: hide suggested rooms that a user is already part of ([#5276](https://github.com/vector-im/element-ios/issues/5276))
13+
- MXFileStore: Do not reuse room files if the room is marked for deletion ([#5717](https://github.com/vector-im/element-ios/issues/5717))
14+
15+
116
## Changes in 0.22.4 (2022-02-25)
217

318
🙌 Improvements

MatrixSDK.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Pod::Spec.new do |s|
22

33
s.name = "MatrixSDK"
4-
s.version = "0.22.4"
4+
s.version = "0.22.5"
55
s.summary = "The iOS SDK to build apps compatible with Matrix (https://www.matrix.org)"
66

77
s.description = <<-DESC

MatrixSDK.xcodeproj/xcshareddata/IDETemplateMacros.plist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<dict>
55
<key>FILEHEADER</key>
66
<string>
7-
// Copyright 2021 The Matrix.org Foundation C.I.C
7+
// Copyright ___YEAR___ The Matrix.org Foundation C.I.C
88
//
99
// Licensed under the Apache License, Version 2.0 (the "License");
1010
// you may not use this file except in compliance with the License.

MatrixSDK/Categories/MXEvent+Extensions.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@ public extension MXEvent {
2323
/// - Parameter session: session instance to read notification rules from
2424
/// - Returns: true if clients should highlight the receiver event
2525
func shouldBeHighlighted(inSession session: MXSession) -> Bool {
26+
if sender == session.myUserId {
27+
// do not highlight any event that the current user sent
28+
return false
29+
}
30+
2631
let displayNameChecker = MXPushRuleDisplayNameCondtionChecker(matrixSession: session,
2732
currentUserDisplayName: nil)
2833

MatrixSDK/Data/MXRoom.m

Lines changed: 50 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -782,37 +782,66 @@ - (MXHTTPOperation*)_sendEventOfType:(MXEventTypeString)eventTypeString
782782
failure:(void (^)(NSError *error))failure
783783
{
784784
NSDictionary *newContent = content;
785-
if (threadId && MXSDKOptions.sharedInstance.enableThreads)
785+
BOOL inThread = NO;
786+
BOOL startsThread = NO;
787+
BOOL isReply = content[kMXEventRelationRelatesToKey][@"m.in_reply_to"][@"event_id"] != nil;
788+
BOOL isEditing = [content[kMXEventRelationRelatesToKey][@"rel_type"] isEqualToString:MXEventRelationTypeReplace];
789+
if (MXSDKOptions.sharedInstance.enableThreads)
786790
{
787-
NSMutableDictionary *mutableContent = [newContent mutableDeepCopy];
788-
BOOL isRealReply = content[kMXEventRelationRelatesToKey][@"m.in_reply_to"][@"event_id"] != nil;
789-
if (isRealReply)
791+
if (threadId)
790792
{
791-
mutableContent[kMXEventRelationRelatesToKey][@"m.in_reply_to"][@"m.render_in"] = @[MXEventRelationTypeThread];
792-
}
793-
else
794-
{
795-
NSString *lastEventId = [mxSession.threadingService threadWithId:threadId].lastMessage.eventId;
796-
NSString *replyToEventId = lastEventId ?: threadId;
797-
798-
if (mutableContent[kMXEventRelationRelatesToKey])
793+
inThread = YES;
794+
NSMutableDictionary *mutableContent = [newContent mutableDeepCopy];
795+
if (isReply)
799796
{
800-
mutableContent[kMXEventRelationRelatesToKey][@"m.in_reply_to"] = @{
801-
@"event_id": replyToEventId
802-
};
797+
// this will be a real in-thread reply
798+
mutableContent[kMXEventRelationRelatesToKey][@"m.in_reply_to"][@"m.render_in"] = @[MXEventRelationTypeThread];
803799
}
804800
else
805801
{
806-
mutableContent[kMXEventRelationRelatesToKey] = @{
807-
@"m.in_reply_to": @{
802+
// this will look like a reply, but only an in-thread event
803+
NSString *lastEventId = [mxSession.threadingService threadWithId:threadId].lastMessage.eventId;
804+
startsThread = lastEventId == nil;
805+
NSString *replyToEventId = lastEventId ?: threadId;
806+
807+
if (mutableContent[kMXEventRelationRelatesToKey])
808+
{
809+
mutableContent[kMXEventRelationRelatesToKey][@"m.in_reply_to"] = @{
810+
@"event_id": replyToEventId
811+
};
812+
}
813+
else
814+
{
815+
mutableContent[kMXEventRelationRelatesToKey] = @{
816+
@"m.in_reply_to": @{
808817
@"event_id": replyToEventId
809-
}
810-
};
818+
}
819+
};
820+
}
811821
}
822+
newContent = mutableContent;
823+
}
824+
else if (isEditing)
825+
{
826+
// detect in-thread edits
827+
NSString *editedEventId = content[kMXEventRelationRelatesToKey][@"event_id"];
828+
MXEvent *editedEvent = [self.mxSession.store eventWithEventId:editedEventId inRoom:self.roomId];
829+
inThread = editedEvent.isInThread;
812830
}
813-
newContent = mutableContent;
814831
}
815-
return [mxSession.matrixRestClient sendEventToRoom:self.roomId threadId:threadId eventType:eventTypeString content:newContent txnId:txnId success:success failure:failure];
832+
return [mxSession.matrixRestClient sendEventToRoom:self.roomId threadId:threadId eventType:eventTypeString content:newContent txnId:txnId success:^(NSString *eventId) {
833+
834+
// track event composed
835+
[MXSDKOptions.sharedInstance.analyticsDelegate trackComposerEventInThread:inThread
836+
isEditing:isEditing
837+
isReply:isReply
838+
startsThread:startsThread];
839+
840+
if (success)
841+
{
842+
success(eventId);
843+
}
844+
} failure:failure];
816845
}
817846

818847
- (MXHTTPOperation*)sendStateEventOfType:(MXEventTypeString)eventTypeString

MatrixSDK/Data/MXRoomState.m

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,9 @@ - (id)initWithRoomId:(NSString*)roomId
7777

7878
stateEvents = [NSMutableDictionary dictionary];
7979
_members = [[MXRoomMembers alloc] initWithRoomState:self andMatrixSession:mxSession];
80-
_membersCount = [MXRoomMembersCount new];
80+
_membersCount = [[MXRoomMembersCount alloc] initWithMembers:_members.members.count
81+
joined:_members.joinedMembers.count
82+
invited:[_members membersWithMembership:MXMembershipInvite].count];
8183
roomAliases = [NSMutableDictionary dictionary];
8284
thirdPartyInvites = [NSMutableDictionary dictionary];
8385
membersWithThirdPartyInviteTokenCache = [NSMutableDictionary dictionary];

MatrixSDK/Data/RoomList/Common/MXRoomListDataFilterable.swift

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,20 @@ extension MXRoomListDataFilterable {
5757
MXMembership.unknown.rawValue)
5858
predicates.append(memberPredicate)
5959
}
60-
60+
6161
if !filterOptions.dataTypes.isEmpty {
62-
let predicate = NSPredicate(format: "(%K & %d) != 0",
62+
let predicate: NSPredicate
63+
if filterOptions.strictMatches {
64+
predicate = NSPredicate(format: "(%K & %d) == %d",
65+
#keyPath(MXRoomSummaryProtocol.dataTypes),
66+
filterOptions.dataTypes.rawValue,
67+
filterOptions.dataTypes.rawValue)
68+
69+
} else {
70+
predicate = NSPredicate(format: "(%K & %d) != 0",
6371
#keyPath(MXRoomSummaryProtocol.dataTypes),
6472
filterOptions.dataTypes.rawValue)
73+
}
6574
predicates.append(predicate)
6675
}
6776

MatrixSDK/Data/RoomList/Common/MXSuggestedRoomListDataFetcher.swift

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,12 @@ import Foundation
2020
internal class MXSuggestedRoomListDataFetcher: NSObject, MXRoomListDataFetcher {
2121

2222
internal let fetchOptions: MXRoomListDataFetchOptions
23+
private weak var session: MXSession?
2324
private let spaceService: MXSpaceService
2425
private let cache: MXSuggestedRoomListDataCache
2526

27+
private var allRoomSummaries: [MXRoomSummaryProtocol] = []
28+
2629
private let multicastDelegate: MXMulticastDelegate<MXRoomListDataFetcherDelegate> = MXMulticastDelegate()
2730
private var space: MXSpace? {
2831
didSet {
@@ -34,6 +37,7 @@ internal class MXSuggestedRoomListDataFetcher: NSObject, MXRoomListDataFetcher {
3437
}
3538
private var spaceEventsListener: Any?
3639
private var currentHttpOperation: MXHTTPOperation?
40+
private var sessionDidSyncObserver: Any?
3741

3842
internal private(set) var data: MXRoomListData? {
3943
didSet {
@@ -48,9 +52,11 @@ internal class MXSuggestedRoomListDataFetcher: NSObject, MXRoomListDataFetcher {
4852
}
4953

5054
internal init(fetchOptions: MXRoomListDataFetchOptions,
55+
session: MXSession,
5156
spaceService: MXSpaceService,
5257
cache: MXSuggestedRoomListDataCache = .shared) {
5358
self.fetchOptions = fetchOptions
59+
self.session = session
5460
self.spaceService = spaceService
5561
self.cache = cache
5662
self.space = fetchOptions.filterOptions.space
@@ -88,10 +94,16 @@ internal class MXSuggestedRoomListDataFetcher: NSObject, MXRoomListDataFetcher {
8894
}
8995
self.refresh()
9096
})
97+
sessionDidSyncObserver = NotificationCenter.default.addObserver(forName: .mxSessionDidSync, object: nil, queue: OperationQueue.main) { [weak self] notification in
98+
self?.updateData()
99+
}
91100
}
92101

93102
private func removeDataObservers(for space: MXSpace?) {
94103
space?.room?.removeListener(spaceEventsListener)
104+
if let observer = sessionDidSyncObserver {
105+
NotificationCenter.default.removeObserver(observer)
106+
}
95107
}
96108

97109
internal func paginate() {
@@ -201,12 +213,24 @@ internal class MXSuggestedRoomListDataFetcher: NSObject, MXRoomListDataFetcher {
201213

202214
private func computeData(from childInfos: [MXSpaceChildInfo]) {
203215
// create room summary objects
204-
var rooms: [MXRoomSummaryProtocol] = childInfos.map({ MXRoomSummary(spaceChildInfo: $0) })
216+
var rooms: [MXRoomSummaryProtocol] = childInfos.compactMap({ MXRoomSummary(spaceChildInfo: $0) })
205217
rooms = filterRooms(rooms)
206218
rooms = sortRooms(rooms)
219+
allRoomSummaries = rooms
220+
updateData()
221+
}
222+
223+
private func updateData() {
224+
let summaries = allRoomSummaries.filter { summary in
225+
guard let room = self.session?.room(withRoomId: summary.roomId), let localsummary = room.summary else {
226+
return true
227+
}
228+
return localsummary.membership != .join && localsummary.membership != .invite && localsummary.membership != .ban
229+
}
230+
207231
// we don't know total rooms count, passing as current number of rooms
208-
self.data = MXRoomListData(rooms: rooms,
209-
counts: MXStoreRoomListDataCounts(withRooms: rooms,
232+
self.data = MXRoomListData(rooms: summaries,
233+
counts: MXStoreRoomListDataCounts(withRooms: summaries,
210234
total: nil),
211235
paginationOptions: fetchOptions.paginationOptions)
212236
}

MatrixSDK/Data/RoomList/CoreData/MXCoreDataRoomListDataFetcher.swift

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,9 +306,18 @@ extension MXCoreDataRoomListDataFetcher: MXRoomListDataFilterable {
306306

307307
// data types
308308
if !filterOptions.dataTypes.isEmpty {
309-
let predicate = NSPredicate(format: "(%K & %d) != 0",
309+
let predicate: NSPredicate
310+
if filterOptions.strictMatches {
311+
predicate = NSPredicate(format: "(%K & %d) == %d",
310312
#keyPath(MXRoomSummaryMO.s_dataTypesInt),
313+
filterOptions.dataTypes.rawValue,
311314
filterOptions.dataTypes.rawValue)
315+
316+
} else {
317+
predicate = NSPredicate(format: "(%K & %d) != 0",
318+
#keyPath(MXRoomSummaryMO.s_dataTypesInt),
319+
filterOptions.dataTypes.rawValue)
320+
}
312321
predicates.append(predicate)
313322
}
314323

MatrixSDK/Data/RoomList/CoreData/MXCoreDataRoomListDataManager.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,11 @@ public class MXCoreDataRoomListDataManager: NSObject, MXRoomListDataManager {
2929
assert(options.async, "[MXCoreDataRoomListDataManager] cannot work with sync fetch options")
3030

3131
if options.filterOptions.onlySuggested {
32-
guard let spaceService = session?.spaceService else {
32+
guard let session = session, let spaceService = session.spaceService else {
3333
fatalError("[MXCoreDataRoomListDataManager] Session has no spaceService")
3434
}
3535
return MXSuggestedRoomListDataFetcher(fetchOptions: options,
36+
session: session,
3637
spaceService: spaceService)
3738
}
3839
guard let session = session, let store = session.store else {

0 commit comments

Comments
 (0)