Skip to content

Commit 21249f7

Browse files
committed
add NotificationContentBuilderTests and use the Dynamic swift package to test the communicationContext
1 parent 8e52ef3 commit 21249f7

File tree

6 files changed

+280
-79
lines changed

6 files changed

+280
-79
lines changed

ElementX.xcodeproj/project.pbxproj

Lines changed: 39 additions & 54 deletions
Large diffs are not rendered by default.

ElementX.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

NSE/Sources/NotificationContentBuilder.swift

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -110,13 +110,13 @@ struct NotificationContentBuilder {
110110
notificationContent.body = body
111111

112112
let name = notificationItem.senderDisplayName ?? notificationItem.roomDisplayName
113-
await addSenderIcon(notificationContent: &notificationContent,
114-
senderID: notificationItem.senderID,
115-
senderAvatarDisplayName: name,
116-
senderDisplayName: name,
117-
icon: icon(for: notificationItem),
118-
forcePlaceholder: userSession.inviteAvatarsVisibility == .off,
119-
mediaProvider: mediaProvider)
113+
await addCommunicationContext(notificationContent: &notificationContent,
114+
senderID: notificationItem.senderID,
115+
senderAvatarDisplayName: name,
116+
senderDisplayName: name,
117+
icon: icon(for: notificationItem),
118+
forcePlaceholder: userSession.inviteAvatarsVisibility == .off,
119+
mediaProvider: mediaProvider)
120120
}
121121

122122
private func processMessageLike(notificationContent: inout UNMutableNotificationContent,
@@ -136,12 +136,12 @@ struct NotificationContentBuilder {
136136

137137
let senderDisplayName = notificationItem.hasMention ? L10n.notificationSenderMentionReply(senderAvatarDisplayName) : senderAvatarDisplayName
138138

139-
await addSenderIcon(notificationContent: &notificationContent,
140-
senderID: notificationItem.senderID,
141-
senderAvatarDisplayName: senderAvatarDisplayName,
142-
senderDisplayName: senderDisplayName,
143-
icon: icon(for: notificationItem),
144-
mediaProvider: mediaProvider)
139+
await addCommunicationContext(notificationContent: &notificationContent,
140+
senderID: notificationItem.senderID,
141+
senderAvatarDisplayName: senderAvatarDisplayName,
142+
senderDisplayName: senderDisplayName,
143+
icon: icon(for: notificationItem),
144+
mediaProvider: mediaProvider)
145145
}
146146

147147
private func icon(for notificationItem: NotificationItemProxyProtocol) -> NotificationIcon {
@@ -231,13 +231,13 @@ struct NotificationContentBuilder {
231231
}
232232
}
233233

234-
private func addSenderIcon(notificationContent: inout UNMutableNotificationContent,
235-
senderID: String,
236-
senderAvatarDisplayName: String,
237-
senderDisplayName: String,
238-
icon: NotificationIcon,
239-
forcePlaceholder: Bool = false,
240-
mediaProvider: MediaProviderProtocol) async {
234+
private func addCommunicationContext(notificationContent: inout UNMutableNotificationContent,
235+
senderID: String,
236+
senderAvatarDisplayName: String,
237+
senderDisplayName: String,
238+
icon: NotificationIcon,
239+
forcePlaceholder: Bool = false,
240+
mediaProvider: MediaProviderProtocol) async {
241241
var fetchedImage: INImage?
242242
let image: INImage
243243
if !forcePlaceholder,
@@ -297,7 +297,9 @@ struct NotificationContentBuilder {
297297
interaction.direction = .incoming
298298

299299
// Donate the interaction before updating notification content.
300-
try? await interaction.donate()
300+
if !ProcessInfo.isRunningTests {
301+
try? await interaction.donate()
302+
}
301303

302304
// Update notification content before displaying the
303305
// communication notification.

0 commit comments

Comments
 (0)