From b2c69afdbd290627f5b262547bccc1a3cbe90cf6 Mon Sep 17 00:00:00 2001 From: mgabdev <> Date: Mon, 10 Aug 2020 22:16:08 -0500 Subject: [PATCH] Added new sorting for "Hot" in GroupCollection, GroupTimeline MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit • Added: - new sorting for "Hot" in GroupCollection, GroupTimeline --- .../v1/timelines/group_collection_controller.rb | 14 ++++++++++---- .../api/v1/timelines/group_controller.rb | 12 +++++++++--- .../gabsocial/components/group_sort_block.js | 7 ++++++- .../popover/group_timeline_sort_options_popover.js | 10 ++++++++++ app/javascript/gabsocial/constants.js | 1 + .../features/group_collection_timeline.js | 9 +++------ 6 files changed, 39 insertions(+), 14 deletions(-) diff --git a/app/controllers/api/v1/timelines/group_collection_controller.rb b/app/controllers/api/v1/timelines/group_collection_controller.rb index a2bcbbff..ef4d4d88 100644 --- a/app/controllers/api/v1/timelines/group_collection_controller.rb +++ b/app/controllers/api/v1/timelines/group_collection_controller.rb @@ -33,6 +33,7 @@ class Api::V1::Timelines::GroupCollectionController < Api::BaseController def set_sort_type @sort_type = 'newest' @sort_type = params[:sort_by] if [ + 'hot', 'newest', 'recent', 'top_today', @@ -43,7 +44,7 @@ class Api::V1::Timelines::GroupCollectionController < Api::BaseController ].include? params[:sort_by] if @collection_type === 'featured' && (@sort_type == 'newest' || @sort_type == 'recent') - @sort_type = 'top_today' + @sort_type = 'hot' end return @sort_type @@ -72,7 +73,12 @@ class Api::V1::Timelines::GroupCollectionController < Api::BaseController date_limit = 30.days.ago top_order = 'status_stats.favourites_count DESC, status_stats.reblogs_count DESC, status_stats.replies_count DESC' - if @sort_type == 'top_today' + if @sort_type == 'hot' + # : todo : + # unique groups + # unique users + date_limit = 8.hours.ago + elsif @sort_type == 'top_today' date_limit = 24.hours.ago elsif @sort_type == 'top_weekly' date_limit = 7.days.ago @@ -99,7 +105,7 @@ class Api::V1::Timelines::GroupCollectionController < Api::BaseController limit_param(DEFAULT_STATUSES_LIMIT), params_slice(:max_id, :since_id, :min_id) ).reject { |status| FeedManager.instance.filter?(:home, status, current_account.id) } - elsif ['top_today', 'top_weekly', 'top_monthly', 'top_yearly', 'top_all_time'].include? @sort_type + elsif ['top_today', 'top_weekly', 'top_monthly', 'top_yearly', 'top_all_time', 'hot'].include? @sort_type if @sort_type == 'top_all_time' statuses = Status.unscoped.where( group: @groupIds, reply: false @@ -133,7 +139,7 @@ class Api::V1::Timelines::GroupCollectionController < Api::BaseController limit_param(DEFAULT_STATUSES_LIMIT), params_slice(:max_id, :since_id, :min_id) ) - elsif ['top_today', 'top_weekly', 'top_monthly', 'top_yearly', 'top_all_time'].include? @sort_type + elsif ['top_today', 'top_weekly', 'top_monthly', 'top_yearly', 'top_all_time', 'hot'].include? @sort_type if @sort_type == 'top_all_time' statuses = Status.unscoped.where( group: @groupIds, reply: false diff --git a/app/controllers/api/v1/timelines/group_controller.rb b/app/controllers/api/v1/timelines/group_controller.rb index 5a4310d6..a73c8494 100644 --- a/app/controllers/api/v1/timelines/group_controller.rb +++ b/app/controllers/api/v1/timelines/group_controller.rb @@ -22,6 +22,7 @@ class Api::V1::Timelines::GroupController < Api::BaseController def set_sort_type @sort_type = 'newest' @sort_type = params[:sort_by] if [ + 'hot', 'newest', 'recent', 'top_today', @@ -52,7 +53,12 @@ class Api::V1::Timelines::GroupController < Api::BaseController date_limit = 30.days.ago top_order = 'status_stats.favourites_count DESC, status_stats.reblogs_count DESC, status_stats.replies_count DESC' - if @sort_type == 'top_today' + if @sort_type == 'hot' + # : todo : + # unique groups + # unique users + date_limit = 8.hours.ago + elsif @sort_type == 'top_today' date_limit = 24.hours.ago elsif @sort_type == 'top_weekly' date_limit = 7.days.ago @@ -79,7 +85,7 @@ class Api::V1::Timelines::GroupController < Api::BaseController limit_param(DEFAULT_STATUSES_LIMIT), params_slice(:max_id, :since_id, :min_id) ).reject { |status| FeedManager.instance.filter?(:home, status, current_account.id) } - elsif ['top_today', 'top_weekly', 'top_monthly', 'top_yearly', 'top_all_time'].include? @sort_type + elsif ['top_today', 'top_weekly', 'top_monthly', 'top_yearly', 'top_all_time', 'hot'].include? @sort_type if @sort_type == 'top_all_time' statuses = Status.unscoped.where( group: @group, reply: false @@ -116,7 +122,7 @@ class Api::V1::Timelines::GroupController < Api::BaseController limit_param(DEFAULT_STATUSES_LIMIT), params_slice(:max_id, :since_id, :min_id) ) - elsif ['top_today', 'top_weekly', 'top_monthly', 'top_yearly', 'top_all_time'].include? @sort_type + elsif ['top_today', 'top_weekly', 'top_monthly', 'top_yearly', 'top_all_time', 'hot'].include? @sort_type if @sort_type == 'top_all_time' statuses = Status.unscoped.where( group: @group, reply: false diff --git a/app/javascript/gabsocial/components/group_sort_block.js b/app/javascript/gabsocial/components/group_sort_block.js index 74663459..b0e29a77 100644 --- a/app/javascript/gabsocial/components/group_sort_block.js +++ b/app/javascript/gabsocial/components/group_sort_block.js @@ -3,6 +3,7 @@ import { openPopover } from '../actions/popover' import { POPOVER_GROUP_TIMELINE_SORT_OPTIONS, POPOVER_GROUP_TIMELINE_SORT_TOP_OPTIONS, + GROUP_TIMELINE_SORTING_TYPE_HOT, GROUP_TIMELINE_SORTING_TYPE_NEWEST, GROUP_TIMELINE_SORTING_TYPE_RECENT_ACTIVITY, GROUP_TIMELINE_SORTING_TYPE_TOP, @@ -15,7 +16,8 @@ import { import SortBlock from '../components/sort_block' const messages = defineMessages({ - sortBy: { id: 'comment_sort.title', defaultMessage: 'Sort by' }, + sortBy: { id: 'comment_sort.title', defaultMessage: 'Sort by' }, + hotTitle: { id: 'group_timeline_sorting.hot_title', defaultMessage: 'Hot Posts' }, topTitle: { id: 'group_timeline_sorting.top_title', defaultMessage: 'Top Posts' }, topTodayTitle: { id: 'group_timeline_sorting.top_today_title', defaultMessage: 'Today' }, topWeekTitle: { id: 'group_timeline_sorting.top_week_title', defaultMessage: 'This Week' }, @@ -85,6 +87,9 @@ class GroupSortBlock extends PureComponent { let sortValueTopTitle = '' switch (sortByValue) { + case GROUP_TIMELINE_SORTING_TYPE_HOT: + sortValueTitle = intl.formatMessage(messages.hotTitle) + break case GROUP_TIMELINE_SORTING_TYPE_NEWEST: sortValueTitle = intl.formatMessage(messages.newTitle) break diff --git a/app/javascript/gabsocial/components/popover/group_timeline_sort_options_popover.js b/app/javascript/gabsocial/components/popover/group_timeline_sort_options_popover.js index f40f480d..12005417 100644 --- a/app/javascript/gabsocial/components/popover/group_timeline_sort_options_popover.js +++ b/app/javascript/gabsocial/components/popover/group_timeline_sort_options_popover.js @@ -3,6 +3,7 @@ import isObject from 'lodash.isobject' import { closePopover } from '../../actions/popover' import { setGroupTimelineSort } from '../../actions/groups' import { + GROUP_TIMELINE_SORTING_TYPE_HOT, GROUP_TIMELINE_SORTING_TYPE_NEWEST, GROUP_TIMELINE_SORTING_TYPE_RECENT_ACTIVITY, GROUP_TIMELINE_SORTING_TYPE_TOP, @@ -17,6 +18,8 @@ const messages = defineMessages({ recentSubtitle: { id: 'group_timeline_sorting.recent_subtitle', defaultMessage: 'See gabs with most recent comments first' }, newTitle: { id: 'group_timeline_sorting.new_title', defaultMessage: 'New Posts' }, newSubtitle: { id: 'group_timeline_sorting.new_subtitle', defaultMessage: 'See most recent gabs first' }, + hotTitle: { id: 'group_timeline_sorting.hot_title', defaultMessage: 'Hot Posts' }, + hotSubtitle: { id: 'group_timeline_sorting.hot_subtitle', defaultMessage: 'See the most popular and recent gabs' }, }) const mapStateToProps = (state) => ({ @@ -64,6 +67,13 @@ class GroupTimelineSortOptionsPopover extends PureComponent { const isFeaturedTimeline = isObject(options) && options.collectionType === 'featured' const items = [ + { + hideArrow: true, + isActive: sorting === GROUP_TIMELINE_SORTING_TYPE_HOT, + title: intl.formatMessage(messages.hotTitle), + subtitle: intl.formatMessage(messages.hotSubtitle), + onClick: () => this.handleOnClick(GROUP_TIMELINE_SORTING_TYPE_HOT), + }, { hideArrow: true, isActive: sorting === GROUP_TIMELINE_SORTING_TYPE_TOP, diff --git a/app/javascript/gabsocial/constants.js b/app/javascript/gabsocial/constants.js index 1aa96b48..4f522322 100644 --- a/app/javascript/gabsocial/constants.js +++ b/app/javascript/gabsocial/constants.js @@ -125,6 +125,7 @@ export const STATUS_EXPIRATION_OPTION_24_HOURS = '24-hours' export const STATUS_EXPIRATION_OPTION_3_DAYS = '3-days' export const STATUS_EXPIRATION_OPTION_7_DAYS = '7-days' +export const GROUP_TIMELINE_SORTING_TYPE_HOT = 'hot' export const GROUP_TIMELINE_SORTING_TYPE_NEWEST = 'newest' export const GROUP_TIMELINE_SORTING_TYPE_RECENT_ACTIVITY = 'recent' export const GROUP_TIMELINE_SORTING_TYPE_TOP = 'top' diff --git a/app/javascript/gabsocial/features/group_collection_timeline.js b/app/javascript/gabsocial/features/group_collection_timeline.js index a29e5b1e..3b2c725e 100644 --- a/app/javascript/gabsocial/features/group_collection_timeline.js +++ b/app/javascript/gabsocial/features/group_collection_timeline.js @@ -9,11 +9,9 @@ import { } from '../actions/timelines' import { setGroupTimelineSort, - setGroupTimelineTopSort, } from '../actions/groups' import { - GROUP_TIMELINE_SORTING_TYPE_TOP, - GROUP_TIMELINE_SORTING_TYPE_TOP_OPTION_TODAY, + GROUP_TIMELINE_SORTING_TYPE_HOT, GROUP_TIMELINE_SORTING_TYPE_NEWEST, } from '../constants' import getSortBy from '../utils/group_sort_by' @@ -53,8 +51,7 @@ const mapDispatchToProps = (dispatch) => ({ dispatch(expandGroupCollectionTimeline(collectionType, options)) }, setFeaturedTop() { - dispatch(setGroupTimelineSort(GROUP_TIMELINE_SORTING_TYPE_TOP)) - dispatch(setGroupTimelineTopSort(GROUP_TIMELINE_SORTING_TYPE_TOP_OPTION_TODAY)) + dispatch(setGroupTimelineSort(GROUP_TIMELINE_SORTING_TYPE_HOT)) }, setMemberNewest() { dispatch(setGroupTimelineSort(GROUP_TIMELINE_SORTING_TYPE_NEWEST)) @@ -115,7 +112,7 @@ class GroupCollectionTimeline extends PureComponent { sortByTopValue, } = this.props - if (this.props.collectionType === 'featured' && sortByValue !== GROUP_TIMELINE_SORTING_TYPE_TOP) { + if (this.props.collectionType === 'featured' && sortByValue !== GROUP_TIMELINE_SORTING_TYPE_HOT) { this.props.setFeaturedTop() } else if (!!me && this.props.collectionType === 'member' && sortByValue !== GROUP_TIMELINE_SORTING_TYPE_NEWEST) { this.props.setMemberNewest()