Sha256: efad0eb7b353f3afb4a82318a51108604a15d771360bf18e6fc625de8ee70597

Contents?: true

Size: 1.42 KB

Versions: 6

Compression:

Stored size: 1.42 KB

Contents

# frozen_string_literal: true

module Decidim
  class UserConversationCell < Decidim::ViewModel
    include Cell::ViewModel::Partial
    include Decidim::FormFactory
    include Decidim::Core::Engine.routes.url_helpers

    def user
      model
    end

    def show
      return render :show if conversation.id

      render :new
    end

    # renders a unique message, useful for ajax calls
    def message(msg)
      render view: :messages, locals: { sender: msg.sender, messages: [msg] }
    end

    def user_grouped_messages
      conversation.messages.includes(:sender).chunk(&:sender)
    end

    def conversation
      context[:conversation]
    end

    def sender_is_user?(sender)
      user.id == sender.id
    end

    def form_ob
      return Messaging::MessageForm.new if conversation.id

      Messaging::ConversationForm.new(recipient_id: interlocutors)
    end

    def interlocutors
      conversation.interlocutors(user)
    end

    def recipients
      return [] if conversation.id

      interlocutors
    end

    def reply_form(&)
      return form_for(form_ob, url: decidim.profile_conversations_path(nickname: user.nickname), method: :post, &) unless conversation.id

      form_for(form_ob, url: decidim.profile_conversation_path(nickname: user.nickname, id: conversation.id), method: :put, remote: true, &)
    end

    def back_path
      decidim.profile_conversations_path(nickname: user.nickname)
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
decidim-core-0.29.1 app/cells/decidim/user_conversation_cell.rb
decidim-core-0.29.0 app/cells/decidim/user_conversation_cell.rb
decidim-core-0.29.0.rc4 app/cells/decidim/user_conversation_cell.rb
decidim-core-0.29.0.rc3 app/cells/decidim/user_conversation_cell.rb
decidim-core-0.29.0.rc2 app/cells/decidim/user_conversation_cell.rb
decidim-core-0.29.0.rc1 app/cells/decidim/user_conversation_cell.rb