@@ -170,10 +170,8 @@ defmodule GroupherServer.CMS.Delegate.CiteTasks do
170
170
# IO.inspect(links, label: "links -> ")
171
171
172
172
Enum . reduce ( links , [ ] , fn link , acc ->
173
- with { :ok , cited_content } <- parse_cited_content ( link ) do
174
- # IO.inspect(cited_content, label: "before shape cited_content")
175
- List . insert_at ( acc , 0 , shape_cited_content ( comment , cited_content , block_id ) )
176
- else
173
+ case parse_cited ( link ) do
174
+ { :ok , cited } -> List . insert_at ( acc , 0 , shape_cited ( comment , cited , block_id ) )
177
175
_ -> acc
178
176
end
179
177
end )
@@ -185,11 +183,8 @@ defmodule GroupherServer.CMS.Delegate.CiteTasks do
185
183
# [{"a", [{"href", "https://coderplanets.com/post/195675"}], []},]
186
184
defp do_parse_cited_info ( article , block_id , links ) do
187
185
Enum . reduce ( links , [ ] , fn link , acc ->
188
- with { :ok , cited_content } <- parse_cited_content ( link ) do
189
- # do not cite artilce itself
190
- # true <- article.id !== cited_content.id do
191
- List . insert_at ( acc , 0 , shape_cited_content ( article , cited_content , block_id ) )
192
- else
186
+ case parse_cited ( link ) do
187
+ { :ok , cited } -> List . insert_at ( acc , 0 , shape_cited ( article , cited , block_id ) )
193
188
_ -> acc
194
189
end
195
190
end )
@@ -198,60 +193,52 @@ defmodule GroupherServer.CMS.Delegate.CiteTasks do
198
193
199
194
# cite article in comment
200
195
# 在评论中引用文章
201
- defp shape_cited_content (
202
- % Comment { } = comment ,
203
- % { type: :article , content: cited_article } ,
204
- block_id
205
- ) do
196
+ defp shape_cited ( % Comment { } = comment , % { type: :article , content: cited } , block_id ) do
206
197
% {
207
- cited_by_id: cited_article . id ,
208
- cited_by_type: cited_article . meta . thread ,
198
+ cited_by_id: cited . id ,
199
+ cited_by_type: cited . meta . thread ,
209
200
comment_id: comment . id ,
210
201
block_linker: [ block_id ] ,
211
202
user_id: comment . author_id ,
212
203
# extra fields for next-step usage
213
204
# used for updating citing_count, avoid load again
214
- cited_content: cited_article ,
205
+ cited_content: cited ,
215
206
# for later insert all
216
207
citing_time: comment . updated_at |> DateTime . truncate ( :second )
217
208
}
218
209
end
219
210
220
211
# cite comment in comment
221
212
# 评论中引用评论
222
- defp shape_cited_content (
223
- % Comment { } = comment ,
224
- % { type: :comment , content: cited_comment } ,
225
- block_id
226
- ) do
213
+ defp shape_cited ( % Comment { } = comment , % { type: :comment , content: cited } , block_id ) do
227
214
% {
228
- cited_by_id: cited_comment . id ,
215
+ cited_by_id: cited . id ,
229
216
cited_by_type: "COMMENT" ,
230
217
comment_id: comment . id ,
231
218
block_linker: [ block_id ] ,
232
219
user_id: comment . author_id ,
233
220
# extra fields for next-step usage
234
221
# used for updating citing_count, avoid load again
235
- cited_content: cited_comment ,
222
+ cited_content: cited ,
236
223
# for later insert all
237
224
citing_time: comment . updated_at |> DateTime . truncate ( :second )
238
225
}
239
226
end
240
227
241
228
# cite article in article
242
229
# 文章之间相互引用
243
- defp shape_cited_content ( article , % { type: :article , content: cited_article } , block_id ) do
230
+ defp shape_cited ( article , % { type: :article , content: cited } , block_id ) do
244
231
{ :ok , thread } = thread_of_article ( article )
245
232
{ :ok , info } = match ( thread )
246
233
247
234
% {
248
- cited_by_id: cited_article . id ,
249
- cited_by_type: cited_article . meta . thread ,
235
+ cited_by_id: cited . id ,
236
+ cited_by_type: cited . meta . thread ,
250
237
block_linker: [ block_id ] ,
251
238
user_id: article . author . user . id ,
252
239
# extra fields for next-step usage
253
240
# used for updating citing_count, avoid load again
254
- cited_content: cited_article ,
241
+ cited_content: cited ,
255
242
# for later insert all
256
243
citing_time: article . updated_at |> DateTime . truncate ( :second )
257
244
}
@@ -260,26 +247,26 @@ defmodule GroupherServer.CMS.Delegate.CiteTasks do
260
247
261
248
# cite comment in article
262
249
# 文章中引用评论
263
- defp shape_cited_content ( article , % { type: :comment , content: cited_comment } , block_id ) do
250
+ defp shape_cited ( article , % { type: :comment , content: cited } , block_id ) do
264
251
{ :ok , thread } = thread_of_article ( article )
265
252
{ :ok , info } = match ( thread )
266
253
267
254
% {
268
- cited_by_id: cited_comment . id ,
255
+ cited_by_id: cited . id ,
269
256
cited_by_type: "COMMENT" ,
270
257
block_linker: [ block_id ] ,
271
258
user_id: article . author . user . id ,
272
259
# extra fields for next-step usage
273
260
# used for updating citing_count, avoid load again
274
- cited_content: cited_comment ,
261
+ cited_content: cited ,
275
262
# for later insert all
276
263
citing_time: article . updated_at |> DateTime . truncate ( :second )
277
264
}
278
265
|> Map . put ( info . foreign_key , article . id )
279
266
end
280
267
281
268
# 要考虑是否有 comment_id 的情况,如果有,那么 就应该 load comment 而不是 article
282
- defp parse_cited_content ( { "a" , attrs , _ } ) do
269
+ defp parse_cited ( { "a" , attrs , _ } ) do
283
270
with { :ok , link } <- parse_link ( attrs ) ,
284
271
true <- is_site_article_link? ( link ) do
285
272
# IO.inspect(link, label: "parse link")