mirror of
https://github.com/element-hq/element-x-ios.git
synced 2025-03-10 21:39:12 +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:
parent
bfd75a335d
commit
9ebc57e1cf
@ -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" */ = {
|
||||
|
@ -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"
|
||||
}
|
||||
},
|
||||
{
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
1
changelog.d/1205.change
Normal file
1
changelog.d/1205.change
Normal file
@ -0,0 +1 @@
|
||||
Push notifications will be displayed as DM only in direct rooms where joined members are at most 2.
|
1
changelog.d/1243.bugfix
Normal file
1
changelog.d/1243.bugfix
Normal file
@ -0,0 +1 @@
|
||||
Caching for the notification placeholder image, to avoid generating it too many times and taking too much memory.
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user