SDK Bump to 1.0.73-alpha (#1043)

* sdk bump

* moved the bump event types to the sliding sync list builder

* removed sync growing mode from notifications even if we are not really using it anymore

* recency order is also for the all room list

* removed the local notification code entirely

* removed unused function

* fixed the code placement for the ordering
This commit is contained in:
Mauro
2023-06-07 15:22:54 +02:00
committed by GitHub
parent 6b79204eec
commit 3e0e4d02cf
9 changed files with 54 additions and 144 deletions

View File

@@ -4780,7 +4780,7 @@
repositoryURL = "https://github.com/matrix-org/matrix-rust-components-swift";
requirement = {
kind = exactVersion;
version = "1.0.72-alpha";
version = "1.0.73-alpha";
};
};
96495DD8554E2F39D3954354 /* XCRemoteSwiftPackageReference "posthog-ios" */ = {

View File

@@ -11,7 +11,7 @@
{
"identity" : "compound-ios",
"kind" : "remoteSourceControl",
"location" : "https://github.com/vector-im/compound-ios.git",
"location" : "https://github.com/vector-im/compound-ios",
"state" : {
"revision" : "aaa43409ca09130cb9e9a0fe02c803c65aa42aed"
}
@@ -102,8 +102,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/matrix-org/matrix-rust-components-swift",
"state" : {
"revision" : "d0533a4ba40ff1d9ea9c6473a07639fa9b9c5079",
"version" : "1.0.72-alpha"
"revision" : "849e6c5c47d0172b28d757dee0c7d203bf4b34cc",
"version" : "1.0.73-alpha"
}
},
{

View File

@@ -159,8 +159,6 @@ final class AppSettings {
@UserPreference(key: UserDefaultsKeys.enableInAppNotifications, defaultValue: true, storageType: .userDefaults(store))
var enableInAppNotifications
let enableLocalPushNotifications = false
/// Tag describing which set of device specific rules a pusher executes.
@UserPreference(key: UserDefaultsKeys.pusherProfileTag, storageType: .userDefaults(store))
var pusherProfileTag: String?

View File

@@ -192,27 +192,27 @@ class SDKClientMock: SDKClientProtocol {
}
//MARK: - `getMediaFile`
public var getMediaFileMediaSourceBodyMimeTypeThrowableError: Error?
public var getMediaFileMediaSourceBodyMimeTypeCallsCount = 0
public var getMediaFileMediaSourceBodyMimeTypeCalled: Bool {
return getMediaFileMediaSourceBodyMimeTypeCallsCount > 0
public var getMediaFileMediaSourceBodyMimeTypeTempDirThrowableError: Error?
public var getMediaFileMediaSourceBodyMimeTypeTempDirCallsCount = 0
public var getMediaFileMediaSourceBodyMimeTypeTempDirCalled: Bool {
return getMediaFileMediaSourceBodyMimeTypeTempDirCallsCount > 0
}
public var getMediaFileMediaSourceBodyMimeTypeReceivedArguments: (`mediaSource`: MediaSource, `body`: String?, `mimeType`: String)?
public var getMediaFileMediaSourceBodyMimeTypeReceivedInvocations: [(`mediaSource`: MediaSource, `body`: String?, `mimeType`: String)] = []
public var getMediaFileMediaSourceBodyMimeTypeReturnValue: MediaFileHandle!
public var getMediaFileMediaSourceBodyMimeTypeClosure: ((MediaSource, String?, String) throws -> MediaFileHandle)?
public var getMediaFileMediaSourceBodyMimeTypeTempDirReceivedArguments: (`mediaSource`: MediaSource, `body`: String?, `mimeType`: String, `tempDir`: String?)?
public var getMediaFileMediaSourceBodyMimeTypeTempDirReceivedInvocations: [(`mediaSource`: MediaSource, `body`: String?, `mimeType`: String, `tempDir`: String?)] = []
public var getMediaFileMediaSourceBodyMimeTypeTempDirReturnValue: MediaFileHandle!
public var getMediaFileMediaSourceBodyMimeTypeTempDirClosure: ((MediaSource, String?, String, String?) throws -> MediaFileHandle)?
public func `getMediaFile`(`mediaSource`: MediaSource, `body`: String?, `mimeType`: String) throws -> MediaFileHandle {
if let error = getMediaFileMediaSourceBodyMimeTypeThrowableError {
public func `getMediaFile`(`mediaSource`: MediaSource, `body`: String?, `mimeType`: String, `tempDir`: String?) throws -> MediaFileHandle {
if let error = getMediaFileMediaSourceBodyMimeTypeTempDirThrowableError {
throw error
}
getMediaFileMediaSourceBodyMimeTypeCallsCount += 1
getMediaFileMediaSourceBodyMimeTypeReceivedArguments = (`mediaSource`: `mediaSource`, `body`: `body`, `mimeType`: `mimeType`)
getMediaFileMediaSourceBodyMimeTypeReceivedInvocations.append((`mediaSource`: `mediaSource`, `body`: `body`, `mimeType`: `mimeType`))
if let getMediaFileMediaSourceBodyMimeTypeClosure = getMediaFileMediaSourceBodyMimeTypeClosure {
return try getMediaFileMediaSourceBodyMimeTypeClosure(`mediaSource`, `body`, `mimeType`)
getMediaFileMediaSourceBodyMimeTypeTempDirCallsCount += 1
getMediaFileMediaSourceBodyMimeTypeTempDirReceivedArguments = (`mediaSource`: `mediaSource`, `body`: `body`, `mimeType`: `mimeType`, `tempDir`: `tempDir`)
getMediaFileMediaSourceBodyMimeTypeTempDirReceivedInvocations.append((`mediaSource`: `mediaSource`, `body`: `body`, `mimeType`: `mimeType`, `tempDir`: `tempDir`))
if let getMediaFileMediaSourceBodyMimeTypeTempDirClosure = getMediaFileMediaSourceBodyMimeTypeTempDirClosure {
return try getMediaFileMediaSourceBodyMimeTypeTempDirClosure(`mediaSource`, `body`, `mimeType`, `tempDir`)
} else {
return getMediaFileMediaSourceBodyMimeTypeReturnValue
return getMediaFileMediaSourceBodyMimeTypeTempDirReturnValue
}
}
//MARK: - `getMediaThumbnail`
@@ -559,23 +559,6 @@ class SDKClientMock: SDKClientProtocol {
setPusherIdentifiersKindAppDisplayNameDeviceDisplayNameProfileTagLangReceivedInvocations.append((`identifiers`: `identifiers`, `kind`: `kind`, `appDisplayName`: `appDisplayName`, `deviceDisplayName`: `deviceDisplayName`, `profileTag`: `profileTag`, `lang`: `lang`))
try setPusherIdentifiersKindAppDisplayNameDeviceDisplayNameProfileTagLangClosure?(`identifiers`, `kind`, `appDisplayName`, `deviceDisplayName`, `profileTag`, `lang`)
}
//MARK: - `slidingSync`
public var slidingSyncCallsCount = 0
public var slidingSyncCalled: Bool {
return slidingSyncCallsCount > 0
}
public var slidingSyncReturnValue: SlidingSyncBuilder!
public var slidingSyncClosure: (() -> SlidingSyncBuilder)?
public func `slidingSync`() -> SlidingSyncBuilder {
slidingSyncCallsCount += 1
if let slidingSyncClosure = slidingSyncClosure {
return slidingSyncClosure()
} else {
return slidingSyncReturnValue
}
}
//MARK: - `unignoreUser`
public var unignoreUserUserIdThrowableError: Error?
@@ -642,5 +625,30 @@ class SDKClientMock: SDKClientProtocol {
return userIdReturnValue
}
}
//MARK: - `slidingSync`
public var slidingSyncIdThrowableError: Error?
public var slidingSyncIdCallsCount = 0
public var slidingSyncIdCalled: Bool {
return slidingSyncIdCallsCount > 0
}
public var slidingSyncIdReceivedId: String?
public var slidingSyncIdReceivedInvocations: [String] = []
public var slidingSyncIdReturnValue: SlidingSyncBuilder!
public var slidingSyncIdClosure: ((String) throws -> SlidingSyncBuilder)?
public func `slidingSync`(`id`: String) throws -> SlidingSyncBuilder {
if let error = slidingSyncIdThrowableError {
throw error
}
slidingSyncIdCallsCount += 1
slidingSyncIdReceivedId = id
slidingSyncIdReceivedInvocations.append(`id`)
if let slidingSyncIdClosure = slidingSyncIdClosure {
return try slidingSyncIdClosure(`id`)
} else {
return slidingSyncIdReturnValue
}
}
}
// swiftlint:enable all

View File

@@ -19,7 +19,7 @@ import Foundation
import MatrixRustSDK
import UIKit
private class WeakClientProxyWrapper: ClientDelegate, NotificationDelegate, SlidingSyncObserver {
private class WeakClientProxyWrapper: ClientDelegate, SlidingSyncObserver {
private weak var clientProxy: ClientProxy?
init(clientProxy: ClientProxy) {
@@ -44,13 +44,6 @@ private class WeakClientProxyWrapper: ClientDelegate, NotificationDelegate, Slid
MXLog.info("Received sliding sync update")
clientProxy?.didReceiveSlidingSyncUpdate(summary: summary)
}
// MARK: - NotificationDelegate
func didReceiveNotification(notification: MatrixRustSDK.NotificationItem) {
guard let userID = clientProxy?.userID else { return }
clientProxy?.didReceiveNotification(notification: NotificationItemProxy(notificationItem: notification, receiverID: userID))
}
}
class ClientProxy: ClientProxyProtocol {
@@ -76,7 +69,7 @@ class ClientProxy: ClientProxyProtocol {
var invitesListProxy: SlidingSyncListProxy?
var invitesSummaryProvider: RoomSummaryProviderProtocol?
var notificationsListBuilder: SlidingSyncListBuilder?
private let roomListRecencyOrderingAllowedEventTypes = ["m.room.message", "m.room.encrypted", "m.sticker"]
private var loadCachedAvatarURLTask: Task<Void, Never>?
private let avatarURLSubject = CurrentValueSubject<URL?, Never>(nil)
@@ -109,13 +102,6 @@ class ClientProxy: ClientProxyProtocol {
let delegate = WeakClientProxyWrapper(clientProxy: self)
client.setDelegate(delegate: delegate)
// Set up sync listener for generating local notifications.
if ServiceLocator.shared.settings.enableLocalPushNotifications {
await Task.dispatch(on: clientQueue) {
client.setNotificationDelegate(notificationDelegate: delegate)
}
}
configureSlidingSync()
@@ -414,31 +400,24 @@ class ClientProxy: ClientProxyProtocol {
}
do {
let slidingSyncBuilder = client.slidingSync()
let slidingSyncBuilder = try client.slidingSync(id: "ElementX")
// List observers need to be setup before calling build() on the SlidingSyncBuilder otherwise
// cold cache state and count updates will be lost
buildAndConfigureVisibleRoomsSlidingSyncList()
buildAndConfigureAllRoomsSlidingSyncList()
buildAndConfigureInvitesSlidingSyncList()
if ServiceLocator.shared.settings.enableLocalPushNotifications {
buildAndConfigureNotificationsSlidingSyncList()
}
guard let visibleRoomsListBuilder else {
MXLog.error("Visible rooms sliding sync view unavailable")
return
}
let roomListRecencyOrderingAllowedEventTypes = ["m.room.message", "m.room.encrypted", "m.sticker"]
// Add the visibleRoomsSlidingSyncList here so that it can take advantage of the SS builder cold cache
// We will still register the allRoomsSlidingSyncList later, and than will have no cache
let slidingSync = try slidingSyncBuilder
.addList(listBuilder: visibleRoomsListBuilder)
.withCommonExtensions()
.bumpEventTypes(bumpEventTypes: roomListRecencyOrderingAllowedEventTypes)
// .storageKey(name: "ElementX")
.build()
// Don't forget to update the view proxies after building the slidingSync
@@ -466,12 +445,13 @@ class ClientProxy: ClientProxyProtocol {
let listName = "CurrentlyVisibleRooms"
let visibleRoomsListProxy = SlidingSyncListProxy(name: listName)
let visibleRoomsListBuilder = SlidingSyncListBuilder(name: listName)
.timelineLimit(limit: UInt32(SlidingSyncConstants.initialTimelineLimit)) // Starts off with zero to quickly load rooms, then goes to 1 while scrolling to quickly load last messages and 20 when the scrolling stops to load room history
.requiredState(requiredState: slidingSyncRequiredState)
.filters(filters: slidingSyncFilters)
.syncModeSelective(selectiveModeBuilder: .init().addRange(start: 0, endInclusive: 20))
.bumpEventTypes(bumpEventTypes: roomListRecencyOrderingAllowedEventTypes)
.onceBuilt(callback: visibleRoomsListProxy)
self.visibleRoomsListBuilder = visibleRoomsListBuilder
@@ -503,6 +483,7 @@ class ClientProxy: ClientProxyProtocol {
.requiredState(requiredState: slidingSyncRequiredState)
.filters(filters: slidingSyncFilters)
.syncModeGrowing(batchSize: 100, maximumNumberOfRoomsToFetch: nil)
.bumpEventTypes(bumpEventTypes: roomListRecencyOrderingAllowedEventTypes)
.onceBuilt(callback: allRoomsListProxy)
self.allRoomsListBuilder = allRoomsListBuilder
@@ -529,20 +510,6 @@ class ClientProxy: ClientProxyProtocol {
self.invitesListProxy = invitesListProxy
}
private func buildAndConfigureNotificationsSlidingSyncList() {
guard notificationsListBuilder == nil else {
fatalError("This shouldn't be called more than once")
}
let notificationsListBuilder = SlidingSyncListBuilder(name: "Notifications")
.noTimelineLimit()
.requiredState(requiredState: slidingSyncNotificationsRequiredState)
.filters(filters: slidingSyncNotificationsFilters)
.syncModeGrowing(batchSize: 100, maximumNumberOfRoomsToFetch: nil)
self.notificationsListBuilder = notificationsListBuilder
}
private func buildRoomSummaryProviders() {
guard visibleRoomsSummaryProvider == nil, allRoomsSummaryProvider == nil, invitesSummaryProvider == nil else {
fatalError("This shouldn't be called more than once")
@@ -569,10 +536,6 @@ class ClientProxy: ClientProxyProtocol {
private lazy var slidingSyncRequiredState = [RequiredState(key: "m.room.avatar", value: ""),
RequiredState(key: "m.room.encryption", value: ""),
RequiredState(key: "m.room.power_levels", value: "")]
private lazy var slidingSyncNotificationsRequiredState = [RequiredState(key: "m.room.member", value: "$ME"),
RequiredState(key: "m.room.power_levels", value: ""),
RequiredState(key: "m.room.name", value: "")]
private lazy var slidingSyncInvitesRequiredState = [RequiredState(key: "m.room.avatar", value: ""),
RequiredState(key: "m.room.encryption", value: ""),
@@ -589,17 +552,6 @@ class ClientProxy: ClientProxyProtocol {
roomNameLike: nil,
tags: [],
notTags: [])
private lazy var slidingSyncNotificationsFilters = SlidingSyncRequestListFilters(isDm: nil,
spaces: [],
isEncrypted: nil,
isInvite: nil,
isTombstoned: false,
roomTypes: [],
notRoomTypes: ["m.space"],
roomNameLike: nil,
tags: [],
notTags: [])
private lazy var slidingSyncInviteFilters = SlidingSyncRequestListFilters(isDm: nil,
spaces: [],
@@ -633,15 +585,6 @@ class ClientProxy: ClientProxyProtocol {
} else {
MXLog.error("Invites sliding sync view unavailable")
}
if ServiceLocator.shared.settings.enableLocalPushNotifications {
if let notificationsListBuilder {
MXLog.info("Registering notifications view")
slidingSyncTasks.append(slidingSync?.addList(listBuilder: notificationsListBuilder))
} else {
MXLog.error("Notifications sliding sync view unavailable")
}
}
}
private func roomTupleForIdentifier(_ identifier: String) -> (SlidingSyncRoom?, Room?) {
@@ -667,10 +610,6 @@ class ClientProxy: ClientProxyProtocol {
fileprivate func didReceiveSlidingSyncUpdate(summary: UpdateSummary) {
callbacks.send(.receivedSyncUpdate)
}
fileprivate func didReceiveNotification(notification: NotificationItemProxyProtocol) {
callbacks.send(.receivedNotification(notification))
}
}
extension ClientProxy: MediaLoaderProtocol {

View File

@@ -21,7 +21,6 @@ import MatrixRustSDK
enum ClientProxyCallback {
case receivedSyncUpdate
case receivedAuthError(isSoftLogout: Bool)
case receivedNotification(NotificationItemProxyProtocol)
case updateRestorationToken
var isSyncUpdate: Bool {

View File

@@ -48,7 +48,7 @@ actor MediaLoader: MediaLoaderProtocol {
func loadMediaFileForSource(_ source: MediaSourceProxy, body: String?) async throws -> MediaFileHandleProxy {
let result = try await Task.dispatch(on: clientQueue) {
try self.client.getMediaFile(mediaSource: source.underlyingSource, body: body, mimeType: source.mimeType ?? "application/octet-stream")
try self.client.getMediaFile(mediaSource: source.underlyingSource, body: body, mimeType: source.mimeType ?? "application/octet-stream", tempDir: nil)
}
return MediaFileHandleProxy(handle: result)

View File

@@ -22,7 +22,6 @@ import UserNotifications
class NotificationManager: NSObject, NotificationManagerProtocol {
private let notificationCenter: UserNotificationCenterProtocol
private var userSession: UserSessionProtocol?
var clientCancellable: AnyCancellable?
init(notificationCenter: UserNotificationCenterProtocol = UNUserNotificationCenter.current()) {
self.notificationCenter = notificationCenter
@@ -73,17 +72,6 @@ class NotificationManager: NSObject, NotificationManagerProtocol {
func setUserSession(_ userSession: UserSessionProtocol?) {
self.userSession = userSession
clientCancellable = userSession?.clientProxy.callbacks.sink { [weak self] value in
guard let self else { return }
switch value {
case let .receivedNotification(notification):
Task {
await self.showLocalNotification(notification)
}
default:
return
}
}
}
func registrationFailed(with error: Error) {
@@ -106,28 +94,6 @@ class NotificationManager: NSObject, NotificationManagerProtocol {
MXLog.error("[NotificationManager] show local notification failed: \(error)")
}
}
private func showLocalNotification(_ notification: NotificationItemProxyProtocol) async {
guard let userSession,
notification.event.timestamp > ServiceLocator.shared.settings.lastLaunchDate else { return }
do {
guard let identifier = notification.id else {
return
}
let content = try await notification.process(mediaProvider: userSession.mediaProvider)
let request = UNNotificationRequest(identifier: identifier, content: content, trigger: nil)
guard !ServiceLocator.shared.settings.servedNotificationIdentifiers.contains(identifier) else {
MXLog.info("NotificationManager] local notification discarded because it has already been served")
return
}
ServiceLocator.shared.settings.servedNotificationIdentifiers.insert(identifier)
try await notificationCenter.add(request)
} catch {
MXLog.error("[NotificationManager] show local notification item failed: \(error)")
}
}
private func setPusher(with deviceToken: Data, clientProxy: ClientProxyProtocol) async -> Bool {
do {

View File

@@ -42,7 +42,7 @@ include:
packages:
MatrixRustSDK:
url: https://github.com/matrix-org/matrix-rust-components-swift
exactVersion: 1.0.72-alpha
exactVersion: 1.0.73-alpha
# path: ../matrix-rust-sdk
DesignKit:
path: DesignKit