Skip to content

Commit bb94379

Browse files
committed
Reimplement reactions and delete, fixed conversation styling css
1 parent 637788b commit bb94379

File tree

20 files changed

+268
-160
lines changed

20 files changed

+268
-160
lines changed

models/conversations/conversation.go

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ func init() {
133133
func (conversation *Conversation) Link() string {
134134
switch conversation.Type {
135135
default:
136-
return fmt.Sprintf("%s/%s/%s", conversation.Repo.Link(), "commits", conversation.CommitSha)
136+
return fmt.Sprintf("%s/%s/%s", conversation.Repo.Link(), "commit", conversation.CommitSha)
137137
}
138138
}
139139

@@ -207,6 +207,10 @@ func (conversation *Conversation) LoadAttributes(ctx context.Context) (err error
207207
return err
208208
}
209209

210+
if err = conversation.loadReactions(ctx); err != nil {
211+
return err
212+
}
213+
210214
if err = conversation.Comments.LoadAttributes(ctx); err != nil {
211215
return err
212216
}
@@ -326,3 +330,32 @@ func (conversation *Conversation) APIURL(ctx context.Context) string {
326330
}
327331
return fmt.Sprintf("%s/commit/%s", conversation.Repo.APIURL(), conversation.CommitSha)
328332
}
333+
334+
func (conversation *Conversation) loadReactions(ctx context.Context) (err error) {
335+
reactions, _, err := FindReactions(ctx, FindReactionsOptions{
336+
ConversationID: conversation.ID,
337+
})
338+
if err != nil {
339+
return err
340+
}
341+
if err = conversation.LoadRepo(ctx); err != nil {
342+
return err
343+
}
344+
// Load reaction user data
345+
if _, err := reactions.LoadUsers(ctx, conversation.Repo); err != nil {
346+
return err
347+
}
348+
349+
// Cache comments to map
350+
comments := make(map[int64]*Comment)
351+
for _, comment := range conversation.Comments {
352+
comments[comment.ID] = comment
353+
}
354+
// Add reactions to comment
355+
for _, react := range reactions {
356+
if comment, ok := comments[react.CommentID]; ok {
357+
comment.Reactions = append(comment.Reactions, react)
358+
}
359+
}
360+
return nil
361+
}

models/conversations/reaction.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -117,24 +117,24 @@ func (opts *FindReactionsOptions) toConds() builder.Cond {
117117
// If Conversation ID is set add to Query
118118
cond := builder.NewCond()
119119
if opts.ConversationID > 0 {
120-
cond = cond.And(builder.Eq{"reaction.conversation_id": opts.ConversationID})
120+
cond = cond.And(builder.Eq{"comment_reaction.conversation_id": opts.ConversationID})
121121
}
122122
// If CommentID is > 0 add to Query
123123
// If it is 0 Query ignore CommentID to select
124124
// If it is -1 it explicit search of Conversation Reactions where CommentID = 0
125125
if opts.CommentID > 0 {
126-
cond = cond.And(builder.Eq{"reaction.comment_id": opts.CommentID})
126+
cond = cond.And(builder.Eq{"comment_reaction.comment_id": opts.CommentID})
127127
} else if opts.CommentID == -1 {
128-
cond = cond.And(builder.Eq{"reaction.comment_id": 0})
128+
cond = cond.And(builder.Eq{"comment_reaction.comment_id": 0})
129129
}
130130
if opts.UserID > 0 {
131131
cond = cond.And(builder.Eq{
132-
"reaction.user_id": opts.UserID,
133-
"reaction.original_author_id": 0,
132+
"comment_reaction.user_id": opts.UserID,
133+
"comment_reaction.original_author_id": 0,
134134
})
135135
}
136136
if opts.Reaction != "" {
137-
cond = cond.And(builder.Eq{"reaction.type": opts.Reaction})
137+
cond = cond.And(builder.Eq{"comment_reaction.type": opts.Reaction})
138138
}
139139

140140
return cond
@@ -161,8 +161,8 @@ func FindConversationReactions(ctx context.Context, conversationID int64, listOp
161161
func FindReactions(ctx context.Context, opts FindReactionsOptions) (ReactionList, int64, error) {
162162
sess := db.GetEngine(ctx).
163163
Where(opts.toConds()).
164-
In("reaction.`type`", setting.UI.Reactions).
165-
Asc("reaction.conversation_id", "reaction.comment_id", "reaction.created_unix", "reaction.id")
164+
In("comment_reaction.`type`", setting.UI.Reactions).
165+
Asc("comment_reaction.conversation_id", "comment_reaction.comment_id", "comment_reaction.created_unix", "comment_reaction.id")
166166
if opts.Page != 0 {
167167
sess = db.SetSessionPagination(sess, &opts)
168168

models/unit/unit.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ var (
6161
TypeProjects,
6262
TypePackages,
6363
TypeActions,
64+
TypeConversations,
6465
}
6566

6667
// DefaultRepoUnits contains the default unit types
@@ -73,6 +74,7 @@ var (
7374
TypeProjects,
7475
TypePackages,
7576
TypeActions,
77+
TypeConversations,
7678
}
7779

7880
// ForkRepoUnits contains the default unit types for forks
@@ -294,6 +296,15 @@ var (
294296
perm.AccessModeOwner,
295297
}
296298

299+
UnitConversations = Unit{
300+
TypeConversations,
301+
"repo.conversations",
302+
"/conversations",
303+
"conversations.unit.desc",
304+
8,
305+
perm.AccessModeOwner,
306+
}
307+
297308
// Units contains all the units
298309
Units = map[Type]Unit{
299310
TypeCode: UnitCode,
@@ -306,6 +317,7 @@ var (
306317
TypeProjects: UnitProjects,
307318
TypePackages: UnitPackages,
308319
TypeActions: UnitActions,
320+
TypeConversations: UnitConversations,
309321
}
310322
)
311323

routers/web/repo/commit.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,9 @@ func Diff(ctx *context.Context) {
463463
}
464464

465465
ctx.Data["Conversation"] = conversation
466+
ctx.Data["ConversationTitle"] = "Comments"
466467
ctx.Data["Comments"] = conversation.Comments
468+
ctx.Data["IsCommit"] = true
467469

468470
ctx.Data["CanBlockUser"] = func(blocker, blockee *user_model.User) bool {
469471
return user_service.CanBlockUser(ctx, ctx.Doer, blocker, blockee)

routers/web/repo/conversation.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1170,7 +1170,7 @@ func ChangeConversationCommentReaction(ctx *context.Context) {
11701170
}
11711171

11721172
html, err := ctx.RenderToHTML(tplReactions, map[string]any{
1173-
"ActionURL": fmt.Sprintf("%s/comments/%d/reactions", ctx.Repo.RepoLink, comment.ID),
1173+
"ActionURL": fmt.Sprintf("%s/conversations/comments/%d/reactions", ctx.Repo.RepoLink, comment.ID),
11741174
"Reactions": comment.Reactions.GroupByType(),
11751175
})
11761176
if err != nil {

routers/web/web.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -815,6 +815,7 @@ func registerRoutes(m *web.Router) {
815815
reqRepoPullsReader := context.RequireRepoReader(unit.TypePullRequests)
816816
reqRepoIssuesOrPullsWriter := context.RequireRepoWriterOr(unit.TypeIssues, unit.TypePullRequests)
817817
reqRepoIssuesOrPullsReader := context.RequireRepoReaderOr(unit.TypeIssues, unit.TypePullRequests)
818+
reqRepoConversationReader := context.RequireRepoReader(unit.TypeConversations)
818819
reqRepoProjectsReader := context.RequireRepoReader(unit.TypeProjects)
819820
reqRepoProjectsWriter := context.RequireRepoWriter(unit.TypeProjects)
820821
reqRepoActionsReader := context.RequireRepoReader(unit.TypeActions)
@@ -1289,7 +1290,7 @@ func registerRoutes(m *web.Router) {
12891290
}, context.RepoMustNotBeArchived())
12901291
})
12911292

1292-
}, reqSignIn, context.RepoAssignment)
1293+
}, reqSignIn, context.RepoAssignment, reqRepoConversationReader)
12931294

12941295
m.Group("/{username}/{reponame}", func() { // repo code
12951296
m.Group("", func() {

services/context/context.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ func NewTemplateContextForWeb(ctx *Context) TemplateContext {
112112
"RepoUnitTypeProjects": unit.TypeProjects,
113113
"RepoUnitTypePackages": unit.TypePackages,
114114
"RepoUnitTypeActions": unit.TypeActions,
115+
"RepoUnitTypeConversations": unit.TypeConversations,
115116
}
116117
return tmplCtx
117118
}

templates/repo/commit_page.tmpl

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -280,10 +280,7 @@
280280
</div>
281281
{{end}}
282282
{{template "repo/diff/box" .}}
283-
284-
<div class="issue-content-left comment-list prevent-before-timeline">
285-
{{template "repo/conversation/conversation" .}}
286-
</div>
283+
{{template "repo/conversation/conversation" .}}
287284
</div>
288285
</div>
289286
{{template "base/footer" .}}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{{if ctx.RootData.IsSigned}}
2+
<div class="item action ui dropdown jump pointing top right select-reaction" data-action-url="{{.ActionURL}}">
3+
<a class="muted">{{svg "octicon-smiley"}}</a>
4+
<div class="menu">
5+
{{range $value := AllowedReactions}}
6+
<a class="item emoji comment-reaction-button" data-tooltip-content="{{$value}}" aria-label="{{$value}}" data-reaction-content="{{$value}}">{{ReactionToEmoji $value}}</a>
7+
{{end}}
8+
</div>
9+
</div>
10+
{{end}}

templates/repo/conversation/comments.tmpl

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<!-- Provide Issue for any types other than type 0 -->
22
{{template "base/alert"}}
33
{{$IsIssue:= .IsIssue}}
4+
{{$IsCommit:= .IsCommit}}
45
{{range .Comments}}
56
{{if call $.ShouldShowCommentType .Type}}
67
{{$createdStr:= TimeSinceUnix .CreatedUnix ctx.Locale}}
@@ -55,9 +56,14 @@
5556
<div class="comment-header-right actions tw-flex tw-items-center">
5657
{{template "repo/issue/view_content/show_role" dict "ShowRole" .ShowRole}}
5758
{{if not $.Repository.IsArchived}}
58-
{{template "repo/issue/view_content/add_reaction" dict "ActionURL" (printf "%s/comments/%d/reactions" $.RepoLink .ID)}}
59+
{{if $IsIssue}}
60+
{{template "repo/conversation/add_reaction" dict "ActionURL" (printf "%s/comments/%d/reactions" $.RepoLink .ID)}}
61+
{{else}}
62+
{{template "repo/conversation/add_reaction" dict "ActionURL" (printf "%s/conversations/comments/%d/reactions" $.RepoLink .ID)}}
63+
{{end}}
5964
{{end}}
60-
{{template "repo/conversation/context_menu" dict "ctxData" $ "item" . "delete" true "issue" $IsIssue "diff" false "IsIssue" $IsIssue "IsCommentPoster" (and $.IsSigned (eq $.SignedUserID .PosterID))}}
65+
66+
{{template "repo/conversation/context_menu" dict "ctxData" $ "item" . "delete" true "issue" $IsIssue "pull" ((and $IsIssue .Issue.IsPull)) "commit" $IsCommit "diff" false "IsIssue" $IsIssue "IsCommentPoster" (and $.IsSigned (eq $.SignedUserID .PosterID))}}
6167
</div>
6268
</div>
6369
<div class="ui attached segment comment-body" role="article">
@@ -76,7 +82,11 @@
7682
</div>
7783
{{$reactions := .Reactions.GroupByType}}
7884
{{if $reactions}}
79-
{{template "repo/issue/view_content/reactions" dict "ActionURL" (printf "%s/comments/%d/reactions" $.RepoLink .ID) "Reactions" $reactions}}
85+
{{if $IsIssue}}
86+
{{template "repo/conversation/reactions" dict "ActionURL" (printf "%s/comments/%d/reactions" $.RepoLink .ID) "Reactions" $reactions}}
87+
{{else}}
88+
{{template "repo/conversation/reactions" dict "ActionURL" (printf "%s/conversations/comments/%d/reactions" $.RepoLink .ID) "Reactions" $reactions}}
89+
{{end}}
8090
{{end}}
8191
</div>
8292
</div>
@@ -429,8 +439,8 @@
429439
<div class="comment-header-right actions tw-flex tw-items-center">
430440
{{template "repo/issue/view_content/show_role" dict "ShowRole" .ShowRole}}
431441
{{if not $.Repository.IsArchived}}
432-
{{template "repo/issue/view_content/add_reaction" dict "ActionURL" (printf "%s/comments/%d/reactions" $.RepoLink .ID)}}
433-
{{template "repo/issue/view_content/context_menu" dict "ctxData" $ "item" . "delete" false "issue" true "diff" false "IsCommentPoster" (and $.IsSigned (eq $.SignedUserID .PosterID))}}
442+
{{template "repo/conversation/add_reaction" dict "ActionURL" (printf "%s/comments/%d/reactions" $.RepoLink .ID)}}
443+
{{template "repo/conversation/context_menu" dict "ctxData" $ "item" . "delete" false "issue" true "diff" false "IsCommentPoster" (and $.IsSigned (eq $.SignedUserID .PosterID))}}
434444
{{end}}
435445
</div>
436446
</div>

0 commit comments

Comments
 (0)