2019-01-13 19:34:38 +00:00
|
|
|
// @flow
|
|
|
|
|
2019-01-01 21:19:34 +00:00
|
|
|
import {
|
|
|
|
ADD_MESSAGE,
|
|
|
|
CLEAR_MESSAGES,
|
|
|
|
SEND_MESSAGE,
|
2020-07-21 12:21:01 +00:00
|
|
|
SET_PRIVATE_MESSAGE_RECIPIENT
|
2019-01-01 21:19:34 +00:00
|
|
|
} from './actionTypes';
|
2018-03-07 00:28:19 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Adds a chat message to the collection of messages.
|
|
|
|
*
|
2018-08-29 17:24:25 +00:00
|
|
|
* @param {Object} messageDetails - The chat message to save.
|
|
|
|
* @param {string} messageDetails.displayName - The displayName of the
|
|
|
|
* participant that authored the message.
|
|
|
|
* @param {boolean} messageDetails.hasRead - Whether or not to immediately mark
|
|
|
|
* the message as read.
|
|
|
|
* @param {string} messageDetails.message - The received message to display.
|
|
|
|
* @param {string} messageDetails.messageType - The kind of message, such as
|
|
|
|
* "error" or "local" or "remote".
|
|
|
|
* @param {string} messageDetails.timestamp - A timestamp to display for when
|
|
|
|
* the message was received.
|
2018-03-07 00:28:19 +00:00
|
|
|
* @returns {{
|
|
|
|
* type: ADD_MESSAGE,
|
2018-08-29 17:24:25 +00:00
|
|
|
* displayName: string,
|
2018-03-07 00:28:19 +00:00
|
|
|
* hasRead: boolean,
|
|
|
|
* message: string,
|
2018-08-29 17:24:25 +00:00
|
|
|
* messageType: string,
|
2018-03-07 00:28:19 +00:00
|
|
|
* timestamp: string,
|
|
|
|
* }}
|
|
|
|
*/
|
2019-01-13 19:34:38 +00:00
|
|
|
export function addMessage(messageDetails: Object) {
|
2018-03-07 00:28:19 +00:00
|
|
|
return {
|
|
|
|
type: ADD_MESSAGE,
|
2018-08-29 17:24:25 +00:00
|
|
|
...messageDetails
|
2018-03-07 00:28:19 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2019-01-01 21:19:34 +00:00
|
|
|
/**
|
2019-01-13 19:34:38 +00:00
|
|
|
* Clears the chat messages in Redux.
|
2019-01-01 21:19:34 +00:00
|
|
|
*
|
|
|
|
* @returns {{
|
|
|
|
* type: CLEAR_MESSAGES
|
|
|
|
* }}
|
|
|
|
*/
|
|
|
|
export function clearMessages() {
|
|
|
|
return {
|
|
|
|
type: CLEAR_MESSAGES
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2018-03-07 00:28:19 +00:00
|
|
|
/**
|
2018-08-29 17:24:25 +00:00
|
|
|
* Sends a chat message to everyone in the conference.
|
2018-03-07 00:28:19 +00:00
|
|
|
*
|
2018-08-29 17:24:25 +00:00
|
|
|
* @param {string} message - The chat message to send out.
|
2019-10-07 12:35:04 +00:00
|
|
|
* @param {boolean} ignorePrivacy - True if the privacy notification should be ignored.
|
2018-08-29 17:24:25 +00:00
|
|
|
* @returns {{
|
|
|
|
* type: SEND_MESSAGE,
|
2019-10-07 12:35:04 +00:00
|
|
|
* ignorePrivacy: boolean,
|
2018-08-29 17:24:25 +00:00
|
|
|
* message: string
|
|
|
|
* }}
|
2018-03-07 00:28:19 +00:00
|
|
|
*/
|
2019-10-07 12:35:04 +00:00
|
|
|
export function sendMessage(message: string, ignorePrivacy: boolean = false) {
|
2018-08-29 17:24:25 +00:00
|
|
|
return {
|
|
|
|
type: SEND_MESSAGE,
|
2019-10-07 12:35:04 +00:00
|
|
|
ignorePrivacy,
|
2018-08-29 17:24:25 +00:00
|
|
|
message
|
2018-03-07 00:28:19 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2019-10-07 12:35:04 +00:00
|
|
|
/**
|
|
|
|
* Initiates the sending of a private message to the supplied participant.
|
|
|
|
*
|
|
|
|
* @param {Participant} participant - The participant to set the recipient to.
|
|
|
|
* @returns {{
|
|
|
|
* participant: Participant,
|
|
|
|
* type: SET_PRIVATE_MESSAGE_RECIPIENT
|
|
|
|
* }}
|
|
|
|
*/
|
|
|
|
export function setPrivateMessageRecipient(participant: Object) {
|
|
|
|
return {
|
|
|
|
participant,
|
|
|
|
type: SET_PRIVATE_MESSAGE_RECIPIENT
|
|
|
|
};
|
|
|
|
}
|