Skip to content
This repository has been archived by the owner on Aug 11, 2024. It is now read-only.

Fetch basic user metadata from SQLite if available #925

Merged
merged 28 commits into from
Oct 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
886449f
Cache our profile data
bfollington Oct 5, 2023
fe865fa
Improve time to first render & resilience of profile
bfollington Oct 5, 2023
fc541b9
Model loading status explicitly for feed
bfollington Oct 5, 2023
d00bfcc
Drop .resolutionStatus from UserProfile
bfollington Oct 5, 2023
e419a30
Load profiles from DB
bfollington Oct 6, 2023
2dbe11a
Guarantee we always know the DID of a user
bfollington Oct 10, 2023
36b50f2
Fix navigation
bfollington Oct 10, 2023
6c9b1eb
Fix duplicate follows
bfollington Oct 10, 2023
77a8f01
Remove comments
bfollington Oct 10, 2023
40dee23
Show alias for our profile
bfollington Oct 10, 2023
326f8f8
Add tests for alias calculation
bfollington Oct 10, 2023
b3ec16b
Restore dropped comment
bfollington Oct 10, 2023
537f8cd
Drop unused action
bfollington Oct 10, 2023
0806460
Formatting
bfollington Oct 10, 2023
8830916
Avoid hardcoding profile slug
bfollington Oct 10, 2023
22e3cc5
Formatting and cleanup
bfollington Oct 10, 2023
463b805
Drop author from EntryStub
bfollington Oct 11, 2023
2cfea03
Drop in-memory cache
bfollington Oct 11, 2023
5e2d734
Assert DID is correct in listRecent
bfollington Oct 11, 2023
3b7cf40
Add test for readRandomEntryInDateRange
bfollington Oct 11, 2023
9c7491f
Restore .toLink()? calls
bfollington Oct 11, 2023
5c38fc5
Introduce testReadRandomEntryMatching
bfollington Oct 11, 2023
541d13b
Test readUserProfile
bfollington Oct 11, 2023
80cbd87
Test identifyUser (many ways)
bfollington Oct 11, 2023
938703f
Constrain contract on identifyUser to take Petname? instead of Peer?
bfollington Oct 11, 2023
8a4f5fe
Rename tests
bfollington Oct 11, 2023
55bcf5c
Remove `writeTestData`
bfollington Oct 11, 2023
12a68bf
Remove comment
bfollington Oct 11, 2023
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
16 changes: 7 additions & 9 deletions xcode/Subconscious/Shared/Components/BacklinksView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@ struct BacklinksView: View {
if backlinks.count > 0 {
ForEach(backlinks) { entry in
TranscludeView(
author: entry.author,
address: entry.address,
excerpt: entry.excerpt,
entry: entry,
action: {
onSelect(EntryLink(entry))
}
Expand Down Expand Up @@ -52,22 +50,22 @@ struct BacklinksView_Previews: PreviewProvider {
BacklinksView(
backlinks: [
EntryStub(
did: Did.dummyData(),
address: Slashlink("@handle/short")!,
excerpt: "Short",
modified: Date.now,
author: UserProfile.dummyData()
modified: Date.now
),
EntryStub(
did: Did.dummyData(),
address: Slashlink("/loomings")!,
excerpt: "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi.",
modified: Date.now,
author: UserProfile.dummyData()
modified: Date.now
),
EntryStub(
did: Did.dummyData(),
address: Slashlink(slug: Slug(formatting: "The Lee Shore")!),
excerpt: "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi.",
modified: Date.now,
author: UserProfile.dummyData()
modified: Date.now
)
],
onSelect: { title in }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@
import SwiftUI

public enum NameVariant {
case petname(Slashlink, Petname.Name)
case proposedName(Slashlink, Petname.Name)
case selfNickname(Slashlink, Petname.Name)
case known(Slashlink, Petname.Name)
case unknown(Slashlink, Petname.Name)
}

extension UserProfile {
Expand All @@ -22,13 +21,13 @@ extension UserProfile {
self.address.petname?.leaf
) {
case (.ourself, _, .some(let selfNickname), _):
return NameVariant.petname(Slashlink.ourProfile, selfNickname)
return NameVariant.known(Slashlink.ourProfile, selfNickname)
case (_, .following(let petname), _, _):
return NameVariant.petname(self.address, petname)
return NameVariant.known(self.address, petname)
case (_, .notFollowing, .some(let selfNickname), _):
return NameVariant.selfNickname(self.address, selfNickname)
return NameVariant.unknown(self.address, selfNickname)
case (_, .notFollowing, _, .some(let proposedName)):
return NameVariant.proposedName(self.address, proposedName)
return NameVariant.unknown(self.address, proposedName)
Comment on lines +24 to +30
Copy link
Collaborator Author

@bfollington bfollington Oct 10, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Simplified the modelling for name display, we either know a user or we don't.

If we know them, we use our name for them falling back to their nickname for themselves. If we don't know them, we use their nickname (if available) or fall back to the leaf of their current address.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the clarity, however, I want to note that this loses us information.

It seems likely at some point we will want to be able to distinguish proposed names from self-proposed names (https://github.com/cwebber/rebooting-the-web-of-trust-spring2018/blob/petnames/draft-documents/petnames.md). For example,

  • We may want to prefer a self-proposed name to a 3p-proposed name when following and suggesting a name.
  • (Speculative) We may wish, in future, to show the user's self-proposed name in context menus or place a badge next to self-proposed names to show user's preferred name.

Copy link
Collaborator Author

@bfollington bfollington Oct 11, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It doesn't actually lose us any information in the model itself, just in the mapping to an (under utilized) view construct. We were rendering proposedName and selfNickname identically before this change so nothing visibly changes as a result of this.

If the kind of cases you point out do arise, we can derive all that we need from a UserProfile regardless.

case _:
return nil
}
Expand Down Expand Up @@ -68,7 +67,7 @@ struct PetnameView: View {

var uniqueAliases: [Petname] {
switch name {
case .petname(_, let name):
case .known(_, let name):
return aliases.filter { alias in
name != alias.leaf
}
Expand All @@ -80,16 +79,15 @@ struct PetnameView: View {
var body: some View {
VStack(alignment: .leading, spacing: AppTheme.unit) {
switch name {
case .petname(_, let name):
case .known(_, let name):
Text(name.toPetname().markup)
.fontWeight(.medium)
.foregroundColor(.accentColor)

if !uniqueAliases.isEmpty {
AliasView(aliases: uniqueAliases)
}
case .selfNickname(let address, let name),
.proposedName(let address, let name):
case .unknown(let address, let name):
Text(showMaybePrefix
? "Maybe: \(name.description)"
: name.description
Expand All @@ -104,32 +102,24 @@ struct PetnameView: View {
}
}



struct PetnameView_Previews: PreviewProvider {
static var previews: some View {
VStack {
PetnameView(
name: .selfNickname(
Slashlink(petname: Petname("melville.bobby.tables")!),
Petname.Name("melville")!
)
)
PetnameView(
name: .proposedName(
name: .unknown(
Slashlink(petname: Petname("melville.bobby.tables")!),
Petname.Name("melville")!
),
showMaybePrefix: true
)
PetnameView(
name: .petname(
name: .known(
Slashlink(petname: Petname("robert")!),
Petname.Name("robert")!
)
)
PetnameView(
name: .petname(
name: .known(
Slashlink(petname: Petname("robert")!),
Petname.Name("robert")!
),
Expand Down
16 changes: 8 additions & 8 deletions xcode/Subconscious/Shared/Components/Common/EntryRow.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ struct EntryRow_Previews: PreviewProvider {
VStack {
EntryRow(
entry: EntryStub(
did: Did.dummyData(),
address: Slashlink(
peer: Peer.did(Did.local),
slug: Slug(formatting: "Anything that can be derived should be derived")!
Expand All @@ -57,38 +58,37 @@ struct EntryRow_Previews: PreviewProvider {
Anything that can be derived should be derived.
Insight from Rich Hickey. Practical example: all information in Git is derived. At Git's core, it is simply a linked list of annotated diffs. All commands are derived via diff/patch/apply.
""",
modified: Date.now,
author: nil
modified: Date.now
)
)
EntryRow(
entry: EntryStub(
did: Did.dummyData(),
address: Slashlink(
"@here/anything-that-can-be-derived-should-be-derived"
)!,
excerpt: "Anything that can be derived should be derived. Insight from Rich Hickey. Practical example: all information in Git is derived. At Git's core, it is simply a linked list of annotated diffs. All commands are derived via diff/patch/apply.",
modified: Date.now,
author: nil
modified: Date.now
)
)
EntryRow(
entry: EntryStub(
did: Did.dummyData(),
address: Slashlink(
"did:key:abc123/anything-that-can-be-derived-should-be-derived"
)!,
excerpt: "Anything that can be derived should be derived. Insight from Rich Hickey. Practical example: all information in Git is derived. At Git's core, it is simply a linked list of annotated diffs. All commands are derived via diff/patch/apply.",
modified: Date.now,
author: nil
modified: Date.now
)
)
EntryRow(
entry: EntryStub(
did: Did.dummyData(),
address: Slashlink(
"did:subconscious:local/anything-that-can-be-derived-should-be-derived"
)!,
excerpt: "Anything that can be derived should be derived. Insight from Rich Hickey. Practical example: all information in Git is derived. At Git's core, it is simply a linked list of annotated diffs. All commands are derived via diff/patch/apply.",
modified: Date.now,
author: nil
modified: Date.now
)
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,6 @@ struct EditProfileSheet: View {
pfp: pfp,
bio: UserProfileBio(state.bioField.validated?.text ?? ""),
category: .ourself,
resolutionStatus: .resolved(Cid("fake-for-preview")),
ourFollowStatus: .notFollowing,
aliases: []
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ struct FollowUserSheet: View {
let name = state.followUserForm.petname.validated {
HStack(spacing: AppTheme.padding) {
ProfilePic(pfp: user.pfp, size: .large)
PetnameView(name: .proposedName(user.address, name))
PetnameView(name: .unknown(user.address, name))
}

Spacer()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@ struct BylineLgView_Previews: PreviewProvider {
pfp: .image("pfp-dog"),
bio: UserProfileBio("Ploofy snooflewhumps burbled, outflonking the zibber-zabber in a traddlewaddle."),
category: .human,
resolutionStatus: .resolved("abc"),
ourFollowStatus: .notFollowing,
aliases: [Petname("alt")!]
)
Expand All @@ -128,7 +127,6 @@ struct BylineLgView_Previews: PreviewProvider {
pfp: .image("pfp-dog"),
bio: UserProfileBio("Ploofy snooflewhumps burbled, outflonking the zibber-zabber in a traddlewaddle."),
category: .geist,
resolutionStatus: .resolved(Cid("ok")),
ourFollowStatus: .following(Petname.Name("ben")!),
aliases: []
),
Expand All @@ -142,7 +140,6 @@ struct BylineLgView_Previews: PreviewProvider {
pfp: .image("pfp-dog"),
bio: UserProfileBio("Ploofy snooflewhumps burbled, outflonking the zibber-zabber in a traddlewaddle."),
category: .ourself,
resolutionStatus: .resolved(Cid("ok")),
ourFollowStatus: .notFollowing,
aliases: []
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,13 @@ struct RecentTabView: View {
var onNavigateToNote: (Slashlink) -> Void

var body: some View {
if let user = state.user {
ForEach(state.recentEntries) { entry in
StoryEntryView(
story: StoryEntry(
author: user,
entry: entry
),
action: { address, _ in onNavigateToNote(address) }
)
}
ForEach(state.recentEntries) { entry in
StoryEntryView(
story: StoryEntry(
entry: entry
),
action: { address, _ in onNavigateToNote(address) }
)
}

if state.recentEntries.count == 0 {
Expand All @@ -54,21 +51,19 @@ struct RecentTabView: View {
struct FollowTabView: View {
var state: UserProfileDetailModel
var send: (UserProfileDetailAction) -> Void
var onNavigateToUser: (UserProfile) -> Void
var onNavigateToUser: (Slashlink) -> Void
var onProfileAction: (UserProfile, UserProfileAction) -> Void

var body: some View {
ForEach(state.following) { follow in
StoryUserView(
story: follow,
action: { _ in onNavigateToUser(follow.user) },
onNavigate: {
onNavigateToUser(follow.user.address)
},
profileAction: onProfileAction,
onRefreshUser: {
guard let petname = follow.user.address.toPetname() else {
return
}

send(.requestWaitForFollowedUserResolution(petname))
send(.requestWaitForFollowedUserResolution(follow.entry.petname))
bfollington marked this conversation as resolved.
Show resolved Hide resolved
}
)
}
Expand All @@ -93,7 +88,7 @@ struct UserProfileView: View {
}

var onNavigateToNote: (Slashlink) -> Void
var onNavigateToUser: (UserProfile) -> Void
var onNavigateToUser: (Slashlink) -> Void

var onProfileAction: (UserProfile, UserProfileAction) -> Void
var onRefresh: () async -> Void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,7 @@ struct StoryComboView: View {
Text(story.prompt)

TranscludeView(
author: UserProfile.dummyData(),
address: story.entryA.address,
excerpt: story.entryA.excerpt,
entry: story.entryA,
action: {
action(
story.entryA.address,
Expand All @@ -42,9 +40,7 @@ struct StoryComboView: View {
)

TranscludeView(
author: UserProfile.dummyData(),
address: story.entryB.address,
excerpt: story.entryB.excerpt,
entry: story.entryB,
action: {
action(
story.entryB.address,
Expand Down Expand Up @@ -97,7 +93,8 @@ struct StoryComboView_Previews: PreviewProvider {
But do we have to go to distant worlds to find other kinds of replicator and other, consequent, kinds of evolution? I think that a new kind of replicator has recently emerged on this very planet. It is staring us in the face.
"""
)
)
),
did: Did.dummyData()
),
entryB: EntryStub(
MemoEntry(
Expand All @@ -117,7 +114,8 @@ struct StoryComboView_Previews: PreviewProvider {
But do we have to go to distant worlds to find other kinds of replicator and other, consequent, kinds of evolution? I think that a new kind of replicator has recently emerged on this very planet. It is staring us in the face.
"""
)
)
),
did: Did.dummyData()
)
),
action: { link, fallback in }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,8 @@ struct StoryEntryView: View {

HStack(alignment: .center, spacing: AppTheme.unit) {
BylineSmView(
pfp: story.author.pfp,
slashlink: Slashlink(
peer: story.author.address.peer,
slug: story.entry.address.slug
)
pfp: .generated(story.entry.did),
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is all we were using author for, which can be derived from just the DID.

slashlink: story.entry.address
)

Spacer()
Expand Down Expand Up @@ -68,7 +65,6 @@ struct StoryPlainView_Previews: PreviewProvider {
static var previews: some View {
StoryEntryView(
story: StoryEntry(
author: UserProfile.dummyData(),
entry: EntryStub(
MemoEntry(
address: Slashlink("@here/meme")!,
Expand All @@ -84,7 +80,8 @@ struct StoryPlainView_Previews: PreviewProvider {
But do we have to go to distant worlds to find other kinds of replicator and other, consequent, kinds of evolution? I think that a new kind of replicator has recently emerged on this very planet. It is staring us in the face.
"""
)
)
),
did: Did.dummyData()
)
),
action: { _, _ in }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,7 @@ struct StoryPromptView: View {
VStack(alignment: .leading, spacing: AppTheme.unit4) {
Text(story.prompt)
TranscludeView(
author: UserProfile.dummyData(),
address: story.entry.address,
excerpt: story.entry.excerpt,
entry: story.entry,
action: {
action(
story.entry.address,
Expand Down Expand Up @@ -82,7 +80,8 @@ struct StoryPromptView_Previews: PreviewProvider {
But do we have to go to distant worlds to find other kinds of replicator and other, consequent, kinds of evolution? I think that a new kind of replicator has recently emerged on this very planet. It is staring us in the face.
"""
)
)
),
did: Did.dummyData()
),
prompt: "Can I invert this?"
),
Expand Down
Loading
Loading