* [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>
313 lines
9.7 KiB
JavaScript
313 lines
9.7 KiB
JavaScript
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
|
// See LICENSE.txt for license information.
|
|
|
|
import React, {Component} from 'react';
|
|
import PropTypes from 'prop-types';
|
|
import {
|
|
Dimensions,
|
|
Platform,
|
|
StyleSheet,
|
|
View,
|
|
} from 'react-native';
|
|
|
|
import SafeAreaView from '@components/safe_area_view';
|
|
import {NavigationTypes, WebsocketEvents} from '@constants';
|
|
import {General} from '@mm-redux/constants';
|
|
import EventEmitter from '@mm-redux/utils/event_emitter';
|
|
import {t} from '@utils/i18n';
|
|
|
|
import ChannelsList from './channels_list';
|
|
import DrawerSwiper from './drawer_swiper';
|
|
import TeamsList from './teams_list';
|
|
|
|
export default class MainSidebarBase extends Component {
|
|
static propTypes = {
|
|
actions: PropTypes.shape({
|
|
getTeams: PropTypes.func.isRequired,
|
|
handleSelectChannel: PropTypes.func,
|
|
joinChannel: PropTypes.func.isRequired,
|
|
makeDirectChannel: PropTypes.func.isRequired,
|
|
setChannelDisplayName: PropTypes.func.isRequired,
|
|
handleNotViewingGlobalThreadsScreen: PropTypes.func,
|
|
}).isRequired,
|
|
children: PropTypes.node,
|
|
currentTeamId: PropTypes.string.isRequired,
|
|
currentUserId: PropTypes.string,
|
|
locale: PropTypes.string,
|
|
teamsCount: PropTypes.number.isRequired,
|
|
theme: PropTypes.object.isRequired,
|
|
viewingGlobalThreads: PropTypes.bool,
|
|
};
|
|
|
|
static defaultProps = {
|
|
viewingGlobalThreads: false,
|
|
};
|
|
|
|
constructor(props) {
|
|
super(props);
|
|
|
|
this.swiperIndex = 1;
|
|
this.channelListRef = React.createRef();
|
|
}
|
|
|
|
componentDidMount() {
|
|
this.mounted = true;
|
|
this.props.actions.getTeams();
|
|
EventEmitter.on(NavigationTypes.CLOSE_MAIN_SIDEBAR, this.closeMainSidebar);
|
|
EventEmitter.on(WebsocketEvents.CHANNEL_UPDATED, this.handleUpdateTitle);
|
|
Dimensions.addEventListener('change', this.handleDimensions);
|
|
}
|
|
|
|
shouldComponentUpdate(nextProps, nextState) {
|
|
const {currentTeamId, teamsCount, theme, viewingGlobalThreads} = this.props;
|
|
const {deviceWidth, openDrawerOffset, isSplitView, permanentSidebar, searching} = this.state;
|
|
|
|
if (viewingGlobalThreads !== nextProps.viewingGlobalThreads) {
|
|
return true;
|
|
}
|
|
if (nextState.openDrawerOffset !== openDrawerOffset && Platform.OS === 'ios') {
|
|
return true;
|
|
}
|
|
|
|
if (nextState.searching !== searching || nextState.deviceWidth !== deviceWidth) {
|
|
return true;
|
|
}
|
|
|
|
const condition = nextProps.currentTeamId !== currentTeamId ||
|
|
nextProps.teamsCount !== teamsCount ||
|
|
nextProps.theme !== theme || this.props.children !== nextProps.children;
|
|
|
|
if (Platform.OS === 'ios') {
|
|
return condition ||
|
|
nextState.isSplitView !== isSplitView ||
|
|
nextState.permanentSidebar !== permanentSidebar;
|
|
}
|
|
|
|
return condition;
|
|
}
|
|
|
|
componentWillUnmount() {
|
|
this.mounted = false;
|
|
EventEmitter.off(NavigationTypes.CLOSE_MAIN_SIDEBAR, this.closeMainSidebar);
|
|
EventEmitter.off(WebsocketEvents.CHANNEL_UPDATED, this.handleUpdateTitle);
|
|
Dimensions.removeEventListener('change', this.handleDimensions);
|
|
}
|
|
|
|
drawerSwiperRef = (ref) => {
|
|
this.drawerSwiper = ref;
|
|
};
|
|
|
|
getIntl = () => {
|
|
const {intl} = this.providerRef ? this.providerRef.getChildContext() : this.context;
|
|
return intl;
|
|
};
|
|
|
|
handleUpdateTitle = (channel) => {
|
|
let channelName = '';
|
|
if (channel.display_name) {
|
|
channelName = channel.display_name;
|
|
}
|
|
this.props.actions.setChannelDisplayName(channelName);
|
|
};
|
|
|
|
joinChannel = async (channel, currentChannelId) => {
|
|
const intl = this.getIntl();
|
|
const {
|
|
actions,
|
|
currentTeamId,
|
|
currentUserId,
|
|
} = this.props;
|
|
|
|
const {
|
|
joinChannel,
|
|
makeDirectChannel,
|
|
} = actions;
|
|
|
|
this.closeMainSidebar();
|
|
|
|
const displayValue = {displayName: channel.display_name};
|
|
const utils = require('app/utils/general');
|
|
|
|
let result;
|
|
if (channel.type === General.DM_CHANNEL) {
|
|
result = await makeDirectChannel(channel.id, false);
|
|
|
|
if (result.error) {
|
|
const dmFailedMessage = {
|
|
id: t('mobile.open_dm.error'),
|
|
defaultMessage: "We couldn't open a direct message with {displayName}. Please check your connection and try again.",
|
|
};
|
|
utils.alertErrorWithFallback(intl, result.error, dmFailedMessage, displayValue);
|
|
}
|
|
} else {
|
|
result = await joinChannel(currentUserId, currentTeamId, channel.id);
|
|
|
|
if (result.error || !result.data || !result.data.channel) {
|
|
const joinFailedMessage = {
|
|
id: t('mobile.join_channel.error'),
|
|
defaultMessage: "We couldn't join the channel {displayName}. Please check your connection and try again.",
|
|
};
|
|
utils.alertErrorWithFallback(intl, result.error, joinFailedMessage, displayValue);
|
|
}
|
|
}
|
|
|
|
if (result.error || (!result.data && !result.data.channel)) {
|
|
return;
|
|
}
|
|
|
|
this.selectChannel(result.data.channel || result.data, currentChannelId, false);
|
|
};
|
|
|
|
onSearchEnds = () => {
|
|
this.setState({searching: false});
|
|
if (this.drawerRef?.current) {
|
|
this.drawerRef.current.canClose = true;
|
|
}
|
|
};
|
|
|
|
onSearchStart = () => {
|
|
if (this.drawerRef?.current) {
|
|
this.drawerRef.current.canClose = false;
|
|
}
|
|
this.setState({searching: true});
|
|
};
|
|
|
|
showTeams = () => {
|
|
if (this.drawerSwiper) {
|
|
this.drawerSwiper.showTeamsPage();
|
|
}
|
|
};
|
|
|
|
resetDrawer = () => {
|
|
if (this.drawerSwiper) {
|
|
this.drawerSwiper.resetPage();
|
|
}
|
|
|
|
if (this.drawerRef?.current) {
|
|
this.drawerRef.current.canClose = true;
|
|
}
|
|
|
|
if (this.channelListRef?.current) {
|
|
this.channelListRef.current.cancelSearch();
|
|
}
|
|
};
|
|
|
|
renderNavigationView = (drawerWidth) => {
|
|
const {
|
|
teamsCount,
|
|
theme,
|
|
} = this.props;
|
|
|
|
const {
|
|
openDrawerOffset,
|
|
searching,
|
|
} = this.state;
|
|
|
|
const offset = Platform.select({android: 64, ios: 0});
|
|
const multipleTeams = teamsCount > 1;
|
|
const showTeams = !searching && multipleTeams;
|
|
if (this.drawerSwiper) {
|
|
if (multipleTeams) {
|
|
this.drawerSwiper.runOnLayout();
|
|
this.drawerSwiper.scrollToInitial();
|
|
} else if (!openDrawerOffset) {
|
|
this.drawerSwiper.scrollToStart();
|
|
}
|
|
}
|
|
|
|
const lists = [];
|
|
if (multipleTeams) {
|
|
const teamsList = (
|
|
<View
|
|
key='teamsList'
|
|
style={style.swiperContent}
|
|
>
|
|
<TeamsList
|
|
testID='main.sidebar.teams_list'
|
|
closeMainSidebar={this.closeMainSidebar}
|
|
/>
|
|
</View>
|
|
);
|
|
lists.push(teamsList);
|
|
}
|
|
|
|
lists.push(
|
|
<View
|
|
key='channelsList'
|
|
style={style.swiperContent}
|
|
>
|
|
<ChannelsList
|
|
testID='main.sidebar.channels_list'
|
|
ref={this.channelListRef}
|
|
onSelectChannel={this.selectChannel}
|
|
onJoinChannel={this.joinChannel}
|
|
onShowTeams={multipleTeams ? this.showTeams : undefined}
|
|
onSearchStart={this.onSearchStart}
|
|
onSearchEnds={this.onSearchEnds}
|
|
theme={theme}
|
|
/>
|
|
</View>,
|
|
);
|
|
|
|
return (
|
|
<SafeAreaView
|
|
excludeFooter={true}
|
|
excludeLeft={true}
|
|
excludeRight={true}
|
|
navBarBackgroundColor={theme.sidebarBg}
|
|
backgroundColor={theme.sidebarHeaderBg}
|
|
footerColor={theme.sidebarBg}
|
|
>
|
|
<DrawerSwiper
|
|
ref={this.drawerSwiperRef}
|
|
onPageSelected={this.onPageSelected}
|
|
showTeams={showTeams}
|
|
drawerOpened={this.state.drawerOpened}
|
|
drawerWidth={drawerWidth - offset}
|
|
testID='main.sidebar'
|
|
>
|
|
{lists}
|
|
</DrawerSwiper>
|
|
</SafeAreaView>
|
|
);
|
|
};
|
|
|
|
selectChannel = (channel, currentChannelId, closeDrawer = true) => {
|
|
const {handleSelectChannel, handleNotViewingGlobalThreadsScreen} = this.props.actions;
|
|
|
|
if (closeDrawer) {
|
|
this.closeMainSidebar();
|
|
}
|
|
|
|
if (channel.id === currentChannelId) {
|
|
handleNotViewingGlobalThreadsScreen();
|
|
return;
|
|
}
|
|
|
|
if (!channel) {
|
|
const utils = require('app/utils/general');
|
|
const intl = this.getIntl();
|
|
|
|
const unableToJoinMessage = {
|
|
id: t('mobile.open_unknown_channel.error'),
|
|
defaultMessage: "We couldn't join the channel. Please reset the cache and try again.",
|
|
};
|
|
const erroMessage = {};
|
|
|
|
utils.alertErrorWithFallback(intl, erroMessage, unableToJoinMessage);
|
|
return;
|
|
}
|
|
|
|
handleSelectChannel(channel.id);
|
|
};
|
|
|
|
render() {
|
|
return; // eslint-disable-line no-useless-return
|
|
}
|
|
}
|
|
|
|
const style = StyleSheet.create({
|
|
swiperContent: {
|
|
flex: 1,
|
|
},
|
|
});
|