Skip to content

Commit

Permalink
doEventActionSideEffects [nfc]: Remove message-event handler.
Browse files Browse the repository at this point in the history
This was a lot of setup for the in-app "notification" sound, which
we removed in a recent commit.
  • Loading branch information
chrisbobbe committed Sep 10, 2021
1 parent 68387d7 commit eb5348c
Showing 1 changed file with 2 additions and 42 deletions.
44 changes: 2 additions & 42 deletions src/events/doEventActionSideEffects.js
Original file line number Diff line number Diff line change
@@ -1,58 +1,18 @@
/* @flow strict-local */
// import { Vibration } from 'react-native';

import { AppState } from 'react-native';
import type { GlobalState, Message, ThunkAction } from '../types';
import type { ThunkAction } from '../types';
import type { EventAction } from '../actionTypes';
import { EVENT_NEW_MESSAGE, EVENT_TYPING_START } from '../actionConstants';
import { isHomeNarrow, isMessageInNarrow } from '../utils/narrow';
import { getActiveAccount, getChatScreenParams } from '../selectors';
import { NULL_ARRAY } from '../nullObjects';
import { EVENT_TYPING_START } from '../actionConstants';
import { ensureTypingStatusExpiryLoop } from '../typing/typingActions';
import { getOwnUserId } from '../users/userSelectors';

/**
* React to incoming `MessageEvent`s.
*/
const messageEvent = (state: GlobalState, message: Message): void => {
const flags = message.flags ?? NULL_ARRAY;

if (AppState.currentState !== 'active') {
return;
}

const isMentioned = flags.includes('mentioned') || flags.includes('wildcard_mentioned');
if (!(message.type === 'private' || isMentioned)) {
return;
}

const activeAccount = getActiveAccount(state);
// Assume (unchecked) that `narrow` is `Narrow` if present
// $FlowFixMe[cannot-resolve-name]
const narrow: Narrow | void = getChatScreenParams().narrow;
const isUserInSameNarrow =
activeAccount
&& narrow !== undefined // chat screen is not at top
&& !isHomeNarrow(narrow)
&& isMessageInNarrow(message, flags, narrow, getOwnUserId(state));
const isSenderSelf = getOwnUserId(state) === message.sender_id;
if (!isUserInSameNarrow && !isSenderSelf) {
// Vibration.vibrate();
}
};

/**
* React to actions dispatched for Zulip server events.
*
* To be dispatched before the event actions are dispatched.
*/
export default (action: EventAction): ThunkAction<Promise<void>> => async (dispatch, getState) => {
const state = getState();
switch (action.type) {
case EVENT_NEW_MESSAGE: {
messageEvent(state, action.message);
break;
}
case EVENT_TYPING_START:
dispatch(ensureTypingStatusExpiryLoop());
break;
Expand Down

0 comments on commit eb5348c

Please sign in to comment.