Skip to content

Commit

Permalink
Change order of announcements in admin page to sort them newest-first (
Browse files Browse the repository at this point in the history
…mastodon#15091)

* Change order of announcements in admin page to sort show newly-created first

Fixes mastodon#15090

* Use reverse-chronological rather than creation date only
  • Loading branch information
ClearlyClaire authored and umonaca committed Nov 8, 2020
1 parent 1d529b3 commit f8d5bc1
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/controllers/admin/announcements_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def destroy
private

def set_announcements
@announcements = AnnouncementFilter.new(filter_params).results.page(params[:page])
@announcements = AnnouncementFilter.new(filter_params).results.reverse_chronological.page(params[:page])
end

def set_announcement
Expand Down
1 change: 1 addition & 0 deletions app/models/announcement.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class Announcement < ApplicationRecord
scope :published, -> { where(published: true) }
scope :without_muted, ->(account) { joins("LEFT OUTER JOIN announcement_mutes ON announcement_mutes.announcement_id = announcements.id AND announcement_mutes.account_id = #{account.id}").where('announcement_mutes.id IS NULL') }
scope :chronological, -> { order(Arel.sql('COALESCE(announcements.starts_at, announcements.scheduled_at, announcements.published_at, announcements.created_at) ASC')) }
scope :reverse_chronological, -> { order(Arel.sql('COALESCE(announcements.starts_at, announcements.scheduled_at, announcements.published_at, announcements.created_at) DESC')) }

has_many :announcement_mutes, dependent: :destroy
has_many :announcement_reactions, dependent: :destroy
Expand Down

0 comments on commit f8d5bc1

Please sign in to comment.