Skip to content

Commit

Permalink
feat(controllers/thread): finish porting hooks for thread create rout…
Browse files Browse the repository at this point in the history
…e, still need to handle parsing and image processing
  • Loading branch information
akinsey committed Oct 23, 2023
1 parent c7227f6 commit 015efe2
Showing 1 changed file with 31 additions and 6 deletions.
37 changes: 31 additions & 6 deletions lib/epochtalk_server_web/controllers/thread.ex
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ defmodule EpochtalkServerWeb.Controllers.Thread do
alias EpochtalkServer.Models.UserThreadView
alias EpochtalkServer.Models.MetadataThread
alias EpochtalkServer.Models.WatchBoard
alias EpochtalkServer.Models.AutoModeration
alias EpochtalkServer.Models.UserActivity
alias EpochtalkServer.Models.ThreadSubscription
alias EpochtalkServer.Models.Mention

@doc """
Used to retrieve recent threads
Expand Down Expand Up @@ -60,8 +64,29 @@ defmodule EpochtalkServerWeb.Controllers.Thread do
{:allows_self_mod, Board.allows_self_moderation?(board_id, attrs["moderated"])},
{:user_can_moderate, true} <-
{:user_can_moderate, handle_check_user_can_moderate(user, attrs["moderated"])},
# pre processing

# pre/parallel hooks
attrs <- AutoModeration.moderate(user, attrs),
attrs <- Mention.username_to_user_id(user, attrs),

# thread creation
{:ok, thread_data} <- Thread.create(attrs, user) do
# post hooks

# Create Mention notification
Mention.handle_user_mention_creation(user, attrs, thread_data.post)

Check warning on line 78 in lib/epochtalk_server_web/controllers/thread.ex

View workflow job for this annotation

GitHub Actions / static_code_analysis

pattern_match

The pattern can never match the type %EpochtalkServer.Models.Thread{

Check warning on line 78 in lib/epochtalk_server_web/controllers/thread.ex

View workflow job for this annotation

GitHub Actions / static_code_analysis

pattern_match

The pattern can never match the type %EpochtalkServer.Models.Thread{

# Correct TSV due to mentions converting username to user id,
# append post id to attrs since this is thread creation
Mention.correct_text_search_vector(attrs |> Map.put("id", thread_data.post.id))

# Update user activity
UserActivity.update_user_activity(user)

# Subscribe to Thread (this will check user preferences)
ThreadSubscription.create(user, thread_data.post.thread_id)

# TODO(akinsey): Implement the following for completion
# Authorizations
# 1) Check base permissions (done)
Expand All @@ -84,15 +109,15 @@ defmodule EpochtalkServerWeb.Controllers.Thread do
# 4) handle filtering out newbie images

# Hooks
# 1) Auto Moderation moderate (pre)
# 1) Auto Moderation moderate (pre) (done)

# 2) Update user Activity (post) (note: this was missing in old code)
# 2) Update user Activity (post) (note: this was missing in old code) (done)

# 3) Mentions -> convert username to user id (pre)
# 4) Mentions -> create mentions (post)
# 5) Mentions -> correct text search vector after creating mentions (post)
# 3) Mentions -> convert username to user id (pre) (done)
# 4) Mentions -> create mentions (post) (done)
# 5) Mentions -> correct text search vector after creating mentions (post) (done)

# 6) Thread Subscriptions -> Subscribe to Thread (post)
# 6) Thread Subscriptions -> Subscribe to Thread (post) (done)
render(conn, :create, %{thread_data: thread_data})
else
{:error, %Ecto.Changeset{} = cs} ->
Expand Down

0 comments on commit 015efe2

Please sign in to comment.