Allow unsharing, only show share controls for owner

This commit is contained in:
Maximilian Friedersdorff 2025-10-09 21:04:45 +01:00
parent a54abeaea2
commit 4fb4bec5a8
3 changed files with 60 additions and 15 deletions

View file

@ -40,8 +40,10 @@ type Note struct {
LastModified time.Time
}
type noteSet map[*Note]bool
type NoteStore struct {
notes map[string][]*Note
notes map[string]noteSet
}
var (
@ -51,7 +53,7 @@ var (
func Init() error {
Notes = NoteStore{
notes: make(map[string][]*Note),
notes: make(map[string]noteSet),
}
md = goldmark.New(
@ -95,14 +97,14 @@ func Init() error {
return nil
}
func (ns *NoteStore) Get(owner string) []*Note {
func (ns *NoteStore) Get(owner string) noteSet {
return ns.notes[owner]
}
func (ns *NoteStore) GetOne(owner string, uid string) (*Note, bool) {
notes := ns.Get(owner)
for _, note := range notes {
for note, _ := range notes {
if note.Uid == uid {
log.Printf("Found single note during GetOne %s", note.Title)
return note, true
@ -112,7 +114,14 @@ func (ns *NoteStore) GetOne(owner string, uid string) (*Note, bool) {
}
func (ns *NoteStore) Add(note *Note, user string) {
ns.notes[user] = append(ns.notes[user], note)
if ns.notes[user] == nil {
ns.notes[user] = make(noteSet)
}
ns.notes[user][note] = true
}
func (ns *NoteStore) Del(note *Note, user string) {
delete(ns.notes[user], note)
}
func fmtPath(path string) string {
@ -268,6 +277,10 @@ func (n *Note) AddViewer(viewer string) {
n.Viewers[viewer] = struct{}{}
}
func (n *Note) DelViewer(viewer string) {
delete(n.Viewers, viewer)
}
func DeleteNote(uid string) error {
filename := filepath.Join(conf.Conf.NotesDir, fmtPath(uid))
return os.Remove(filename)