2021-07-23 22:13:12 +00:00
|
|
|
alias MatrixServer.{Repo, Room, Event, Account, Device}
|
|
|
|
|
2021-08-16 17:30:47 +00:00
|
|
|
timestamp = fn n -> DateTime.from_unix!(n, :microsecond) end
|
|
|
|
|
2021-07-23 22:13:12 +00:00
|
|
|
Repo.insert!(%Account{
|
|
|
|
localpart: "chuck",
|
|
|
|
password_hash: Bcrypt.hash_pwd_salt("sneed")
|
|
|
|
})
|
|
|
|
|
|
|
|
Repo.insert(%Device{
|
|
|
|
device_id: "android",
|
|
|
|
display_name: "My Android",
|
|
|
|
localpart: "chuck"
|
|
|
|
})
|
2021-07-23 19:00:01 +00:00
|
|
|
|
|
|
|
# Auth difference example from here:
|
|
|
|
# https://matrix.org/docs/guides/implementing-stateres#auth-differences
|
|
|
|
|
2021-07-27 10:55:36 +00:00
|
|
|
alice =
|
|
|
|
Repo.insert!(%Account{
|
|
|
|
localpart: "alice",
|
|
|
|
password_hash: Bcrypt.hash_pwd_salt("sneed")
|
|
|
|
})
|
|
|
|
|
|
|
|
bob =
|
|
|
|
Repo.insert!(%Account{
|
|
|
|
localpart: "bob",
|
|
|
|
password_hash: Bcrypt.hash_pwd_salt("sneed")
|
|
|
|
})
|
|
|
|
|
|
|
|
charlie =
|
|
|
|
Repo.insert!(%Account{
|
|
|
|
localpart: "charlie",
|
|
|
|
password_hash: Bcrypt.hash_pwd_salt("sneed")
|
|
|
|
})
|
|
|
|
|
2021-07-26 21:42:35 +00:00
|
|
|
room =
|
|
|
|
Repo.insert!(%Room{
|
|
|
|
id: "room1",
|
|
|
|
visibility: :public
|
|
|
|
})
|
2021-07-23 19:00:01 +00:00
|
|
|
|
2021-08-18 21:22:04 +00:00
|
|
|
create_room =
|
|
|
|
Repo.insert!(
|
|
|
|
Event.create_room(room, alice, "v1", false)
|
|
|
|
|> Map.put(:origin_server_ts, timestamp.(0))
|
|
|
|
|> Event.post_process()
|
|
|
|
|> elem(1)
|
|
|
|
)
|
2021-07-23 19:00:01 +00:00
|
|
|
|
|
|
|
Repo.insert!(
|
2021-08-18 21:22:04 +00:00
|
|
|
Event.join(room, alice, false)
|
2021-07-23 19:00:01 +00:00
|
|
|
|> Map.put(:prev_events, ["create"])
|
|
|
|
|> Map.put(:auth_events, ["create"])
|
2021-08-16 17:30:47 +00:00
|
|
|
|> Map.put(:origin_server_ts, timestamp.(1))
|
2021-07-23 19:00:01 +00:00
|
|
|
|> Map.put(:event_id, "join_alice")
|
|
|
|
)
|
|
|
|
|
|
|
|
Repo.insert!(
|
2021-07-27 10:55:36 +00:00
|
|
|
Event.join(room, bob)
|
2021-08-18 21:22:04 +00:00
|
|
|
|> elem(1)
|
2021-07-23 19:00:01 +00:00
|
|
|
|> Map.put(:prev_events, ["join_alice"])
|
|
|
|
|> Map.put(:auth_events, ["create"])
|
2021-08-16 17:30:47 +00:00
|
|
|
|> Map.put(:origin_server_ts, timestamp.(2))
|
2021-07-23 19:00:01 +00:00
|
|
|
|> Map.put(:event_id, "join_bob")
|
|
|
|
)
|
|
|
|
|
|
|
|
Repo.insert!(
|
2021-07-27 10:55:36 +00:00
|
|
|
Event.join(room, charlie)
|
2021-08-18 21:22:04 +00:00
|
|
|
|> elem(1)
|
2021-07-23 19:00:01 +00:00
|
|
|
|> Map.put(:prev_events, ["join_bob"])
|
|
|
|
|> Map.put(:auth_events, ["create"])
|
2021-08-16 17:30:47 +00:00
|
|
|
|> Map.put(:origin_server_ts, timestamp.(3))
|
2021-07-23 19:00:01 +00:00
|
|
|
|> Map.put(:event_id, "join_charlie")
|
|
|
|
)
|
|
|
|
|
2021-08-18 21:22:04 +00:00
|
|
|
%Event{content: content} = event = Event.power_levels(room, alice) |> elem(1)
|
2021-07-23 19:00:01 +00:00
|
|
|
event = %Event{event | content: %{content | "users" => %{"alice" => 100, "bob" => 100}}}
|
|
|
|
|
|
|
|
Repo.insert!(
|
|
|
|
event
|
|
|
|
|> Map.put(:prev_events, ["join_alice"])
|
|
|
|
|> Map.put(:auth_events, ["create", "join_alice"])
|
2021-08-16 17:30:47 +00:00
|
|
|
|> Map.put(:origin_server_ts, timestamp.(4))
|
2021-07-23 19:00:01 +00:00
|
|
|
|> Map.put(:event_id, "a")
|
|
|
|
)
|
|
|
|
|
2021-08-18 21:22:04 +00:00
|
|
|
%Event{content: content} = event = Event.power_levels(room, bob) |> elem(1)
|
2021-07-23 19:00:01 +00:00
|
|
|
|
|
|
|
event = %Event{
|
|
|
|
event
|
|
|
|
| content: %{content | "users" => %{"alice" => 100, "bob" => 100, "charlie" => 100}}
|
|
|
|
}
|
|
|
|
|
|
|
|
Repo.insert!(
|
|
|
|
event
|
|
|
|
|> Map.put(:prev_events, ["a"])
|
|
|
|
|> Map.put(:auth_events, ["create", "join_bob", "a"])
|
2021-08-16 17:30:47 +00:00
|
|
|
|> Map.put(:origin_server_ts, timestamp.(5))
|
2021-07-23 19:00:01 +00:00
|
|
|
|> Map.put(:event_id, "b")
|
|
|
|
)
|
|
|
|
|
|
|
|
Repo.insert!(
|
2021-07-27 10:55:36 +00:00
|
|
|
Event.topic(room, alice, "sneed")
|
2021-08-18 21:22:04 +00:00
|
|
|
|> elem(1)
|
2021-07-23 19:00:01 +00:00
|
|
|
|> Map.put(:prev_events, ["a"])
|
|
|
|
|> Map.put(:auth_events, ["create", "join_alice", "a"])
|
2021-08-16 17:30:47 +00:00
|
|
|
|> Map.put(:origin_server_ts, timestamp.(5))
|
2021-07-23 19:00:01 +00:00
|
|
|
|> Map.put(:event_id, "fork")
|
|
|
|
)
|