@@ -575,35 +575,57 @@ func (d *Discussion) AcceptComment(ctx context.Context, user model.UserInfo, dis
575575 if disc .UserID != user .UID {
576576 return errors .New ("not allowed to accept comment" )
577577 }
578- if disc .Resolved {
579- return errors .New ("discussion already resolved" )
580- }
581- alreadyAccepted , err := d .in .CommRepo .Exist (ctx ,
582- repo .QueryWithEqual ("discussion_id" , disc .ID ),
583- repo .QueryWithEqual ("accepted" , true ),
584- )
578+
579+ comment , err := d .in .CommRepo .Detail (ctx , commentID )
585580 if err != nil {
586581 return err
587582 }
588- if alreadyAccepted {
589- return errors .New ("comment already accepted" )
583+
584+ if comment .Accepted {
585+ err = d .in .CommRepo .Update (ctx , map [string ]any {
586+ "accepted" : false ,
587+ "accepted_at" : gorm .Expr ("null" ),
588+ }, repo .QueryWithEqual ("id" , commentID ))
589+ if err != nil {
590+ return err
591+ }
592+
593+ err = d .in .DiscRepo .Update (ctx , map [string ]any {
594+ "resolved" : false ,
595+ "resolved_at" : gorm .Expr ("null" ),
596+ }, repo .QueryWithEqual ("id" , disc .ID ))
597+ if err != nil {
598+ return err
599+ }
600+
601+ return nil
590602 }
591- comment , err := d .in .CommRepo .Detail (ctx , commentID )
603+
604+ err = d .in .CommRepo .Update (ctx , map [string ]any {
605+ "accepted" : false ,
606+ "accepted_at" : gorm .Expr ("null" ),
607+ }, repo .QueryWithEqual ("discussion_id" , disc .ID ),
608+ repo .QueryWithEqual ("accepted" , true ))
592609 if err != nil {
593610 return err
594611 }
612+
595613 if err := d .in .CommRepo .UpdateByModel (ctx , & model.Comment {
596614 Accepted : true ,
597615 AcceptedAt : model .Timestamp (time .Now ().Unix ()),
598616 }, repo .QueryWithEqual ("id" , commentID )); err != nil {
599617 return err
600618 }
601- if err := d .in .DiscRepo .Update (ctx , map [string ]any {
602- "resolved" : true ,
603- "resolved_at" : model .Timestamp (time .Now ().Unix ()),
604- }, repo .QueryWithEqual ("id" , disc .ID )); err != nil {
605- return err
619+
620+ if ! disc .Resolved {
621+ if err := d .in .DiscRepo .Update (ctx , map [string ]any {
622+ "resolved" : true ,
623+ "resolved_at" : model .Timestamp (time .Now ().Unix ()),
624+ }, repo .QueryWithEqual ("id" , disc .ID )); err != nil {
625+ return err
626+ }
606627 }
628+
607629 notifyMsg := topic.MsgMessageNotify {
608630 DiscussID : disc .ID ,
609631 ForumID : disc .ForumID ,
0 commit comments