+14
-63
appview/db/reaction.go
+14
-63
appview/db/reaction.go
···
5
5
"time"
6
6
7
7
"github.com/bluesky-social/indigo/atproto/syntax"
8
-
)
9
-
10
-
type ReactionKind string
11
-
12
-
const (
13
-
Like ReactionKind = "๐"
14
-
Unlike ReactionKind = "๐"
15
-
Laugh ReactionKind = "๐"
16
-
Celebration ReactionKind = "๐"
17
-
Confused ReactionKind = "๐ซค"
18
-
Heart ReactionKind = "โค๏ธ"
19
-
Rocket ReactionKind = "๐"
20
-
Eyes ReactionKind = "๐"
8
+
"tangled.org/core/appview/models"
21
9
)
22
10
23
-
func (rk ReactionKind) String() string {
24
-
return string(rk)
25
-
}
26
-
27
-
var OrderedReactionKinds = []ReactionKind{
28
-
Like,
29
-
Unlike,
30
-
Laugh,
31
-
Celebration,
32
-
Confused,
33
-
Heart,
34
-
Rocket,
35
-
Eyes,
36
-
}
37
-
38
-
func ParseReactionKind(raw string) (ReactionKind, bool) {
39
-
k, ok := (map[string]ReactionKind{
40
-
"๐": Like,
41
-
"๐": Unlike,
42
-
"๐": Laugh,
43
-
"๐": Celebration,
44
-
"๐ซค": Confused,
45
-
"โค๏ธ": Heart,
46
-
"๐": Rocket,
47
-
"๐": Eyes,
48
-
})[raw]
49
-
return k, ok
50
-
}
51
-
52
-
type Reaction struct {
53
-
ReactedByDid string
54
-
ThreadAt syntax.ATURI
55
-
Created time.Time
56
-
Rkey string
57
-
Kind ReactionKind
58
-
}
59
-
60
-
func AddReaction(e Execer, reactedByDid string, threadAt syntax.ATURI, kind ReactionKind, rkey string) error {
11
+
func AddReaction(e Execer, reactedByDid string, threadAt syntax.ATURI, kind models.ReactionKind, rkey string) error {
61
12
query := `insert or ignore into reactions (reacted_by_did, thread_at, kind, rkey) values (?, ?, ?, ?)`
62
13
_, err := e.Exec(query, reactedByDid, threadAt, kind, rkey)
63
14
return err
64
15
}
65
16
66
17
// Get a reaction record
67
-
func GetReaction(e Execer, reactedByDid string, threadAt syntax.ATURI, kind ReactionKind) (*Reaction, error) {
18
+
func GetReaction(e Execer, reactedByDid string, threadAt syntax.ATURI, kind models.ReactionKind) (*models.Reaction, error) {
68
19
query := `
69
20
select reacted_by_did, thread_at, created, rkey
70
21
from reactions
71
22
where reacted_by_did = ? and thread_at = ? and kind = ?`
72
23
row := e.QueryRow(query, reactedByDid, threadAt, kind)
73
24
74
-
var reaction Reaction
25
+
var reaction models.Reaction
75
26
var created string
76
27
err := row.Scan(&reaction.ReactedByDid, &reaction.ThreadAt, &created, &reaction.Rkey)
77
28
if err != nil {
···
90
41
}
91
42
92
43
// Remove a reaction
93
-
func DeleteReaction(e Execer, reactedByDid string, threadAt syntax.ATURI, kind ReactionKind) error {
44
+
func DeleteReaction(e Execer, reactedByDid string, threadAt syntax.ATURI, kind models.ReactionKind) error {
94
45
_, err := e.Exec(`delete from reactions where reacted_by_did = ? and thread_at = ? and kind = ?`, reactedByDid, threadAt, kind)
95
46
return err
96
47
}
···
101
52
return err
102
53
}
103
54
104
-
func GetReactionCount(e Execer, threadAt syntax.ATURI, kind ReactionKind) (int, error) {
55
+
func GetReactionCount(e Execer, threadAt syntax.ATURI, kind models.ReactionKind) (int, error) {
105
56
count := 0
106
57
err := e.QueryRow(
107
58
`select count(reacted_by_did) from reactions where thread_at = ? and kind = ?`, threadAt, kind).Scan(&count)
···
111
62
return count, nil
112
63
}
113
64
114
-
func GetReactionCountMap(e Execer, threadAt syntax.ATURI) (map[ReactionKind]int, error) {
115
-
countMap := map[ReactionKind]int{}
116
-
for _, kind := range OrderedReactionKinds {
65
+
func GetReactionCountMap(e Execer, threadAt syntax.ATURI) (map[models.ReactionKind]int, error) {
66
+
countMap := map[models.ReactionKind]int{}
67
+
for _, kind := range models.OrderedReactionKinds {
117
68
count, err := GetReactionCount(e, threadAt, kind)
118
69
if err != nil {
119
-
return map[ReactionKind]int{}, nil
70
+
return map[models.ReactionKind]int{}, nil
120
71
}
121
72
countMap[kind] = count
122
73
}
123
74
return countMap, nil
124
75
}
125
76
126
-
func GetReactionStatus(e Execer, userDid string, threadAt syntax.ATURI, kind ReactionKind) bool {
77
+
func GetReactionStatus(e Execer, userDid string, threadAt syntax.ATURI, kind models.ReactionKind) bool {
127
78
if _, err := GetReaction(e, userDid, threadAt, kind); err != nil {
128
79
return false
129
80
} else {
···
131
82
}
132
83
}
133
84
134
-
func GetReactionStatusMap(e Execer, userDid string, threadAt syntax.ATURI) map[ReactionKind]bool {
135
-
statusMap := map[ReactionKind]bool{}
136
-
for _, kind := range OrderedReactionKinds {
85
+
func GetReactionStatusMap(e Execer, userDid string, threadAt syntax.ATURI) map[models.ReactionKind]bool {
86
+
statusMap := map[models.ReactionKind]bool{}
87
+
for _, kind := range models.OrderedReactionKinds {
137
88
count := GetReactionStatus(e, userDid, threadAt, kind)
138
89
statusMap[kind] = count
139
90
}
+2
-2
appview/issues/issues.go
+2
-2
appview/issues/issues.go
···
88
88
l.Error("failed to get issue reactions", "err", err)
89
89
}
90
90
91
-
userReactions := map[db.ReactionKind]bool{}
91
+
userReactions := map[models.ReactionKind]bool{}
92
92
if user != nil {
93
93
userReactions = db.GetReactionStatusMap(rp.db, user.Did, issue.AtUri())
94
94
}
···
114
114
RepoInfo: f.RepoInfo(user),
115
115
Issue: issue,
116
116
CommentList: issue.CommentList(),
117
-
OrderedReactionKinds: db.OrderedReactionKinds,
117
+
OrderedReactionKinds: models.OrderedReactionKinds,
118
118
Reactions: reactionCountMap,
119
119
UserReacted: userReactions,
120
120
LabelDefs: defs,
+57
appview/models/reaction.go
+57
appview/models/reaction.go
···
1
+
package models
2
+
3
+
import (
4
+
"time"
5
+
6
+
"github.com/bluesky-social/indigo/atproto/syntax"
7
+
)
8
+
9
+
type ReactionKind string
10
+
11
+
const (
12
+
Like ReactionKind = "๐"
13
+
Unlike ReactionKind = "๐"
14
+
Laugh ReactionKind = "๐"
15
+
Celebration ReactionKind = "๐"
16
+
Confused ReactionKind = "๐ซค"
17
+
Heart ReactionKind = "โค๏ธ"
18
+
Rocket ReactionKind = "๐"
19
+
Eyes ReactionKind = "๐"
20
+
)
21
+
22
+
func (rk ReactionKind) String() string {
23
+
return string(rk)
24
+
}
25
+
26
+
var OrderedReactionKinds = []ReactionKind{
27
+
Like,
28
+
Unlike,
29
+
Laugh,
30
+
Celebration,
31
+
Confused,
32
+
Heart,
33
+
Rocket,
34
+
Eyes,
35
+
}
36
+
37
+
func ParseReactionKind(raw string) (ReactionKind, bool) {
38
+
k, ok := (map[string]ReactionKind{
39
+
"๐": Like,
40
+
"๐": Unlike,
41
+
"๐": Laugh,
42
+
"๐": Celebration,
43
+
"๐ซค": Confused,
44
+
"โค๏ธ": Heart,
45
+
"๐": Rocket,
46
+
"๐": Eyes,
47
+
})[raw]
48
+
return k, ok
49
+
}
50
+
51
+
type Reaction struct {
52
+
ReactedByDid string
53
+
ThreadAt syntax.ATURI
54
+
Created time.Time
55
+
Rkey string
56
+
Kind ReactionKind
57
+
}
+9
-9
appview/pages/pages.go
+9
-9
appview/pages/pages.go
···
908
908
CommentList []models.CommentListItem
909
909
LabelDefs map[string]*models.LabelDefinition
910
910
911
-
OrderedReactionKinds []db.ReactionKind
912
-
Reactions map[db.ReactionKind]int
913
-
UserReacted map[db.ReactionKind]bool
911
+
OrderedReactionKinds []models.ReactionKind
912
+
Reactions map[models.ReactionKind]int
913
+
UserReacted map[models.ReactionKind]bool
914
914
}
915
915
916
916
func (p *Pages) RepoSingleIssue(w io.Writer, params RepoSingleIssueParams) error {
···
932
932
933
933
type ThreadReactionFragmentParams struct {
934
934
ThreadAt syntax.ATURI
935
-
Kind db.ReactionKind
935
+
Kind models.ReactionKind
936
936
Count int
937
937
IsReacted bool
938
938
}
···
1060
1060
ResubmitCheck ResubmitResult
1061
1061
Pipelines map[string]models.Pipeline
1062
1062
1063
-
OrderedReactionKinds []db.ReactionKind
1064
-
Reactions map[db.ReactionKind]int
1065
-
UserReacted map[db.ReactionKind]bool
1063
+
OrderedReactionKinds []models.ReactionKind
1064
+
Reactions map[models.ReactionKind]int
1065
+
UserReacted map[models.ReactionKind]bool
1066
1066
}
1067
1067
1068
1068
func (p *Pages) RepoSinglePull(w io.Writer, params RepoSinglePullParams) error {
···
1078
1078
Diff *types.NiceDiff
1079
1079
Round int
1080
1080
Submission *models.PullSubmission
1081
-
OrderedReactionKinds []db.ReactionKind
1081
+
OrderedReactionKinds []models.ReactionKind
1082
1082
DiffOpts types.DiffOpts
1083
1083
}
1084
1084
···
1093
1093
Pull *models.Pull
1094
1094
Round int
1095
1095
Interdiff *patchutil.InterdiffResult
1096
-
OrderedReactionKinds []db.ReactionKind
1096
+
OrderedReactionKinds []models.ReactionKind
1097
1097
DiffOpts types.DiffOpts
1098
1098
}
1099
1099
+2
-2
appview/pulls/pulls.go
+2
-2
appview/pulls/pulls.go
···
195
195
s.pages.Notice(w, "pulls", "Failed to load pull. Try again later.")
196
196
}
197
197
198
-
userReactions := map[db.ReactionKind]bool{}
198
+
userReactions := map[models.ReactionKind]bool{}
199
199
if user != nil {
200
200
userReactions = db.GetReactionStatusMap(s.db, user.Did, pull.PullAt())
201
201
}
···
210
210
ResubmitCheck: resubmitResult,
211
211
Pipelines: m,
212
212
213
-
OrderedReactionKinds: db.OrderedReactionKinds,
213
+
OrderedReactionKinds: models.OrderedReactionKinds,
214
214
Reactions: reactionCountMap,
215
215
UserReacted: userReactions,
216
216
})
+2
-1
appview/state/reaction.go
+2
-1
appview/state/reaction.go
···
11
11
lexutil "github.com/bluesky-social/indigo/lex/util"
12
12
"tangled.org/core/api/tangled"
13
13
"tangled.org/core/appview/db"
14
+
"tangled.org/core/appview/models"
14
15
"tangled.org/core/appview/pages"
15
16
"tangled.org/core/tid"
16
17
)
···
30
31
return
31
32
}
32
33
33
-
reactionKind, ok := db.ParseReactionKind(r.URL.Query().Get("kind"))
34
+
reactionKind, ok := models.ParseReactionKind(r.URL.Query().Get("kind"))
34
35
if !ok {
35
36
log.Println("invalid reaction kind")
36
37
return