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