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/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([]) } } - } 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/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..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,5 +605,4 @@ success:(nonnull void (^)(NSString * _Nullable filterId))success failure:(nullable void (^)(NSError * _Nullable error))failure; - @end 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/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"; 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]