Skip to content

Commit

Permalink
Fix conversations
Browse files Browse the repository at this point in the history
  • Loading branch information
JoonasAapro committed May 28, 2024
1 parent 78c54d1 commit 9149b0c
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 2 deletions.
4 changes: 2 additions & 2 deletions app/cells/decidim/author/avatar_image.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<% if model.is_a?(Decidim::User) %>
<% if mode.public? %>
<% if model.class == Decidim::UserPresenter %>
<% if model.public? %>
<%= image_tag model.avatar_url, alt: t("decidim.author.avatar", name: display_name), class: "author__avatar" %>
<% else %>
<%= image_tag model.default_avatar_url, alt: t("decidim.author.avatar", name: display_name), class: "author__avatar" %>
Expand Down
46 changes: 46 additions & 0 deletions app/views/decidim/messaging/conversations/_conversation.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<% nickname ||= false %>
<% conversation_path = nickname ? decidim.profile_conversation_path(conversation, nickname:) : decidim.conversation_path(conversation) %>

<%= link_to conversation_path, id: "conversation-#{conversation.id}", class: "conversation__item" do %>
<div class="conversation__item-avatar">
<% if conversation.interlocutors(current_user).count == 1 %>
<%= cell "decidim/author", present(conversation.interlocutors(current_user).first), layout: :avatar, skip_profile_link: true %>
<% else %>
<%= icon "group-line", class: "w-4 h-4 text-gray fill-current" %>
<% end %>
</div>

<div class="conversation__item-snippet">
<div class="conversation__item-snippet-title" data-interlocutors-list>
<h2 class="h5 text-secondary">
<% if conversation.interlocutors(current_user).last.public? %>
<%= conversation.interlocutors(current_user).last.name %>
<% else %>
<%= I18n.t("unnamed_user", scope: "decidim.privacy.private_account") %>
<% end %>
</h2>

<% if conversation.interlocutors(current_user).count > 1 %>
<div class="flex -space-x-2">
<% conversation.interlocutors(current_user).each do |interlocutor| %>
<span class="rounded-full border border-white inline-block w-6 h-6">
<%= cell "decidim/author", present(interlocutor), layout: :avatar, skip_profile_link: true %>
</span>
<% end %>
</div>
<% end %>
</div>

<p class="conversation__item-snippet-message"><%= truncate conversation.last_message.body, length: 150 %></p>

<div class="conversation__item-snippet-time">
<%= t("decidim.user_conversations.index.time_ago", time: time_ago_in_words(Time.zone.parse(conversation.last_message.created_at.to_s))) %>
</div>
</div>

<div class="conversation__item-unread">
<% if conversation.unread_count(current_user).positive? %>
<span><%= conversation.unread_count(current_user) %></span>
<% end %>
</div>
<% end %>
23 changes: 23 additions & 0 deletions app/views/decidim/messaging/conversations/_messages.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<% messages.each do |message| %>
<div class="conversation__message<%= " flex-row-reverse ml-auto" if sender_is_user?(sender) %>">
<div class="w-8 h-8 flex-none border border-white">
<%= cell "decidim/author", present(sender), layout: :avatar %>
</div>

<div class="conversation__message-text">
<span class="conversation__message-sender<%= " ml-auto" if sender_is_user?(sender) %>">
<%= if sender.public?
sender.name
else
I18n.t("unnamed_user", scope: "decidim.privacy.private_account")
end %>
</span>
<div>
<%= simple_format(message.body_with_links) %>
</div>
<span class="conversation__message-time" title="<%= messages.last.created_at.strftime("%d-%m-%Y %H:%M:%S%z") %>">
<%= messages.last.friendly_created_at %>
</span>
</div>
</div>
<% end %>

0 comments on commit 9149b0c

Please sign in to comment.