@@ -18,7 +18,6 @@ defmodule GroupherServer.CMS.Delegate.ArticleOperation do
1818 JobCommunityFlag ,
1919 RepoCommunityFlag ,
2020 Tag ,
21- Topic ,
2221 PinedPost ,
2322 PinedJob ,
2423 PinedRepo
@@ -27,13 +26,12 @@ defmodule GroupherServer.CMS.Delegate.ArticleOperation do
2726 alias GroupherServer.CMS.Repo , as: CMSRepo
2827 alias GroupherServer.Repo
2928
30- def pin_content ( % Post { id: post_id } , % Community { id: community_id } , topic ) do
31- with { :ok , % { id: topic_id } } <- ORM . find_by ( Topic , % { raw: topic } ) ,
32- { :ok , pined } <-
29+ def pin_content ( % Post { id: post_id } , % Community { id: community_id } ) do
30+ with { :ok , pined } <-
3331 ORM . findby_or_insert (
3432 PinedPost ,
35- ~m( post_id community_id topic_id ) a ,
36- ~m( post_id community_id topic_id ) a
33+ ~m( post_id community_id) a ,
34+ ~m( post_id community_id) a
3735 ) do
3836 Post |> ORM . find ( pined . post_id )
3937 end
@@ -55,9 +53,8 @@ defmodule GroupherServer.CMS.Delegate.ArticleOperation do
5553 end
5654 end
5755
58- def undo_pin_content ( % Post { id: post_id } , % Community { id: community_id } , topic ) do
59- with { :ok , % { id: topic_id } } <- ORM . find_by ( Topic , % { raw: topic } ) ,
60- { :ok , pined } <- ORM . find_by ( PinedPost , ~m( post_id community_id topic_id) a ) ,
56+ def undo_pin_content ( % Post { id: post_id } , % Community { id: community_id } ) do
57+ with { :ok , pined } <- ORM . find_by ( PinedPost , ~m( post_id community_id) a ) ,
6158 { :ok , deleted } <- ORM . delete ( pined ) do
6259 Post |> ORM . find ( deleted . post_id )
6360 end
@@ -177,55 +174,33 @@ defmodule GroupherServer.CMS.Delegate.ArticleOperation do
177174 @ doc """
178175 set refined_tag to common content
179176 """
180- def set_refined_tag ( % Community { id: community_id } , thread , topic_raw , content_id ) do
177+ def set_refined_tag ( % Community { id: community_id } , thread , content_id ) do
181178 with { :ok , action } <- match_action ( thread , :tag ) ,
182179 { :ok , content } <- ORM . find ( action . target , content_id , preload: :tags ) ,
183- { :ok , topic } <- ORM . find_by ( Topic , % { raw: topic_raw } ) ,
184180 { :ok , tag } <-
185181 ORM . find_by ( action . reactor , % {
186182 title: "refined" ,
187- community_id: community_id ,
188- topic_id: topic . id
183+ community_id: community_id
189184 } ) do
190185 update_content_tag ( content , tag )
191186 end
192187 end
193188
194- def set_refined_tag ( % Community { id: community_id } , thread , content_id ) do
195- with { :ok , action } <- match_action ( thread , :tag ) ,
196- { :ok , content } <- ORM . find ( action . target , content_id , preload: :tags ) ,
197- { :ok , tag } <-
198- ORM . find_by ( action . reactor , % { title: "refined" , community_id: community_id } ) do
199- update_content_tag ( content , tag )
200- end
201- end
202-
203189 @ doc """
204190 unset refined_tag to common content
205191 """
206- def unset_refined_tag ( % Community { id: community_id } , thread , topic_raw , content_id ) do
192+ def unset_refined_tag ( % Community { id: community_id } , thread , content_id ) do
207193 with { :ok , action } <- match_action ( thread , :tag ) ,
208194 { :ok , content } <- ORM . find ( action . target , content_id , preload: :tags ) ,
209- { :ok , topic } <- ORM . find_by ( Topic , % { raw: topic_raw } ) ,
210195 { :ok , tag } <-
211196 ORM . find_by ( action . reactor , % {
212197 title: "refined" ,
213- community_id: community_id ,
214- topic_id: topic . id
198+ community_id: community_id
215199 } ) do
216200 update_content_tag ( content , tag , :drop )
217201 end
218202 end
219203
220- def unset_refined_tag ( % Community { id: community_id } , thread , content_id ) do
221- with { :ok , action } <- match_action ( thread , :tag ) ,
222- { :ok , content } <- ORM . find ( action . target , content_id , preload: :tags ) ,
223- { :ok , tag } <-
224- ORM . find_by ( action . reactor , % { title: "refined" , community_id: community_id } ) do
225- update_content_tag ( content , tag , :drop )
226- end
227- end
228-
229204 defp update_content_tag ( content , % Tag { } = tag , opt \\ :add ) do
230205 new_tags = if opt == :add , do: content . tags ++ [ tag ] , else: content . tags -- [ tag ]
231206
@@ -235,26 +210,6 @@ defmodule GroupherServer.CMS.Delegate.ArticleOperation do
235210 |> Repo . update ( )
236211 end
237212
238- @ doc """
239- set topic only for post
240- """
241- def set_topic ( % Topic { title: title } , :post , content_id ) do
242- with { :ok , content } <- ORM . find ( Post , content_id , preload: :topics ) ,
243- { :ok , topic } <-
244- ORM . findby_or_insert ( Topic , % { title: title } , % {
245- title: title ,
246- thread: "post" ,
247- raw: title
248- } ) do
249- content
250- |> Ecto.Changeset . change ( )
251- |> Ecto.Changeset . put_assoc ( :topics , content . topics ++ [ topic ] )
252- |> Repo . update ( )
253- end
254- end
255-
256- def set_topic ( _topic , _thread , _content_id ) , do: { :ok , :pass }
257-
258213 @ doc "update isEdited meta label if needed"
259214 # TODO: diff history
260215 def update_edit_status ( % { meta: % Embeds.ArticleMeta { is_edited: false } = meta } = content ) do
0 commit comments