add thread show in BBS frontend

This commit is contained in:
duponin 2022-05-19 00:56:20 +02:00
parent 39c47073a3
commit 5086d6d5e9
1 changed files with 28 additions and 0 deletions

View File

@ -53,6 +53,7 @@ def handle_command(state, "help") do
IO.puts("home - Show the home timeline") IO.puts("home - Show the home timeline")
IO.puts("p <text> - Post the given text") IO.puts("p <text> - Post the given text")
IO.puts("r <id> <text> - Reply to the post with the given id") IO.puts("r <id> <text> - Reply to the post with the given id")
IO.puts("t <id> - Show a thread from the given id")
IO.puts("quit - Quit") IO.puts("quit - Quit")
state state
@ -73,6 +74,33 @@ def handle_command(%{user: user} = state, "r " <> text) do
state state
end end
def handle_command(%{user: user} = state, "t " <> activity_id) do
with %Activity{} = activity <- Activity.get_by_id(activity_id) do
activities =
ActivityPub.fetch_activities_for_context(activity.data["context"], %{
blocking_user: user,
user: user,
exclude_id: activity.id
})
case activities do
[] ->
activity_id
|> Activity.get_by_id()
|> puts_activity()
_ ->
activities
|> Enum.reverse()
|> Enum.each(&puts_activity/1)
end
else
_e -> IO.puts("An error occured when trying to show the thread...")
end
state
end
def handle_command(%{user: user} = state, "p " <> text) do def handle_command(%{user: user} = state, "p " <> text) do
text = String.trim(text) text = String.trim(text)