Skip to content

Commit 9075c4f

Browse files
square-tombclaude
andcommitted
fix(mobile): drop the # from Solo chat names in push notifications
The notification extension titled every stream and forum conversation #name, including Solo chats, which the app presents as personal chats rather than channels. Cache whether relay metadata marks a channel as Solo (a private stream labelled buzz.solo, matching Channel.isSolo) and use the bare name for those conversations. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Tom Brow <[email protected]>
1 parent fa395e9 commit 9075c4f

4 files changed

Lines changed: 103 additions & 0 deletions

File tree

‎mobile/ios/BuzzPushKit/Sources/BuzzPushKit/BuzzPushNotificationResolver.swift‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -462,6 +462,9 @@ public final class BuzzPushNotificationResolver: BuzzPushNotificationResolving {
462462
channelType: metadataEvent.map {
463463
BuzzPushPresentationCacheStore.normalizedChannelType(tagValue("t", in: $0))
464464
} ?? cached?.channelType,
465+
isSolo: metadataEvent.map {
466+
BuzzPushPresentationCacheStore.isSoloChannel($0)
467+
} ?? cached?.isSolo,
465468
memberCount: membership?.count ?? cached?.memberCount,
466469
memberDigests: membership?.digests ?? cached?.memberDigests,
467470
membershipEventID: acceptedMembershipEvent?.id ?? cached?.membershipEventID,
@@ -508,6 +511,8 @@ public final class BuzzPushNotificationResolver: BuzzPushNotificationResolving {
508511
["stream", "forum"].contains(channelType),
509512
let displayName = channel.displayName
510513
else { return nil }
514+
// Solo chats are personal conversations, not channels, so they get no `#`.
515+
if channel.isSolo == true { return (displayName, recipientCount) }
511516
return (displayName.hasPrefix("#") ? displayName : "#\(displayName)", recipientCount)
512517
}
513518

‎mobile/ios/BuzzPushKit/Sources/BuzzPushKit/BuzzPushPresentationCache.swift‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ public struct BuzzPushCachedChannel: Codable, Equatable, Sendable {
4545
public let displayName: String?
4646
/// Relay-verified Buzz channel type, when recognized.
4747
public let channelType: String?
48+
/// Whether relay metadata marks this as a private Solo stream (`buzz.solo` label).
49+
public let isSolo: Bool?
4850
/// Exact unique-member count when bounded, or a value above the bound when oversized.
4951
public let memberCount: Int?
5052
/// Complete community-and-channel-scoped member digests, when within bounds.
@@ -66,6 +68,7 @@ public struct BuzzPushCachedChannel: Codable, Equatable, Sendable {
6668
relayMetadataPubkey: String,
6769
displayName: String?,
6870
channelType: String? = nil,
71+
isSolo: Bool? = nil,
6972
memberCount: Int? = nil,
7073
memberDigests: [String]? = nil,
7174
membershipEventID: String? = nil,
@@ -81,6 +84,7 @@ public struct BuzzPushCachedChannel: Codable, Equatable, Sendable {
8184
self.relayMetadataPubkey = relayMetadataPubkey
8285
self.displayName = displayName
8386
self.channelType = channelType
87+
self.isSolo = isSolo
8488
self.memberCount = memberCount
8589
self.memberDigests = memberDigests
8690
self.membershipEventID = membershipEventID
@@ -327,6 +331,7 @@ public final class BuzzPushPresentationCacheStore: @unchecked Sendable {
327331
relayMetadataPubkey: normalizedRelayPubkey,
328332
displayName: Self.normalizedDisplayName(Self.tagValue("name", in: event)),
329333
channelType: Self.normalizedChannelType(Self.tagValue("t", in: event)),
334+
isSolo: Self.isSoloChannel(event),
330335
memberCount: hasCurrentAuthority ? existing?.memberCount : nil,
331336
memberDigests: hasCurrentAuthority ? existing?.memberDigests : nil,
332337
membershipEventID: hasCurrentAuthority ? existing?.membershipEventID : nil,
@@ -378,6 +383,7 @@ public final class BuzzPushPresentationCacheStore: @unchecked Sendable {
378383
relayMetadataPubkey: existing.relayMetadataPubkey,
379384
displayName: existing.displayName,
380385
channelType: existing.channelType,
386+
isSolo: existing.isSolo,
381387
memberCount: membership.count,
382388
memberDigests: membership.digests,
383389
membershipEventID: event.id,
@@ -532,6 +538,16 @@ public final class BuzzPushPresentationCacheStore: @unchecked Sendable {
532538
return bounded.isEmpty ? nil : bounded
533539
}
534540

541+
/// Mirrors the app's Solo rule (`Channel.isSolo`): a private stream whose
542+
/// NIP-CL labels (every `t` after the leading type) include `buzz.solo`.
543+
static func isSoloChannel(_ event: VerifiedNostrEvent) -> Bool {
544+
let types = event.tags.filter { $0.count >= 2 && $0[0] == "t" }.map { $0[1] }
545+
let isPrivate =
546+
!event.tags.contains { $0.first == "public" }
547+
&& event.tags.contains { $0.first == "private" }
548+
return types.first == "stream" && isPrivate && types.dropFirst().contains("buzz.solo")
549+
}
550+
535551
static func normalizedChannelType(_ value: String?) -> String? {
536552
guard let value, ["stream", "forum", "dm"].contains(value) else { return nil }
537553
return value
@@ -714,6 +730,7 @@ public final class BuzzPushPresentationCacheStore: @unchecked Sendable {
714730
relayMetadataPubkey: channel.relayMetadataPubkey,
715731
displayName: channel.displayName,
716732
channelType: channel.channelType,
733+
isSolo: channel.isSolo,
717734
memberCount: channel.memberCount,
718735
memberDigests: nil,
719736
membershipEventID: channel.membershipEventID,

‎mobile/ios/BuzzPushKit/Tests/BuzzPushKitTests/BuzzPushNotificationResolverTests.swift‎

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -753,6 +753,51 @@ final class BuzzPushNotificationResolverTests: XCTestCase {
753753
XCTAssertEqual(URLProtocolStub.requests.count, 4)
754754
}
755755

756+
func testSoloChatConversationNameHasNoChannelHash() throws {
757+
let message = try Self.signedEvent(
758+
privateKey: Self.profilePrivateKey,
759+
createdAt: Self.now,
760+
kind: 9,
761+
tags: [["h", Self.channelID]],
762+
content: "Agent reply"
763+
)
764+
let channel = try Self.signedEvent(
765+
privateKey: Self.relayPrivateKey,
766+
createdAt: Self.now,
767+
kind: 39_000,
768+
tags: [
769+
["d", Self.channelID], ["name", "Trip planning"], ["t", "stream"],
770+
["t", "buzz.solo"], ["P", Self.ownPubkey], ["private"],
771+
]
772+
)
773+
let membership = try Self.signedEvent(
774+
privateKey: Self.relayPrivateKey,
775+
createdAt: Self.now,
776+
kind: 39_002,
777+
tags: [["d", Self.channelID], ["p", Self.ownPubkey], ["p", message.pubkey]]
778+
)
779+
URLProtocolStub.handler = { request in
780+
if URLProtocolStub.requests.count == 1 {
781+
return Self.response(request, status: 200, data: try JSONEncoder().encode([message]))
782+
}
783+
return Self.response(
784+
request, status: 200, data: try JSONEncoder().encode([channel, membership]))
785+
}
786+
787+
let result = try XCTUnwrap(
788+
resolve(
789+
makeResolver(
790+
communitiesData: try snapshotData([
791+
community(relayMetadataPubkey: channel.pubkey)
792+
]),
793+
now: Date(timeIntervalSince1970: TimeInterval(Self.now))
794+
)
795+
)
796+
)
797+
798+
XCTAssertEqual(result.conversationDisplayName, "Trip planning")
799+
}
800+
756801
func testMalformedAndUnverifiedRefreshFallsBackWithoutBlockingMessage() throws {
757802
let message = try Self.signedEvent(
758803
privateKey: Self.profilePrivateKey,

‎mobile/ios/BuzzPushKit/Tests/BuzzPushKitTests/BuzzPushPresentationCacheTests.swift‎

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,42 @@ struct BuzzPushPresentationCacheTests {
253253
#expect(cached.relayMetadataPubkey == relayPubkey)
254254
}
255255

256+
@Test("Channel metadata marks only private buzz.solo streams as Solo")
257+
func soloClassification() throws {
258+
let directory = try temporaryDirectory()
259+
defer { try? FileManager.default.removeItem(at: directory) }
260+
let store = BuzzPushPresentationCacheStore(containerURL: directory)
261+
let relayPubkey = try pubkey(for: relayKey)
262+
let cases: [(String, [[String]], Bool)] = [
263+
("solo", [["t", "stream"], ["t", "buzz.solo"], ["private"]], true),
264+
("open-solo", [["t", "stream"], ["t", "buzz.solo"], ["public"]], false),
265+
("forum-solo", [["t", "forum"], ["t", "buzz.solo"], ["private"]], false),
266+
("type-only", [["t", "buzz.solo"], ["private"]], false),
267+
("private", [["t", "stream"], ["private"]], false),
268+
]
269+
let events = try cases.map { id, tags, _ in
270+
try signedEvent(
271+
privateKey: relayKey, createdAt: 100, kind: 39_000,
272+
tags: [["d", id], ["name", id]] + tags)
273+
}
274+
275+
try store.updateChannels(
276+
communityID: "community-a",
277+
relayOrigin: "wss://relay.example",
278+
relayMetadataPubkey: relayPubkey,
279+
metadataEvents: events,
280+
membershipEvents: []
281+
)
282+
283+
let snapshot = try loadSnapshot(directory)
284+
for (id, _, expected) in cases {
285+
let cached = try #require(
286+
snapshot.channel(
287+
communityID: "community-a", relayOrigin: "https://relay.example", channelID: id))
288+
#expect(cached.isSolo == expected, "\(id)")
289+
}
290+
}
291+
256292
@Test("Channel membership requires the same relay authority and keeps exact scoped digests")
257293
func channelMembershipAuthorityAndOrdering() throws {
258294
let directory = try temporaryDirectory()

0 commit comments

Comments
 (0)