diff --git a/ElementX.xcodeproj/project.pbxproj b/ElementX.xcodeproj/project.pbxproj index ff999f9a0..1e8f39027 100644 --- a/ElementX.xcodeproj/project.pbxproj +++ b/ElementX.xcodeproj/project.pbxproj @@ -5163,7 +5163,7 @@ repositoryURL = "https://github.com/matrix-org/matrix-rust-components-swift"; requirement = { kind = exactVersion; - version = "1.0.94-alpha"; + version = "1.0.95-alpha"; }; }; 96495DD8554E2F39D3954354 /* XCRemoteSwiftPackageReference "posthog-ios" */ = { diff --git a/ElementX.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved b/ElementX.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved index 4d9210683..5f60712be 100644 --- a/ElementX.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved +++ b/ElementX.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -111,8 +111,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/matrix-org/matrix-rust-components-swift", "state" : { - "revision" : "6d6c13bcf3bf900932599a62e2a157224d762630", - "version" : "1.0.94-alpha" + "revision" : "822c8b33dc6da7eb0951890af0197f633095188a", + "version" : "1.0.95-alpha" } }, { diff --git a/ElementX/Sources/Other/Extensions/UNNotificationContent.swift b/ElementX/Sources/Other/Extensions/UNNotificationContent.swift index 466737a5d..b43b8c995 100644 --- a/ElementX/Sources/Other/Extensions/UNNotificationContent.swift +++ b/ElementX/Sources/Other/Extensions/UNNotificationContent.swift @@ -112,15 +112,15 @@ extension UNMutableNotificationContent { var fetchedImage: INImage? let image: INImage if let mediaSource = icon.mediaSource { - if let mediaProvider { - switch await mediaProvider.loadImageDataFromSource(mediaSource) { - case .success(let data): - fetchedImage = INImage(imageData: data) - case .failure(let error): - MXLog.error("Couldn't add sender icon: \(error)") - // ...The provider failed to fetch - needsPlaceholder = true - } + switch await mediaProvider?.loadImageDataFromSource(mediaSource) { + case .success(let data): + fetchedImage = INImage(imageData: data) + case .failure(let error): + MXLog.error("Couldn't add sender icon: \(error)") + // ...The provider failed to fetch + needsPlaceholder = true + case .none: + break } } else { // ...There is no media diff --git a/ElementX/Sources/Services/Notification/Proxy/NotificationItemProxy.swift b/ElementX/Sources/Services/Notification/Proxy/NotificationItemProxy.swift index 700dd15fd..ee763e499 100644 --- a/ElementX/Sources/Services/Notification/Proxy/NotificationItemProxy.swift +++ b/ElementX/Sources/Services/Notification/Proxy/NotificationItemProxy.swift @@ -37,69 +37,14 @@ protocol NotificationItemProxyProtocol { var roomAvatarMediaSource: MediaSourceProxy? { get } + var roomJoinedMembers: Int { get } + + var isRoomDirect: Bool { get } + var isNoisy: Bool { get } - - var isDirect: Bool { get } - - /// Returns `true` if the event of the notification belongs to an encrypted room - var isRoomEncrypted: Bool? { get } - - /// Returns `true` if was not possible to decrypt the notification content - var isEncrypted: Bool { get } } -struct NotificationItemProxy: NotificationItemProxyProtocol { - let notificationItem: NotificationItem - let receiverID: String - - var event: TimelineEventProxyProtocol { - TimelineEventProxy(timelineEvent: notificationItem.event) - } - - var roomID: String { - notificationItem.roomId - } - - var senderDisplayName: String? { - notificationItem.senderDisplayName - } - - var roomDisplayName: String { - notificationItem.roomDisplayName - } - - var roomCanonicalAlias: String? { - notificationItem.roomCanonicalAlias - } - - var isNoisy: Bool { - notificationItem.isNoisy - } - - var isDirect: Bool { - notificationItem.isDirect - } - - var isRoomEncrypted: Bool? { - notificationItem.isEncrypted - } - - var senderAvatarMediaSource: MediaSourceProxy? { - if let senderAvatarURLString = notificationItem.senderAvatarUrl, - let senderAvatarURL = URL(string: senderAvatarURLString) { - return MediaSourceProxy(url: senderAvatarURL, mimeType: nil) - } - return nil - } - - var roomAvatarMediaSource: MediaSourceProxy? { - if let roomAvatarURLString = notificationItem.roomAvatarUrl, - let roomAvatarURL = URL(string: roomAvatarURLString) { - return MediaSourceProxy(url: roomAvatarURL, mimeType: nil) - } - return nil - } - +extension NotificationItemProxyProtocol { var isEncrypted: Bool { switch event.type { case .messageLike(let content): @@ -113,6 +58,63 @@ struct NotificationItemProxy: NotificationItemProxyProtocol { return false } } + + var isDM: Bool { + isRoomDirect && roomJoinedMembers <= 2 + } +} + +struct NotificationItemProxy: NotificationItemProxyProtocol { + let notificationItem: NotificationItem + let receiverID: String + + var event: TimelineEventProxyProtocol { + TimelineEventProxy(timelineEvent: notificationItem.event) + } + + var roomID: String { + notificationItem.roomInfo.id + } + + var senderDisplayName: String? { + notificationItem.senderInfo.displayName + } + + var roomDisplayName: String { + notificationItem.roomInfo.displayName + } + + var roomCanonicalAlias: String? { + notificationItem.roomInfo.canonicalAlias + } + + var isRoomDirect: Bool { + notificationItem.roomInfo.isDirect + } + + var roomJoinedMembers: Int { + Int(notificationItem.roomInfo.joinedMembersCount) + } + + var isNoisy: Bool { + notificationItem.isNoisy + } + + var senderAvatarMediaSource: MediaSourceProxy? { + if let senderAvatarURLString = notificationItem.senderInfo.avatarUrl, + let senderAvatarURL = URL(string: senderAvatarURLString) { + return MediaSourceProxy(url: senderAvatarURL, mimeType: nil) + } + return nil + } + + var roomAvatarMediaSource: MediaSourceProxy? { + if let roomAvatarURLString = notificationItem.roomInfo.avatarUrl, + let roomAvatarURL = URL(string: roomAvatarURLString) { + return MediaSourceProxy(url: roomAvatarURL, mimeType: nil) + } + return nil + } } struct EmptyNotificationItemProxy: NotificationItemProxyProtocol { @@ -138,7 +140,7 @@ struct EmptyNotificationItemProxy: NotificationItemProxyProtocol { var isNoisy: Bool { false } - var isDirect: Bool { false } + var isRoomDirect: Bool { false } var isRoomEncrypted: Bool? { nil } @@ -148,7 +150,7 @@ struct EmptyNotificationItemProxy: NotificationItemProxyProtocol { var notificationIdentifier: String { "" } - var isEncrypted: Bool { false } + var roomJoinedMembers: Int { 0 } } extension NotificationItemProxyProtocol { @@ -164,8 +166,8 @@ extension NotificationItemProxyProtocol { } var hasMedia: Bool { - if (isDirect && senderAvatarMediaSource != nil) || - (!isDirect && roomAvatarMediaSource != nil) { + if (isDM && senderAvatarMediaSource != nil) || + (!isDM && roomAvatarMediaSource != nil) { return true } switch event.type { @@ -187,7 +189,7 @@ extension NotificationItemProxyProtocol { } var icon: NotificationIcon { - if isDirect { + if isDM { return NotificationIcon(mediaSource: senderAvatarMediaSource, groupInfo: nil) } else { return NotificationIcon(mediaSource: roomAvatarMediaSource, @@ -247,7 +249,7 @@ extension NotificationItemProxyProtocol { notification.categoryIdentifier = NotificationConstants.Category.invite let body: String - if !isDirect { + if !isDM { body = L10n.notificationRoomInviteBody } else { body = L10n.notificationInviteBody diff --git a/changelog.d/1205.change b/changelog.d/1205.change new file mode 100644 index 000000000..5bb97f04d --- /dev/null +++ b/changelog.d/1205.change @@ -0,0 +1 @@ +Push notifications will be displayed as DM only in direct rooms where joined members are at most 2. \ No newline at end of file diff --git a/changelog.d/1243.bugfix b/changelog.d/1243.bugfix new file mode 100644 index 000000000..bfd1f741d --- /dev/null +++ b/changelog.d/1243.bugfix @@ -0,0 +1 @@ +Caching for the notification placeholder image, to avoid generating it too many times and taking too much memory. \ No newline at end of file diff --git a/project.yml b/project.yml index 41bf75954..6a5b765f8 100644 --- a/project.yml +++ b/project.yml @@ -44,7 +44,7 @@ include: packages: MatrixRustSDK: url: https://github.com/matrix-org/matrix-rust-components-swift - exactVersion: 1.0.94-alpha + exactVersion: 1.0.95-alpha # path: ../matrix-rust-sdk DesignKit: path: DesignKit