Fixed issue with pagination of ChatConversations
• Fixed: - issue with pagination of ChatConversations
This commit is contained in:
parent
4297e1f81a
commit
4d2a4cc44d
@ -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
|
||||
|
@ -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())
|
||||
|
||||
|
@ -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'
|
||||
>
|
||||
|
@ -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))
|
||||
}))
|
||||
}
|
||||
|
||||
|
@ -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)))
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user