From 4d2a4cc44da4f37010d7d53415b6d47b438920ed Mon Sep 17 00:00:00 2001 From: mgabdev <> Date: Thu, 31 Dec 2020 20:51:02 -0500 Subject: [PATCH] Fixed issue with pagination of ChatConversations MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit • Fixed: - issue with pagination of ChatConversations --- .../requested_conversations_controller.rb | 2 +- .../gabsocial/actions/chat_conversations.js | 22 ++++++++++--------- .../components/chat_conversations_list.js | 2 ++ .../reducers/chat_conversation_lists.js | 8 +++++-- .../gabsocial/reducers/chat_conversations.js | 2 ++ 5 files changed, 23 insertions(+), 13 deletions(-) diff --git a/app/controllers/api/v1/chat_conversations/requested_conversations_controller.rb b/app/controllers/api/v1/chat_conversations/requested_conversations_controller.rb index aa91b43e..b56f2200 100644 --- a/app/controllers/api/v1/chat_conversations/requested_conversations_controller.rb +++ b/app/controllers/api/v1/chat_conversations/requested_conversations_controller.rb @@ -15,7 +15,7 @@ class Api::V1::ChatConversations::RequestedConversationsController < Api::BaseCo count = ChatConversationAccount.where( account: current_account, is_hidden: false, - is_approved: false, + is_approved: false ).where.not(last_chat_message_id: nil).count render json: count end diff --git a/app/javascript/gabsocial/actions/chat_conversations.js b/app/javascript/gabsocial/actions/chat_conversations.js index c1ebe430..ecba6d5e 100644 --- a/app/javascript/gabsocial/actions/chat_conversations.js +++ b/app/javascript/gabsocial/actions/chat_conversations.js @@ -119,10 +119,10 @@ export const fetchChatConversationsFail = (error) => ({ export const expandChatConversations = () => (dispatch, getState) => { if (!me) return - const url = getState().getIn(['chat_conversations', 'approved', 'next']) - const isLoading = getState().getIn(['chat_conversations', 'approved', 'isLoading']) + const url = getState().getIn(['chat_conversation_lists', 'approved', 'next']) + const isLoading = getState().getIn(['chat_conversation_lists', 'approved', 'isLoading']) - if (url === null || isLoading) return + if (!url || url === null || isLoading) return dispatch(expandChatConversationsRequest()) @@ -196,10 +196,10 @@ export const fetchChatConversationRequestedFail = (error) => ({ export const expandChatConversationRequested = () => (dispatch, getState) => { if (!me) return - const url = getState().getIn(['chat_conversations', 'requested', 'next']) - const isLoading = getState().getIn(['chat_conversations', 'requested', 'isLoading']) + const url = getState().getIn(['chat_conversation_lists', 'requested', 'next']) + const isLoading = getState().getIn(['chat_conversation_lists', 'requested', 'isLoading']) - if (url === null || isLoading) return + if (!url || url === null || isLoading) return dispatch(expandChatConversationRequestedRequest()) @@ -211,7 +211,9 @@ export const expandChatConversationRequested = () => (dispatch, getState) => { dispatch(importFetchedAccounts(conversationsAccounts)) // dispatch(importFetchedChatMessages(conversationsChatMessages)) dispatch(expandChatConversationRequestedSuccess(response.data, next ? next.uri : null)) - }).catch(error => dispatch(expandChatConversationRequestedFail(error))) + }).catch(error => { + dispatch(expandChatConversationRequestedFail(error)) + }) } export const expandChatConversationRequestedRequest = () => ({ @@ -273,10 +275,10 @@ export const fetchChatConversationMutedFail = (error) => ({ export const expandChatConversationMuted = () => (dispatch, getState) => { if (!me) return - const url = getState().getIn(['chat_conversations', 'muted', 'next']) - const isLoading = getState().getIn(['chat_conversations', 'muted', 'isLoading']) + const url = getState().getIn(['chat_conversation_lists', 'muted', 'next']) + const isLoading = getState().getIn(['chat_conversation_lists', 'muted', 'isLoading']) - if (url === null || isLoading) return + if (!url || url === null || isLoading) return dispatch(expandChatConversationMutedRequest()) diff --git a/app/javascript/gabsocial/features/messages/components/chat_conversations_list.js b/app/javascript/gabsocial/features/messages/components/chat_conversations_list.js index b97627be..9e080a0c 100644 --- a/app/javascript/gabsocial/features/messages/components/chat_conversations_list.js +++ b/app/javascript/gabsocial/features/messages/components/chat_conversations_list.js @@ -2,6 +2,7 @@ import React from 'react' import PropTypes from 'prop-types' import { connect } from 'react-redux' import debounce from 'lodash.debounce' +import noop from 'lodash.noop' import ImmutablePureComponent from 'react-immutable-pure-component' import ImmutablePropTypes from 'react-immutable-proptypes' import { @@ -43,6 +44,7 @@ class ChatConversationsList extends ImmutablePureComponent { isLoading={isLoading} showLoading={isLoading} placeholderComponent={AccountPlaceholder} + onScrollToTop={noop} placeholderCount={3} emptyMessage='Empty' > diff --git a/app/javascript/gabsocial/reducers/chat_conversation_lists.js b/app/javascript/gabsocial/reducers/chat_conversation_lists.js index cb60b4ef..ea0fd367 100644 --- a/app/javascript/gabsocial/reducers/chat_conversation_lists.js +++ b/app/javascript/gabsocial/reducers/chat_conversation_lists.js @@ -49,18 +49,22 @@ const initialState = ImmutableMap({ const normalizeList = (state, source, chatConversations, next) => { return state.update(source, listMap => listMap.withMutations(map => { + const items = Array.isArray(chatConversations) ? ImmutableList(chatConversations.map(chatConversation => chatConversation.chat_conversation_id)) : ImmutableList() + map.set('next', next) map.set('loaded', true) map.set('isLoading', false) - map.set('items', ImmutableList(chatConversations.map(chatConversation => chatConversation.chat_conversation_id))) + map.set('items', items) })) } const appendToList = (state, source, chatConversations, next) => { return state.update(source, listMap => listMap.withMutations(map => { + const items = Array.isArray(chatConversations) ? chatConversations.map(chatConversation => chatConversation.chat_conversation_id) : [] + map.set('next', next) map.set('isLoading', false) - map.set('items', map.get('items').concat(chatConversations.map(chatConversation => chatConversation.chat_conversation_id))) + map.set('items', map.get('items').concat(items)) })) } diff --git a/app/javascript/gabsocial/reducers/chat_conversations.js b/app/javascript/gabsocial/reducers/chat_conversations.js index 81d15eb7..f848ea78 100644 --- a/app/javascript/gabsocial/reducers/chat_conversations.js +++ b/app/javascript/gabsocial/reducers/chat_conversations.js @@ -41,6 +41,8 @@ const setLastChatMessage = (state, chatMessage) => { const importChatConversation = (state, chatConversation) => state.set(chatConversation.chat_conversation_id, normalizeChatConversation(chatConversation)) const importChatConversations = (state, chatConversations) => { + if (!Array.isArray(chatConversations)) return state + return state.withMutations((mutable) => chatConversations.forEach((chatConversation) => importChatConversation(mutable, chatConversation))) }