Monorepo for Tangled
tangled.org
1package models
2
3import (
4 "fmt"
5 "time"
6
7 "github.com/bluesky-social/indigo/atproto/syntax"
8
9 "tangled.org/core/api/tangled"
10)
11
12type ReactionKind string
13
14const (
15 Like ReactionKind = "👍"
16 Unlike ReactionKind = "👎"
17 Laugh ReactionKind = "😆"
18 Celebration ReactionKind = "🎉"
19 Confused ReactionKind = "🫤"
20 Heart ReactionKind = "❤️"
21 Rocket ReactionKind = "🚀"
22 Eyes ReactionKind = "👀"
23)
24
25func (rk ReactionKind) String() string {
26 return string(rk)
27}
28
29var OrderedReactionKinds = []ReactionKind{
30 Like,
31 Unlike,
32 Laugh,
33 Celebration,
34 Confused,
35 Heart,
36 Rocket,
37 Eyes,
38}
39
40func ParseReactionKind(raw string) (ReactionKind, bool) {
41 k, ok := (map[string]ReactionKind{
42 "👍": Like,
43 "👎": Unlike,
44 "😆": Laugh,
45 "🎉": Celebration,
46 "🫤": Confused,
47 "❤️": Heart,
48 "🚀": Rocket,
49 "👀": Eyes,
50 })[raw]
51 return k, ok
52}
53
54type Reaction struct {
55 ReactedByDid string
56 ThreadAt syntax.ATURI
57 Created time.Time
58 Rkey string
59 Kind ReactionKind
60}
61
62type ReactionDisplayData struct {
63 Count int
64 Users []string
65}
66
67func NormalizeReactionSubject(subject syntax.ATURI) syntax.ATURI {
68 switch subject.Collection() {
69 case tangled.RepoIssueCommentNSID, tangled.RepoPullCommentNSID:
70 return syntax.ATURI(fmt.Sprintf("at://%s/%s/%s", subject.Authority(), tangled.FeedCommentNSID, subject.RecordKey()))
71 }
72 return subject
73}