Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions Bitkit/Managers/PubkyProfileManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,7 @@ class PubkyProfileManager: ObservableObject {
tags: [String] = [],
existingImageUrl: String? = nil,
baseRevision: String? = nil,
baseTagsUnread: Bool = false,
avatarImage: UIImage? = nil,
loadStoredSecretKey: () async throws -> String? = {
await Task.detached { PubkyProfileManager.activeSecretKeyHex() }.value
Expand All @@ -501,6 +502,7 @@ class PubkyProfileManager: ObservableObject {
tags: tags,
existingImageUrl: existingImageUrl,
baseRevision: baseRevision,
baseTagsUnread: baseTagsUnread,
avatarImage: avatarImage
)
return
Expand Down Expand Up @@ -536,6 +538,7 @@ class PubkyProfileManager: ObservableObject {
tags: tags,
existingImageUrl: existingImageUrl,
baseRevision: baseRevision,
baseTagsUnread: baseTagsUnread,
avatarImage: avatarImage
)
},
Expand Down Expand Up @@ -755,6 +758,7 @@ class PubkyProfileManager: ObservableObject {
tags: [String],
existingImageUrl: String?,
baseRevision: String?,
baseTagsUnread: Bool,
avatarImage: UIImage?
) async throws {
var avatarUri: String?
Expand All @@ -771,6 +775,7 @@ class PubkyProfileManager: ObservableObject {
links: links,
tags: tags,
baseRevision: baseRevision,
baseTagsUnread: baseTagsUnread,
expectedIdentity: publicKey
)
if tagsNotSavedAt != nil {
Expand Down
1 change: 1 addition & 0 deletions Bitkit/Views/Profile/CreateProfileView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ struct CreateProfileView: View {
tags: existingProfile?.tags ?? [],
existingImageUrl: existingProfile?.imageUrl,
baseRevision: existingProfile?.revision,
baseTagsUnread: existingProfile?.tagsUnread ?? false,
avatarImage: avatarImage
)
navigation.navigate(.payContacts)
Expand Down
44 changes: 44 additions & 0 deletions BitkitTests/PubkyProfileManagerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1313,6 +1313,50 @@ final class PubkyProfileManagerTests: XCTestCase {
}
}

@MainActor
func testCreateIdentityPreservesUnreadTagsFromTheRestoreFormAfterRefresh() async throws {
try await withRestoredProfileDefaults {
UserDefaults.standard.set(true, forKey: "pubky_profile_setup_pending")
var unread = makeProfile(publicKey: ringKeyA, name: "Alice")
unread.revision = "restored-revision"
unread.tagsUnread = true
let stub = RemoteProfileStub(profiles: [ringKeyA: unread])
let publications = ProfilePublications()
let manager = PubkyProfileManager(
remoteProfileResolver: { try await stub.resolve($0) },
profilePublisher: { try await publications.publish($0, expectedIdentity: $1) }
)
manager.publicKey = ringKeyA
await manager.loadProfile()
let restored = try XCTUnwrap(manager.profile)
XCTAssertTrue(restored.tagsUnread)
XCTAssertTrue(restored.tags.isEmpty)

let refreshed = unread.withTags(["friend", "work"])
var readable = refreshed
readable.tagsUnread = false
await stub.setProfile(readable, for: ringKeyA)
await manager.loadProfile()
XCTAssertEqual(manager.profile?.tags, ["friend", "work"])
XCTAssertEqual(manager.profile?.tagsUnread, false)

try await manager.createIdentity(
name: "Renamed",
bio: restored.bio,
links: restored.links,
tags: restored.tags,
baseRevision: restored.revision,
baseTagsUnread: restored.tagsUnread
)

let published = await publications.published
let profile = try XCTUnwrap(published.first)
XCTAssertEqual(published.count, 1)
XCTAssertEqual(profile.baseRevision, "restored-revision")
XCTAssertTrue(profile.baseTagsUnread, "The store must preserve the tags the restore form could not show")
}
}

@MainActor
func testSignupDoesNotRestoreProfileStateAfterWalletReset() async throws {
snapshotAppDefaultsDomain()
Expand Down
1 change: 1 addition & 0 deletions changelog.d/next/1303.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Restoring a Pubky profile preserves its saved tags when the profile initially loads without them.
Loading