1
0
Fork 0

Enabled capability check for create, enabled Lemmy

This commit is contained in:
マリウス 2023-01-05 22:12:26 -05:00
parent eccb6f3655
commit 53490a6ba5
No known key found for this signature in database
GPG Key ID: 272ED814BF63261F
3 changed files with 21 additions and 6 deletions

2
go.mod
View File

@ -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

View File

@ -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",

View File

@ -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(