Files
mattermost-mobile/app/components/post_list/post/index.ts
Jesús Espino 49462bd4a0 Voicechannels (#5753)
* Some extra work on voice channels interface

* Fixing some TODOs

* Improving styling of call in channel

* Improve calls monitoring

* Replacing some of the fontawesome icons with the compass ones

* Improving the layout

* Migrating to webrtc2 for unified plan

* Add screen on and off behavior

* Adding incall manager plugin

* Moving everything into the products/calls folder

* Make products modules routes relatives

* Make products modules routes @mmproducts

* Removing initiator parameter

* Removing trickle parameter

* Simplifying code

* Removing underscore from private variables

* Removing underscore from private things

* More simplifications

* More simplifications

* More simplifications

* Changing sha sum for mmjstool

* Fixing typo

* Migrating simple-peer to typescript

* Migrating simple-peer to typescript

* Improving the size of the screen share

* Adding feature flag to disable the calls feature in mobile

* Fixing some tests

* Removing obsolte tests

* Added call ended support for the post messages

* Fixing some warnings in the tests

* Adding JoinCall tests

* Adding CallMessage tests

* Adding CurrentCall unit tests

* Adding CallAvatar unit tests

* Adding FloatingCallContainer unit tests

* Adding StartCall unit tests

* Adding EnableDisableCalls unit tests

* Adding CallDuration tests

* Improving CallDuration tests

* Adding CallScreen unit tests

* Adding CallOtherActions screen tests

* Fixing some dark theme styles

* Fixing tests

* More robustness around connecting/disconnecting

* Adding FormattedRelativeTime tests

* Adding tests for ChannelItem

* Adding tests for ChannelInfo

* Adding selectors tests

* Adding reducers unit tests

* Adding actions tests

* Removing most of the TODOs

* Removing another TODO

* Updating tests snapshots

* Removing the last TODO

* Fixed a small problem on pressing while a call is ongoing

* Remove all the inlined functions

* Replacing usage of isLandscape selector with useWindowDimensions

* Removed unnecesary makeStyleSheetFromTheme

* Removing unneded  properties from call_duration

* Fixing possible null channels return from getChannel selector

* Moving other inlined functions to its own constant

* Simplifiying enable/disable calls component

* Improving the behavior when you are in the call of the current channel

* Adding missing translation strings

* Simplified a bit the EnableDisableCalls component

* Moving other inlined functions to its own constant

* Updating snapshots

* Improving usage of makeStyleSheetFromTheme

* Moving data reformating from the rest client to the redux action

* Adding calls to the blocklist to the redux-persist

* Fixing tests

* Updating snapshots

* Update file icon name to the last compass icons version

* Fix loading state

* Only show the call connected if the websocket gets connected

* Taking into consideration the indicator bar to position the calls new bars

* Making the MoreMessagesButton component aware of calls components

* Updating snapshots

* Fixing tests

* Updating snapshot

* Fixing different use cases for start call channel menu

* Fixing tests

* Ask for confirmation to start a call when you are already in another call

* Update app/products/calls/components/floating_call_container.tsx

Co-authored-by: Elias Nahum <nahumhbl@gmail.com>

* Memoizing userIds in join call

* Applying suggestion around combine the blocklist for calls with the one for typing

* Adding explicit types to the rest client

* Removing unneeded permission

* Making updateIntervalInSeconds prop optional in FormattedRelativeTime

* Making updateIntervalInSeconds prop optional in CallDuration

Co-authored-by: Elias Nahum <nahumhbl@gmail.com>
2021-11-11 11:33:30 +01:00

111 lines
4.3 KiB
TypeScript

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import {connect} from 'react-redux';
import {showPermalink} from '@actions/views/permalink';
import {THREAD} from '@constants/screen';
import {removePost} from '@mm-redux/actions/posts';
import {getChannel} from '@mm-redux/selectors/entities/channels';
import {getConfig, getFeatureFlagValue} from '@mm-redux/selectors/entities/general';
import {getPost, isRootPost} from '@mm-redux/selectors/entities/posts';
import {getMyPreferences, getTeammateNameDisplaySetting, isCollapsedThreadsEnabled} from '@mm-redux/selectors/entities/preferences';
import {getCurrentTeamId} from '@mm-redux/selectors/entities/teams';
import {getThread} from '@mm-redux/selectors/entities/threads';
import {getUser} from '@mm-redux/selectors/entities/users';
import {UserThread} from '@mm-redux/types/threads';
import {isPostFlagged, isSystemMessage} from '@mm-redux/utils/post_utils';
import {canDeletePost} from '@selectors/permissions';
import {areConsecutivePosts, postUserDisplayName} from '@utils/post';
import Post from './post';
import type {Post as PostType} from '@mm-redux/types/posts';
import type {GlobalState} from '@mm-redux/types/store';
import type {Theme} from '@mm-redux/types/theme';
import type {StyleProp, ViewStyle} from 'react-native';
type OwnProps = {
location: string;
highlight?: boolean;
postId: string;
post?: PostType;
previousPostId?: string;
nextPostId?: string;
style?: StyleProp<ViewStyle>;
testID: string;
theme: Theme;
}
function mapSateToProps(state: GlobalState, ownProps: OwnProps) {
const {nextPostId, postId, previousPostId} = ownProps;
const post = ownProps.post || getPost(state, postId);
const myPreferences = getMyPreferences(state);
const channel = getChannel(state, post.channel_id);
const teamId = getCurrentTeamId(state);
const author = getUser(state, post.user_id);
const previousPost = previousPostId ? getPost(state, previousPostId) : undefined;
const config = getConfig(state);
const teammateNameDisplay = getTeammateNameDisplaySetting(state);
const enablePostUsernameOverride = config.EnablePostUsernameOverride === 'true';
const isConsecutivePost = post && previousPost && !author?.is_bot && !isRootPost(state, post.id) && areConsecutivePosts(post, previousPost);
const callsFeatureEnabled = getFeatureFlagValue(state, 'CallsMobile') === 'true';
let isFirstReply = true;
let isLastReply = true;
let canDelete = false;
let rootPostAuthor;
if (post && channel?.delete_at === 0) {
canDelete = canDeletePost(state, channel?.team_id || teamId, post?.channel_id, post, false);
}
if (post.root_id) {
const nextPost = nextPostId ? getPost(state, nextPostId) : undefined;
isFirstReply = (previousPost?.id === post.root_id || previousPost?.root_id === post.root_id);
isLastReply = !(nextPost?.root_id === post.root_id);
}
if (!isSystemMessage(post)) {
const rootPost = post.root_id ? getPost(state, post.root_id) : undefined;
const rootPostUser = rootPost?.user_id ? getUser(state, rootPost.user_id) : undefined;
const differentThreadSequence = previousPost?.root_id ? previousPost?.root_id !== post.root_id : previousPost?.id !== post.root_id;
if (rootPost?.user_id &&
previousPostId &&
differentThreadSequence
) {
rootPostAuthor = postUserDisplayName(rootPost, rootPostUser, teammateNameDisplay, enablePostUsernameOverride);
}
}
const collapsedThreadsEnabled = isCollapsedThreadsEnabled(state);
let thread: UserThread | null = null;
if (collapsedThreadsEnabled && ownProps.location !== THREAD) {
thread = getThread(state, post.id, true);
}
return {
canDelete,
enablePostUsernameOverride,
isConsecutivePost,
collapsedThreadsEnabled,
isFirstReply,
isFlagged: isPostFlagged(post.id, myPreferences),
isLastReply,
post,
rootPostAuthor,
teammateNameDisplay,
thread,
threadStarter: getUser(state, post.user_id),
callsFeatureEnabled,
};
}
const mapDispatchToProps = {
removePost,
showPermalink,
};
export default connect(mapSateToProps, mapDispatchToProps)(Post);