message. */ const getSelectedMessage = createSelector( state => state.messages, ({ selectedMessage }) => (selectedMessage ? selectedMessage : undefined) ); /** * Returns summary data of the list of messages that are visible to the user. * Filtered messages by types and text are factored in. */ const getDisplayedMessagesSummary = createSelector( getDisplayedMessages, displayedMessages => { let firstStartedMs = +Infinity; let lastEndedMs = -Infinity; let sentSize = 0; let receivedSize = 0; let totalSize = 0; displayedMessages.forEach(message => { if (message.type == "received") { receivedSize += message.payload.length; } else if (message.type == "sent") { sentSize += message.payload.length; } totalSize += message.payload.length; if (message.timeStamp < firstStartedMs) { firstStartedMs = message.timeStamp; } if (message.timeStamp > lastEndedMs) { lastEndedMs = message.timeStamp; } }); return { count: displayedMessages.length, totalMs: (lastEndedMs - firstStartedMs) / 1000, sentSize, receivedSize, totalSize, }; } ); /** * Returns if the currentChannelId is closed */ const isCurrentChannelClosed = createSelector( state => state.messages, ({ closedConnections, currentChannelId }) => closedConnections.has(currentChannelId) ); /** * Returns the closed connection details of the currentChannelId * Null, if the connection is still open */ const getClosedConnectionDetails = createSelector( state => state.messages, ({ closedConnections, currentChannelId }) => closedConnections.get(currentChannelId) ); module.exports = { getSelectedMessage, isSelectedMessageVisible, getDisplayedMessages, getDisplayedMessagesSummary, isCurrentChannelClosed, getClosedConnectionDetails, }; PK