@@ -19,6 +19,7 @@ function clearAccepted(topic) {
19
19
accepted_answer : false ,
20
20
can_accept_answer : true ,
21
21
can_unaccept_answer : false ,
22
+ topic_accepted_answer : false ,
22
23
} ) ;
23
24
}
24
25
} ) ;
@@ -78,24 +79,25 @@ function initializeWithApi(api) {
78
79
api . includePostAttributes (
79
80
"can_accept_answer" ,
80
81
"can_unaccept_answer" ,
81
- "accepted_answer"
82
+ "accepted_answer" ,
83
+ "topic_accepted_answer"
82
84
) ;
83
85
84
86
if ( api . addDiscoveryQueryParam ) {
85
87
api . addDiscoveryQueryParam ( "solved" , { replace : true , refreshModel : true } ) ;
86
88
}
87
89
88
90
api . addPostMenuButton ( "solved" , ( attrs ) => {
89
- const isOp = currentUser ?. id === attrs . topicCreatedById ;
90
-
91
91
if ( attrs . can_accept_answer ) {
92
+ const isOp = currentUser ?. id === attrs . topicCreatedById ;
93
+
92
94
return {
93
95
action : "acceptAnswer" ,
94
96
icon : "far-check-square" ,
95
97
className : "unaccepted" ,
96
98
title : "solved.accept_answer" ,
97
99
label : isOp ? "solved.solution" : null ,
98
- position : isOp ? "first " : "second " ,
100
+ position : attrs . topic_accepted_answer ? "second-last-hidden " : "first " ,
99
101
} ;
100
102
} else if ( attrs . accepted_answer ) {
101
103
if ( attrs . can_unaccept_answer ) {
@@ -104,8 +106,8 @@ function initializeWithApi(api) {
104
106
icon : "check-square" ,
105
107
title : "solved.unaccept_answer" ,
106
108
className : "accepted fade-out" ,
107
- position : isOp ? "first" : "second ",
108
- label : isOp ? "solved.solution" : null ,
109
+ position : "first" ,
110
+ label : "solved.solution" ,
109
111
} ;
110
112
} else {
111
113
return {
@@ -168,23 +170,22 @@ function initializeWithApi(api) {
168
170
169
171
api . attachWidgetAction ( "post" , "acceptAnswer" , function ( ) {
170
172
const post = this . model ;
171
- const current = post . get ( "topic.postStream.posts" ) . filter ( ( p ) => {
172
- return p . post_number === 1 || p . accepted_answer ;
173
- } ) ;
174
173
acceptPost ( post ) ;
175
174
176
- current . forEach ( ( p ) =>
177
- this . appEvents . trigger ( "post-stream:refresh" , { id : p . id } )
178
- ) ;
175
+ post . get ( "topic.postStream.posts" ) . forEach ( ( p ) => {
176
+ p . set ( "topic_accepted_answer" , true ) ;
177
+ this . appEvents . trigger ( "post-stream:refresh" , { id : p . id } ) ;
178
+ } ) ;
179
179
} ) ;
180
180
181
181
api . attachWidgetAction ( "post" , "unacceptAnswer" , function ( ) {
182
182
const post = this . model ;
183
- const op = post
184
- . get ( "topic.postStream.posts" )
185
- . find ( ( p ) => p . post_number === 1 ) ;
186
183
unacceptPost ( post ) ;
187
- this . appEvents . trigger ( "post-stream:refresh" , { id : op . id } ) ;
184
+
185
+ post . get ( "topic.postStream.posts" ) . forEach ( ( p ) => {
186
+ p . set ( "topic_accepted_answer" , false ) ;
187
+ this . appEvents . trigger ( "post-stream:refresh" , { id : p . id } ) ;
188
+ } ) ;
188
189
} ) ;
189
190
190
191
if ( api . registerConnectorClass ) {
0 commit comments