mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-04 10:33:45 +00:00
isDM in Notifications (#1254)
* isDm * isDm added and some code improvements * Bump SDK and fix one name. * changelog --------- Co-authored-by: Mauro Romito <mauro.romito@element.io>
This commit is contained in:
@@ -5163,7 +5163,7 @@
|
|||||||
repositoryURL = "https://github.com/matrix-org/matrix-rust-components-swift";
|
repositoryURL = "https://github.com/matrix-org/matrix-rust-components-swift";
|
||||||
requirement = {
|
requirement = {
|
||||||
kind = exactVersion;
|
kind = exactVersion;
|
||||||
version = "1.0.94-alpha";
|
version = "1.0.95-alpha";
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
96495DD8554E2F39D3954354 /* XCRemoteSwiftPackageReference "posthog-ios" */ = {
|
96495DD8554E2F39D3954354 /* XCRemoteSwiftPackageReference "posthog-ios" */ = {
|
||||||
|
|||||||
@@ -111,8 +111,8 @@
|
|||||||
"kind" : "remoteSourceControl",
|
"kind" : "remoteSourceControl",
|
||||||
"location" : "https://github.com/matrix-org/matrix-rust-components-swift",
|
"location" : "https://github.com/matrix-org/matrix-rust-components-swift",
|
||||||
"state" : {
|
"state" : {
|
||||||
"revision" : "6d6c13bcf3bf900932599a62e2a157224d762630",
|
"revision" : "822c8b33dc6da7eb0951890af0197f633095188a",
|
||||||
"version" : "1.0.94-alpha"
|
"version" : "1.0.95-alpha"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -112,15 +112,15 @@ extension UNMutableNotificationContent {
|
|||||||
var fetchedImage: INImage?
|
var fetchedImage: INImage?
|
||||||
let image: INImage
|
let image: INImage
|
||||||
if let mediaSource = icon.mediaSource {
|
if let mediaSource = icon.mediaSource {
|
||||||
if let mediaProvider {
|
switch await mediaProvider?.loadImageDataFromSource(mediaSource) {
|
||||||
switch await mediaProvider.loadImageDataFromSource(mediaSource) {
|
case .success(let data):
|
||||||
case .success(let data):
|
fetchedImage = INImage(imageData: data)
|
||||||
fetchedImage = INImage(imageData: data)
|
case .failure(let error):
|
||||||
case .failure(let error):
|
MXLog.error("Couldn't add sender icon: \(error)")
|
||||||
MXLog.error("Couldn't add sender icon: \(error)")
|
// ...The provider failed to fetch
|
||||||
// ...The provider failed to fetch
|
needsPlaceholder = true
|
||||||
needsPlaceholder = true
|
case .none:
|
||||||
}
|
break
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// ...There is no media
|
// ...There is no media
|
||||||
|
|||||||
@@ -37,69 +37,14 @@ protocol NotificationItemProxyProtocol {
|
|||||||
|
|
||||||
var roomAvatarMediaSource: MediaSourceProxy? { get }
|
var roomAvatarMediaSource: MediaSourceProxy? { get }
|
||||||
|
|
||||||
|
var roomJoinedMembers: Int { get }
|
||||||
|
|
||||||
|
var isRoomDirect: Bool { get }
|
||||||
|
|
||||||
var isNoisy: 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 {
|
extension 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
|
|
||||||
}
|
|
||||||
|
|
||||||
var isEncrypted: Bool {
|
var isEncrypted: Bool {
|
||||||
switch event.type {
|
switch event.type {
|
||||||
case .messageLike(let content):
|
case .messageLike(let content):
|
||||||
@@ -113,6 +58,63 @@ struct NotificationItemProxy: NotificationItemProxyProtocol {
|
|||||||
return false
|
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 {
|
struct EmptyNotificationItemProxy: NotificationItemProxyProtocol {
|
||||||
@@ -138,7 +140,7 @@ struct EmptyNotificationItemProxy: NotificationItemProxyProtocol {
|
|||||||
|
|
||||||
var isNoisy: Bool { false }
|
var isNoisy: Bool { false }
|
||||||
|
|
||||||
var isDirect: Bool { false }
|
var isRoomDirect: Bool { false }
|
||||||
|
|
||||||
var isRoomEncrypted: Bool? { nil }
|
var isRoomEncrypted: Bool? { nil }
|
||||||
|
|
||||||
@@ -148,7 +150,7 @@ struct EmptyNotificationItemProxy: NotificationItemProxyProtocol {
|
|||||||
|
|
||||||
var notificationIdentifier: String { "" }
|
var notificationIdentifier: String { "" }
|
||||||
|
|
||||||
var isEncrypted: Bool { false }
|
var roomJoinedMembers: Int { 0 }
|
||||||
}
|
}
|
||||||
|
|
||||||
extension NotificationItemProxyProtocol {
|
extension NotificationItemProxyProtocol {
|
||||||
@@ -164,8 +166,8 @@ extension NotificationItemProxyProtocol {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var hasMedia: Bool {
|
var hasMedia: Bool {
|
||||||
if (isDirect && senderAvatarMediaSource != nil) ||
|
if (isDM && senderAvatarMediaSource != nil) ||
|
||||||
(!isDirect && roomAvatarMediaSource != nil) {
|
(!isDM && roomAvatarMediaSource != nil) {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
switch event.type {
|
switch event.type {
|
||||||
@@ -187,7 +189,7 @@ extension NotificationItemProxyProtocol {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var icon: NotificationIcon {
|
var icon: NotificationIcon {
|
||||||
if isDirect {
|
if isDM {
|
||||||
return NotificationIcon(mediaSource: senderAvatarMediaSource, groupInfo: nil)
|
return NotificationIcon(mediaSource: senderAvatarMediaSource, groupInfo: nil)
|
||||||
} else {
|
} else {
|
||||||
return NotificationIcon(mediaSource: roomAvatarMediaSource,
|
return NotificationIcon(mediaSource: roomAvatarMediaSource,
|
||||||
@@ -247,7 +249,7 @@ extension NotificationItemProxyProtocol {
|
|||||||
notification.categoryIdentifier = NotificationConstants.Category.invite
|
notification.categoryIdentifier = NotificationConstants.Category.invite
|
||||||
|
|
||||||
let body: String
|
let body: String
|
||||||
if !isDirect {
|
if !isDM {
|
||||||
body = L10n.notificationRoomInviteBody
|
body = L10n.notificationRoomInviteBody
|
||||||
} else {
|
} else {
|
||||||
body = L10n.notificationInviteBody
|
body = L10n.notificationInviteBody
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
Push notifications will be displayed as DM only in direct rooms where joined members are at most 2.
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
Caching for the notification placeholder image, to avoid generating it too many times and taking too much memory.
|
||||||
+1
-1
@@ -44,7 +44,7 @@ include:
|
|||||||
packages:
|
packages:
|
||||||
MatrixRustSDK:
|
MatrixRustSDK:
|
||||||
url: https://github.com/matrix-org/matrix-rust-components-swift
|
url: https://github.com/matrix-org/matrix-rust-components-swift
|
||||||
exactVersion: 1.0.94-alpha
|
exactVersion: 1.0.95-alpha
|
||||||
# path: ../matrix-rust-sdk
|
# path: ../matrix-rust-sdk
|
||||||
DesignKit:
|
DesignKit:
|
||||||
path: DesignKit
|
path: DesignKit
|
||||||
|
|||||||
Reference in New Issue
Block a user