A vibe coded tangled fork which supports pijul.
at sl/tap-appview 97 lines 2.0 kB view raw
1package models 2 3import ( 4 "fmt" 5 "time" 6 7 "github.com/bluesky-social/indigo/atproto/syntax" 8 "tangled.org/core/api/tangled" 9) 10 11type ReactionKind string 12 13const ( 14 Like ReactionKind = "👍" 15 Unlike ReactionKind = "👎" 16 Laugh ReactionKind = "😆" 17 Celebration ReactionKind = "🎉" 18 Confused ReactionKind = "🫤" 19 Heart ReactionKind = "❤️" 20 Rocket ReactionKind = "🚀" 21 Eyes ReactionKind = "👀" 22) 23 24func (rk ReactionKind) String() string { 25 return string(rk) 26} 27 28var OrderedReactionKinds = []ReactionKind{ 29 Like, 30 Unlike, 31 Laugh, 32 Celebration, 33 Confused, 34 Heart, 35 Rocket, 36 Eyes, 37} 38 39func ParseReactionKind(raw string) (ReactionKind, bool) { 40 k, ok := (map[string]ReactionKind{ 41 "👍": Like, 42 "👎": Unlike, 43 "😆": Laugh, 44 "🎉": Celebration, 45 "🫤": Confused, 46 "❤️": Heart, 47 "🚀": Rocket, 48 "👀": Eyes, 49 })[raw] 50 return k, ok 51} 52 53type Reaction struct { 54 ReactedByDid string 55 ThreadAt syntax.ATURI 56 Created time.Time 57 Rkey string 58 Kind ReactionKind 59} 60 61func (r *Reaction) AsRecord() tangled.FeedReaction { 62 return tangled.FeedReaction{ 63 Subject: r.ThreadAt.String(), 64 Reaction: r.Kind.String(), 65 CreatedAt: r.Created.Format(time.RFC3339), 66 } 67} 68 69func ReactionFromRecord(did syntax.DID, rkey syntax.RecordKey, record tangled.FeedReaction) (Reaction, error) { 70 subjectAt, err := syntax.ParseATURI(record.Subject) 71 if err != nil { 72 return Reaction{}, fmt.Errorf("subject should be valid at-uri: %w", err) 73 } 74 75 kind, ok := ParseReactionKind(record.Reaction) 76 if !ok { 77 return Reaction{}, fmt.Errorf("invalid reaction kind '%s'", record.Reaction) 78 } 79 80 created, err := time.Parse(time.RFC3339, record.CreatedAt) 81 if err != nil { 82 return Reaction{}, fmt.Errorf("invalid time format '%s'", record.CreatedAt) 83 } 84 85 return Reaction{ 86 ReactedByDid: did.String(), 87 Rkey: rkey.String(), 88 ThreadAt: subjectAt, 89 Kind: kind, 90 Created: created, 91 }, nil 92} 93 94type ReactionDisplayData struct { 95 Count int 96 Users []string 97}