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

Configure per-room retention period for messages #287

Merged
merged 7 commits into from
Jan 27, 2020
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
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ def import_MatrixKit
pod 'MatrixKit', :path => '../matrix-ios-kit/MatrixKit.podspec'
else
if $matrixKitVersion == 'develop'
pod 'MatrixSDK', :git => 'https://github.com/matrix-org/matrix-ios-sdk.git', :branch => 'develop'
pod 'MatrixSDK/SwiftSupport', :git => 'https://github.com/matrix-org/matrix-ios-sdk.git', :branch => 'develop'
pod 'MatrixSDK/JingleCallStack', :git => 'https://github.com/matrix-org/matrix-ios-sdk.git', :branch => 'develop'
pod 'MatrixSDK', :git => 'https://github.com/matrix-org/matrix-ios-sdk.git', :branch => 'dinum'
pod 'MatrixSDK/SwiftSupport', :git => 'https://github.com/matrix-org/matrix-ios-sdk.git', :branch => 'dinum'
pod 'MatrixSDK/JingleCallStack', :git => 'https://github.com/matrix-org/matrix-ios-sdk.git', :branch => 'dinum'
pod 'MatrixKit', :git => 'https://github.com/matrix-org/matrix-ios-kit.git', :branch => 'develop'
else
pod 'MatrixKit', $matrixKitVersion
Expand All @@ -46,8 +46,8 @@ def import_MatrixKitAppExtension
pod 'MatrixKit/AppExtension', :path => '../matrix-ios-kit/MatrixKit.podspec'
else
if $matrixKitVersion == 'develop'
pod 'MatrixSDK', :git => 'https://github.com/matrix-org/matrix-ios-sdk.git', :branch => 'develop'
pod 'MatrixSDK/SwiftSupport', :git => 'https://github.com/matrix-org/matrix-ios-sdk.git', :branch => 'develop'
pod 'MatrixSDK', :git => 'https://github.com/matrix-org/matrix-ios-sdk.git', :branch => 'dinum'
pod 'MatrixSDK/SwiftSupport', :git => 'https://github.com/matrix-org/matrix-ios-sdk.git', :branch => 'dinum'
pod 'MatrixKit/AppExtension', :git => 'https://github.com/matrix-org/matrix-ios-kit.git', :branch => 'develop'
else
pod 'MatrixKit/AppExtension', $matrixKitVersion
Expand Down
12 changes: 6 additions & 6 deletions Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,9 @@ DEPENDENCIES:
- MatomoTracker (~> 7.2.0)
- MatrixKit (from `https://github.com/matrix-org/matrix-ios-kit.git`, branch `develop`)
- MatrixKit/AppExtension (from `https://github.com/matrix-org/matrix-ios-kit.git`, branch `develop`)
- MatrixSDK (from `https://github.com/matrix-org/matrix-ios-sdk.git`, branch `develop`)
- MatrixSDK/JingleCallStack (from `https://github.com/matrix-org/matrix-ios-sdk.git`, branch `develop`)
- MatrixSDK/SwiftSupport (from `https://github.com/matrix-org/matrix-ios-sdk.git`, branch `develop`)
- MatrixSDK (from `https://github.com/matrix-org/matrix-ios-sdk.git`, branch `dinum`)
- MatrixSDK/JingleCallStack (from `https://github.com/matrix-org/matrix-ios-sdk.git`, branch `dinum`)
- MatrixSDK/SwiftSupport (from `https://github.com/matrix-org/matrix-ios-sdk.git`, branch `dinum`)
- OLMKit
- Reusable (~> 4.1)
- RxSwift (~> 4.3)
Expand Down Expand Up @@ -144,7 +144,7 @@ EXTERNAL SOURCES:
:branch: develop
:git: https://github.com/matrix-org/matrix-ios-kit.git
MatrixSDK:
:branch: develop
:branch: dinum
:git: https://github.com/matrix-org/matrix-ios-sdk.git
SwiftUTI:
:branch: master
Expand All @@ -155,7 +155,7 @@ CHECKOUT OPTIONS:
:commit: 78d96ec35b868bccf66f705486bab9eebbace931
:git: https://github.com/matrix-org/matrix-ios-kit.git
MatrixSDK:
:commit: 756a3c32dbcfbd48c205dea65d32d2d9936db324
:commit: 509fdc062040f4970c5bb0b76734eb5734295a78
:git: https://github.com/matrix-org/matrix-ios-sdk.git
SwiftUTI:
:commit: b6b46942fb3aad819610851f62a70e17a528444e
Expand Down Expand Up @@ -183,6 +183,6 @@ SPEC CHECKSUMS:
SwiftLint: 4105f061f9812b214568b736dab580ab2c73a582
SwiftUTI: 917993c124f8eac25e88ced0202fc58d7eb50fa8

PODFILE CHECKSUM: c68ee2ab4839245ea4d46618f0ac174b8fa40a98
PODFILE CHECKSUM: 3701ad39833ed7bb719d87770a74c0bb3ad09200

COCOAPODS: 1.8.4
82 changes: 71 additions & 11 deletions Tchap.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions Tchap/Assets/Localizations/fr.lproj/Tchap.strings
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,8 @@
// MARK: Room title
"room_title_room_members_count" = "%d membre(s)";
"room_title_unrestricted_room" = "Salon accessible aux externes";
"room_title_retention_info_one_day" = "Historique limité à 1 jour";
"room_title_retention_info_in_days" = "Historique limité à %d jours";

////////////////////////////////////////////////////////////////////////////////
// MARK: Room
Expand Down Expand Up @@ -172,6 +174,10 @@
"room_settings_room_access_unrestricted" = "Les externes sont autorisés à rejoindre ce salon";
"room_settings_allow_external_users_to_join" = "Autoriser l’accès aux externes à ce salon";
"room_settings_allow_external_users_to_join_prompt_msg" = "Cette action est irréversible.\nVoulez-vous vraiment autoriser les externes à rejoindre ce salon ?";
"room_settings_retention_title" = "Limitation de l’historique";
"room_settings_retention_period_one_day" = "1 jour";
"room_settings_retention_period_in_days" = "%d jours";
"room_settings_fail_to_update_retention_period" = "Échec de mise à jour de la durée de l'historique";

////////////////////////////////////////////////////////////////////////////////
// MARK: Room Attachment Antivirus Scan
Expand Down Expand Up @@ -199,6 +205,8 @@
"room_creation_public_room_federation_title" = "Limiter l'accès à ce salon aux membres du domaine \"%@\"";
"room_creation_add_avatar_action" = "Ajouter une photo";
"room_creation_room_access_title" = "Autoriser l’accès aux externes à ce salon";
"room_creation_room_retention_period_one_day" = "Limiter l’historique du salon à 1 jour";
"room_creation_room_retention_period_days" = "Limiter l’historique du salon à %d jours";

////////////////////////////////////////////////////////////////////////////////
// MARK: Room creation
Expand Down
43 changes: 42 additions & 1 deletion Tchap/Extensions/MXRoomSummary.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2019 New Vector Ltd
Copyright 2019-2020 New Vector Ltd

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand All @@ -16,13 +16,20 @@

import Foundation

extension Notification.Name {
static let roomSummaryDidRemoveExpiredDataFromStore = Notification.Name(MXRoomSummary.roomSummaryDidRemoveExpiredDataFromStore)
}

@objc extension MXRoomSummary {

static let roomSummaryDidRemoveExpiredDataFromStore = "roomSummaryDidRemoveExpiredDataFromStore"

// MARK: - Constants

private enum Constants {
static let isFederatedKey = "isFederated"
static let roomAccessRuleKey = "roomAccessRule"
static let roomRetentionInDaysKey = "roomRetentionInDays"
}

/// Called to update the room summary on received state events.
Expand Down Expand Up @@ -50,6 +57,11 @@ import Foundation
self.others[Constants.roomAccessRuleKey] = rule
updated = true
}
} else if type == RoomService.roomRetentionStateEventType {
if let maxLifetime = event.content[RoomService.roomRetentionContentMaxLifetimeKey] as? UInt64 {
self.others[Constants.roomRetentionInDaysKey] = Tools.numberOfDaysFromDuration(inMs: maxLifetime)
updated = true
}
}
}
}
Expand Down Expand Up @@ -81,4 +93,33 @@ import Foundation
func tc_roomAccessRuleIdentifier() -> String {
return tc_roomAccessRule().identifier
}

/// Get the room messages retention period in days
func tc_roomRetentionPeriodInDays() -> uint {
if let period = self.others[Constants.roomRetentionInDaysKey] as? uint {
return period
} else {
return 365
}
}

/// Get the timestamp below which the received messages must be removed from the store, and the display
func tc_mininumTimestamp() -> UInt64 {
let periodInMs = Tools.durationInMs(fromDays: self.tc_roomRetentionPeriodInDays())
let currentTs = (UInt64)(Date().timeIntervalSince1970 * 1000)
return (currentTs - periodInMs)
}

/// Remove the expired messages from the store.
/// If some data are removed, this operation posts the notification: roomSummaryDidRemoveExpiredDataFromStore.
/// This operation does not commit the potential change. We let the caller trigger the commit when this is the more suitable.
///
/// Provide a boolean telling whether some data have been removed.
func tc_removeExpiredRoomContentsFromStore() -> Bool {
let ret = self.mxSession.store.removeAllMessagesSent(before: self.tc_mininumTimestamp(), inRoom: roomId)
if ret {
NotificationCenter.default.post(name: .roomSummaryDidRemoveExpiredDataFromStore, object: self)
}
return ret
}
}
32 changes: 32 additions & 0 deletions Tchap/Extensions/MXSession.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
Copyright 2020 New Vector Ltd

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

import Foundation

@objc extension MXSession {

/// Clean the storage of a session by removing the expired contents.
func tc_removeExpiredMessages() {
var hasStoreChanged = false
for summary in self.roomsSummaries() {
hasStoreChanged = hasStoreChanged || summary.tc_removeExpiredRoomContentsFromStore()
}

if hasStoreChanged {
self.store.commit?()
}
}
}
22 changes: 22 additions & 0 deletions Tchap/Generated/Strings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,12 @@ internal enum TchapL10n {
internal static let roomCreationPublicVisibilityTitle = TchapL10n.tr("Tchap", "room_creation_public_visibility_title")
/// Autoriser l’accès aux externes à ce salon
internal static let roomCreationRoomAccessTitle = TchapL10n.tr("Tchap", "room_creation_room_access_title")
/// Limiter l’historique du salon à %d jours
internal static func roomCreationRoomRetentionPeriodDays(_ p1: Int) -> String {
return TchapL10n.tr("Tchap", "room_creation_room_retention_period_days", p1)
}
/// Limiter l’historique du salon à 1 jour
internal static let roomCreationRoomRetentionPeriodOneDay = TchapL10n.tr("Tchap", "room_creation_room_retention_period_one_day")
/// Nouveau salon
internal static let roomCreationTitle = TchapL10n.tr("Tchap", "room_creation_title")
/// Fichiers
Expand All @@ -282,10 +288,20 @@ internal enum TchapL10n {
internal static let roomSettingsAllowExternalUsersToJoin = TchapL10n.tr("Tchap", "room_settings_allow_external_users_to_join")
/// Cette action est irréversible.\nVoulez-vous vraiment autoriser les externes à rejoindre ce salon ?
internal static let roomSettingsAllowExternalUsersToJoinPromptMsg = TchapL10n.tr("Tchap", "room_settings_allow_external_users_to_join_prompt_msg")
/// Échec de mise à jour de la durée de l'historique
internal static let roomSettingsFailToUpdateRetentionPeriod = TchapL10n.tr("Tchap", "room_settings_fail_to_update_retention_period")
/// Retirer ce salon de la liste des salons publics
internal static let roomSettingsRemoveFromRoomsDirectory = TchapL10n.tr("Tchap", "room_settings_remove_from_rooms_directory")
/// Cette action est irréversible.\nVoulez-vous vraiment retirer ce salon des salons publics ?
internal static let roomSettingsRemoveFromRoomsDirectoryPrompt = TchapL10n.tr("Tchap", "room_settings_remove_from_rooms_directory_prompt")
/// %d jours
internal static func roomSettingsRetentionPeriodInDays(_ p1: Int) -> String {
return TchapL10n.tr("Tchap", "room_settings_retention_period_in_days", p1)
}
/// 1 jour
internal static let roomSettingsRetentionPeriodOneDay = TchapL10n.tr("Tchap", "room_settings_retention_period_one_day")
/// Limitation de l’historique
internal static let roomSettingsRetentionTitle = TchapL10n.tr("Tchap", "room_settings_retention_title")
/// Les externes ne sont pas autorisés à rejoindre ce salon
internal static let roomSettingsRoomAccessRestricted = TchapL10n.tr("Tchap", "room_settings_room_access_restricted")
/// Information complémentaire :
Expand All @@ -294,6 +310,12 @@ internal enum TchapL10n {
internal static let roomSettingsRoomAccessUnrestricted = TchapL10n.tr("Tchap", "room_settings_room_access_unrestricted")
/// Paramètres
internal static let roomSettingsTabTitle = TchapL10n.tr("Tchap", "room_settings_tab_title")
/// Historique limité à %d jours
internal static func roomTitleRetentionInfoInDays(_ p1: Int) -> String {
return TchapL10n.tr("Tchap", "room_title_retention_info_in_days", p1)
}
/// Historique limité à 1 jour
internal static let roomTitleRetentionInfoOneDay = TchapL10n.tr("Tchap", "room_title_retention_info_one_day")
/// %d membre(s)
internal static func roomTitleRoomMembersCount(_ p1: Int) -> String {
return TchapL10n.tr("Tchap", "room_title_room_members_count", p1)
Expand Down
Loading