From 5fe354f6421e44d72c013325f33bbe9335fa8d42 Mon Sep 17 00:00:00 2001 From: fiatjaf Date: Sun, 9 Mar 2025 00:13:30 -0300 Subject: [PATCH] fs: symlink from @me to ourselves. --- nostrfs/npubdir.go | 4 ++-- nostrfs/root.go | 31 +++++++++++++++++++++++-------- 2 files changed, 25 insertions(+), 10 deletions(-) diff --git a/nostrfs/npubdir.go b/nostrfs/npubdir.go index 8eed441..962544e 100644 --- a/nostrfs/npubdir.go +++ b/nostrfs/npubdir.go @@ -18,8 +18,8 @@ type NpubDir struct { fetched atomic.Bool } -func CreateNpubDir(ctx context.Context, parent fs.InodeEmbedder, pointer nostr.ProfilePointer) *fs.Inode { - npubdir := &NpubDir{pointer: pointer} +func CreateNpubDir(ctx context.Context, sys *sdk.System, parent fs.InodeEmbedder, pointer nostr.ProfilePointer) *fs.Inode { + npubdir := &NpubDir{ctx: ctx, sys: sys, pointer: pointer} return parent.EmbeddedInode().NewPersistentInode( ctx, npubdir, diff --git a/nostrfs/root.go b/nostrfs/root.go index 201ec70..0a30436 100644 --- a/nostrfs/root.go +++ b/nostrfs/root.go @@ -39,17 +39,32 @@ func (r *NostrRoot) OnAdd(context.Context) { return } + // add our contacts fl := r.sys.FetchFollowList(r.ctx, r.rootPubKey) - for _, f := range fl.Items { - h := r.NewPersistentInode( - r.ctx, - &NpubDir{sys: r.sys, pointer: nostr.ProfilePointer{PublicKey: f.Pubkey, Relays: []string{f.Relay}}}, - fs.StableAttr{Mode: syscall.S_IFDIR}, - ) + pointer := nostr.ProfilePointer{PublicKey: f.Pubkey, Relays: []string{f.Relay}} npub, _ := nip19.EncodePublicKey(f.Pubkey) - r.AddChild(npub, h, true) + r.AddChild( + npub, + CreateNpubDir(r.ctx, r.sys, r, pointer), + true, + ) } + + // add ourselves + npub, _ := nip19.EncodePublicKey(r.rootPubKey) + if r.GetChild(npub) == nil { + pointer := nostr.ProfilePointer{PublicKey: r.rootPubKey} + r.AddChild( + npub, + CreateNpubDir(r.ctx, r.sys, r, pointer), + true, + ) + } + + // add a link to ourselves + me := r.NewPersistentInode(r.ctx, &fs.MemSymlink{Data: []byte(npub)}, fs.StableAttr{Mode: syscall.S_IFLNK}) + r.AddChild("@me", me, true) } func (r *NostrRoot) Lookup(ctx context.Context, name string, out *fuse.EntryOut) (*fs.Inode, syscall.Errno) { @@ -66,7 +81,7 @@ func (r *NostrRoot) Lookup(ctx context.Context, name string, out *fuse.EntryOut) switch p := pointer.(type) { case nostr.ProfilePointer: - npubdir := CreateNpubDir(ctx, r, p) + npubdir := CreateNpubDir(ctx, r.sys, r, p) return npubdir, fs.OK case nostr.EventPointer: eventdir, err := FetchAndCreateEventDir(ctx, r, r.sys, p)