Gab-Social/app/services/hashtag_query_service.rb

22 lines
529 B
Ruby
Raw Normal View History

2019-07-02 07:10:25 +00:00
# frozen_string_literal: true
class HashtagQueryService < BaseService
2020-05-01 05:50:27 +00:00
LIMIT_PER_MODE = 1
def call(tag, params, account = nil)
2019-07-02 07:10:25 +00:00
tags = tags_for(Array(tag.name) | Array(params[:any])).pluck(:id)
all = tags_for(params[:all])
none = tags_for(params[:none])
Status.distinct
.as_tag_timeline(tags, account)
2019-07-02 07:10:25 +00:00
.tagged_with_all(all)
.tagged_with_none(none)
end
private
2020-05-01 16:46:31 +00:00
def tags_for(tags)
Tag.where(name: tags.map(&:downcase)).limit(LIMIT_PER_MODE) if tags.presence
2019-07-02 07:10:25 +00:00
end
2020-05-01 05:50:27 +00:00
end