From e9fb93da7b8c02e9d2c62d23c6cfc281c3243f11 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=83=9E=E3=83=AA=E3=82=A6=E3=82=B9?= Date: Thu, 5 Jan 2023 00:23:44 -0500 Subject: [PATCH] Added capability checks to replies, reply create --- ui/windows/postshow/handlers.go | 14 ++++++++++++++ ui/windows/postshow/view.go | 6 +++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/ui/windows/postshow/handlers.go b/ui/windows/postshow/handlers.go index 62c04a6..e7baae0 100644 --- a/ui/windows/postshow/handlers.go +++ b/ui/windows/postshow/handlers.go @@ -1,6 +1,7 @@ package postshow import ( + "errors" "strconv" "github.com/charmbracelet/bubbles/viewport" @@ -18,6 +19,19 @@ func handleReply(mi interface{}) (bool, []tea.Cmd) { m.tk.CacheView(m) + caps := (*m.ctx.Systems[m.activePost.SysIDX]).GetCapabilities() + if !caps.IsCapableOf("create:reply") { + cmds = append(cmds, cmd.New( + cmd.MsgError, + WIN_ID, + cmd.Arg{ + Name: "error", + Value: errors.New("This system doesn't support replies yet!"), + }, + ).Tea()) + return true, cmds + } + if m.buffer != "" { replyToIdx, err = strconv.Atoi(m.buffer) diff --git a/ui/windows/postshow/view.go b/ui/windows/postshow/view.go index 2b1b0bb..8d1c048 100644 --- a/ui/windows/postshow/view.go +++ b/ui/windows/postshow/view.go @@ -65,7 +65,11 @@ func (m *Model) renderViewport(p *post.Post) string { m.replyIDs = []string{p.ID} m.activePost = p - out += m.renderReplies(0, p.Author.Name, &p.Replies) + + caps := (*m.ctx.Systems[p.SysIDX]).GetCapabilities() + if caps.IsCapableOf("list:replies") { + out += m.renderReplies(0, p.Author.Name, &p.Replies) + } return out }