Leonard Kim 14cc4ea54a ref(hangup): clean up some UI state on hangup
- Reset some state on the singletons conference
  and VideoLayout.
- Add a way for LocalVideo to clean itself up
  by sharing logic with the other SmallVideos.
- Add clearing of chat messages so they don't
  linger.
- Remove some UI event listeners.
2019-01-02 09:54:05 -08:00

53 lines
1.2 KiB
JavaScript

// @flow
import { ReducerRegistry } from '../base/redux';
import { ADD_MESSAGE, CLEAR_MESSAGES, TOGGLE_CHAT } from './actionTypes';
const DEFAULT_STATE = {
isOpen: false,
lastReadMessage: undefined,
messages: []
};
ReducerRegistry.register('features/chat', (state = DEFAULT_STATE, action) => {
switch (action.type) {
case ADD_MESSAGE: {
const newMessage = {
displayName: action.displayName,
error: action.error,
id: action.id,
messageType: action.messageType,
message: action.message,
timestamp: action.timestamp
};
return {
...state,
lastReadMessage:
action.hasRead ? newMessage : state.lastReadMessage,
messages: [
...state.messages,
newMessage
]
};
}
case CLEAR_MESSAGES:
return {
...state,
lastReadMessage: undefined,
messages: []
};
case TOGGLE_CHAT:
return {
...state,
isOpen: !state.isOpen,
lastReadMessage: state.messages[state.messages.length - 1]
};
}
return state;
});