making use of the extended perms and added future work

This commit is contained in:
ari committed 2026-11-01 13:55:25 -05:00
1 parent 296e465f48
commit 22fd8fbce8
19 files changed
+617 -40

No files matched your search

+46 -3
View File
@@ -16,9 +16,10 @@ type Store struct {
path string
mu sync.Mutex
data struct {
Owners map[string]*model.Owner `json:"owners"`
Sessions map[string]*model.Session `json:"sessions"`
Permissions *model.PermissionsConfig `json:"permissions,omitempty"`
Owners map[string]*model.Owner `json:"owners"`
Sessions map[string]*model.Session `json:"sessions"`
Permissions *model.PermissionsConfig `json:"permissions,omitempty"`
Listen map[string]model.ListenMode `json:"listen,omitempty"`
}
}
@@ -26,6 +27,7 @@ func Open(path string) (*Store, error) {
s := &Store{path: path}
s.data.Owners = map[string]*model.Owner{}
s.data.Sessions = map[string]*model.Session{}
s.data.Listen = map[string]model.ListenMode{}
b, err := os.ReadFile(path)
if errors.Is(err, os.ErrNotExist) {
@@ -43,6 +45,9 @@ func Open(path string) (*Store, error) {
if s.data.Sessions == nil {
s.data.Sessions = map[string]*model.Session{}
}
if s.data.Listen == nil {
s.data.Listen = map[string]model.ListenMode{}
}
return s, nil
}
@@ -220,6 +225,44 @@ func (s *Store) AddSession(x *model.Session) error {
return s.save()
}
func (s *Store) SetSessionListen(channel, threadTS string, mode model.ListenMode) error {
s.mu.Lock()
defer s.mu.Unlock()
if x, ok := s.data.Sessions[sessionKey(channel, threadTS)]; ok {
x.Listen = mode
return s.save()
}
return nil
}
func (s *Store) ChannelListen(channel string) model.ListenMode {
s.mu.Lock()
defer s.mu.Unlock()
if mode, ok := s.data.Listen[channel]; ok {
return mode
}
return model.ListenMentions
}
func (s *Store) SetChannelListen(channel string, mode model.ListenMode) error {
s.mu.Lock()
defer s.mu.Unlock()
if mode == model.ListenMentions {
delete(s.data.Listen, channel)
} else {
s.data.Listen[channel] = mode
}
return s.save()
}
// What a thread uses: its own setting if it has one, else the channel's.
func (s *Store) ThreadListen(channel, threadTS string) model.ListenMode {
if x := s.Session(channel, threadTS); x != nil && x.Listen != "" {
return x.Listen
}
return s.ChannelListen(channel)
}
func (s *Store) Sessions(ownerID string, limit int) []model.Session {
s.mu.Lock()
defer s.mu.Unlock()