Sha256: 67dda5450daab1e10ab94ccc3bf6561836d879c3c430b9b5ac85f3bbd1e6e9b2

Contents?: true

Size: 1.09 KB

Versions: 37

Compression:

Stored size: 1.09 KB

Contents

# frozen_string_literal: true

module Decidim
  # This class serializes a Message so can be exported to CSV
  module DataPortabilitySerializers
    class DataPortabilityConversationSerializer < Decidim::Exporters::Serializer
      include Decidim::ResourceHelper

      # Public: Initializes the serializer with a conversation.
      def initialize(conversation)
        @conversation = conversation
      end

      # Public: Exports a hash with the serialized data for this conversation.
      def serialize
        {
          id: conversation.id,
          messages: messages,
          created_at: conversation.created_at,
          updated_at: conversation.updated_at
        }
      end

      private

      attr_reader :conversation

      def messages
        conversation.messages.map do |message|
          {
            message_id: message.id,
            sender_id: message.sender.id,
            sender_name: message.sender.name,
            body: message.body,
            created_at: message.created_at,
            updated_at: message.updated_at
          }
        end
      end
    end
  end
end

Version data entries

37 entries across 37 versions & 1 rubygems

Version Path
decidim-core-0.24.3 lib/decidim/data_portability_serializers/data_portability_conversation_serializer.rb
decidim-core-0.23.6 lib/decidim/data_portability_serializers/data_portability_conversation_serializer.rb
decidim-core-0.24.2 lib/decidim/data_portability_serializers/data_portability_conversation_serializer.rb
decidim-core-0.23.5 lib/decidim/data_portability_serializers/data_portability_conversation_serializer.rb
decidim-core-0.24.1 lib/decidim/data_portability_serializers/data_portability_conversation_serializer.rb
decidim-core-0.24.0 lib/decidim/data_portability_serializers/data_portability_conversation_serializer.rb
decidim-core-0.24.0.rc2 lib/decidim/data_portability_serializers/data_portability_conversation_serializer.rb
decidim-core-0.23.4 lib/decidim/data_portability_serializers/data_portability_conversation_serializer.rb
decidim-core-0.24.0.rc1 lib/decidim/data_portability_serializers/data_portability_conversation_serializer.rb
decidim-core-0.23.3 lib/decidim/data_portability_serializers/data_portability_conversation_serializer.rb
decidim-core-0.23.2 lib/decidim/data_portability_serializers/data_portability_conversation_serializer.rb
decidim-core-0.23.1 lib/decidim/data_portability_serializers/data_portability_conversation_serializer.rb
decidim-core-0.23.1.rc1 lib/decidim/data_portability_serializers/data_portability_conversation_serializer.rb
decidim-core-0.23.0 lib/decidim/data_portability_serializers/data_portability_conversation_serializer.rb
decidim-core-0.22.0 lib/decidim/data_portability_serializers/data_portability_conversation_serializer.rb
decidim-core-0.21.0 lib/decidim/data_portability_serializers/data_portability_conversation_serializer.rb
decidim-core-0.20.1 lib/decidim/data_portability_serializers/data_portability_conversation_serializer.rb
decidim-core-0.20.0 lib/decidim/data_portability_serializers/data_portability_conversation_serializer.rb
decidim-core-0.19.1 lib/decidim/data_portability_serializers/data_portability_conversation_serializer.rb
decidim-core-0.18.1 lib/decidim/data_portability_serializers/data_portability_conversation_serializer.rb