From 82f93fbc0dbcb5ada8a03b7ab6c58624ad83e0f5 Mon Sep 17 00:00:00 2001 From: Stefan Ceriu Date: Thu, 13 Jun 2024 15:23:26 +0300 Subject: [PATCH 1/6] Prepare for new sprint From 8ae5269a65d8f5fd0c49371a5480b050de6e4e8d Mon Sep 17 00:00:00 2001 From: Giom Foret Date: Sun, 28 Mar 2021 00:19:38 +0100 Subject: [PATCH 2/6] Add a new state event type: "m.room.retention" # Conflicts: # MatrixSDK/Contrib/Swift/JSONModels/MXEvent.swift # MatrixSDK/JSONModels/MXEvent.h # MatrixSDK/JSONModels/MXEvent.m # MatrixSDK/Utils/MXTools.m --- MatrixSDK/Contrib/Swift/JSONModels/MXEvent.swift | 4 +++- MatrixSDK/JSONModels/MXEvent.h | 2 ++ MatrixSDK/JSONModels/MXEvent.m | 1 + MatrixSDK/Utils/MXTools.m | 3 ++- 4 files changed, 8 insertions(+), 2 deletions(-) diff --git a/MatrixSDK/Contrib/Swift/JSONModels/MXEvent.swift b/MatrixSDK/Contrib/Swift/JSONModels/MXEvent.swift index dde0e04ae6..00f137b785 100644 --- a/MatrixSDK/Contrib/Swift/JSONModels/MXEvent.swift +++ b/MatrixSDK/Contrib/Swift/JSONModels/MXEvent.swift @@ -86,6 +86,7 @@ public enum MXEventType: Equatable, Hashable { case beaconInfo case beacon + case roomRetention case custom(String) @@ -141,6 +142,7 @@ public enum MXEventType: Equatable, Hashable { case .taggedEvents: return kMXEventTypeStringTaggedEvents case .spaceChild: return kMXEventTypeStringSpaceChild case .spaceOrder: return kMXEventTypeStringSpaceOrderMSC3230 + case .roomRetention: return kMXEventTypeStringRoomRetention case .pollStart: return kMXEventTypeStringPollStartMSC3381 case .pollResponse: return kMXEventTypeStringPollResponseMSC3381 @@ -157,7 +159,7 @@ public enum MXEventType: Equatable, Hashable { } public init(identifier: String) { - 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, .secretRequest, .secretSend, .secretStorageDefaultKey, .taggedEvents, .spaceChild, .spaceOrder, .pollStart, .pollResponse, .pollEnd, .beaconInfo, .beacon] + 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, .secretRequest, .secretSend, .secretStorageDefaultKey, .taggedEvents, .spaceChild, .spaceOrder, .pollStart, .pollResponse, .pollEnd, .beaconInfo, .beacon, .roomRetention] if let type = events.first(where: { $0.identifier == identifier }) { self = type diff --git a/MatrixSDK/JSONModels/MXEvent.h b/MatrixSDK/JSONModels/MXEvent.h index 2c549b0531..96dd31fc3c 100644 --- a/MatrixSDK/JSONModels/MXEvent.h +++ b/MatrixSDK/JSONModels/MXEvent.h @@ -103,6 +103,7 @@ typedef NS_ENUM(NSInteger, MXEventType) MXEventTypeSpaceOrder, MXEventTypeBeaconInfo, MXEventTypeBeacon, + MXEventTypeRoomRetention, // The event is a custom event. Refer to its `MXEventTypeString` version MXEventTypeCustom = 1000 @@ -163,6 +164,7 @@ FOUNDATION_EXPORT NSString *const kMXEventTypeStringSpaceChild; FOUNDATION_EXPORT NSString *const kMXEventTypeStringSpaceOrder; FOUNDATION_EXPORT NSString *const kMXEventTypeStringSpaceOrderMSC3230; FOUNDATION_EXPORT NSString *const kMXEventTypeStringSpaceOrderKey; +FOUNDATION_EXPORT NSString *const kMXEventTypeStringRoomRetention; // Interactive key verification FOUNDATION_EXPORT NSString *const kMXEventTypeStringKeyVerificationRequest; diff --git a/MatrixSDK/JSONModels/MXEvent.m b/MatrixSDK/JSONModels/MXEvent.m index af7324b967..7f6d898fd1 100644 --- a/MatrixSDK/JSONModels/MXEvent.m +++ b/MatrixSDK/JSONModels/MXEvent.m @@ -115,6 +115,7 @@ NSString *const kMXMessageTypeLocation = @"m.location"; NSString *const kMXMessageTypeFile = @"m.file"; NSString *const kMXMessageTypeServerNotice = @"m.server_notice"; +NSString *const kMXEventTypeStringRoomRetention = @"m.room.retention"; NSString *const kMXMessageTypeKeyVerificationRequest = @"m.key.verification.request"; NSString *const kMXMessageBodyKey = @"body"; diff --git a/MatrixSDK/Utils/MXTools.m b/MatrixSDK/Utils/MXTools.m index 22435cd7dc..26e86564e7 100644 --- a/MatrixSDK/Utils/MXTools.m +++ b/MatrixSDK/Utils/MXTools.m @@ -215,7 +215,8 @@ + (void)initialize kMXEventTypeStringBeaconInfoMSC3672 : @(MXEventTypeBeaconInfo), kMXEventTypeStringBeaconInfo : @(MXEventTypeBeaconInfo), kMXEventTypeStringBeaconMSC3672 : @(MXEventTypeBeacon), - kMXEventTypeStringBeacon : @(MXEventTypeBeacon) + kMXEventTypeStringBeacon : @(MXEventTypeBeacon), + kMXEventTypeStringRoomRetention: @(MXEventTypeRoomRetention), }; isEmailAddressRegex = [NSRegularExpression regularExpressionWithPattern:[NSString stringWithFormat:@"^%@$", kMXToolsRegexStringForEmailAddress] From b9bee86c81c969a00d9cc54a79fd1a4ac5e90c3b Mon Sep 17 00:00:00 2001 From: Mauro Romito Date: Fri, 14 Jun 2024 14:51:19 +0200 Subject: [PATCH 3/6] added some functions to remove messages before a certain timestamp --- .../Store/MXMemoryStore/MXMemoryRoomStore.h | 10 +++++++ .../Store/MXMemoryStore/MXMemoryRoomStore.m | 27 +++++++++++++++++++ .../Data/Store/MXMemoryStore/MXMemoryStore.m | 6 +++++ MatrixSDK/Data/Store/MXNoStore/MXNoStore.m | 11 ++++++++ MatrixSDK/Data/Store/MXStore.h | 12 +++++++++ 5 files changed, 66 insertions(+) diff --git a/MatrixSDK/Data/Store/MXMemoryStore/MXMemoryRoomStore.h b/MatrixSDK/Data/Store/MXMemoryStore/MXMemoryRoomStore.h index d085fbfcc1..3ff2312d81 100644 --- a/MatrixSDK/Data/Store/MXMemoryStore/MXMemoryRoomStore.h +++ b/MatrixSDK/Data/Store/MXMemoryStore/MXMemoryRoomStore.h @@ -48,6 +48,16 @@ */ - (void)replaceEvent:(MXEvent*)event; +/** + Remove all the messages sent before a specific timestamp in a room. + The state events are not removed during this operation. We keep them in the timeline. + + @param limitTs the timestamp from which the messages are kept. + + @return YES if at least one event has been removed. + */ +- (BOOL)removeAllMessagesSentBefore:(uint64_t)limitTs; + /** Get an event from this room. diff --git a/MatrixSDK/Data/Store/MXMemoryStore/MXMemoryRoomStore.m b/MatrixSDK/Data/Store/MXMemoryStore/MXMemoryRoomStore.m index 2da23e99d3..d413bc28a8 100644 --- a/MatrixSDK/Data/Store/MXMemoryStore/MXMemoryRoomStore.m +++ b/MatrixSDK/Data/Store/MXMemoryStore/MXMemoryRoomStore.m @@ -197,4 +197,31 @@ - (NSString *)description return [NSString stringWithFormat:@"%tu messages - paginationToken: %@ - hasReachedHomeServerPaginationEnd: %@ - hasLoadedAllRoomMembersForRoom: %@", messages.count, _paginationToken, @(_hasReachedHomeServerPaginationEnd), @(_hasLoadedAllRoomMembersForRoom)]; } +- (BOOL)removeAllMessagesSentBefore:(uint64_t)limitTs +{ + NSUInteger index = 0; + BOOL didChange = NO; + while (index < messages.count) + { + MXEvent *anEvent = [messages objectAtIndex:index]; + if (anEvent.isState) + { + // Keep state event + index ++; + } + else if (anEvent.originServerTs < limitTs) + { + [messages removeObjectAtIndex:index]; + [messagesByEventIds removeObjectForKey:anEvent.eventId]; + didChange = YES; + } + else + { + // Break the loop, we've reached the first non-state event in the timeline which is not expired + break; + } + } + return didChange; +} + @end diff --git a/MatrixSDK/Data/Store/MXMemoryStore/MXMemoryStore.m b/MatrixSDK/Data/Store/MXMemoryStore/MXMemoryStore.m index 969a0bb932..aad34e943b 100644 --- a/MatrixSDK/Data/Store/MXMemoryStore/MXMemoryStore.m +++ b/MatrixSDK/Data/Store/MXMemoryStore/MXMemoryStore.m @@ -83,6 +83,12 @@ - (void)replaceEvent:(MXEvent *)event inRoom:(NSString *)roomId [roomStore replaceEvent:event]; } +- (BOOL)removeAllMessagesSentBefore:(uint64_t)limitTs inRoom:(nonnull NSString *)roomId +{ + MXMemoryRoomStore *roomStore = [self getOrCreateRoomStore:roomId]; + return [roomStore removeAllMessagesSentBefore:limitTs]; +} + - (BOOL)eventExistsWithEventId:(NSString *)eventId inRoom:(NSString *)roomId { return (nil != [self eventWithEventId:eventId inRoom:roomId]); diff --git a/MatrixSDK/Data/Store/MXNoStore/MXNoStore.m b/MatrixSDK/Data/Store/MXNoStore/MXNoStore.m index 99c956e4ec..03b44302fa 100644 --- a/MatrixSDK/Data/Store/MXNoStore/MXNoStore.m +++ b/MatrixSDK/Data/Store/MXNoStore/MXNoStore.m @@ -124,6 +124,17 @@ - (BOOL)eventExistsWithEventId:(NSString *)eventId inRoom:(NSString *)roomId return NO; } +- (BOOL)removeAllMessagesSentBefore:(uint64_t)limitTs inRoom:(nonnull NSString *)roomId +{ + // Only the last message is stored + MXEvent *lastMessage = lastMessages[roomId]; + if (!lastMessage.isState && lastMessage.originServerTs < limitTs) { + lastMessages[roomId] = nil; + return YES; + } + return NO; +} + - (MXEvent *)eventWithEventId:(NSString *)eventId inRoom:(NSString *)roomId { // Events are not stored. So, we cannot find it. diff --git a/MatrixSDK/Data/Store/MXStore.h b/MatrixSDK/Data/Store/MXStore.h index d17982a3e9..40a92db930 100644 --- a/MatrixSDK/Data/Store/MXStore.h +++ b/MatrixSDK/Data/Store/MXStore.h @@ -593,5 +593,17 @@ success:(nonnull void (^)(NSString * _Nullable filterId))success failure:(nullable void (^)(NSError * _Nullable error))failure; +/** + Remove all the messages sent before a specific timestamp in a room. + The state events are not removed during this operation. We keep them in the timeline. + This operation doesn't change the pagination token, and the flag indicating that the SDK has reached the end of pagination. + + @param limitTs the timestamp from which the messages are kept. + @param roomId the id of the room. + + @return YES if at least one event has been removed. + */ +- (BOOL)removeAllMessagesSentBefore:(uint64_t)limitTs inRoom:(nonnull NSString *)roomId; + @end From 9cfe050aa8f420a544e96fcc3e5535bfd6cbe38a Mon Sep 17 00:00:00 2001 From: Mauro Romito Date: Fri, 14 Jun 2024 14:58:36 +0200 Subject: [PATCH 4/6] remove all messages sent --- MatrixSDK/Data/Store/MXStore.h | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/MatrixSDK/Data/Store/MXStore.h b/MatrixSDK/Data/Store/MXStore.h index 40a92db930..c427cb62f0 100644 --- a/MatrixSDK/Data/Store/MXStore.h +++ b/MatrixSDK/Data/Store/MXStore.h @@ -426,6 +426,18 @@ */ - (void)storeOutgoingMessageForRoom:(nonnull NSString*)roomId outgoingMessage:(nonnull MXEvent*)outgoingMessage; +/** + Remove all the messages sent before a specific timestamp in a room. + The state events are not removed during this operation. We keep them in the timeline. + This operation doesn't change the pagination token, and the flag indicating that the SDK has reached the end of pagination. + + @param limitTs the timestamp from which the messages are kept. + @param roomId the id of the room. + + @return YES if at least one event has been removed. + */ +- (BOOL)removeAllMessagesSentBefore:(uint64_t)limitTs inRoom:(nonnull NSString *)roomId; + /** Remove all outgoing messages from a room. @@ -593,17 +605,4 @@ success:(nonnull void (^)(NSString * _Nullable filterId))success failure:(nullable void (^)(NSError * _Nullable error))failure; -/** - Remove all the messages sent before a specific timestamp in a room. - The state events are not removed during this operation. We keep them in the timeline. - This operation doesn't change the pagination token, and the flag indicating that the SDK has reached the end of pagination. - - @param limitTs the timestamp from which the messages are kept. - @param roomId the id of the room. - - @return YES if at least one event has been removed. - */ -- (BOOL)removeAllMessagesSentBefore:(uint64_t)limitTs inRoom:(nonnull NSString *)roomId; - - @end From d3f4ec07db3ac92ca01d2bfead8daffc0edd962b Mon Sep 17 00:00:00 2001 From: Mauro Romito Date: Fri, 14 Jun 2024 15:01:10 +0200 Subject: [PATCH 5/6] fixing a compilation error --- MatrixSDK/Background/MXBackgroundStore.swift | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/MatrixSDK/Background/MXBackgroundStore.swift b/MatrixSDK/Background/MXBackgroundStore.swift index a171d84c4c..a414eba9a0 100644 --- a/MatrixSDK/Background/MXBackgroundStore.swift +++ b/MatrixSDK/Background/MXBackgroundStore.swift @@ -298,6 +298,11 @@ class MXBackgroundStore: NSObject, MXStore { func isRoomMarked(asUnread roomId: String) -> Bool { return false } + + func removeAllMessagesSent(before limitTs: UInt64, inRoom roomId: String) -> Bool { + // Not sure if this needs to be implemented + false + } } // MARK: - MXRoomSummaryStore @@ -334,5 +339,4 @@ extension MXBackgroundStore: MXRoomSummaryStore { completion([]) } } - } From 643dd94978be2be9e0ea4610789f1ecdecd7393c Mon Sep 17 00:00:00 2001 From: Doug Date: Mon, 17 Jun 2024 09:49:26 +0100 Subject: [PATCH 6/6] version++ --- CHANGES.md | 5 +++++ MatrixSDK.podspec | 2 +- MatrixSDK/MatrixSDKVersion.m | 2 +- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 114ccd0871..0b47fde22a 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,3 +1,8 @@ +## Changes in 0.27.10 (2024-06-17) + +No significant changes. + + ## Changes in 0.27.9 (2024-06-13) No significant changes. diff --git a/MatrixSDK.podspec b/MatrixSDK.podspec index 00366b738e..60f71c6bb0 100644 --- a/MatrixSDK.podspec +++ b/MatrixSDK.podspec @@ -1,7 +1,7 @@ Pod::Spec.new do |s| s.name = "MatrixSDK" - s.version = "0.27.9" + s.version = "0.27.10" s.summary = "The iOS SDK to build apps compatible with Matrix (https://www.matrix.org)" s.description = <<-DESC diff --git a/MatrixSDK/MatrixSDKVersion.m b/MatrixSDK/MatrixSDKVersion.m index 705e2e1b0d..2c5662a9a3 100644 --- a/MatrixSDK/MatrixSDKVersion.m +++ b/MatrixSDK/MatrixSDKVersion.m @@ -16,4 +16,4 @@ #import -NSString *const MatrixSDKVersion = @"0.27.8"; +NSString *const MatrixSDKVersion = @"0.27.10";