@@ -105,18 +105,11 @@ func (t CommentType) HasMailReplySupport() bool {
105105 return false
106106}
107107
108- // CommentMetaData stores metadata for a comment, these data will not be changed once inserted into database
109- type CommentMetaData struct {
110- ProjectColumnID int64 `json:"project_column_id,omitempty"`
111- ProjectColumnTitle string `json:"project_column_title,omitempty"`
112- ProjectTitle string `json:"project_title,omitempty"`
113- }
114-
115- // Comment represents a comment in commit and conversation page.
116- // Comment struct should not contain any pointers unrelated to Conversation unless absolutely necessary.
108+ // ConversationComment represents a comment in commit and conversation page.
109+ // ConversationComment struct should not contain any pointers unrelated to Conversation unless absolutely necessary.
117110// To have pointers outside of conversation, create another comment type (e.g. ConversationComment) and use a converter to load it in.
118111// The database data for the comments however, for all comment types, are defined here.
119- type Comment struct {
112+ type ConversationComment struct {
120113 ID int64 `xorm:"pk autoincr"`
121114 Type CommentType `xorm:"INDEX"`
122115
@@ -143,11 +136,11 @@ type Comment struct {
143136}
144137
145138func init () {
146- db .RegisterModel (new (Comment ))
139+ db .RegisterModel (new (ConversationComment ))
147140}
148141
149142// LoadPoster loads comment poster
150- func (c * Comment ) LoadPoster (ctx context.Context ) (err error ) {
143+ func (c * ConversationComment ) LoadPoster (ctx context.Context ) (err error ) {
151144 if c .Poster != nil {
152145 return nil
153146 }
@@ -165,7 +158,7 @@ func (c *Comment) LoadPoster(ctx context.Context) (err error) {
165158}
166159
167160// LoadReactions loads comment reactions
168- func (c * Comment ) LoadReactions (ctx context.Context , repo * repo_model.Repository ) (err error ) {
161+ func (c * ConversationComment ) LoadReactions (ctx context.Context , repo * repo_model.Repository ) (err error ) {
169162 if c .Reactions != nil {
170163 return nil
171164 }
@@ -184,7 +177,7 @@ func (c *Comment) LoadReactions(ctx context.Context, repo *repo_model.Repository
184177}
185178
186179// AfterDelete is invoked from XORM after the object is deleted.
187- func (c * Comment ) AfterDelete (ctx context.Context ) {
180+ func (c * ConversationComment ) AfterDelete (ctx context.Context ) {
188181 if c .ID <= 0 {
189182 return
190183 }
@@ -236,7 +229,7 @@ type CreateCommentOptions struct {
236229}
237230
238231// CreateComment creates comment with context
239- func CreateComment (ctx context.Context , opts * CreateCommentOptions ) (_ * Comment , err error ) {
232+ func CreateComment (ctx context.Context , opts * CreateCommentOptions ) (_ * ConversationComment , err error ) {
240233 ctx , committer , err := db .TxContext (ctx )
241234 if err != nil {
242235 return nil , err
@@ -245,7 +238,7 @@ func CreateComment(ctx context.Context, opts *CreateCommentOptions) (_ *Comment,
245238
246239 e := db .GetEngine (ctx )
247240
248- comment := & Comment {
241+ comment := & ConversationComment {
249242 Type : opts .Type ,
250243 PosterID : opts .Doer .ID ,
251244 Poster : opts .Doer ,
@@ -267,8 +260,8 @@ func CreateComment(ctx context.Context, opts *CreateCommentOptions) (_ *Comment,
267260}
268261
269262// GetCommentByID returns the comment by given ID.
270- func GetCommentByID (ctx context.Context , id int64 ) (* Comment , error ) {
271- c := new (Comment )
263+ func GetCommentByID (ctx context.Context , id int64 ) (* ConversationComment , error ) {
264+ c := new (ConversationComment )
272265 has , err := db .GetEngine (ctx ).ID (id ).Get (c )
273266 if err != nil {
274267 return nil , err
@@ -301,43 +294,28 @@ func (opts FindCommentsOptions) ToConds() builder.Cond {
301294 cond = cond .And (builder.Eq {"conversation.repo_id" : opts .RepoID })
302295 }
303296 if opts .ConversationID > 0 {
304- cond = cond .And (builder.Eq {"comment .conversation_id" : opts .ConversationID })
297+ cond = cond .And (builder.Eq {"conversation_comment .conversation_id" : opts .ConversationID })
305298 } else if len (opts .ConversationIDs ) > 0 {
306- cond = cond .And (builder .In ("comment.conversation_id" , opts .ConversationIDs ))
307- }
308- if opts .ReviewID > 0 {
309- cond = cond .And (builder.Eq {"comment.review_id" : opts .ReviewID })
299+ cond = cond .And (builder .In ("conversation_comment.conversation_id" , opts .ConversationIDs ))
310300 }
311301 if opts .Since > 0 {
312- cond = cond .And (builder.Gte {"comment .updated_unix" : opts .Since })
302+ cond = cond .And (builder.Gte {"conversation_comment .updated_unix" : opts .Since })
313303 }
314304 if opts .Before > 0 {
315- cond = cond .And (builder.Lte {"comment .updated_unix" : opts .Before })
305+ cond = cond .And (builder.Lte {"conversation_comment .updated_unix" : opts .Before })
316306 }
317307 if opts .Type != CommentTypeUndefined {
318- cond = cond .And (builder.Eq {"comment.type" : opts .Type })
319- }
320- if opts .Line != 0 {
321- cond = cond .And (builder.Eq {"comment.line" : opts .Line })
322- }
323- if len (opts .TreePath ) > 0 {
324- cond = cond .And (builder.Eq {"comment.tree_path" : opts .TreePath })
325- }
326- if opts .Invalidated .Has () {
327- cond = cond .And (builder.Eq {"comment.invalidated" : opts .Invalidated .Value ()})
328- }
329- if opts .IsPull .Has () {
330- cond = cond .And (builder.Eq {"conversation.is_pull" : opts .IsPull .Value ()})
308+ cond = cond .And (builder.Eq {"conversation_comment.type" : opts .Type })
331309 }
332310 return cond
333311}
334312
335313// FindComments returns all comments according options
336314func FindComments (ctx context.Context , opts * FindCommentsOptions ) (CommentList , error ) {
337- comments := make ([]* Comment , 0 , 10 )
315+ comments := make ([]* ConversationComment , 0 , 10 )
338316 sess := db .GetEngine (ctx ).Where (opts .ToConds ())
339317 if opts .RepoID > 0 {
340- sess .Join ("INNER" , "conversation" , "conversation.id = comment .conversation_id" )
318+ sess .Join ("INNER" , "conversation" , "conversation.id = conversation_comment .conversation_id" )
341319 }
342320
343321 if opts .Page != 0 {
@@ -347,28 +325,28 @@ func FindComments(ctx context.Context, opts *FindCommentsOptions) (CommentList,
347325 // WARNING: If you change this order you will need to fix createCodeComment
348326
349327 return comments , sess .
350- Asc ("comment .created_unix" ).
351- Asc ("comment .id" ).
328+ Asc ("conversation_comment .created_unix" ).
329+ Asc ("conversation_comment .id" ).
352330 Find (& comments )
353331}
354332
355333// CountComments count all comments according options by ignoring pagination
356334func CountComments (ctx context.Context , opts * FindCommentsOptions ) (int64 , error ) {
357335 sess := db .GetEngine (ctx ).Where (opts .ToConds ())
358336 if opts .RepoID > 0 {
359- sess .Join ("INNER" , "conversation" , "conversation.id = comment .conversation_id" )
337+ sess .Join ("INNER" , "conversation" , "conversation.id = conversation_comment .conversation_id" )
360338 }
361- return sess .Count (& Comment {})
339+ return sess .Count (& ConversationComment {})
362340}
363341
364342// UpdateCommentInvalidate updates comment invalidated column
365- func UpdateCommentInvalidate (ctx context.Context , c * Comment ) error {
343+ func UpdateCommentInvalidate (ctx context.Context , c * ConversationComment ) error {
366344 _ , err := db .GetEngine (ctx ).ID (c .ID ).Cols ("invalidated" ).Update (c )
367345 return err
368346}
369347
370- // UpdateComment updates information of comment.
371- func UpdateComment (ctx context.Context , c * Comment , contentVersion int , doer * user_model.User ) error {
348+ // UpdateComment updates information of comment
349+ func UpdateComment (ctx context.Context , c * ConversationComment , contentVersion int , doer * user_model.User ) error {
372350 ctx , committer , err := db .TxContext (ctx )
373351 if err != nil {
374352 return err
@@ -393,7 +371,7 @@ func UpdateComment(ctx context.Context, c *Comment, contentVersion int, doer *us
393371}
394372
395373// DeleteComment deletes the comment
396- func DeleteComment (ctx context.Context , comment * Comment ) error {
374+ func DeleteComment (ctx context.Context , comment * ConversationComment ) error {
397375 e := db .GetEngine (ctx )
398376 if _ , err := e .ID (comment .ID ).NoAutoCondition ().Delete (comment ); err != nil {
399377 return err
@@ -418,11 +396,11 @@ func DeleteComment(ctx context.Context, comment *Comment) error {
418396
419397// UpdateCommentsMigrationsByType updates comments' migrations information via given git service type and original id and poster id
420398func UpdateCommentsMigrationsByType (ctx context.Context , tp structs.GitServiceType , originalAuthorID string , posterID int64 ) error {
421- _ , err := db .GetEngine (ctx ).Table ("comment " ).
422- Join ("INNER" , "conversation" , "conversation.id = comment .conversation_id" ).
399+ _ , err := db .GetEngine (ctx ).Table ("conversation_comment " ).
400+ Join ("INNER" , "conversation" , "conversation.id = conversation_comment .conversation_id" ).
423401 Join ("INNER" , "repository" , "conversation.repo_id = repository.id" ).
424402 Where ("repository.original_service_type = ?" , tp ).
425- And ("comment .original_author_id = ?" , originalAuthorID ).
403+ And ("conversation_comment .original_author_id = ?" , originalAuthorID ).
426404 Update (map [string ]any {
427405 "poster_id" : posterID ,
428406 "original_author" : "" ,
@@ -431,7 +409,7 @@ func UpdateCommentsMigrationsByType(ctx context.Context, tp structs.GitServiceTy
431409 return err
432410}
433411
434- func UpdateAttachments (ctx context.Context , opts * CreateCommentOptions , comment * Comment ) error {
412+ func UpdateAttachments (ctx context.Context , opts * CreateCommentOptions , comment * ConversationComment ) error {
435413 attachments , err := repo_model .GetAttachmentsByUUIDs (ctx , opts .Attachments )
436414 if err != nil {
437415 return fmt .Errorf ("getAttachmentsByUUIDs [uuids: %v]: %w" , opts .Attachments , err )
@@ -449,7 +427,7 @@ func UpdateAttachments(ctx context.Context, opts *CreateCommentOptions, comment
449427}
450428
451429// LoadConversation loads the conversation reference for the comment
452- func (c * Comment ) LoadConversation (ctx context.Context ) (err error ) {
430+ func (c * ConversationComment ) LoadConversation (ctx context.Context ) (err error ) {
453431 if c .Conversation != nil {
454432 return nil
455433 }
@@ -458,7 +436,7 @@ func (c *Comment) LoadConversation(ctx context.Context) (err error) {
458436}
459437
460438// LoadAttachments loads attachments (it never returns error, the error during `GetAttachmentsByCommentIDCtx` is ignored)
461- func (c * Comment ) LoadAttachments (ctx context.Context ) error {
439+ func (c * ConversationComment ) LoadAttachments (ctx context.Context ) error {
462440 if len (c .Attachments ) > 0 {
463441 return nil
464442 }
@@ -472,7 +450,7 @@ func (c *Comment) LoadAttachments(ctx context.Context) error {
472450}
473451
474452// UpdateAttachments update attachments by UUIDs for the comment
475- func (c * Comment ) UpdateAttachments (ctx context.Context , uuids []string ) error {
453+ func (c * ConversationComment ) UpdateAttachments (ctx context.Context , uuids []string ) error {
476454 ctx , committer , err := db .TxContext (ctx )
477455 if err != nil {
478456 return err
@@ -494,16 +472,16 @@ func (c *Comment) UpdateAttachments(ctx context.Context, uuids []string) error {
494472}
495473
496474// HashTag returns unique hash tag for conversation.
497- func (c * Comment ) HashTag () string {
475+ func (c * ConversationComment ) HashTag () string {
498476 return fmt .Sprintf ("comment-%d" , c .ID )
499477}
500478
501- func (c * Comment ) hashLink () string {
479+ func (c * ConversationComment ) hashLink () string {
502480 return "#" + c .HashTag ()
503481}
504482
505483// HTMLURL formats a URL-string to the conversation-comment
506- func (c * Comment ) HTMLURL (ctx context.Context ) string {
484+ func (c * ConversationComment ) HTMLURL (ctx context.Context ) string {
507485 err := c .LoadConversation (ctx )
508486 if err != nil { // Silently dropping errors :unamused:
509487 log .Error ("LoadConversation(%d): %v" , c .ConversationID , err )
@@ -518,7 +496,7 @@ func (c *Comment) HTMLURL(ctx context.Context) string {
518496}
519497
520498// APIURL formats a API-string to the conversation-comment
521- func (c * Comment ) APIURL (ctx context.Context ) string {
499+ func (c * ConversationComment ) APIURL (ctx context.Context ) string {
522500 err := c .LoadConversation (ctx )
523501 if err != nil { // Silently dropping errors :unamused:
524502 log .Error ("LoadConversation(%d): %v" , c .ConversationID , err )
@@ -534,11 +512,11 @@ func (c *Comment) APIURL(ctx context.Context) string {
534512}
535513
536514// HasOriginalAuthor returns if a comment was migrated and has an original author.
537- func (c * Comment ) HasOriginalAuthor () bool {
515+ func (c * ConversationComment ) HasOriginalAuthor () bool {
538516 return c .OriginalAuthor != "" && c .OriginalAuthorID != 0
539517}
540518
541- func (c * Comment ) ConversationURL (ctx context.Context ) string {
519+ func (c * ConversationComment ) ConversationURL (ctx context.Context ) string {
542520 err := c .LoadConversation (ctx )
543521 if err != nil { // Silently dropping errors :unamused:
544522 log .Error ("LoadConversation(%d): %v" , c .ConversationID , err )
@@ -554,12 +532,12 @@ func (c *Comment) ConversationURL(ctx context.Context) string {
554532}
555533
556534// InsertConversationComments inserts many comments of conversations.
557- func InsertConversationComments (ctx context.Context , comments []* Comment ) error {
535+ func InsertConversationComments (ctx context.Context , comments []* ConversationComment ) error {
558536 if len (comments ) == 0 {
559537 return nil
560538 }
561539
562- conversationIDs := container .FilterSlice (comments , func (comment * Comment ) (int64 , bool ) {
540+ conversationIDs := container .FilterSlice (comments , func (comment * ConversationComment ) (int64 , bool ) {
563541 return comment .ConversationID , true
564542 })
565543
0 commit comments