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(
|
count = ChatConversationAccount.where(
|
||||||
account: current_account,
|
account: current_account,
|
||||||
is_hidden: false,
|
is_hidden: false,
|
||||||
is_approved: false,
|
is_approved: false
|
||||||
).where.not(last_chat_message_id: nil).count
|
).where.not(last_chat_message_id: nil).count
|
||||||
render json: count
|
render json: count
|
||||||
end
|
end
|
||||||
|
@ -119,10 +119,10 @@ export const fetchChatConversationsFail = (error) => ({
|
|||||||
export const expandChatConversations = () => (dispatch, getState) => {
|
export const expandChatConversations = () => (dispatch, getState) => {
|
||||||
if (!me) return
|
if (!me) return
|
||||||
|
|
||||||
const url = getState().getIn(['chat_conversations', 'approved', 'next'])
|
const url = getState().getIn(['chat_conversation_lists', 'approved', 'next'])
|
||||||
const isLoading = getState().getIn(['chat_conversations', 'approved', 'isLoading'])
|
const isLoading = getState().getIn(['chat_conversation_lists', 'approved', 'isLoading'])
|
||||||
|
|
||||||
if (url === null || isLoading) return
|
if (!url || url === null || isLoading) return
|
||||||
|
|
||||||
dispatch(expandChatConversationsRequest())
|
dispatch(expandChatConversationsRequest())
|
||||||
|
|
||||||
@ -196,10 +196,10 @@ export const fetchChatConversationRequestedFail = (error) => ({
|
|||||||
export const expandChatConversationRequested = () => (dispatch, getState) => {
|
export const expandChatConversationRequested = () => (dispatch, getState) => {
|
||||||
if (!me) return
|
if (!me) return
|
||||||
|
|
||||||
const url = getState().getIn(['chat_conversations', 'requested', 'next'])
|
const url = getState().getIn(['chat_conversation_lists', 'requested', 'next'])
|
||||||
const isLoading = getState().getIn(['chat_conversations', 'requested', 'isLoading'])
|
const isLoading = getState().getIn(['chat_conversation_lists', 'requested', 'isLoading'])
|
||||||
|
|
||||||
if (url === null || isLoading) return
|
if (!url || url === null || isLoading) return
|
||||||
|
|
||||||
dispatch(expandChatConversationRequestedRequest())
|
dispatch(expandChatConversationRequestedRequest())
|
||||||
|
|
||||||
@ -211,7 +211,9 @@ export const expandChatConversationRequested = () => (dispatch, getState) => {
|
|||||||
dispatch(importFetchedAccounts(conversationsAccounts))
|
dispatch(importFetchedAccounts(conversationsAccounts))
|
||||||
// dispatch(importFetchedChatMessages(conversationsChatMessages))
|
// dispatch(importFetchedChatMessages(conversationsChatMessages))
|
||||||
dispatch(expandChatConversationRequestedSuccess(response.data, next ? next.uri : null))
|
dispatch(expandChatConversationRequestedSuccess(response.data, next ? next.uri : null))
|
||||||
}).catch(error => dispatch(expandChatConversationRequestedFail(error)))
|
}).catch(error => {
|
||||||
|
dispatch(expandChatConversationRequestedFail(error))
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
export const expandChatConversationRequestedRequest = () => ({
|
export const expandChatConversationRequestedRequest = () => ({
|
||||||
@ -273,10 +275,10 @@ export const fetchChatConversationMutedFail = (error) => ({
|
|||||||
export const expandChatConversationMuted = () => (dispatch, getState) => {
|
export const expandChatConversationMuted = () => (dispatch, getState) => {
|
||||||
if (!me) return
|
if (!me) return
|
||||||
|
|
||||||
const url = getState().getIn(['chat_conversations', 'muted', 'next'])
|
const url = getState().getIn(['chat_conversation_lists', 'muted', 'next'])
|
||||||
const isLoading = getState().getIn(['chat_conversations', 'muted', 'isLoading'])
|
const isLoading = getState().getIn(['chat_conversation_lists', 'muted', 'isLoading'])
|
||||||
|
|
||||||
if (url === null || isLoading) return
|
if (!url || url === null || isLoading) return
|
||||||
|
|
||||||
dispatch(expandChatConversationMutedRequest())
|
dispatch(expandChatConversationMutedRequest())
|
||||||
|
|
||||||
|
@ -2,6 +2,7 @@ import React from 'react'
|
|||||||
import PropTypes from 'prop-types'
|
import PropTypes from 'prop-types'
|
||||||
import { connect } from 'react-redux'
|
import { connect } from 'react-redux'
|
||||||
import debounce from 'lodash.debounce'
|
import debounce from 'lodash.debounce'
|
||||||
|
import noop from 'lodash.noop'
|
||||||
import ImmutablePureComponent from 'react-immutable-pure-component'
|
import ImmutablePureComponent from 'react-immutable-pure-component'
|
||||||
import ImmutablePropTypes from 'react-immutable-proptypes'
|
import ImmutablePropTypes from 'react-immutable-proptypes'
|
||||||
import {
|
import {
|
||||||
@ -43,6 +44,7 @@ class ChatConversationsList extends ImmutablePureComponent {
|
|||||||
isLoading={isLoading}
|
isLoading={isLoading}
|
||||||
showLoading={isLoading}
|
showLoading={isLoading}
|
||||||
placeholderComponent={AccountPlaceholder}
|
placeholderComponent={AccountPlaceholder}
|
||||||
|
onScrollToTop={noop}
|
||||||
placeholderCount={3}
|
placeholderCount={3}
|
||||||
emptyMessage='Empty'
|
emptyMessage='Empty'
|
||||||
>
|
>
|
||||||
|
@ -49,18 +49,22 @@ const initialState = ImmutableMap({
|
|||||||
|
|
||||||
const normalizeList = (state, source, chatConversations, next) => {
|
const normalizeList = (state, source, chatConversations, next) => {
|
||||||
return state.update(source, listMap => listMap.withMutations(map => {
|
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('next', next)
|
||||||
map.set('loaded', true)
|
map.set('loaded', true)
|
||||||
map.set('isLoading', false)
|
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) => {
|
const appendToList = (state, source, chatConversations, next) => {
|
||||||
return state.update(source, listMap => listMap.withMutations(map => {
|
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('next', next)
|
||||||
map.set('isLoading', false)
|
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 importChatConversation = (state, chatConversation) => state.set(chatConversation.chat_conversation_id, normalizeChatConversation(chatConversation))
|
||||||
|
|
||||||
const importChatConversations = (state, chatConversations) => {
|
const importChatConversations = (state, chatConversations) => {
|
||||||
|
if (!Array.isArray(chatConversations)) return state
|
||||||
|
|
||||||
return state.withMutations((mutable) => chatConversations.forEach((chatConversation) => importChatConversation(mutable, chatConversation)))
|
return state.withMutations((mutable) => chatConversations.forEach((chatConversation) => importChatConversation(mutable, chatConversation)))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user