mirror of
https://github.com/permissionlesstech/bitchat.git
synced 2026-10-18 07:33:46 +00:00
Merge 64613895c5add4b7385584e50e1019c8f2574299 into dba67c1466b79855cb513ed68b07ae91c72ccfe2
This commit is contained in:
commit
1e082e97b3
File diff suppressed because it is too large
Load Diff
@ -229,7 +229,20 @@ final class NotificationService {
|
||||
}
|
||||
|
||||
func sendMentionNotification(from sender: String, message: String) {
|
||||
let title = hidePreviews ? Redacted.mentionTitle : "🫵 you were mentioned by \(sender)"
|
||||
let title: String
|
||||
if hidePreviews {
|
||||
title = Redacted.mentionTitle
|
||||
} else {
|
||||
title = String(
|
||||
format: String(
|
||||
localized: "notification.mention.title",
|
||||
defaultValue: "🫵 you were mentioned by %@",
|
||||
comment: "Lock-screen notification title when someone is mentioned; %@ is the sender nickname"
|
||||
),
|
||||
locale: .current,
|
||||
sender
|
||||
)
|
||||
}
|
||||
let body = hidePreviews ? Redacted.body : message
|
||||
let identifier = "mention-\(UUID().uuidString)"
|
||||
|
||||
@ -237,7 +250,20 @@ final class NotificationService {
|
||||
}
|
||||
|
||||
func sendPrivateMessageNotification(from sender: String, message: String, peerID: PeerID) {
|
||||
let title = hidePreviews ? Redacted.directMessageTitle : "🔒 DM from \(sender)"
|
||||
let title: String
|
||||
if hidePreviews {
|
||||
title = Redacted.directMessageTitle
|
||||
} else {
|
||||
title = String(
|
||||
format: String(
|
||||
localized: "notification.dm.title",
|
||||
defaultValue: "🔒 DM from %@",
|
||||
comment: "Lock-screen notification title for a direct message; %@ is the sender nickname"
|
||||
),
|
||||
locale: .current,
|
||||
sender
|
||||
)
|
||||
}
|
||||
let body = hidePreviews ? Redacted.body : message
|
||||
let identifier = "private-\(UUID().uuidString)"
|
||||
// Routing payload, not display copy: `userInfo` never reaches the lock
|
||||
@ -260,8 +286,12 @@ final class NotificationService {
|
||||
}
|
||||
|
||||
func sendNetworkAvailableNotification(peerCount: Int) {
|
||||
let title = "👥 bitchatters nearby!"
|
||||
let body = peerCount == 1 ? "1 person around" : "\(peerCount) people around"
|
||||
let title = String(
|
||||
localized: "notification.nearby.title",
|
||||
defaultValue: "👥 bitchatters nearby!",
|
||||
comment: "Lock-screen notification title when mesh peers are nearby"
|
||||
)
|
||||
let body = Self.nearbyBody(peerCount: peerCount)
|
||||
// Fixed identifier so iOS updates the existing notification instead of creating new ones
|
||||
let identifier = "network-available"
|
||||
|
||||
@ -273,4 +303,16 @@ final class NotificationService {
|
||||
categoryIdentifier: Self.nearbyCategoryID
|
||||
)
|
||||
}
|
||||
|
||||
static func nearbyBody(peerCount: Int) -> String {
|
||||
String(
|
||||
format: String(
|
||||
localized: "notification.nearby.body",
|
||||
defaultValue: "%#@people@",
|
||||
comment: "Lock-screen notification body for mesh peers nearby; %#@people@ is the peer count with plural variations"
|
||||
),
|
||||
locale: .current,
|
||||
peerCount
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@ -71,7 +71,18 @@ final class NotificationServiceTests: XCTestCase {
|
||||
service.sendPrivateMessageNotification(from: "Alice", message: "hi", peerID: peerID)
|
||||
|
||||
let request = deliverer.requests.singleValue
|
||||
XCTAssertEqual(request?.content.title, "🔒 DM from Alice")
|
||||
XCTAssertEqual(
|
||||
request?.content.title,
|
||||
String(
|
||||
format: String(
|
||||
localized: "notification.dm.title",
|
||||
defaultValue: "🔒 DM from %@",
|
||||
comment: "Lock-screen notification title for a direct message; %@ is the sender nickname"
|
||||
),
|
||||
locale: .current,
|
||||
"Alice"
|
||||
)
|
||||
)
|
||||
XCTAssertEqual(request?.content.body, "hi")
|
||||
XCTAssertEqual(request?.content.userInfo["peerID"] as? String, peerID.id)
|
||||
XCTAssertEqual(request?.content.userInfo["senderName"] as? String, "Alice")
|
||||
@ -114,7 +125,23 @@ final class NotificationServiceTests: XCTestCase {
|
||||
XCTAssertTrue(deliverer.requests[0].identifier.hasPrefix("geo-activity-87yv-"))
|
||||
XCTAssertEqual(deliverer.requests[1].identifier, "network-available")
|
||||
XCTAssertEqual(deliverer.requests[1].content.interruptionLevel, .timeSensitive)
|
||||
XCTAssertEqual(deliverer.requests[1].content.body, "2 people around")
|
||||
XCTAssertEqual(
|
||||
deliverer.requests[1].content.body,
|
||||
NotificationService.nearbyBody(peerCount: 2)
|
||||
)
|
||||
}
|
||||
|
||||
func test_sendNetworkAvailableNotification_onePeerUsesPluralBody() {
|
||||
let deliverer = RecordingNotificationRequestDeliverer()
|
||||
let service = NotificationService(
|
||||
isRunningTestsProvider: { false },
|
||||
authorizer: RecordingNotificationAuthorizer(),
|
||||
requestDeliverer: deliverer
|
||||
)
|
||||
|
||||
service.sendNetworkAvailableNotification(peerCount: 1)
|
||||
|
||||
XCTAssertEqual(deliverer.requests.singleValue?.content.body, NotificationService.nearbyBody(peerCount: 1))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user