diff --git a/go.mod b/go.mod index dee5b35..1968802 100644 --- a/go.mod +++ b/go.mod @@ -13,6 +13,7 @@ require ( github.com/hashicorp/go-retryablehttp v0.7.2 github.com/hermanschaaf/hackernews v1.0.1 github.com/mattn/go-runewidth v0.0.14 + github.com/mergestat/timediff v0.0.3 github.com/muesli/ansi v0.0.0-20221106050444-61f0cd9a192a github.com/muesli/reflow v0.3.0 github.com/muesli/termenv v0.13.0 @@ -46,7 +47,6 @@ require ( github.com/magiconair/properties v1.8.7 // indirect github.com/mattn/go-isatty v0.0.17 // indirect github.com/mattn/go-localereader v0.0.1 // indirect - github.com/mergestat/timediff v0.0.3 // indirect github.com/microcosm-cc/bluemonday v1.0.21 // indirect github.com/mitchellh/mapstructure v1.5.0 // indirect github.com/muesli/cancelreader v0.2.2 // indirect diff --git a/system/lemmy/lemmy.go b/system/lemmy/lemmy.go index 615e148..9aa02ac 100644 --- a/system/lemmy/lemmy.go +++ b/system/lemmy/lemmy.go @@ -55,11 +55,10 @@ func (sys *System) GetCapabilities() adapter.Capabilities { ID: "list:posts", Name: "List Posts", }, - // TODO - // adapter.Capability{ - // ID: "create:post", - // Name: "Create Post", - // }, + adapter.Capability{ + ID: "create:post", + Name: "Create Post", + }, adapter.Capability{ ID: "list:replies", Name: "List Replies", diff --git a/ui/views/posts/posts.go b/ui/views/posts/posts.go index 6d2a625..56fdaab 100644 --- a/ui/views/posts/posts.go +++ b/ui/views/posts/posts.go @@ -1,6 +1,7 @@ package posts import ( + "errors" "strings" "github.com/charmbracelet/bubbles/key" @@ -110,6 +111,21 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { case key.Matches(msg, m.keymap.NewPost): i, ok := m.list.SelectedItem().(post.Post) if ok { + caps := (*m.ctx.Systems[i.SysIDX]).GetCapabilities() + if !caps.IsCapableOf("create:post") { + cmds = append(cmds, cmd.New( + cmd.MsgError, + VIEW_ID, + cmd.Arg{ + Name: "error", + Value: errors.New( + "This system doesn't support posting yet!\n", + ), + }, + ).Tea()) + return m, tea.Batch(cmds...) + } + m.focused = false // TODO: Refactor and use ToolKit m.viewcache = m.buildView(false) cmd := cmd.New(