group_serializer.rb 578 Bytes
Newer Older
Rob Colbert's avatar
Rob Colbert committed
1 2 3 4 5
# frozen_string_literal: true

class REST::GroupSerializer < ActiveModel::Serializer
  include RoutingHelper
  
2458773093's avatar
2458773093 committed
6
  attributes :id, :title, :description, :cover_image_url, :is_archived, :member_count
Rob Colbert's avatar
Rob Colbert committed
7 8 9 10 11

  def id
    object.id.to_s
  end

2458773093's avatar
2458773093 committed
12 13 14 15 16 17
  def clean_migrated_url
    object
      .cover_image_file_name
      .sub("gab://groups/", "https://gab.com/media/user/")
  end

Rob Colbert's avatar
Rob Colbert committed
18
  def cover_image_url
2458773093's avatar
2458773093 committed
19 20 21 22
    if object.cover_image_file_name and object.cover_image_file_name.start_with? "gab://groups/"
      return clean_migrated_url
    end

Rob Colbert's avatar
Rob Colbert committed
23 24 25
    full_asset_url(object.cover_image.url)
  end
end