Skip to content

Commit 12f9343

Browse files
square-tombclaude
andcommitted
fix(mobile): keep # for Solo chats created by someone else
Match Channel.isPersonalChat: a buzz.solo stream is only a personal chat for its creator. Cache the relay-authored P creator and drop the # only when it is the current user. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Tom Brow <[email protected]>
1 parent 9075c4f commit 12f9343

4 files changed

Lines changed: 64 additions & 34 deletions

File tree

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -465,6 +465,9 @@ public final class BuzzPushNotificationResolver: BuzzPushNotificationResolving {
465465
isSolo: metadataEvent.map {
466466
BuzzPushPresentationCacheStore.isSoloChannel($0)
467467
} ?? cached?.isSolo,
468+
creatorPubkey: metadataEvent.map {
469+
BuzzPushPresentationCacheStore.normalizedCreator($0)
470+
} ?? cached?.creatorPubkey,
468471
memberCount: membership?.count ?? cached?.memberCount,
469472
memberDigests: membership?.digests ?? cached?.memberDigests,
470473
membershipEventID: acceptedMembershipEvent?.id ?? cached?.membershipEventID,
@@ -511,8 +514,12 @@ public final class BuzzPushNotificationResolver: BuzzPushNotificationResolving {
511514
["stream", "forum"].contains(channelType),
512515
let displayName = channel.displayName
513516
else { return nil }
514-
// Solo chats are personal conversations, not channels, so they get no `#`.
515-
if channel.isSolo == true { return (displayName, recipientCount) }
517+
// Your own Solo chats are personal conversations, not channels, so they
518+
// get no `#`. Like the app (`Channel.isPersonalChat`), someone else's
519+
// Solo chat you belong to stays an ordinary channel.
520+
if channel.isSolo == true, channel.creatorPubkey == currentUser {
521+
return (displayName, recipientCount)
522+
}
516523
return (displayName.hasPrefix("#") ? displayName : "#\(displayName)", recipientCount)
517524
}
518525

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ public struct BuzzPushCachedChannel: Codable, Equatable, Sendable {
4747
public let channelType: String?
4848
/// Whether relay metadata marks this as a private Solo stream (`buzz.solo` label).
4949
public let isSolo: Bool?
50+
/// Relay-authored creator (`P`), lowercased, when it is a valid pubkey.
51+
public let creatorPubkey: String?
5052
/// Exact unique-member count when bounded, or a value above the bound when oversized.
5153
public let memberCount: Int?
5254
/// Complete community-and-channel-scoped member digests, when within bounds.
@@ -69,6 +71,7 @@ public struct BuzzPushCachedChannel: Codable, Equatable, Sendable {
6971
displayName: String?,
7072
channelType: String? = nil,
7173
isSolo: Bool? = nil,
74+
creatorPubkey: String? = nil,
7275
memberCount: Int? = nil,
7376
memberDigests: [String]? = nil,
7477
membershipEventID: String? = nil,
@@ -85,6 +88,7 @@ public struct BuzzPushCachedChannel: Codable, Equatable, Sendable {
8588
self.displayName = displayName
8689
self.channelType = channelType
8790
self.isSolo = isSolo
91+
self.creatorPubkey = creatorPubkey
8892
self.memberCount = memberCount
8993
self.memberDigests = memberDigests
9094
self.membershipEventID = membershipEventID
@@ -332,6 +336,7 @@ public final class BuzzPushPresentationCacheStore: @unchecked Sendable {
332336
displayName: Self.normalizedDisplayName(Self.tagValue("name", in: event)),
333337
channelType: Self.normalizedChannelType(Self.tagValue("t", in: event)),
334338
isSolo: Self.isSoloChannel(event),
339+
creatorPubkey: Self.normalizedCreator(event),
335340
memberCount: hasCurrentAuthority ? existing?.memberCount : nil,
336341
memberDigests: hasCurrentAuthority ? existing?.memberDigests : nil,
337342
membershipEventID: hasCurrentAuthority ? existing?.membershipEventID : nil,
@@ -384,6 +389,7 @@ public final class BuzzPushPresentationCacheStore: @unchecked Sendable {
384389
displayName: existing.displayName,
385390
channelType: existing.channelType,
386391
isSolo: existing.isSolo,
392+
creatorPubkey: existing.creatorPubkey,
387393
memberCount: membership.count,
388394
memberDigests: membership.digests,
389395
membershipEventID: event.id,
@@ -548,6 +554,13 @@ public final class BuzzPushPresentationCacheStore: @unchecked Sendable {
548554
return types.first == "stream" && isPrivate && types.dropFirst().contains("buzz.solo")
549555
}
550556

557+
/// The relay-authored creator `P` tag, lowercased, when it is a valid pubkey.
558+
static func normalizedCreator(_ event: VerifiedNostrEvent) -> String? {
559+
guard let creator = tagValue("P", in: event)?.lowercased(), isHexPubkey(creator)
560+
else { return nil }
561+
return creator
562+
}
563+
551564
static func normalizedChannelType(_ value: String?) -> String? {
552565
guard let value, ["stream", "forum", "dm"].contains(value) else { return nil }
553566
return value
@@ -731,6 +744,7 @@ public final class BuzzPushPresentationCacheStore: @unchecked Sendable {
731744
displayName: channel.displayName,
732745
channelType: channel.channelType,
733746
isSolo: channel.isSolo,
747+
creatorPubkey: channel.creatorPubkey,
734748
memberCount: channel.memberCount,
735749
memberDigests: nil,
736750
membershipEventID: channel.membershipEventID,

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

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

756-
func testSoloChatConversationNameHasNoChannelHash() throws {
756+
func testOnlyOwnSoloChatConversationNameDropsChannelHash() throws {
757757
let message = try Self.signedEvent(
758758
privateKey: Self.profilePrivateKey,
759759
createdAt: Self.now,
760760
kind: 9,
761761
tags: [["h", Self.channelID]],
762762
content: "Agent reply"
763763
)
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]))
764+
// Like the app's Channel.isPersonalChat: only the viewer's own Solo chat
765+
// is personal; someone else's Solo chat stays an ordinary channel.
766+
for (creator, expected) in [
767+
(Self.ownPubkey, "Trip planning"), (message.pubkey, "#Trip planning"),
768+
] {
769+
URLProtocolStub.requests = []
770+
let channel = try Self.signedEvent(
771+
privateKey: Self.relayPrivateKey,
772+
createdAt: Self.now,
773+
kind: 39_000,
774+
tags: [
775+
["d", Self.channelID], ["name", "Trip planning"], ["t", "stream"],
776+
["t", "buzz.solo"], ["P", creator], ["private"],
777+
]
778+
)
779+
let membership = try Self.signedEvent(
780+
privateKey: Self.relayPrivateKey,
781+
createdAt: Self.now,
782+
kind: 39_002,
783+
tags: [["d", Self.channelID], ["p", Self.ownPubkey], ["p", message.pubkey]]
784+
)
785+
URLProtocolStub.handler = { request in
786+
if URLProtocolStub.requests.count == 1 {
787+
return Self.response(request, status: 200, data: try JSONEncoder().encode([message]))
788+
}
789+
return Self.response(
790+
request, status: 200, data: try JSONEncoder().encode([channel, membership]))
782791
}
783-
return Self.response(
784-
request, status: 200, data: try JSONEncoder().encode([channel, membership]))
785-
}
786792

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))
793+
let result = try XCTUnwrap(
794+
resolve(
795+
makeResolver(
796+
communitiesData: try snapshotData([
797+
community(relayMetadataPubkey: channel.pubkey)
798+
]),
799+
now: Date(timeIntervalSince1970: TimeInterval(Self.now))
800+
)
794801
)
795802
)
796-
)
797803

798-
XCTAssertEqual(result.conversationDisplayName, "Trip planning")
804+
XCTAssertEqual(result.conversationDisplayName, expected)
805+
}
799806
}
800807

801808
func testMalformedAndUnverifiedRefreshFallsBackWithoutBlockingMessage() throws {

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,8 +259,9 @@ struct BuzzPushPresentationCacheTests {
259259
defer { try? FileManager.default.removeItem(at: directory) }
260260
let store = BuzzPushPresentationCacheStore(containerURL: directory)
261261
let relayPubkey = try pubkey(for: relayKey)
262+
let creator = try pubkey(for: profileKey)
262263
let cases: [(String, [[String]], Bool)] = [
263-
("solo", [["t", "stream"], ["t", "buzz.solo"], ["private"]], true),
264+
("solo", [["t", "stream"], ["t", "buzz.solo"], ["private"], ["P", creator.uppercased()]], true),
264265
("open-solo", [["t", "stream"], ["t", "buzz.solo"], ["public"]], false),
265266
("forum-solo", [["t", "forum"], ["t", "buzz.solo"], ["private"]], false),
266267
("type-only", [["t", "buzz.solo"], ["private"]], false),
@@ -286,6 +287,7 @@ struct BuzzPushPresentationCacheTests {
286287
snapshot.channel(
287288
communityID: "community-a", relayOrigin: "https://relay.example", channelID: id))
288289
#expect(cached.isSolo == expected, "\(id)")
290+
#expect(cached.creatorPubkey == (id == "solo" ? creator : nil), "\(id)")
289291
}
290292
}
291293

0 commit comments

Comments
 (0)