use Sshd.ShellHandler
alias Pleroma.Web.CommonAPI
alias Pleroma.Web.ActivityPub.ActivityPub
+ alias Pleroma.Activity
def on_shell(username, _pubkey, _ip, _port) do
:ok = IO.puts("Welcome to #{Pleroma.Config.get([:instance, :name])}!")
def puts_activity(activity) do
status = Pleroma.Web.MastodonAPI.StatusView.render("status.json", %{activity: activity})
- IO.puts("#{status.id} by #{status.account.display_name} (#{status.account.acct}):")
+ IO.puts("-- #{status.id} by #{status.account.display_name} (#{status.account.acct})")
IO.puts(HtmlSanitizeEx.strip_tags(status.content))
IO.puts("")
end
IO.puts("help - This help")
IO.puts("home - Show the home timeline")
IO.puts("p <text> - Post the given text")
+ IO.puts("r <id> <text> - Reply to the post with the given id")
IO.puts("quit - Quit")
state
end
+ def handle_command(%{user: user} = state, "r " <> text) do
+ text = String.trim(text)
+ [activity_id, rest] = String.split(text, " ", parts: 2)
+
+ with %Activity{} <- Activity.get_by_id(activity_id),
+ {:ok, _activity} <-
+ CommonAPI.post(user, %{"status" => rest, "in_reply_to_status_id" => activity_id}) do
+ IO.puts("Replied!")
+ else
+ _e -> IO.puts("Could not reply...")
+ end
+
+ state
+ end
+
def handle_command(%{user: user} = state, "p " <> text) do
text = String.trim(text)
{:input, ^input, code} when is_binary(code) ->
code = String.trim(code)
- handle_command(state, code)
+ state = handle_command(state, code)
loop(%{state | counter: state.counter + 1})
alias Pleroma.BBS.Handler
alias Pleroma.Web.CommonAPI
alias Pleroma.User
+ alias Pleroma.Repo
+ alias Pleroma.Activity
import ExUnit.CaptureIO
import Pleroma.Factory
+ import Ecto.Query
test "getting the home timeline" do
user = insert(:user)
assert output =~ "hey"
assert output =~ "hello"
end
+
+ test "posting" do
+ user = insert(:user)
+
+ output =
+ capture_io(fn ->
+ Handler.handle_command(%{user: user}, "p this is a test post")
+ end)
+
+ assert output =~ "Posted"
+
+ activity =
+ Repo.one(
+ from(a in Activity,
+ where: fragment("?->>'type' = ?", a.data, "Create")
+ )
+ )
+
+ assert activity.actor == user.ap_id
+ assert activity.data["object"]["content"] == "this is a test post"
+ end
+
+ test "replying" do
+ user = insert(:user)
+ another_user = insert(:user)
+
+ {:ok, activity} = CommonAPI.post(another_user, %{"status" => "this is a test post"})
+
+ output =
+ capture_io(fn ->
+ Handler.handle_command(%{user: user}, "r #{activity.id} this is a reply")
+ end)
+
+ assert output =~ "Replied"
+
+ reply =
+ Repo.one(
+ from(a in Activity,
+ where: fragment("?->>'type' = ?", a.data, "Create"),
+ where: a.actor == ^user.ap_id
+ )
+ )
+
+ assert reply.actor == user.ap_id
+ assert reply.data["object"]["content"] == "this is a reply"
+ assert reply.data["object"]["inReplyTo"] == activity.data["object"]["id"]
+ end
end