2021-06-22 12:09:25 +00:00
|
|
|
defmodule MatrixServer do
|
2021-06-25 15:43:12 +00:00
|
|
|
def get_mxid(localpart) when is_binary(localpart) do
|
|
|
|
"@#{localpart}:#{server_name()}"
|
|
|
|
end
|
|
|
|
|
|
|
|
def server_name do
|
|
|
|
Application.get_env(:matrix_server, :server_name)
|
|
|
|
end
|
2021-06-26 20:02:18 +00:00
|
|
|
|
2021-07-10 21:16:00 +00:00
|
|
|
def maybe_update_map(map, old_key, new_key) do
|
|
|
|
maybe_update_map(map, old_key, new_key, &Function.identity/1)
|
2021-06-26 20:02:18 +00:00
|
|
|
end
|
|
|
|
|
2021-07-10 21:16:00 +00:00
|
|
|
def maybe_update_map(map, old_key, new_key, fun) when is_map_key(map, old_key) do
|
2021-06-26 20:02:18 +00:00
|
|
|
value = Map.fetch!(map, old_key)
|
|
|
|
|
|
|
|
map
|
|
|
|
|> Map.put(new_key, fun.(value))
|
|
|
|
|> Map.delete(old_key)
|
|
|
|
end
|
|
|
|
|
2021-07-10 21:16:00 +00:00
|
|
|
def maybe_update_map(map, _, _, _), do: map
|
|
|
|
|
|
|
|
def localpart_regex, do: ~r/^([a-z0-9\._=\/])+$/
|
|
|
|
|
|
|
|
@alphabet Enum.into(?a..?z, []) ++ Enum.into(?A..?Z, [])
|
2021-07-13 17:35:02 +00:00
|
|
|
def random_string(length), do: random_string(length, @alphabet)
|
|
|
|
|
|
|
|
def random_string(length, alphabet) when length >= 1 do
|
|
|
|
for _ <- 1..length, into: "", do: <<Enum.random(alphabet)>>
|
2021-07-10 21:16:00 +00:00
|
|
|
end
|
2021-07-17 15:38:20 +00:00
|
|
|
|
|
|
|
def default_room_version, do: "7"
|
2021-06-22 12:09:25 +00:00
|
|
|
end
|