Add function to query whether server participates in a room

Move from integer timestamps to datetimes
This commit is contained in:
Pim Kunis 2021-08-16 19:30:47 +02:00
parent 5d75244bc0
commit 02edff90e7
7 changed files with 65 additions and 20 deletions

View file

@ -0,0 +1,15 @@
defmodule MatrixServer.Repo.Migrations.ChangeTimestampsToDatetime do
use Ecto.Migration
def change do
alter table(:events) do
remove :origin_server_ts, :integer, null: false
add :origin_server_ts, :utc_datetime_usec, null: false
end
alter table(:server_key_info) do
remove :valid_until, :bigint, default: 0, null: false
add :valid_until, :utc_datetime_usec, null: false
end
end
end

View file

@ -1,5 +1,7 @@
alias MatrixServer.{Repo, Room, Event, Account, Device}
timestamp = fn n -> DateTime.from_unix!(n, :microsecond) end
Repo.insert!(%Account{
localpart: "chuck",
password_hash: Bcrypt.hash_pwd_salt("sneed")
@ -40,7 +42,7 @@ room =
Repo.insert!(
Event.create_room(room, alice, "v1")
|> Map.put(:origin_server_ts, 0)
|> Map.put(:origin_server_ts, timestamp.(0))
|> Map.put(:event_id, "create")
)
@ -48,7 +50,7 @@ Repo.insert!(
Event.join(room, alice)
|> Map.put(:prev_events, ["create"])
|> Map.put(:auth_events, ["create"])
|> Map.put(:origin_server_ts, 1)
|> Map.put(:origin_server_ts, timestamp.(1))
|> Map.put(:event_id, "join_alice")
)
@ -56,7 +58,7 @@ Repo.insert!(
Event.join(room, bob)
|> Map.put(:prev_events, ["join_alice"])
|> Map.put(:auth_events, ["create"])
|> Map.put(:origin_server_ts, 2)
|> Map.put(:origin_server_ts, timestamp.(2))
|> Map.put(:event_id, "join_bob")
)
@ -64,7 +66,7 @@ Repo.insert!(
Event.join(room, charlie)
|> Map.put(:prev_events, ["join_bob"])
|> Map.put(:auth_events, ["create"])
|> Map.put(:origin_server_ts, 3)
|> Map.put(:origin_server_ts, timestamp.(3))
|> Map.put(:event_id, "join_charlie")
)
@ -75,7 +77,7 @@ Repo.insert!(
event
|> Map.put(:prev_events, ["join_alice"])
|> Map.put(:auth_events, ["create", "join_alice"])
|> Map.put(:origin_server_ts, 4)
|> Map.put(:origin_server_ts, timestamp.(4))
|> Map.put(:event_id, "a")
)
@ -90,7 +92,7 @@ Repo.insert!(
event
|> Map.put(:prev_events, ["a"])
|> Map.put(:auth_events, ["create", "join_bob", "a"])
|> Map.put(:origin_server_ts, 5)
|> Map.put(:origin_server_ts, timestamp.(5))
|> Map.put(:event_id, "b")
)
@ -98,6 +100,6 @@ Repo.insert!(
Event.topic(room, alice, "sneed")
|> Map.put(:prev_events, ["a"])
|> Map.put(:auth_events, ["create", "join_alice", "a"])
|> Map.put(:origin_server_ts, 5)
|> Map.put(:origin_server_ts, timestamp.(5))
|> Map.put(:event_id, "fork")
)