Skip to content

Commit

Permalink
Merge branch 'release/0.19.8/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
SBiOSoftWhare committed Aug 26, 2021
2 parents 0f358da + ce6dbf7 commit d632e09
Show file tree
Hide file tree
Showing 20 changed files with 605 additions and 202 deletions.
12 changes: 12 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
## Changes in 0.19.8 (2021-08-26)

✨ Features

- MxNotificationCenter: For new account notification settings and keywords support, added updatePushRuleActions and addContentRuleWithMatchingRuleIdAndPattern. Also fixed the url encoding on ruleId. ([#4467](https://github.com/vector-im/element-ios/issues/4467))

🙌 Improvements

- MXSession: Introduce `MXSessionStateProcessingLocalCache` state. Merge local cached sync responses when resuming the session. ([#4471](https://github.com/vector-im/element-ios/issues/4471))
- MXRoom: Added extensible keys to sent file payloads. ([#4720](https://github.com/vector-im/element-ios/issues/4720))


## Changes in 0.19.7 (2021-08-11)

🙌 Improvements
Expand Down
2 changes: 1 addition & 1 deletion MatrixSDK.podspec
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Pod::Spec.new do |s|

s.name = "MatrixSDK"
s.version = "0.19.7"
s.version = "0.19.8"
s.summary = "The iOS SDK to build apps compatible with Matrix (https://www.matrix.org)"

s.description = <<-DESC
Expand Down
6 changes: 6 additions & 0 deletions MatrixSDK.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1334,6 +1334,8 @@
EC383BB72541C518002FBBE6 /* MXBackgroundPushRulesManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = EC383BB52540E15E002FBBE6 /* MXBackgroundPushRulesManager.swift */; };
EC383BBF2542F1E3002FBBE6 /* MXBackgroundSyncServiceTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = EC383BBD2542F141002FBBE6 /* MXBackgroundSyncServiceTests.swift */; };
EC383BC02542F1E4002FBBE6 /* MXBackgroundSyncServiceTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = EC383BBD2542F141002FBBE6 /* MXBackgroundSyncServiceTests.swift */; };
EC51019D26C41981007D6D88 /* MXSyncResponseUnitTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = EC51019C26C41981007D6D88 /* MXSyncResponseUnitTests.swift */; };
EC51019E26C41981007D6D88 /* MXSyncResponseUnitTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = EC51019C26C41981007D6D88 /* MXSyncResponseUnitTests.swift */; };
EC60ED5D265CFC2C00B39A4E /* MXSyncResponse.h in Headers */ = {isa = PBXBuildFile; fileRef = EC60ED5B265CFC2C00B39A4E /* MXSyncResponse.h */; settings = {ATTRIBUTES = (Public, ); }; };
EC60ED5E265CFC2C00B39A4E /* MXSyncResponse.h in Headers */ = {isa = PBXBuildFile; fileRef = EC60ED5B265CFC2C00B39A4E /* MXSyncResponse.h */; settings = {ATTRIBUTES = (Public, ); }; };
EC60ED5F265CFC2C00B39A4E /* MXSyncResponse.m in Sources */ = {isa = PBXBuildFile; fileRef = EC60ED5C265CFC2C00B39A4E /* MXSyncResponse.m */; };
Expand Down Expand Up @@ -2252,6 +2254,7 @@
EC383BB52540E15E002FBBE6 /* MXBackgroundPushRulesManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MXBackgroundPushRulesManager.swift; sourceTree = "<group>"; };
EC383BBD2542F141002FBBE6 /* MXBackgroundSyncServiceTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MXBackgroundSyncServiceTests.swift; sourceTree = "<group>"; };
EC383BC12542F251002FBBE6 /* MatrixSDKTests-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "MatrixSDKTests-Bridging-Header.h"; sourceTree = "<group>"; };
EC51019C26C41981007D6D88 /* MXSyncResponseUnitTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MXSyncResponseUnitTests.swift; sourceTree = "<group>"; };
EC60ED5B265CFC2C00B39A4E /* MXSyncResponse.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MXSyncResponse.h; sourceTree = "<group>"; };
EC60ED5C265CFC2C00B39A4E /* MXSyncResponse.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MXSyncResponse.m; sourceTree = "<group>"; };
EC60ED65265CFC7200B39A4E /* MXPresenceSyncResponse.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MXPresenceSyncResponse.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -3407,6 +3410,7 @@
327E9ACE2284783E00A98BC1 /* MXEventAnnotationUnitTests.swift */,
32B0E3E623A3864C0054FF1A /* MXEventReferenceUnitTests.swift */,
EC383BBD2542F141002FBBE6 /* MXBackgroundSyncServiceTests.swift */,
EC51019C26C41981007D6D88 /* MXSyncResponseUnitTests.swift */,
329E808E22512DF500A48C3A /* MXCryptoKeyVerificationTests.m */,
322D01C322492B0700150C68 /* MXCryptoShareTests.m */,
32720DA1222EB5650086FFF5 /* MXAutoDiscoveryTests.m */,
Expand Down Expand Up @@ -5402,6 +5406,7 @@
32C9B71823E81A1C00C6F30A /* MXCrossSigningVerificationTests.m in Sources */,
323C5A081A70E53500FB0549 /* MXToolsUnitTests.m in Sources */,
3281E89E19E299C000976E1A /* MXErrorUnitTests.m in Sources */,
EC51019D26C41981007D6D88 /* MXSyncResponseUnitTests.swift in Sources */,
3265CB3B1A151C3800E24B2F /* MXRoomStateTests.m in Sources */,
32CEEF3D23AD134A0039BA98 /* MXCrossSigningTests.m in Sources */,
326D1EF51BFC79300030947B /* MXPushRuleUnitTests.m in Sources */,
Expand Down Expand Up @@ -5832,6 +5837,7 @@
B1E09A3D2397FD820057C069 /* MXStoreFileStoreTests.m in Sources */,
32CEEF3E23AD134A0039BA98 /* MXCrossSigningTests.m in Sources */,
32EEA8402603CA140041425B /* MXRestClientExtensionsTests.m in Sources */,
EC51019E26C41981007D6D88 /* MXSyncResponseUnitTests.swift in Sources */,
32B477AA2638186000EA5800 /* MXHTTPAdditionalHeadersUnitTests.m in Sources */,
B1E09A2B2397FD6B0057C069 /* MatrixSDKTestsE2EData.m in Sources */,
B1E09A3C2397FD820057C069 /* MXStoreMemoryStoreTests.m in Sources */,
Expand Down
22 changes: 11 additions & 11 deletions MatrixSDK/Aggregations/Data/Store/Realm/MXRealmAggregationsStore.m
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ - (BOOL)hasReactionCountsOnEvent:(NSString*)eventId

- (nullable MXReactionCount *)reactionCountForReaction:(nonnull NSString *)reaction onEvent:(nonnull NSString *)eventId
{
MXRealmReactionCount *realmReactionCount = [MXRealmReactionCount objectsInRealm:self.realm
where:@"primaryKey = %@", [MXRealmReactionCount primaryKeyFromEventId:eventId andReaction:reaction]].firstObject;
NSString *primaryKey = [MXRealmReactionCount primaryKeyFromEventId:eventId andReaction:reaction];
MXRealmReactionCount *realmReactionCount = [MXRealmReactionCount objectInRealm:self.realm forPrimaryKey:primaryKey];

MXReactionCount *reactionCount;
if (realmReactionCount)
Expand All @@ -88,9 +88,10 @@ - (void)deleteReactionCountsForReaction:(nonnull NSString *)reaction onEvent:(no
RLMRealm *realm = self.realm;

[realm transactionWithBlock:^{
RLMResults<MXRealmReactionCount *> *realmReactionCounts = [MXRealmReactionCount objectsInRealm:self.realm
where:@"primaryKey = %@", [MXRealmReactionCount primaryKeyFromEventId:eventId andReaction:reaction]];
[realm deleteObjects:realmReactionCounts];
NSString *primaryKey = [MXRealmReactionCount primaryKeyFromEventId:eventId andReaction:reaction];

MXRealmReactionCount *realmReactionCount = [MXRealmReactionCount objectInRealm:realm forPrimaryKey:primaryKey];
[realm deleteObject:realmReactionCount];
}];
}

Expand All @@ -103,7 +104,7 @@ - (void)setReactionCounts:(nonnull NSArray<MXReactionCount *> *)reactionCounts o

[realm transactionWithBlock:^{
// Flush previous data
RLMResults<MXRealmReactionCount *> *realmReactionCounts = [MXRealmReactionCount objectsInRealm:self.realm
RLMResults<MXRealmReactionCount *> *realmReactionCounts = [MXRealmReactionCount objectsInRealm:realm
where:@"eventId = %@", eventId];
[realm deleteObjects:realmReactionCounts];

Expand Down Expand Up @@ -142,7 +143,7 @@ - (void)deleteAllReactionCountsInRoom:(nonnull NSString *)roomId
RLMRealm *realm = self.realm;

[realm transactionWithBlock:^{
RLMResults<MXRealmReactionCount *> *results = [MXRealmReactionCount objectsInRealm:self.realm
RLMResults<MXRealmReactionCount *> *results = [MXRealmReactionCount objectsInRealm:realm
where:@"roomId = %@", roomId];
[realm deleteObjects:results];
}];
Expand Down Expand Up @@ -183,9 +184,8 @@ - (void)deleteReactionRelation:(MXReactionRelation*)relation
[realm transactionWithBlock:^{
NSString *primaryKey = [MXRealmReactionRelation primaryKeyFromEventId:relation.eventId andReactionEventId:relation.reactionEventId];

RLMResults<MXRealmReactionRelation *> *results = [MXRealmReactionRelation objectsInRealm:self.realm
where:@"primaryKey = %@", primaryKey];
[realm deleteObjects:results];
MXRealmReactionRelation *result = [MXRealmReactionRelation objectInRealm:realm forPrimaryKey:primaryKey];
[realm deleteObject:result];
}];
}

Expand Down Expand Up @@ -215,7 +215,7 @@ - (void)deleteAllReactionRelationsInRoom:(NSString*)roomId
RLMRealm *realm = self.realm;

[realm transactionWithBlock:^{
RLMResults<MXRealmReactionRelation *> *results = [MXRealmReactionRelation objectsInRealm:self.realm
RLMResults<MXRealmReactionRelation *> *results = [MXRealmReactionRelation objectsInRealm:realm
where:@"roomId = %@", roomId];
[realm deleteObjects:results];
}];
Expand Down
154 changes: 118 additions & 36 deletions MatrixSDK/Background/Store/MXSyncResponseStoreManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ public class MXSyncResponseStoreManager: NSObject {
/// The actual store
let syncResponseStore: MXSyncResponseStore

/// Serial queue to merge sync responses
private lazy var mergeQueue: DispatchQueue = {
return DispatchQueue(label: String(describing: self) + "-MergeQueue")
}()

public init(syncResponseStore: MXSyncResponseStore) {
self.syncResponseStore = syncResponseStore
}
Expand Down Expand Up @@ -76,6 +81,46 @@ public class MXSyncResponseStoreManager: NSObject {
syncResponseStore.markOutdated(syncResponseIds: syncResponseIds)
}

public func mergedSyncResponse(fromSyncResponseIds responseIds: [String],
completion: @escaping (MXCachedSyncResponse?) -> Void) {
if responseIds.isEmpty {
// empty array
DispatchQueue.main.async {
completion(nil)
}
return
}

let stopwatch = MXStopwatch()

mergeQueue.async {
var result: MXSyncResponse?
var syncToken: String?
for responseId in responseIds {
if let response = try? self.syncResponseStore.syncResponse(withId: responseId) {
if let tmpResult = result {
result = self.merged(response.syncResponse, onto: tmpResult)
} else {
result = response.syncResponse
syncToken = response.syncToken
}
}
}

MXLog.debug("[MXSyncResponseStoreManager] mergedSyncResponse: merging \(responseIds.count) sync responses lasted \(stopwatch.readable())")

if let result = result {
DispatchQueue.main.async {
completion(MXCachedSyncResponse(syncToken: syncToken,
syncResponse: result))
}
} else {
DispatchQueue.main.async {
completion(nil)
}
}
}
}

/// Cache a sync response.
/// - Parameters:
Expand All @@ -92,46 +137,13 @@ public class MXSyncResponseStoreManager: NSObject {

MXLog.debug("[MXSyncResponseStoreManager] updateStore: Merge new sync response to the previous one")

// handle new limited timelines
newSyncResponse.rooms?.join?.filter({ $1.timeline.limited == true }).forEach { (roomId, _) in
if let joinedRoomSync = cachedSyncResponse.syncResponse.rooms?.join?[roomId] {
// remove old events
joinedRoomSync.timeline.events = []
// mark old timeline as limited too
joinedRoomSync.timeline.limited = true
}
}
newSyncResponse.rooms?.leave?.filter({ $1.timeline.limited == true }).forEach { (roomId, _) in
if let leftRoomSync = cachedSyncResponse.syncResponse.rooms?.leave?[roomId] {
// remove old events
leftRoomSync.timeline.events = []
// mark old timeline as limited too
leftRoomSync.timeline.limited = true
}
}

// handle old limited timelines
cachedSyncResponse.syncResponse.rooms?.join?.filter({ $1.timeline.limited == true }).forEach { (roomId, _) in
if let joinedRoomSync = newSyncResponse.rooms?.join?[roomId] {
// mark new timeline as limited too, to avoid losing value of limited
joinedRoomSync.timeline.limited = true
}
}
cachedSyncResponse.syncResponse.rooms?.leave?.filter({ $1.timeline.limited == true }).forEach { (roomId, _) in
if let leftRoomSync = newSyncResponse.rooms?.leave?[roomId] {
// mark new timeline as limited too, to avoid losing value of limited
leftRoomSync.timeline.limited = true
}
}

// Merge the new sync response to the old one
var dictionary = NSDictionary(dictionary: cachedSyncResponse.syncResponse.jsonDictionary())
dictionary = dictionary + NSDictionary(dictionary: newSyncResponse.jsonDictionary())
let updatedSyncResponse = merged(newSyncResponse, onto: cachedSyncResponse.syncResponse)

// And update it to the store.
// Note we we care only about the cached sync token. syncToken is now useless
let updatedCachedSyncResponse = MXCachedSyncResponse(syncToken: cachedSyncResponse.syncToken,
syncResponse: MXSyncResponse(fromJSON: dictionary as? [AnyHashable : Any]))
syncResponse: updatedSyncResponse)

syncResponseStore.updateSyncResponse(withId: id, syncResponse: updatedCachedSyncResponse)


Expand Down Expand Up @@ -240,6 +252,60 @@ public class MXSyncResponseStoreManager: NSObject {
return nil
}

// MARK: - Private

private func merged(_ newSyncResponse: MXSyncResponse, onto oldSyncResponse: MXSyncResponse) -> MXSyncResponse {
let stopwatch = MXStopwatch()

// handle new limited timelines
newSyncResponse.rooms?.joinedOrLeftRoomSyncs?.filter({ $1.timeline.limited == true }).forEach { (roomId, _) in
if let joinedRoomSync = oldSyncResponse.rooms?.join?[roomId] {
// remove old events
joinedRoomSync.timeline.events = []
// mark old timeline as limited too
joinedRoomSync.timeline.limited = true
}
}

// handle old limited timelines
oldSyncResponse.rooms?.joinedOrLeftRoomSyncs?.filter({ $1.timeline.limited == true }).forEach { (roomId, _) in
if let joinedRoomSync = newSyncResponse.rooms?.join?[roomId] {
// mark new timeline as limited too, to avoid losing value of limited
joinedRoomSync.timeline.limited = true
}
}

// handle newly joined/left rooms for when invited
newSyncResponse.rooms?.joinedOrLeftRoomSyncs?.forEach { (roomId, newRoomSync) in
if let invitedRoomSync = oldSyncResponse.rooms?.invite?[roomId] {
// add inviteState events into the beginning of the state events
newRoomSync.state.events.insert(contentsOf: invitedRoomSync.inviteState.events, at: 0)
// remove invited room from old sync response
oldSyncResponse.rooms?.invite?.removeValue(forKey: roomId)
}
}

// handle newly left rooms for when joined
newSyncResponse.rooms?.leave?.forEach { (roomId, leftRoomSync) in
if let joinedRoomSync = oldSyncResponse.rooms?.join?[roomId] {
// add inviteState events into the beginning of the state events
leftRoomSync.state.events.insert(contentsOf: joinedRoomSync.state.events, at: 0)
// add joined timeline events into the beginning of the left timeline events
leftRoomSync.timeline.events.insert(contentsOf: joinedRoomSync.timeline.events, at: 0)
// remove joined room from old sync response
oldSyncResponse.rooms?.join?.removeValue(forKey: roomId)
}
}

// Merge the new sync response to the old one
var dictionary = NSDictionary(dictionary: oldSyncResponse.jsonDictionary())
dictionary = dictionary + NSDictionary(dictionary: newSyncResponse.jsonDictionary())

MXLog.debug("[MXSyncResponseStoreManager] merged: merging two sync responses lasted \(stopwatch.readable())")

return MXSyncResponse(fromJSON: dictionary as? [AnyHashable : Any])
}

private func roomSummary(forRoomId roomId: String, using summary: MXRoomSummary, inSyncResponse response: MXCachedSyncResponse) -> MXRoomSummary? {
var eventsToProcess: [MXEvent] = []

Expand Down Expand Up @@ -292,3 +358,19 @@ private extension Array {
}

}

private extension MXRoomsSyncResponse {

var joinedOrLeftRoomSyncs: [String: MXRoomSync]? {
guard let joined = join else {
return leave
}
guard let left = leave else {
return joined
}
return joined.merging(left) { current, _ in
current
}
}

}
Loading

0 comments on commit d632e09

Please sign in to comment.