Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
let screen = 'SelectServer';
if (this.token && this.url) {
screen = 'Channel';
tracker.initialLoad = Date.now();
try {
dispatch(loadMe());
} catch (e) {
// Fall through since we should have a previous version of the current user because we have a token
console.warn('Failed to load current user when starting on Channel screen', e); // eslint-disable-line no-console
}
}
switch (screen) {
case 'SelectServer':
EventEmitter.emit(ViewTypes.LAUNCH_LOGIN, true);
break;
case 'Channel':
EventEmitter.emit(ViewTypes.LAUNCH_CHANNEL, true);
break;
}
this.setAppStarted(true);
}
}
loadFromNotification = async (notification) => {
// Set appStartedFromPushNotification to avoid channel screen to call selectInitialChannel
EphemeralStore.appStartedFromPushNotification = true;
await this.store.dispatch(loadFromPushNotification(notification));
// if we have a componentId means that the app is already initialized
const componentId = EphemeralStore.getNavigationTopComponentId();
if (componentId) {
EventEmitter.emit('close_channel_drawer');
EventEmitter.emit('close_settings_sidebar');
await dismissAllModals();
await popToRoot();
PushNotifications.resetNotification();
}
};
handleTextChange = (value, autocomplete = false) => {
const {
actions,
channelId,
rootId,
cursorPositionEvent,
valueEvent,
} = this.props;
if (valueEvent) {
EventEmitter.emit(valueEvent, value);
}
const nextState = {value};
// Workaround for some Android keyboards that don't play well with cursors (e.g. Samsung keyboards)
if (autocomplete && this.input?.current) {
if (Platform.OS === 'android') {
RNTextInputReset.resetKeyboardInput(findNodeHandle(this.input.current));
} else {
nextState.cursorPosition = value.length;
if (cursorPositionEvent) {
EventEmitter.emit(cursorPositionEvent, nextState.cursorPosition);
}
}
}
function handleChannelViewedEvent(msg) {
// Useful for when multiple devices have the app open to different channels
if ((!window.isActive || getCurrentChannelId(getState()) !== msg.data.channel_id) &&
getCurrentUserId(getState()) === msg.broadcast.user_id) {
dispatch(markChannelAsRead(msg.data.channel_id, '', false));
}
}
function handleChannelViewedEvent(msg) {
// Useful for when multiple devices have the app open to different channels
if ((!window.isActive || getCurrentChannelId(getState()) !== msg.data.channel_id) &&
getCurrentUserId(getState()) === msg.broadcast.user_id) {
dispatch(markChannelAsRead(msg.data.channel_id, '', false));
}
}
const enableTimezone = isTimezoneEnabled(state);
const userTimezone = enableTimezone ? getUserCurrentTimezone(currentUser.timezone) : '';
return {
commentedOnDisplayName: ownProps.commentedOnUserId ? displayUsername(commentedOnUser, teammateNameDisplay) : '',
commentCount: getCommentCountForPost(state, {post}),
createAt: post.create_at,
displayName: displayUsername(user, teammateNameDisplay),
enablePostUsernameOverride: config.EnablePostUsernameOverride === 'true',
fromWebHook: post?.props?.from_webhook === 'true', // eslint-disable-line camelcase
militaryTime,
isPendingOrFailedPost: isPostPendingOrFailed(post),
isSystemMessage: isSystemMessage(post),
fromAutoResponder: fromAutoResponder(post),
overrideUsername: post?.props?.override_username, // eslint-disable-line camelcase
theme: getTheme(state),
username: user.username,
isBot: user.is_bot || false,
isGuest: isGuest(user),
isLandscape: isLandscape(state),
userTimezone,
};
};
}
changeCss('.app__body .attachment__content, .app__body .attachment-actions button', 'background:' + theme.centerChannelBg);
changeCss('body.app__body', 'scrollbar-face-color:' + theme.centerChannelBg);
changeCss('body.app__body', 'scrollbar-track-color:' + theme.centerChannelBg);
changeCss('.app__body .shortcut-key, .app__body .post-list__new-messages-below', 'color:' + theme.centerChannelBg);
changeCss('.app__body .emoji-picker, .app__body .emoji-picker__search', 'background:' + theme.centerChannelBg);
changeCss('.app__body .nav-tabs, .app__body .nav-tabs > li.active > a', 'background:' + theme.centerChannelBg);
changeCss('.app__body .post .file-view--single', `background:${theme.centerChannelBg}`);
changeCss('.app__body .modal-tabs .nav-tabs > li', `background:${theme.centerChannelBg}`);
changeCss('.app__body .modal-tabs .nav-tabs > li > a', `background:${theme.centerChannelBg}`);
// Fade out effect for collapsed posts (not hovered, not from current user)
changeCss(
'.app__body .post-list__table .post:not(.current--user) .post-collapse__gradient, ' +
'.app__body .post-list__table .post.post--compact .post-collapse__gradient, ' +
'.app__body .sidebar-right__body .post.post--compact .post-collapse__gradient',
`background:linear-gradient(${changeOpacity(theme.centerChannelBg, 0)}, ${theme.centerChannelBg})`,
);
changeCss(
'.app__body .post-list__table .post-attachment-collapse__gradient, ' +
'.app__body .sidebar-right__body .post-attachment-collapse__gradient',
`background:linear-gradient(${changeOpacity(theme.centerChannelBg, 0)}, ${theme.centerChannelBg})`,
);
changeCss(
'.app__body .post-list__table .post:not(.current--user) .post-collapse__show-more, ' +
'.app__body .post-list__table .post.post--compact .post-collapse__show-more, ' +
'.app__body .sidebar-right__body .post:not(.post--root) .post-collapse__show-more',
`background-color:${theme.centerChannelBg}`,
);
changeCss(
'.app__body .post-list__table .post-attachment-collapse__show-more, ' +
'.app__body .sidebar-right__body .post-attachment-collapse__show-more',
changeCss('.app__body .post.post--comment.current--user .post__body', 'border-color:' + changeOpacity(theme.centerChannelColor, 0.2));
changeCss('.app__body .channel-header__info .status .offline--icon', 'fill:' + theme.centerChannelColor);
changeCss('.app__body .navbar .status .offline--icon', 'fill:' + theme.centerChannelColor);
changeCss('.app__body .post-reaction:not(.post-reaction--current-user)', 'border-color:' + changeOpacity(theme.centerChannelColor, 0.25));
changeCss('.app__body .post-reaction:not(.post-reaction--current-user)', 'color:' + changeOpacity(theme.centerChannelColor, 0.7));
changeCss('.app__body .emoji-picker', 'color:' + theme.centerChannelColor);
changeCss('.app__body .emoji-picker', 'border-color:' + changeOpacity(theme.centerChannelColor, 0.2));
changeCss('.app__body .emoji-picker__search-icon', 'color:' + changeOpacity(theme.centerChannelColor, 0.4));
changeCss('.app__body .emoji-picker__preview, .app__body .emoji-picker__items, .app__body .emoji-picker__search-container', 'border-color:' + changeOpacity(theme.centerChannelColor, 0.2));
changeCss('.emoji-picker__category .fa:hover', 'color:' + changeOpacity(theme.centerChannelColor, 0.8));
changeCss('.app__body .emoji-picker__category, .app__body .emoji-picker__category:focus, .app__body .emoji-picker__category:hover', 'color:' + changeOpacity(theme.centerChannelColor, 0.3));
changeCss('.app__body .emoji-picker__category--selected, .app__body .emoji-picker__category--selected:focus, .app__body .emoji-picker__category--selected:hover', 'color:' + theme.centerChannelColor);
changeCss('.app__body .emoji-picker__item-wrapper:hover', 'background-color:' + changeOpacity(theme.centerChannelColor, 0.8));
changeCss('.app__body .emoji-picker-items__container .emoji-picker__item.selected', 'background-color:' + changeOpacity(theme.centerChannelColor, 0.07));
changeCss('.app__body .icon__postcontent_picker:hover', 'color:' + changeOpacity(theme.centerChannelColor, 0.8));
changeCss('.app__body .popover', 'border-color:' + changeOpacity(theme.centerChannelColor, 0.07));
changeCss('.app__body .emoji-picker .nav-tabs li a', 'fill:' + theme.centerChannelColor);
changeCss('.app__body .post .post-collapse__show-more-button', `border-color:${changeOpacity(theme.centerChannelColor, 0.1)}`);
changeCss('.app__body .post .post-collapse__show-more-line', `background-color:${changeOpacity(theme.centerChannelColor, 0.1)}`);
if (theme.centerChannelBg) {
const ownPostBg = blendColors(theme.centerChannelBg, theme.centerChannelColor, 0.05);
const hoveredPostBg = blendColors(theme.centerChannelBg, theme.centerChannelColor, 0.08);
const hoveredPostBgLight = blendColors(theme.centerChannelBg, theme.centerChannelColor, 0.05);
// Fade out effect for collapsed posts made by the current user
changeCss(
'.app__body .post-list__table .post.current--user:not(.post--compact):not(:hover):not(.post--hovered):not(.post--highlight) .post-collapse__gradient, ' +
'.app__body .sidebar-right__body .post.current--user:not(.post--compact):not(:hover):not(.post--hovered):not(.post--highlight) .post-collapse__gradient, ' +
'.app__body .post--root .post-collapse__gradient',
`background:linear-gradient(${changeOpacity(ownPostBg, 0)}, ${ownPostBg})`,
);
dispatch(batchActions([
{
type: UserTypes.RECEIVED_PROFILE_NOT_IN_TEAM,
data: {id: msg.data.team_id, user_id: msg.data.user_id},
},
{
type: TeamTypes.REMOVE_MEMBER_FROM_TEAM,
data: {team_id: msg.data.team_id, user_id: msg.data.user_id},
},
]));
if (getCurrentUserId(state) === msg.data.user_id) {
dispatch({type: TeamTypes.LEAVE_TEAM, data: {id: msg.data.team_id}});
// if they are on the team being removed redirect them to default team
if (getCurrentTeamId(state) === msg.data.team_id) {
if (!global.location.pathname.startsWith('/admin_console')) {
GlobalActions.redirectUserToDefaultTeam();
}
}
}
}
return async (dispatch, getState) => {
const state = getState();
const teamId = getCurrentTeamId(state);
let args = {
channel_id: channelId,
team_id: teamId,
root_id: rootId,
parent_id: rootId,
};
let {message} = draft;
const hookResult = await dispatch(runSlashCommandWillBePostedHooks(message, args));
if (hookResult.error) {
return {error: hookResult.error};
} else if (!hookResult.data.message && !hookResult.data.args) {
// do nothing with an empty return from a hook
return {};