clone

a self-hosted multitenant nostr relay with sites, file storage, git hosting, and inbox and outbox delivery

feat/ui-updates
tinyrelay / tinyclient / collaboration.go
collaboration.go 2.0K
1package tinyclient23import "encoding/json"45// The in-process backend can return typed slices inside a map. Normalize the6// 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 rows11 }12 var rows []any13 encoded, err := json.Marshal(items)14 if err == nil {15 _ = json.Unmarshal(encoded, &rows)16 }17 return rows18}1920func collaborationItems(value any) []any { return collaborationSlice(value, "items") }21func collaborationReplies(value any) []any { return collaborationSlice(value, "replies") }2223// collaborationProposalView is how an issue, pull request or comment's24// 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 wikiProposalView28 ID, Author, Kind string29}3031// collaborationProposal reads an item's proposal state for the viewer. The32// 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's34// 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 view47}4849func collaborationLabels(value any) []string {50 var labels []string51 encoded, err := json.Marshal(valueMap(value)["labels"])52 if err == nil {53 _ = json.Unmarshal(encoded, &labels)54 }55 return labels56}