feat: sort the conversations before rendering

This commit is contained in:
Shivam Mishra
2025-10-01 16:53:10 +05:30
parent 77832436f3
commit 2fab5f4c9a

View File

@@ -75,14 +75,17 @@ const getters = {
getMineChats: (_state, _, __, rootGetters) => activeFilters => { getMineChats: (_state, _, __, rootGetters) => activeFilters => {
const currentUserID = rootGetters.getCurrentUser?.id; const currentUserID = rootGetters.getCurrentUser?.id;
return _state.allConversations.filter(conversation => { // Sort after filtering so tab lists keep server pagination order despite merge appends.
const { assignee } = conversation.meta; return _state.allConversations
const isAssignedToMe = assignee && assignee.id === currentUserID; .filter(conversation => {
const shouldFilter = applyPageFilters(conversation, activeFilters); const { assignee } = conversation.meta;
const isChatMine = isAssignedToMe && shouldFilter; const isAssignedToMe = assignee && assignee.id === currentUserID;
const shouldFilter = applyPageFilters(conversation, activeFilters);
const isChatMine = isAssignedToMe && shouldFilter;
return isChatMine; return isChatMine;
}); })
.sort((a, b) => sortComparator(a, b, _state.chatSortFilter));
}, },
getAppliedConversationFiltersV2: _state => { getAppliedConversationFiltersV2: _state => {
// TODO: Replace existing one with V2 after migrating the filters to use camelcase // TODO: Replace existing one with V2 after migrating the filters to use camelcase
@@ -96,11 +99,13 @@ const getters = {
return hasAppliedFilters ? filterQueryGenerator(_state.appliedFilters) : []; return hasAppliedFilters ? filterQueryGenerator(_state.appliedFilters) : [];
}, },
getUnAssignedChats: _state => activeFilters => { getUnAssignedChats: _state => activeFilters => {
return _state.allConversations.filter(conversation => { return _state.allConversations
const isUnAssigned = !conversation.meta.assignee; .filter(conversation => {
const shouldFilter = applyPageFilters(conversation, activeFilters); const isUnAssigned = !conversation.meta.assignee;
return isUnAssigned && shouldFilter; const shouldFilter = applyPageFilters(conversation, activeFilters);
}); return isUnAssigned && shouldFilter;
})
.sort((a, b) => sortComparator(a, b, _state.chatSortFilter));
}, },
getAllStatusChats: (_state, _, __, rootGetters) => activeFilters => { getAllStatusChats: (_state, _, __, rootGetters) => activeFilters => {
const currentUser = rootGetters.getCurrentUser; const currentUser = rootGetters.getCurrentUser;
@@ -110,17 +115,19 @@ const getters = {
const permissions = getUserPermissions(currentUser, currentAccountId); const permissions = getUserPermissions(currentUser, currentAccountId);
const userRole = getUserRole(currentUser, currentAccountId); const userRole = getUserRole(currentUser, currentAccountId);
return _state.allConversations.filter(conversation => { return _state.allConversations
const shouldFilter = applyPageFilters(conversation, activeFilters); .filter(conversation => {
const allowedForRole = applyRoleFilter( const shouldFilter = applyPageFilters(conversation, activeFilters);
conversation, const allowedForRole = applyRoleFilter(
userRole, conversation,
permissions, userRole,
currentUserId permissions,
); currentUserId
);
return shouldFilter && allowedForRole; return shouldFilter && allowedForRole;
}); })
.sort((a, b) => sortComparator(a, b, _state.chatSortFilter));
}, },
getChatListLoadingStatus: ({ listLoadingStatus }) => listLoadingStatus, getChatListLoadingStatus: ({ listLoadingStatus }) => listLoadingStatus,
getAllMessagesLoaded(_state) { getAllMessagesLoaded(_state) {