Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix storage issue for room retention event #7816

Merged
merged 1 commit into from
Jun 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,17 @@ PODS:
- LoggerAPI (1.9.200):
- Logging (~> 1.1)
- Logging (1.4.0)
- MatrixSDK (0.27.9):
- MatrixSDK/Core (= 0.27.9)
- MatrixSDK/Core (0.27.9):
- MatrixSDK (0.27.10):
- MatrixSDK/Core (= 0.27.10)
- MatrixSDK/Core (0.27.10):
- AFNetworking (~> 4.0.0)
- GZIP (~> 1.3.0)
- libbase58 (~> 0.1.4)
- MatrixSDKCrypto (= 0.4.2)
- OLMKit (~> 3.2.5)
- Realm (= 10.27.0)
- SwiftyBeaver (= 1.9.5)
- MatrixSDK/JingleCallStack (0.27.9):
- MatrixSDK/JingleCallStack (0.27.10):
- JitsiMeetSDKLite (= 8.1.2-lite)
- MatrixSDK/Core
- MatrixSDKCrypto (0.4.2)
Expand Down Expand Up @@ -187,7 +187,7 @@ SPEC CHECKSUMS:
libPhoneNumber-iOS: 0a32a9525cf8744fe02c5206eb30d571e38f7d75
LoggerAPI: ad9c4a6f1e32f518fdb43a1347ac14d765ab5e3d
Logging: beeb016c9c80cf77042d62e83495816847ef108b
MatrixSDK: 246fd1d3620afcbf8cb76794e9343ebf3cbf881b
MatrixSDK: c805f9306d60955215f4b15043ed0f96fd4867b3
MatrixSDKCrypto: 736069ee0a5ec12852ab3498bf2242acecc443fc
OLMKit: da115f16582e47626616874e20f7bb92222c7a51
ReadMoreTextView: 19147adf93abce6d7271e14031a00303fe28720d
Expand Down
13 changes: 6 additions & 7 deletions Riot/Categories/MXRoomSummary.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,21 @@ extension Notification.Name {
extension MXRoomSummary {
@objc static let roomSummaryDidRemoveExpiredDataFromStore = "roomSummaryDidRemoveExpiredDataFromStore"
@objc static let roomRetentionStateEventType = "m.room.retention"
@objc static let roomRetentionEventMaxLifetimeKey = "max_lifetime"
@objc static let roomRetentionMaxLifetime = "roomRetentionMaxLifetime"

private enum Constants {
static let roomRetentionInDaysKey = "roomRetentionInDays"
}
/// Get the room messages retention period in days
func roomRetentionPeriodInDays() -> uint {
if let period = self.others[Constants.roomRetentionInDaysKey] as? uint {
private func roomRetentionPeriodInMillis() -> UInt64 {
if let period = self.others[MXRoomSummary.roomRetentionMaxLifetime] as? UInt64 {
return period
} else {
return 365
return Tools.durationInMs(fromDays: 365)
}
}

/// Get the timestamp below which the received messages must be removed from the store, and the display
@objc func minimumTimestamp() -> UInt64 {
let periodInMs = Tools.durationInMs(fromDays: self.roomRetentionPeriodInDays())
let periodInMs = self.roomRetentionPeriodInMillis()
let currentTs = (UInt64)(Date().timeIntervalSince1970 * 1000)
return (currentTs - periodInMs)
}
Expand Down
17 changes: 15 additions & 2 deletions Riot/Utils/EventFormatter.m
Original file line number Diff line number Diff line change
Expand Up @@ -632,7 +632,14 @@ - (MXEvent *)voiceBroadcastInfoStartedEventWithEvent:(MXEvent *)voiceBroadcastIn
- (BOOL)session:(MXSession *)session updateRoomSummary:(MXRoomSummary *)summary withStateEvents:(NSArray<MXEvent *> *)stateEvents roomState:(MXRoomState *)roomState
{
BOOL updated = [super session:session updateRoomSummary:summary withStateEvents:stateEvents roomState:roomState];


MXEvent* lastRoomRetentionEvent = [self roomRetentionEventFromStateEvents:stateEvents];
if (lastRoomRetentionEvent)
{
summary.others[MXRoomSummary.roomRetentionMaxLifetime] = lastRoomRetentionEvent.content[MXRoomSummary.roomRetentionEventMaxLifetimeKey];
updated = YES;
}

// Customisation for EMS Functional Members in direct rooms
if (BuildSettings.supportFunctionalMembers && summary.room.isDirect)
{
Expand All @@ -645,7 +652,7 @@ - (BOOL)session:(MXSession *)session updateRoomSummary:(MXRoomSummary *)summary
// room name which we'll do twice more in updateRoomSummary:withServerRoomSummary:roomState: anyway.
//
// So return YES and let that happen there.
return YES;
updated = YES;
}
}

Expand Down Expand Up @@ -801,6 +808,12 @@ - (MXEvent *)functionalMembersEventFromStateEvents:(NSArray<MXEvent *> *)stateEv
return [stateEvents filteredArrayUsingPredicate:functionalMembersPredicate].lastObject;
}

- (MXEvent *)roomRetentionEventFromStateEvents:(NSArray<MXEvent *> *)stateEvents
{
NSPredicate *functionalMembersPredicate = [NSPredicate predicateWithFormat:@"type == %@", kMXEventTypeStringRoomRetention];
return [stateEvents filteredArrayUsingPredicate:functionalMembersPredicate].lastObject;
}

#pragma mark - Timestamp formatting

- (NSString*)dateStringFromDate:(NSDate *)date withTime:(BOOL)time
Expand Down
6 changes: 0 additions & 6 deletions Riot/Utils/Tools.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,4 @@
*/
+ (uint64_t)durationInMsFromDays:(uint)days;

/**
* Convert a duration in ms to a number of days.
*/
+ (uint)numberOfDaysFromDurationInMs:(uint64_t)duration;


@end
5 changes: 0 additions & 5 deletions Riot/Utils/Tools.m
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,4 @@ + (uint64_t)durationInMsFromDays:(uint)days
return days * (uint64_t)(86400000);
}

+ (uint)numberOfDaysFromDurationInMs:(uint64_t)duration
{
return (uint)(duration / 86400000);
}

@end
Loading