feat(external_api) add event for chat updates (unread counter, open state)
This commit is contained in:
parent
63f0166f75
commit
dcaad41e69
|
@ -556,6 +556,21 @@ class API {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Notify external application (if API is enabled) that the chat state has been updated.
|
||||||
|
*
|
||||||
|
* @param {number} unreadCount - The unread messages counter.
|
||||||
|
* @param {boolean} isOpen - True if the chat panel is open.
|
||||||
|
* @returns {void}
|
||||||
|
*/
|
||||||
|
notifyChatUpdated(unreadCount: number, isOpen: boolean) {
|
||||||
|
this._sendEvent({
|
||||||
|
name: 'chat-updated',
|
||||||
|
unreadCount,
|
||||||
|
isOpen
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Notify external application (if API is enabled) that message was sent.
|
* Notify external application (if API is enabled) that message was sent.
|
||||||
*
|
*
|
||||||
|
|
|
@ -64,6 +64,7 @@ const events = {
|
||||||
'audio-availability-changed': 'audioAvailabilityChanged',
|
'audio-availability-changed': 'audioAvailabilityChanged',
|
||||||
'audio-mute-status-changed': 'audioMuteStatusChanged',
|
'audio-mute-status-changed': 'audioMuteStatusChanged',
|
||||||
'camera-error': 'cameraError',
|
'camera-error': 'cameraError',
|
||||||
|
'chat-updated': 'chatUpdated',
|
||||||
'content-sharing-participants-changed': 'contentSharingParticipantsChanged',
|
'content-sharing-participants-changed': 'contentSharingParticipantsChanged',
|
||||||
'device-list-changed': 'deviceListChanged',
|
'device-list-changed': 'deviceListChanged',
|
||||||
'display-name-change': 'displayNameChange',
|
'display-name-change': 'displayNameChange',
|
||||||
|
@ -572,6 +573,12 @@ export default class JitsiMeetExternalAPI extends EventEmitter {
|
||||||
* logLevel: the message log level
|
* logLevel: the message log level
|
||||||
* arguments: an array of strings that compose the actual log message
|
* arguments: an array of strings that compose the actual log message
|
||||||
* }}
|
* }}
|
||||||
|
* {@code chatUpdated} - receives event notifications about chat state being
|
||||||
|
* updated. The listener will receive object with the following structure:
|
||||||
|
* {{
|
||||||
|
* 'unreadCount': unreadCounter, // the unread message(s) counter,
|
||||||
|
* 'isOpen': isOpen, // whether the chat panel is open or not
|
||||||
|
* }}
|
||||||
* {@code incomingMessage} - receives event notifications about incoming
|
* {@code incomingMessage} - receives event notifications about incoming
|
||||||
* messages. The listener will receive object with the following structure:
|
* messages. The listener will receive object with the following structure:
|
||||||
* {{
|
* {{
|
||||||
|
|
|
@ -20,7 +20,7 @@ import { MiddlewareRegistry, StateListenerRegistry } from '../base/redux';
|
||||||
import { playSound, registerSound, unregisterSound } from '../base/sounds';
|
import { playSound, registerSound, unregisterSound } from '../base/sounds';
|
||||||
import { showToolbox } from '../toolbox/actions';
|
import { showToolbox } from '../toolbox/actions';
|
||||||
|
|
||||||
import { SEND_MESSAGE, SET_PRIVATE_MESSAGE_RECIPIENT } from './actionTypes';
|
import { ADD_MESSAGE, TOGGLE_CHAT, SEND_MESSAGE, SET_PRIVATE_MESSAGE_RECIPIENT } from './actionTypes';
|
||||||
import { addMessage, clearMessages, toggleChat } from './actions';
|
import { addMessage, clearMessages, toggleChat } from './actions';
|
||||||
import { ChatPrivacyDialog } from './components';
|
import { ChatPrivacyDialog } from './components';
|
||||||
import {
|
import {
|
||||||
|
@ -30,6 +30,7 @@ import {
|
||||||
MESSAGE_TYPE_LOCAL,
|
MESSAGE_TYPE_LOCAL,
|
||||||
MESSAGE_TYPE_REMOTE
|
MESSAGE_TYPE_REMOTE
|
||||||
} from './constants';
|
} from './constants';
|
||||||
|
import { getUnreadCount } from './functions';
|
||||||
import { INCOMING_MSG_SOUND_FILE } from './sounds';
|
import { INCOMING_MSG_SOUND_FILE } from './sounds';
|
||||||
|
|
||||||
declare var APP: Object;
|
declare var APP: Object;
|
||||||
|
@ -50,9 +51,26 @@ const PRIVACY_NOTICE_TIMEOUT = 20 * 1000;
|
||||||
* @returns {Function}
|
* @returns {Function}
|
||||||
*/
|
*/
|
||||||
MiddlewareRegistry.register(store => next => action => {
|
MiddlewareRegistry.register(store => next => action => {
|
||||||
const { dispatch } = store;
|
const { dispatch, getState } = store;
|
||||||
|
let isOpen, unreadCount;
|
||||||
|
|
||||||
switch (action.type) {
|
switch (action.type) {
|
||||||
|
case ADD_MESSAGE:
|
||||||
|
unreadCount = action.hasRead ? 0 : getUnreadCount(getState()) + 1;
|
||||||
|
isOpen = getState()['features/chat'].isOpen;
|
||||||
|
|
||||||
|
if (typeof APP !== 'undefined') {
|
||||||
|
APP.API.notifyChatUpdated(unreadCount, isOpen);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case TOGGLE_CHAT:
|
||||||
|
unreadCount = 0;
|
||||||
|
isOpen = !getState()['features/chat'].isOpen;
|
||||||
|
|
||||||
|
if (typeof APP !== 'undefined') {
|
||||||
|
APP.API.notifyChatUpdated(unreadCount, isOpen);
|
||||||
|
}
|
||||||
|
break;
|
||||||
case APP_WILL_MOUNT:
|
case APP_WILL_MOUNT:
|
||||||
dispatch(
|
dispatch(
|
||||||
registerSound(INCOMING_MSG_SOUND_ID, INCOMING_MSG_SOUND_FILE));
|
registerSound(INCOMING_MSG_SOUND_ID, INCOMING_MSG_SOUND_FILE));
|
||||||
|
|
Loading…
Reference in New Issue