{
@@ -83,7 +90,7 @@ class WhoToFollowPanel extends ImmutablePureComponent {
showDismiss
key={accountId}
id={accountId}
- dismissAction={dismissSuggestion}
+ dismissAction={dismissRelatedSuggestion}
/>
))
}
diff --git a/app/javascript/gabsocial/reducers/suggestions.js b/app/javascript/gabsocial/reducers/suggestions.js
index 9f4b89d5..b31aad18 100644
--- a/app/javascript/gabsocial/reducers/suggestions.js
+++ b/app/javascript/gabsocial/reducers/suggestions.js
@@ -3,28 +3,38 @@ import {
SUGGESTIONS_FETCH_SUCCESS,
SUGGESTIONS_FETCH_FAIL,
SUGGESTIONS_DISMISS,
-} from '../actions/suggestions';
-import { Map as ImmutableMap, List as ImmutableList, fromJS } from 'immutable';
+} from '../actions/suggestions'
+import {
+ Map as ImmutableMap,
+ List as ImmutableList,
+ fromJS,
+} from 'immutable'
const initialState = ImmutableMap({
- items: ImmutableList(),
- isLoading: false,
-});
+ related: ImmutableMap({
+ items: ImmutableList(),
+ isLoading: false,
+ }),
+ verified: ImmutableMap({
+ items: ImmutableList(),
+ isLoading: false,
+ }),
+})
export default function suggestionsReducer(state = initialState, action) {
switch(action.type) {
case SUGGESTIONS_FETCH_REQUEST:
- return state.set('isLoading', true);
+ return state.setIn([action.suggestionType, 'isLoading'], true)
case SUGGESTIONS_FETCH_SUCCESS:
- return state.withMutations(map => {
- map.set('items', fromJS(action.accounts.map(x => x.id)));
- map.set('isLoading', false);
- });
+ return state.withMutations((map) => {
+ map.setIn([action.suggestionType, 'items'], fromJS(action.accounts.map(x => x.id)))
+ map.setIn([action.suggestionType, 'isLoading'], false)
+ })
case SUGGESTIONS_FETCH_FAIL:
- return state.set('isLoading', false);
+ return state.setIn([action.suggestionType, 'isLoading'], false)
case SUGGESTIONS_DISMISS:
- return state.update('items', list => list.filterNot(id => id === action.id));
+ return state.updateIn([action.suggestionType, 'items'], list => list.filterNot(id => id === action.id))
default:
- return state;
+ return state
}
-};
+}
diff --git a/app/lib/verified_suggestions.rb b/app/lib/verified_suggestions.rb
new file mode 100644
index 00000000..8c80b42e
--- /dev/null
+++ b/app/lib/verified_suggestions.rb
@@ -0,0 +1,38 @@
+# frozen_string_literal: true
+
+class VerifiedSuggestions
+ EXPIRE_AFTER = 12.minute.seconds
+ MAX_ITEMS = 12
+ KEY = 'popularsuggestions'
+
+ class << self
+ include Redisable
+
+ def set(account_ids)
+ return if account_ids.nil? || account_ids.empty?
+ redis.setex(KEY, EXPIRE_AFTER, account_ids)
+ end
+
+ def get(account_id)
+ account_ids = redis.get(KEY)
+
+ if account_ids.nil? || account_ids.empty?
+ account_ids = Account.searchable
+ .where(is_verified: true)
+ .discoverable
+ .by_recent_status
+ .local
+ .limit(MAX_ITEMS)
+ .pluck(:id)
+
+ set(account_ids) if account_ids.nil? || account_ids.empty?
+ else
+ account_ids = JSON.parse(account_ids)
+ end
+
+ return [] if account_ids.nil? || account_ids.empty?
+
+ Account.where(id: account_ids)
+ end
+ end
+end