philomena/lib/philomena_web/views/conversation_view.ex

41 lines
1 KiB
Elixir
Raw Normal View History

2019-11-16 05:38:42 +01:00
defmodule PhilomenaWeb.ConversationView do
use PhilomenaWeb, :view
2019-11-18 17:00:08 +01:00
def other_party(%{id: user_id}, %{to_id: user_id} = conversation),
2019-11-16 05:38:42 +01:00
do: conversation.from
2019-11-18 17:00:08 +01:00
def other_party(_user, conversation),
2019-11-16 05:38:42 +01:00
do: conversation.to
2019-11-18 17:00:08 +01:00
def read_by?(%{id: user_id}, %{to_id: user_id} = conversation),
do: conversation.to_read
def read_by?(%{id: user_id}, %{from_id: user_id} = conversation),
do: conversation.from_read
def read_by?(_user, _conversation),
do: false
def hidden_by?(%{id: user_id}, %{to_id: user_id} = conversation),
do: conversation.to_hidden
def hidden_by?(%{id: user_id}, %{from_id: user_id} = conversation),
do: conversation.from_hidden
def hidden_by?(_user, _conversation),
do: false
2019-11-18 17:00:08 +01:00
def conversation_class(user, conversation) do
case read_by?(user, conversation) do
false -> "warning"
2020-01-11 05:20:19 +01:00
_ -> nil
2019-11-18 17:00:08 +01:00
end
end
2019-12-08 00:24:37 +01:00
2024-06-06 22:28:35 +02:00
def last_message_path(conversation, count) do
2019-12-08 00:24:37 +01:00
page = trunc(Float.ceil(count / 25))
2024-06-06 22:28:35 +02:00
~p"/conversations/#{conversation}?#{[page: page]}"
2019-12-08 00:24:37 +01:00
end
2020-01-11 05:20:19 +01:00
end