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);
}
}
}
notificationTapped = () => {
this.tapped = true;
this.clearDismissTimer();
const {actions, notification} = this.props;
EventEmitter.emit('close_channel_drawer');
EventEmitter.emit('close_settings_sidebar');
InteractionManager.runAfterInteractions(() => {
this.dismissOverlay();
if (!notification.localNotification) {
actions.loadFromPushNotification(notification);
}
});
};
handleMentionKeyClick(e) {
e.preventDefault();
if (!this.props.user) {
return;
}
if (this.props.hide) {
this.props.hide();
}
EventEmitter.emit('mention_key_click', this.props.user.username, this.props.isRHS);
}
export function forceLogoutIfNecessary(clientError) {
if (clientError.status_code === HTTP_UNAUTHORIZED && clientError.url && clientError.url.indexOf('/login') === -1) {
EventEmitter.emit(NavigationTypes.NAVIGATION_RESET);
}
}
getTeams().then(() => {
EventEmitter.emit(NavigationTypes.NAVIGATION_NO_TEAMS);
});
}
this.player.playPause((err, paused) => {
if (paused) {
clearInterval(this.progressInterval);
} else {
EventEmitter.emit(MediaTypes.STOP_AUDIO, this.props.file.id);
this.progressInterval = setInterval(this.updateProgress, 100);
}
if (this.mounted) {
this.setState({
error: err?.message,
isPlaying: !paused,
});
}
});
}
return (dispatch, getState) => {
const state = getState();
const threadId = state.entities.posts.selectedPostId;
const insertEvent = threadId ? INSERT_TO_COMMENT : INSERT_TO_DRAFT;
EventEmitter.emit(insertEvent, value);
};
}
handleDrawerTween = (ratio) => {
const opacity = (ratio / 2);
EventEmitter.emit('drawer_opacity', opacity);
return {
mainOverlay: {
backgroundColor: this.props.theme.centerChannelBg,
opacity
},
drawerOverlay: {
backgroundColor: ratio ? '#000' : '#FFF',
opacity: ratio ? (1 - ratio) / 2 : 1
}
};
};