tinyrelayfile
tinyrelay/tinyclient/collaboration.go/

tinyclient/collaboration.go raw
1package tinyclient
2
3import "encoding/json"
4
5// The in-process backend can return typed slices inside a map. Normalize the
6// slice before handing it to templates, just as a JSON client would receive it.
7func collaborationSlice(value any, field string) []any {
8 items := valueMap(value)[field]
9 if rows, ok := items.([]any); ok {
10 return rows
11 }
12 var rows []any
13 encoded, err := json.Marshal(items)
14 if err == nil {
15 _ = json.Unmarshal(encoded, &rows)
16 }
17 return rows
18}
19
20func collaborationItems(value any) []any { return collaborationSlice(value, "items") }
21func collaborationReplies(value any) []any { return collaborationSlice(value, "replies") }
22
23// collaborationProposalView is how an issue, pull request or comment's
24// proposal state reads for one viewer, with what the decision buttons need.
25// Shown, Decide, State, At and By follow wikiProposalView.
26type collaborationProposalView struct {
27 wikiProposalView
28 ID, Author, Kind string
29}
30
31// collaborationProposal reads an item's proposal state for the viewer. The
32// item is a list or detail item, whose author is under author, or a reply,
33// whose author is under pubkey. canApprove is the browse result's
34// can_approve flag.
35func collaborationProposal(item any, actor string, canApprove any) collaborationProposalView {
36 m := valueMap(item)
37 if m == nil || m["proposal"] != true {
38 return collaborationProposalView{}
39 }
40 author := plainString(m["author"])
41 if author == "" {
42 author = plainString(m["pubkey"])
43 }
44 view := collaborationProposalView{ID: plainString(m["id"]), Author: author, Kind: plainString(m["kind"])}
45 view.wikiProposalView = wikiProposal(map[string]any{"proposal": true, "author": author, "approval": m["approval"], "approval_at": m["approval_at"], "approval_by": m["approval_by"]}, actor, canApprove)
46 return view
47}
48
49func collaborationLabels(value any) []string {
50 var labels []string
51 encoded, err := json.Marshal(valueMap(value)["labels"])
52 if err == nil {
53 _ = json.Unmarshal(encoded, &labels)
54 }
55 return labels
56}

About

ownerc01503e8035f
visibilitypublic
headd730679639bf

Maintainers

  • c01503e8035f owner
  • ba1b5beed5b5 agent hermes

Clone

  • https://012.run/npub1cq2s86qrtadf36eqq3epm38wmhdynrrcwxf84eldk3f94dkv7ttsrulrz5/tinyrelay.git

Refs