-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor: generate notification user contact join - WPB-11660 #2383
base: refactor/generate-notification-conversation-member-leave
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,7 +19,7 @@ | |
import WireAPI | ||
import WireDataModel | ||
|
||
struct NewUserMessageNotificationBuilder: NotificationBuilder { | ||
struct ConversationUserMessageNotificationBuilder: NotificationBuilder { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess this was renamed from another PR, but it still confuses me slightly. I think the structure of the builders could follow the structure of events, so |
||
|
||
private enum AssetType { | ||
case image | ||
|
@@ -143,19 +143,19 @@ struct NewUserMessageNotificationBuilder: NotificationBuilder { | |
|
||
let body: NotificationBody = switch assetType { | ||
case .image: | ||
.newUserMessage( | ||
.conversationUserMessage( | ||
.sharedPicture(senderName: isGroupConversation ? senderName : nil) | ||
) | ||
case .video: | ||
.newUserMessage( | ||
.conversationUserMessage( | ||
.sharedVideo(senderName: isGroupConversation ? senderName : nil) | ||
) | ||
case .audio: | ||
.newUserMessage( | ||
.conversationUserMessage( | ||
.sharedAudio(senderName: isGroupConversation ? senderName : nil) | ||
) | ||
case .fileUpload: | ||
.newUserMessage( | ||
.conversationUserMessage( | ||
.sharedFile(senderName: isGroupConversation ? senderName : nil) | ||
) | ||
} | ||
|
@@ -177,7 +177,7 @@ struct NewUserMessageNotificationBuilder: NotificationBuilder { | |
content.title = title | ||
} | ||
|
||
let body = NotificationBody.newUserMessage( | ||
let body = NotificationBody.conversationUserMessage( | ||
.ping(senderName: context.isGroupConversation ? senderName : nil) | ||
) | ||
|
||
|
@@ -194,7 +194,7 @@ struct NewUserMessageNotificationBuilder: NotificationBuilder { | |
let content = UNMutableNotificationContent() | ||
|
||
// No title for hidden message, only a body. | ||
let body: NotificationBody = .newUserMessage(.hidden) | ||
let body: NotificationBody = .conversationUserMessage(.hidden) | ||
content.body = body.make() | ||
content.categoryIdentifier = makeCategory() | ||
content.sound = makeSound() | ||
|
@@ -241,7 +241,7 @@ struct NewUserMessageNotificationBuilder: NotificationBuilder { | |
.text(content: text, senderName: senderName) | ||
} | ||
|
||
let body = NotificationBody.newUserMessage( | ||
let body = NotificationBody.conversationUserMessage( | ||
format | ||
) | ||
|
||
|
@@ -263,7 +263,7 @@ struct NewUserMessageNotificationBuilder: NotificationBuilder { | |
content.title = title | ||
} | ||
|
||
let body = NotificationBody.newUserMessage( | ||
let body = NotificationBody.conversationUserMessage( | ||
.sharedLocation(senderName: isGroupConversation ? senderName : nil) | ||
) | ||
|
||
|
@@ -310,7 +310,7 @@ struct NewUserMessageNotificationBuilder: NotificationBuilder { | |
.sentWithUnknownSender | ||
} | ||
|
||
let body = NotificationBody.newUserMessage( | ||
let body = NotificationBody.conversationUserMessage( | ||
format | ||
) | ||
|
||
|
@@ -351,7 +351,7 @@ struct NewUserMessageNotificationBuilder: NotificationBuilder { | |
} | ||
|
||
return NotificationTitle | ||
.newMessage(format) | ||
.conversationMessage(format) | ||
.make() | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
// | ||
// Wire | ||
// Copyright (C) 2025 Wire Swiss GmbH | ||
// | ||
// This program is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// This program is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU General Public License | ||
// along with this program. If not, see http://www.gnu.org/licenses/. | ||
// | ||
|
||
import UserNotifications | ||
|
||
struct UserConnectionNotificationBuilder: NotificationBuilder { | ||
|
||
enum ConnectionStatus { | ||
case joined | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess this is for the case where someone in your address book creates an account on Wire. But I don't think we get this event anymore, in which case I don't think we need to support this notification. Best to check with BE. |
||
case pending | ||
case accepted | ||
} | ||
|
||
struct Context { | ||
let connectionStatus: ConnectionStatus | ||
let username: String | ||
} | ||
|
||
private let context: Context | ||
|
||
init( | ||
connectionStatus: ConnectionStatus, | ||
username: String | ||
) { | ||
self.context = Context( | ||
connectionStatus: connectionStatus, | ||
username: username | ||
) | ||
} | ||
|
||
func shouldBuildNotification() async -> Bool { | ||
true | ||
} | ||
|
||
func buildContent() async -> UNMutableNotificationContent { | ||
switch context.connectionStatus { | ||
case .joined: | ||
buildUserJoinNotification() | ||
case .pending: | ||
// TODO: [WPB-11659] To implement | ||
UNMutableNotificationContent() | ||
case .accepted: | ||
// TODO: [WPB-11659] To implement | ||
UNMutableNotificationContent() | ||
} | ||
} | ||
|
||
// MARK: - Build notifications | ||
|
||
private func buildUserJoinNotification() -> UNMutableNotificationContent { | ||
let content = UNMutableNotificationContent() | ||
|
||
let body = NotificationBody.userConnection( | ||
.userJoined(username: context.username) | ||
) | ||
|
||
content.body = body.make() | ||
content.categoryIdentifier = makeCategory() | ||
content.sound = makeSound() | ||
|
||
return content | ||
} | ||
|
||
// MARK: - Helpers | ||
|
||
private func makeSound(type: NotificationSound = .default) -> UNNotificationSound { | ||
let notificationSoundName = UNNotificationSoundName(type.rawValue) | ||
return UNNotificationSound(named: notificationSoundName) | ||
} | ||
|
||
private func makeCategory() -> String { | ||
switch context.connectionStatus { | ||
case .joined: | ||
NotificationCategory.nonActionable.rawValue | ||
case .pending, .accepted: | ||
// TODO: [WPB-11659] To implement | ||
"" | ||
} | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
// | ||
// Wire | ||
// Copyright (C) 2025 Wire Swiss GmbH | ||
// | ||
// This program is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// This program is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU General Public License | ||
// along with this program. If not, see http://www.gnu.org/licenses/. | ||
// | ||
|
||
import UserNotifications | ||
import WireAPI | ||
import WireDataModel | ||
|
||
struct UserNotificationBuilder: NotificationBuilder { | ||
|
||
private let event: UserEvent | ||
|
||
init( | ||
event: UserEvent | ||
) { | ||
self.event = event | ||
} | ||
|
||
func shouldBuildNotification() async -> Bool { | ||
true | ||
} | ||
|
||
func buildContent() async -> UNMutableNotificationContent { | ||
let builder: NotificationBuilder | ||
|
||
switch event { | ||
case let .connection(userConnectionEvent): | ||
let isPending = userConnectionEvent.connection.status == .pending | ||
|
||
builder = UserConnectionNotificationBuilder( | ||
connectionStatus: isPending ? .pending : .accepted, | ||
username: userConnectionEvent.userName | ||
) | ||
|
||
case let .contactJoin(userContactJoinEvent): | ||
|
||
builder = UserConnectionNotificationBuilder( | ||
connectionStatus: .joined, | ||
username: userContactJoinEvent.name | ||
) | ||
|
||
default: | ||
return UNMutableNotificationContent() | ||
} | ||
|
||
guard await builder.shouldBuildNotification() else { | ||
return UNMutableNotificationContent() | ||
} | ||
|
||
return await builder.buildContent() | ||
} | ||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm confused by the naming, what is the relevance of "system message"?