function _addMessage()

in openmeetings-web/src/main/front/src/chat/chat.js [272:345]


function _addMessage(m) {
	if ($('#chat').length > 0 && m && m.type === "chat") {
		let msg, cm, notify = false;
		while (!!(cm = m.msg.pop())) {
			let area = $('#' + cm.scope);
			if (cm.from.id !== userId && (isClosed() || !area.is(':visible'))) {
				notify = true;
			}
			const actions = ('full' === cm.actions ? 'full' : 'short') + (cm.needModeration ? '-mod' : '');
			msg = OmUtil.tmpl('#chat-msg-template', msgIdPrefix + cm.id)
			const row = msg.find('.user-row')
				.data('userId', cm.from.id)
				.data('actions', actions)
				.mouseenter(function() {
					__hideActions();
					__getActions($(this))
						.data('userId', $(this).data('userId'))
						.data('roomId', $(this).data('roomId'))
						.data('msgId', $(this).data('msgId'))
						.css('top', ($(this).closest('.msg-row')[0].offsetTop + 20) + 'px')
						.show();
				});
			if (cm.needModeration) {
				row.parent().addClass('need-moderation');
				row.data('roomId', cm.scope.substring(9))
					.data('msgId', cm.id);
			}
			area.mouseleave(function() {
				__hideActions();
			});
			msg.find('.from').data('user-id', cm.from.id).html(cm.from.displayName || cm.from.name);
			msg.find('.time').html(cm.time).attr('title', cm.sent);
			if (!area.length) {
				_addTab(cm.scope, cm.scopeName);
				area = $('#' + cm.scope);
			}
			if (m.mode === "accept") {
				$('#chat-msg-id-' + cm.id).remove();
			}
			const btm = area[0].scrollHeight - (area.scrollTop() + area.innerHeight()) < 3; //approximately equal
			if (area.data('lastDate') !== cm.date) {
				area.append(OmUtil.tmpl('#chat-date-template').html(cm.date).mouseenter(function() {
					__hideActions();
				}));
				area.data('lastDate', cm.date);
			}
			area.append(msg);
			msg.find('.user-row')[0].style.cssText = `
				background-image: url(${(!!cm.from.img ? cm.from.img : './profile/' + cm.from.id + '?anticache=' + Date.now())});
				background-position-x: ${Settings.isRtl ? 'right' : 'left'};
			`;

			msg.find('.msg').html(CSSEmoticon.emoticonize(!!cm.message ? cm.message : ""));
			if (btm) {
				_scrollDown(area);
			}
		}
		if (notify) {
			ctrlBlk.addClass('bg-warning');
			if (chatPanel.is(':visible') && !muted) {
				OmUtil.notify(newMsgNotification, 'new_chat_msg', () => {
					// impossible to use Notification API from iFrame
					audio.play()
						.then(function() {
							// Automatic playback started!
						}).catch(function() {
							// Automatic playback failed.
						});
				});
			}
		}
		CSSEmoticon.animate();
	}
}