* [MM-31133]: participants screen component (#5116) * Fixed imports * Misc fixes * Added i18n string * Moved '(you)' after the name * [MM-30386][MM-30387] Client and redux changes for collapsed reply threads (#5175) * [MM-30386][MM-30387] Client and redux changes for collapsed reply threads * fix tests * add and use flat shim * use test helper function * use test helper function * revert crt changes to unused client and action functions * use toEqual * incorporate code review feedback * don't assume server success * batch actions * clearer code * WIP in changes, websockets and more redux changes * Added mark thread as read and mark all as read in a team * Added isCollapsedThreadEnabled entity * Fixed loading global screens on load if it's the last visited screen * Added root count and websocker and redux events related to threads * Fixed Message, Mention count root count on init and decrement actions * Moved old client to new client/rest * Misc fix * Misc fix * Misc. * Old redux test cases fix * Added polyfill back for array flat * Fixes mark as unread and pariticipants error in thread * Fixed initial load when CRT not enabled * Handling CRT preference change * Get threads fallsback to search in posts in case of unfollowed or unloaded threads * Gets threads on reconnect * DM, Channel counter fix * Added threads redux tests * Fixed channel dot issue when child post is arrived channel not active * Cleaning up threads on load, not letting posts included in threads getting deleted which can trigger many posts to be loaded at once * Fixed crash on team switch, partly fixed enable/disable from webapp * Fix when viewing a post from notification, to prevent from navigating back to global threads * Fixed when preferences are changed before app is launched * Fixed issue of NO THREADS appearing on reconnect * Excludes CRT handling for newly logged in users * Fixed unread dot showing even when all messages are read * Update app/mm-redux/selectors/entities/threads.ts Co-authored-by: Elias Nahum <nahumhbl@gmail.com> * Not viewing threads action is pushed only when suer is in Global Threads * Fixed cleanup to exclude current team when cleanup starts on app going to background * Dispatch is not passed as param, misc code fixes * Preferences check and handling code refactored * added redux-mock-store * Preference change fix * Removed user login dispatch when handling crt change * Fixed fallback thread support * Return getThread * Added threads to sidebar, moved teamId logic to action * [MM-29106, MM-34847, MM-34843, MM-34846] Collapsed reply threads, Global Threads & In Channel experience UI implementation (#5376) * feat: global threads screen * Refactored global thread menu and misc design fixes * Added empty states for threads, unread. Removing markdown from thread messages. * Added friendly date, fixed long usernames & channel names in threads view. * Mark thread as read * Added intl, refactored code, seperated thread footer from thread item * Added intl to global threads, added global threads to android * Added Follow button to thread view * Added thread badges * In Channel experience .. WIP * Clean posts in channel incase CRT is enabled. * Added follow button, deleted messages doesnot have footer and design is now according to figma * Removed old post and post header * Added for follow/unfollow thread and fixed old one * MISC design & code fixes * Added options-follow/unfollow to the post's long press menu * Shows ORIGINAL MESSAGE DELETED in thread when root post gets deleted * Post list ts fix * Old testcases fix * Eslint fix * Added custom status emoji in at mention autocomplete * Fixed the width of the displayname and username * Changed the max width for the full name and username in the autocomplete item * Review fixes Changed the behaviour of ellipses for long names * Removed safearea bottom * Fixes Mark and unread and thread header theme * Fixes mark as unread and pariticipants error in thread * Unfollowing post fix and misc * Merge with master fix * Added fallback to get thread from posts in case of not following/unloaded threads * Refactored code and added tests for screens * Loads threads from global threads screen, marks thread as marked on new thread posts * Fixed tabs render on no threads, threads footer items styling and tests * Loads threads based on tab and items according to constant * Added infinite loading, unreads based on redux and not active thread list * Fixed the username cutting off after truncating display name issue * Changed avatars to touchableOpacity and added prop for parent component to style * Fixed infinite loading, tab switching scroll to top, misc styles, team switching, scroll indicator insets * Added follow button to DMs, moved follow button further right only on ios * Snapshot updated * Moved from useSelector to connect HOC * Scrolls to top on team change, changed thread constant from mm-redux * Fix merge issue * Test case fix * Fixed participants list * Update app/components/global_threads/global_threads.tsx Co-authored-by: Elias Nahum <nahumhbl@gmail.com> * Update app/components/global_threads/thread_footer/thread_footer.tsx Co-authored-by: Elias Nahum <nahumhbl@gmail.com> * Update app/components/sidebars/main/channels_list/channel_item/index.js Co-authored-by: Elias Nahum <nahumhbl@gmail.com> * Update app/screens/thread/index.js Co-authored-by: Elias Nahum <nahumhbl@gmail.com> * Moved date numbers to constants * Fixed global threads component issues * Thread item display logic moved to redux * Misc fixes * Reverted to TouchableWithFeedback with opacity * Removed obselete snapshots * Removing currentTeamId as we aregetting it in action * Moved to connect component from useSelect for sidebar * Thread read issue fix * Removed react-native-navigation mock Co-authored-by: Anurag Shivarathri <anurag6713@gmail.com> Co-authored-by: Mattermod <mattermod@users.noreply.github.com> Co-authored-by: Manoj <manoj@brightscout.com> Co-authored-by: Elias Nahum <nahumhbl@gmail.com> Co-authored-by: Anurag Shivarathri <anurag6713@gmail.com> Co-authored-by: Mattermod <mattermod@users.noreply.github.com> Co-authored-by: Elias Nahum <nahumhbl@gmail.com> Co-authored-by: Manoj <manoj@brightscout.com> Co-authored-by: Ashish Bhate <bhate.ashish@gmail.com> Co-authored-by: Ashish Bhate <ashish.bhate@mattermost.com> Co-authored-by: Mattermod <mattermod@users.noreply.github.com> Co-authored-by: Elias Nahum <nahumhbl@gmail.com> Co-authored-by: Manoj <manoj@brightscout.com>
398 lines
9.6 KiB
JavaScript
398 lines
9.6 KiB
JavaScript
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
|
// See LICENSE.txt for license information.
|
|
|
|
import {combineReducers} from 'redux';
|
|
|
|
import {ViewTypes} from '@constants';
|
|
import {
|
|
ChannelTypes,
|
|
FileTypes,
|
|
PostTypes,
|
|
} from '@mm-redux/action_types';
|
|
|
|
function displayName(state = '', action) {
|
|
switch (action.type) {
|
|
case ViewTypes.SET_CHANNEL_DISPLAY_NAME:
|
|
return action.displayName || '';
|
|
case ChannelTypes.SELECT_CHANNEL:
|
|
return '';
|
|
default:
|
|
return state;
|
|
}
|
|
}
|
|
|
|
function handlePostDraftChanged(state, action) {
|
|
return {
|
|
...state,
|
|
[action.channelId]: Object.assign({}, state[action.channelId], {draft: action.draft}),
|
|
};
|
|
}
|
|
|
|
function handleSetPostDraft(state, action) {
|
|
return {
|
|
...state,
|
|
[action.channelId]: {
|
|
draft: action.draft,
|
|
cursorPosition: 0,
|
|
files: action.files,
|
|
},
|
|
};
|
|
}
|
|
|
|
function handleSelectChannel(state, action) {
|
|
let data = {...state};
|
|
if (action.data && !data[action.data]) {
|
|
data = {
|
|
...state,
|
|
[action.data]: {
|
|
draft: '',
|
|
cursorPosition: 0,
|
|
files: [],
|
|
},
|
|
};
|
|
}
|
|
|
|
return data;
|
|
}
|
|
|
|
export function handleSetTempUploadFilesForPostDraft(state, action) {
|
|
if (action.rootId) {
|
|
return state;
|
|
}
|
|
|
|
const tempFiles = action.clientIds.map((temp) => ({...temp, loading: true}));
|
|
const files = [
|
|
...state[action.channelId]?.files || [],
|
|
...tempFiles,
|
|
];
|
|
|
|
return {
|
|
...state,
|
|
[action.channelId]: Object.assign({}, state[action.channelId], {files}),
|
|
};
|
|
}
|
|
|
|
function handleRetryUploadFileForPost(state, action) {
|
|
if (action.rootId) {
|
|
return state;
|
|
}
|
|
|
|
const files = state[action.channelId].files.map((f) => {
|
|
if (f.clientId === action.clientId) {
|
|
return {
|
|
...f,
|
|
loading: true,
|
|
failed: false,
|
|
};
|
|
}
|
|
|
|
return f;
|
|
});
|
|
|
|
return {
|
|
...state,
|
|
[action.channelId]: Object.assign({}, state[action.channelId], {files}),
|
|
};
|
|
}
|
|
|
|
function handleReceivedUploadFiles(state, action) {
|
|
if (action.rootId || !state[action.channelId].files) {
|
|
return state;
|
|
}
|
|
|
|
// Reconcile tempFiles with the received uploaded files
|
|
const files = state[action.channelId].files.map((tempFile) => {
|
|
const file = action.data.find((f) => f.clientId === tempFile.clientId);
|
|
if (file) {
|
|
return {
|
|
...file,
|
|
localPath: tempFile.localPath,
|
|
loading: false,
|
|
};
|
|
}
|
|
|
|
return tempFile;
|
|
});
|
|
|
|
return {
|
|
...state,
|
|
[action.channelId]: Object.assign({}, state[action.channelId], {files}),
|
|
};
|
|
}
|
|
|
|
function handleUploadFilesFailure(state, action) {
|
|
if (action.rootId) {
|
|
return state;
|
|
}
|
|
|
|
const clientIds = action.clientIds;
|
|
const files = state[action.channelId].files.map((tempFile) => {
|
|
if (clientIds.includes(tempFile.clientId)) {
|
|
return {
|
|
...tempFile,
|
|
loading: false,
|
|
failed: true,
|
|
};
|
|
}
|
|
|
|
return tempFile;
|
|
});
|
|
|
|
return {
|
|
...state,
|
|
[action.channelId]: Object.assign({}, state[action.channelId], {files}),
|
|
};
|
|
}
|
|
|
|
function handleClearFilesForPostDraft(state, action) {
|
|
if (action.rootId) {
|
|
return state;
|
|
}
|
|
|
|
return {
|
|
...state,
|
|
[action.channelId]: Object.assign({}, state[action.channelId], {files: []}),
|
|
};
|
|
}
|
|
|
|
function handleRemoveFileFromPostDraft(state, action) {
|
|
if (action.rootId) {
|
|
return state;
|
|
}
|
|
|
|
const files = state[action.channelId].files.filter((file) => (file.clientId !== action.clientId));
|
|
|
|
return {
|
|
...state,
|
|
[action.channelId]: Object.assign({}, state[action.channelId], {files}),
|
|
};
|
|
}
|
|
|
|
function handleRemoveLastFileFromPostDraft(state, action) {
|
|
if (action.rootId) {
|
|
return state;
|
|
}
|
|
|
|
const files = [...state[action.channelId].files];
|
|
files.splice(-1);
|
|
|
|
return {
|
|
...state,
|
|
[action.channelId]: Object.assign({}, state[action.channelId], {files}),
|
|
};
|
|
}
|
|
|
|
function handleRemoveFailedFilesFromPostDraft(state, action) {
|
|
if (action.rootId) {
|
|
return state;
|
|
}
|
|
|
|
const files = state[action.channelId].files.filter((f) => !f.failed);
|
|
return {
|
|
...state,
|
|
[action.channelId]: Object.assign({}, state[action.channelId], {files}),
|
|
};
|
|
}
|
|
|
|
function drafts(state = {}, action) { // eslint-disable-line complexity
|
|
switch (action.type) {
|
|
case ViewTypes.POST_DRAFT_CHANGED:
|
|
return handlePostDraftChanged(state, action);
|
|
case ViewTypes.SET_POST_DRAFT:
|
|
return handleSetPostDraft(state, action);
|
|
case ChannelTypes.SELECT_CHANNEL:
|
|
return handleSelectChannel(state, action);
|
|
case ViewTypes.SET_TEMP_UPLOAD_FILES_FOR_POST_DRAFT:
|
|
return handleSetTempUploadFilesForPostDraft(state, action);
|
|
case ViewTypes.RETRY_UPLOAD_FILE_FOR_POST:
|
|
return handleRetryUploadFileForPost(state, action);
|
|
case FileTypes.RECEIVED_UPLOAD_FILES:
|
|
return handleReceivedUploadFiles(state, action);
|
|
case FileTypes.UPLOAD_FILES_FAILURE:
|
|
return handleUploadFilesFailure(state, action);
|
|
case ViewTypes.CLEAR_FILES_FOR_POST_DRAFT:
|
|
return handleClearFilesForPostDraft(state, action);
|
|
case ViewTypes.CLEAR_FAILED_FILES_FOR_POST_DRAFT:
|
|
return handleRemoveFailedFilesFromPostDraft(state, action);
|
|
case ViewTypes.REMOVE_FILE_FROM_POST_DRAFT:
|
|
return handleRemoveFileFromPostDraft(state, action);
|
|
case ViewTypes.REMOVE_LAST_FILE_FROM_POST_DRAFT:
|
|
return handleRemoveLastFileFromPostDraft(state, action);
|
|
default:
|
|
return state;
|
|
}
|
|
}
|
|
|
|
function loading(state = false, action) {
|
|
switch (action.type) {
|
|
case ViewTypes.SET_CHANNEL_LOADER:
|
|
return action.loading;
|
|
default:
|
|
return state;
|
|
}
|
|
}
|
|
|
|
function refreshing(state = false, action) {
|
|
switch (action.type) {
|
|
case ViewTypes.SET_CHANNEL_REFRESHING:
|
|
return action.loading;
|
|
default:
|
|
return state;
|
|
}
|
|
}
|
|
|
|
function retryFailed(state = false, action) {
|
|
switch (action.type) {
|
|
case ViewTypes.SET_CHANNEL_RETRY_FAILED:
|
|
return action.failed;
|
|
case PostTypes.GET_POSTS_SUCCESS:
|
|
case PostTypes.GET_POSTS_SINCE_SUCCESS: {
|
|
if (state) {
|
|
return false;
|
|
}
|
|
|
|
return state;
|
|
}
|
|
default:
|
|
return state;
|
|
}
|
|
}
|
|
|
|
function loadingPosts(state = {}, action) {
|
|
switch (action.type) {
|
|
case ViewTypes.LOADING_POSTS: {
|
|
const nextState = {...state};
|
|
nextState[action.channelId] = action.data;
|
|
return nextState;
|
|
}
|
|
default:
|
|
return state;
|
|
}
|
|
}
|
|
|
|
function lastGetPosts(state = {}, action) {
|
|
switch (action.type) {
|
|
case ViewTypes.RECEIVED_POSTS_FOR_CHANNEL_AT_TIME:
|
|
return {
|
|
...state,
|
|
[action.channelId]: action.time,
|
|
};
|
|
|
|
default:
|
|
return state;
|
|
}
|
|
}
|
|
|
|
function loadMorePostsVisible(state = true, action) {
|
|
switch (action.type) {
|
|
case ChannelTypes.SELECT_CHANNEL:
|
|
return true;
|
|
case ViewTypes.SET_LOAD_MORE_POSTS_VISIBLE:
|
|
return action.data;
|
|
|
|
default:
|
|
return state;
|
|
}
|
|
}
|
|
|
|
function lastChannelViewTime(state = {}, action) {
|
|
switch (action.type) {
|
|
case ChannelTypes.SELECT_CHANNEL: {
|
|
if (action.extra?.member) {
|
|
const {member} = action.extra;
|
|
const nextState = {...state};
|
|
nextState[action.data] = member.last_viewed_at;
|
|
return nextState;
|
|
}
|
|
|
|
return state;
|
|
}
|
|
|
|
case ChannelTypes.POST_UNREAD_SUCCESS: {
|
|
const data = action.data;
|
|
return {...state, [data.channelId]: data.lastViewedAt};
|
|
}
|
|
|
|
case PostTypes.RECEIVED_POST:
|
|
case PostTypes.RECEIVED_NEW_POST: {
|
|
const data = action.data;
|
|
if (!data.ownPost) {
|
|
return state;
|
|
}
|
|
|
|
return {...state, [data.channel_id]: data.create_at + 1};
|
|
}
|
|
|
|
default:
|
|
return state;
|
|
}
|
|
}
|
|
|
|
function keepChannelIdAsUnread(state = null, action) {
|
|
switch (action.type) {
|
|
case ChannelTypes.SELECT_CHANNEL: {
|
|
if (!action.extra && (action.data || action.data === '')) {
|
|
return {
|
|
id: action.data,
|
|
hadMentions: false,
|
|
};
|
|
}
|
|
|
|
const {channel, member} = action.extra;
|
|
|
|
if (!member || !channel) {
|
|
return state;
|
|
}
|
|
|
|
const msgCount = channel.total_msg_count - member.msg_count;
|
|
const hadMentions = member.mention_count > 0;
|
|
const hadUnreads = member.notify_props.mark_unread !== ViewTypes.NotificationLevels.MENTION && msgCount > 0;
|
|
|
|
if (hadMentions || hadUnreads) {
|
|
return {
|
|
id: member.channel_id,
|
|
hadMentions,
|
|
};
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
case ViewTypes.RECEIVED_FOCUSED_POST: {
|
|
if (state && action.channelId !== state.id) {
|
|
return null;
|
|
}
|
|
return state;
|
|
}
|
|
default:
|
|
return state;
|
|
}
|
|
}
|
|
|
|
function unreadMessageCount(state = {}, action) {
|
|
switch (action.type) {
|
|
case ChannelTypes.SET_UNREAD_MSG_COUNT: {
|
|
const {channelId, count} = action.data;
|
|
return {
|
|
...state,
|
|
[channelId]: count,
|
|
};
|
|
}
|
|
default:
|
|
return state;
|
|
}
|
|
}
|
|
|
|
export default combineReducers({
|
|
displayName,
|
|
drafts,
|
|
loading,
|
|
refreshing,
|
|
loadingPosts,
|
|
lastGetPosts,
|
|
retryFailed,
|
|
loadMorePostsVisible,
|
|
lastChannelViewTime,
|
|
keepChannelIdAsUnread,
|
|
unreadMessageCount,
|
|
});
|