Skip to content

Commit

Permalink
Fix Typing Start
Browse files Browse the repository at this point in the history
  • Loading branch information
theADAMJR committed Aug 13, 2021
1 parent 0297178 commit 0f3f44a
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions frontend/src/store/channels.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { createSelector, createSlice } from '@reduxjs/toolkit';
import moment from 'moment';
import { actions as api } from './api';

const slice = createSlice({
Expand Down Expand Up @@ -31,11 +32,13 @@ export const getTypersInChannel = (channelId: string) => createSelector<any, any
typing => typing.filter(t => t.channelId === channelId),
) as (channelId: string) => Store.AppStore['entities']['channels']['typing'];

let lastTypedAt: Date;

export const startTyping = (channelId: string) => (dispatch, getState) => {
const typing = getState().entities.channels.typing;
const userId = getState().auth.user.id;
const alreadyTyping = getIndex(typing, userId, channelId) >= 0;
if (alreadyTyping) return;
const minsAgo = moment(lastTypedAt).diff(new Date(), 'minutes');
if (lastTypedAt && minsAgo < 5) return;

lastTypedAt = new Date();

dispatch(api.wsCallBegan({
event: 'TYPING_START',
Expand Down

0 comments on commit 0f3f44a

Please sign in to comment.