mattermost-redux
Version:
Common code (API client, Redux stores, logic, utility functions) for building a Mattermost client
42 lines (41 loc) • 1.4 kB
JavaScript
;
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = typing;
const action_types_1 = require("mattermost-redux/action_types");
function typing(state = {}, action) {
const { data, type, } = action;
switch (type) {
case action_types_1.WebSocketTypes.TYPING: {
const { id, userId, now, } = data;
if (id && userId) {
return {
...state,
[id]: {
...(state[id] || {}),
[userId]: now,
},
};
}
return state;
}
case action_types_1.WebSocketTypes.STOPPED_TYPING: {
const { id, userId, now, } = data;
if (state[id] && state[id][userId] <= now) {
const nextState = {
...state,
[id]: { ...state[id] },
};
Reflect.deleteProperty(nextState[id], userId);
if (Object.keys(nextState[id]).length === 0) {
Reflect.deleteProperty(nextState, id);
}
return nextState;
}
return state;
}
default:
return state;
}
}