Skip to content
Snippets Groups Projects
Verified Commit 9d0123fd authored by Jean-Baptiste Pasquier's avatar Jean-Baptiste Pasquier
Browse files

minor: add RAI

parent 97d2645e
No related branches found
No related tags found
No related merge requests found
Pipeline #5441 passed
(function (root, factory) {
if (typeof define === 'function' && define.amd) {
define(["converse"], factory);
} else {
factory(converse);
}
}(this, function (converse) {
var raiDialog = null,
_converse = null;
converse.plugins.add("rai", {
'dependencies': [],
'initialize': function () {
_converse = this._converse;
_converse.api.settings.update({
rai_notification: true,
rai_notification_label: "Room Activity Indicator"
});
_converse.api.listen.on('connected', function () {
setupRoomActivityIndicators(function (supported) {
if (supported) listenForRoomActivityIndicators();
});
});
}
});
function setupRoomActivityIndicators(callback) {
try {
const id = Math.random().toString(36).substr(2, 9);
const to = "conference." + _converse.domain;
_converse.connection.send(converse.env.$pres({
to: to,
id: id
}).c('rai', {
'xmlns': "xmpp:prosody.im/protocol/rai"
}));
if (callback) callback(true);
} catch (e) {
if (callback) callback(false);
}
}
function listenForRoomActivityIndicators() {
_converse.connection.addHandler(function (message) {
message.querySelectorAll('activity').forEach(function (activity) {
if (activity) {
const jid = activity.innerHTML;
_converse.api.trigger('chatRoomActivityIndicators', jid);
if (_converse.api.settings.get("rai_notification")) {
notifyText(_converse.api.settings.get("rai_notification_label"), jid, null, function (notificationId, buttonIndex) {
_converse.api.rooms.open(jid);
});
}
}
});
return true;
}, "xmpp:prosody.im/protocol/rai", 'message');
}
function notifyText(message, title, notifyId, callback) {
if (!notifyId) notifyId = Math.random().toString(36).substr(2, 9);
var prompt = new Notification(title, {
body: message,
requireInteraction: true
});
prompt.onclick = function (event) {
event.preventDefault();
if (callback) callback(notifyId, 0);
}
prompt.onclose = function (event) {
event.preventDefault();
if (callback) callback(notifyId, 1);
}
}
}));
\ No newline at end of file
import 'https://cdn.happy-dev.fr/conversejs/dist/converse.min.js';
import 'https://cdn.happy-dev.fr/conversejs/dist/emojis.js';
import 'https://unpkg.com/@startinblox/component-chat/plugins/converse-rai.js';
import { Helpers, store } from 'https://unpkg.com/@startinblox/core@0.9';
import { Sib } from "https://unpkg.com/@startinblox/core@0.9/dist/libs/Sib.js";
import { StoreMixin } from 'https://unpkg.com/@startinblox/core@0.9/dist/mixins/storeMixin.js';
......@@ -50,7 +51,7 @@ export const SibChat = {
});
this.element.shadowRoot.append(...Helpers.importCSS(
'https://cdn.happy-dev.fr/conversejs/dist/converse.min.css',
'https://unpkg.com/@startinblox/component-chat@0.5/themes/converse-hd.css'
'https://unpkg.com/@startinblox/component-chat/themes/converse-hd.css'
));
if (window.converse_sib === undefined) {
this.initializeConverse();
......@@ -145,6 +146,19 @@ export const SibChat = {
}
});
// Initialize rai plugin
converse.plugins.add('conversejs-rai', {
initialize() {
this._converse.api.listen.on('chatRoomActivityIndicators', function (jid) {
window.dispatchEvent(new CustomEvent('newMessage', {
detail: {
jid: jid
}
}));
});
}
});
// Initialize deferred resolution plugin
converse.plugins.add('conversejs-sib-focused', {
initialize() {
......@@ -195,7 +209,6 @@ export const SibChat = {
'auto_register_muc_nickname': true,
'bosh_service_url': this.element.dataset.boshServiceUrl,
"clear_messages_on_reconnection": false,
'i18n': 'en',
'jid': jabberID.toLowerCase(),
'i18n': this.element.dataset.i18n,
'message_archiving': 'always',
......@@ -220,7 +233,7 @@ export const SibChat = {
fileupload: false,
toggle_occupants: false
},
'whitelisted_plugins': ['conversejs-sib-connected', 'conversejs-sib-focused', 'conversejs-changechat'],
'whitelisted_plugins': ['rai', 'conversejs-sib-connected', 'conversejs-sib-focused', 'conversejs-changechat', 'conversejs-rai'],
});
converse_sib.loaded_deferred.resolve();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment