-
-
Notifications
You must be signed in to change notification settings - Fork 6.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add hashtag filter to profiles #9755
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
8798811
Add hashtag filter to profiles
Gargron 00226db
Display featured hashtags on public profile
Gargron 425a876
Use separate model for featured tags
Gargron 2d5d471
Update featured hashtag counters on-write
Gargron d799336
Limit featured tags to 10
Gargron File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
# frozen_string_literal: true | ||
|
||
class Settings::FeaturedTagsController < Settings::BaseController | ||
layout 'admin' | ||
|
||
before_action :authenticate_user! | ||
before_action :set_featured_tags, only: :index | ||
before_action :set_featured_tag, except: [:index, :create] | ||
before_action :set_most_used_tags, only: :index | ||
|
||
def index | ||
@featured_tag = FeaturedTag.new | ||
end | ||
|
||
def create | ||
@featured_tag = current_account.featured_tags.new(featured_tag_params) | ||
@featured_tag.reset_data | ||
|
||
if @featured_tag.save | ||
redirect_to settings_featured_tags_path | ||
else | ||
set_featured_tags | ||
set_most_used_tags | ||
|
||
render :index | ||
end | ||
end | ||
|
||
def destroy | ||
@featured_tag.destroy! | ||
redirect_to settings_featured_tags_path | ||
end | ||
|
||
private | ||
|
||
def set_featured_tag | ||
@featured_tag = current_account.featured_tags.find(params[:id]) | ||
end | ||
|
||
def set_featured_tags | ||
@featured_tags = current_account.featured_tags.reject(&:new_record?) | ||
end | ||
|
||
def set_most_used_tags | ||
@most_used_tags = Tag.most_used(current_account).where.not(id: @featured_tags.map(&:id)).limit(10) | ||
end | ||
|
||
def featured_tag_params | ||
params.require(:featured_tag).permit(:name) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,6 +32,6 @@ def account_params | |
end | ||
|
||
def set_account | ||
@account = current_user.account | ||
@account = current_account | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -288,3 +288,7 @@ | |
border-bottom: 0; | ||
} | ||
} | ||
|
||
.directory__tag .trends__item__current { | ||
width: auto; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# frozen_string_literal: true | ||
# == Schema Information | ||
# | ||
# Table name: featured_tags | ||
# | ||
# id :bigint(8) not null, primary key | ||
# account_id :bigint(8) | ||
# tag_id :bigint(8) | ||
# statuses_count :bigint(8) default(0), not null | ||
# last_status_at :datetime | ||
# created_at :datetime not null | ||
# updated_at :datetime not null | ||
# | ||
|
||
class FeaturedTag < ApplicationRecord | ||
belongs_to :account, inverse_of: :featured_tags, required: true | ||
belongs_to :tag, inverse_of: :featured_tags, required: true | ||
|
||
delegate :name, to: :tag, allow_nil: true | ||
|
||
validates :name, presence: true | ||
validate :validate_featured_tags_limit, on: :create | ||
|
||
def name=(str) | ||
self.tag = Tag.find_or_initialize_by(name: str.delete('#').mb_chars.downcase.to_s) | ||
end | ||
|
||
def increment(timestamp) | ||
update(statuses_count: statuses_count + 1, last_status_at: timestamp) | ||
end | ||
|
||
def decrement(deleted_status_id) | ||
update(statuses_count: [0, statuses_count - 1].max, last_status_at: account.statuses.where(visibility: %i(public unlisted)).tagged_with(tag).where.not(id: deleted_status_id).select(:created_at).first&.created_at) | ||
end | ||
|
||
def reset_data | ||
self.statuses_count = account.statuses.where(visibility: %i(public unlisted)).tagged_with(tag).count | ||
self.last_status_at = account.statuses.where(visibility: %i(public unlisted)).tagged_with(tag).select(:created_at).first&.created_at | ||
end | ||
|
||
private | ||
|
||
def validate_featured_tags_limit | ||
errors.add(:base, I18n.t('featured_tags.errors.limit')) if account.featured_tags.count >= 10 | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
- content_for :page_title do | ||
= t('settings.featured_tags') | ||
|
||
= simple_form_for @featured_tag, url: settings_featured_tags_path do |f| | ||
= render 'shared/error_messages', object: @featured_tag | ||
|
||
.fields-group | ||
= f.input :name, wrapper: :with_block_label, hint: safe_join([t('simple_form.hints.featured_tag.name'), safe_join(@most_used_tags.map { |tag| link_to("##{tag.name}", settings_featured_tags_path(featured_tag: { name: tag.name }), method: :post) }, ', ')], ' ') | ||
|
||
.actions | ||
= f.button :button, t('featured_tags.add_new'), type: :submit | ||
|
||
%hr.spacer/ | ||
|
||
- @featured_tags.each do |featured_tag| | ||
.directory__tag{ class: params[:tag] == featured_tag.name ? 'active' : nil } | ||
%div | ||
%h4 | ||
= fa_icon 'hashtag' | ||
= featured_tag.name | ||
%small | ||
- if featured_tag.last_status_at.nil? | ||
= t('accounts.nothing_here') | ||
- else | ||
%time{ datetime: featured_tag.last_status_at.iso8601, title: l(featured_tag.last_status_at) }= l featured_tag.last_status_at | ||
= table_link_to 'trash', t('filters.index.delete'), settings_featured_tag_path(featured_tag), method: :delete, data: { confirm: t('admin.accounts.are_you_sure') } | ||
.trends__item__current= number_to_human featured_tag.statuses_count, strip_insignificant_zeros: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure what the project's preference is, but I've been seeing a lot of people move from
#[]
to#fetch()
since it tells the reader a lot more about the intent. For example, in this method we EXPECT:tag
to be a key, thusparams.fetch(:tag)
, but if we didn'tparams.fetch(:tag, nil)
and of course we get all the niceness of#fetch
's other default api:fetch(:key) {dynamicvalue}
.Either way, seems like what you want here could also be expressed as:
Status.tagged_with(Tag.where(name: params[:tag]).pluck(:id).first)
, though iftagged_with
allows an array you can just drop.first
.