Commit 85e9169b authored by JC Brand's avatar JC Brand

Use the API to read settings

parent 830e0605
......@@ -2047,7 +2047,7 @@ describe("A XEP-0333 Chat Marker", function () {
.map(s => _.isElement(s) ? s : s.nodeTree)
.filter(e => e.nodeName === 'message');
expect(sent_messages.length).toBe(2);
await u.waitUntil(() => sent_messages.length === 2);
expect(Strophe.serialize(sent_messages[0])).toBe(
`<message id="${sent_messages[0].getAttribute('id')}" to="${contact_jid}" type="chat" xmlns="jabber:client">`+
`<active xmlns="http://jabber.org/protocol/chatstates"/>`+
......
......@@ -616,9 +616,12 @@ describe("Message Retractions", function () {
expect(occupant.get('role')).toBe('moderator');
occupant.save('role', 'member');
const retraction_stanza = await sendAndThenRetractMessage(_converse, view);
await u.waitUntil(() => view.el.querySelectorAll('.chat-msg--retracted').length === 1);
await u.waitUntil(() => view.el.querySelectorAll('.chat-msg--retracted').length === 1, 1000);
console.log('XXX: First message retracted by author');
const msg_obj = view.model.messages.last();
expect(msg_obj.get('retracted')).toBeTruthy();
expect(Strophe.serialize(retraction_stanza)).toBe(
`<message id="${retraction_stanza.getAttribute('id')}" to="${muc_jid}" type="groupchat" xmlns="jabber:client">`+
`<store xmlns="urn:xmpp:hints"/>`+
......@@ -627,7 +630,6 @@ describe("Message Retractions", function () {
`</apply-to>`+
`</message>`);
await u.waitUntil(() => view.model.messages.last().get('retracted'));
const message = view.model.messages.last();
expect(message.get('is_ephemeral')).toBe(false);
expect(message.get('editable')).toBeFalsy();
......@@ -645,9 +647,11 @@ describe("Message Retractions", function () {
spyOn(view.model, 'handleRetraction').and.callThrough();
_converse.connection._dataRecv(mock.createRequest(reflection));
await u.waitUntil(() => view.model.handleRetraction.calls.count() === 1);
await u.waitUntil(() => view.model.handleRetraction.calls.count() === 1, 1000);
console.log('XXX: Handle retraction was called on reflection');
await u.waitUntil(() => view.model.messages.length === 1);
await u.waitUntil(() => view.model.messages.length === 1, 1000);
console.log('XXX: We have one message');
expect(view.model.messages.last().get('retracted')).toBeTruthy();
expect(view.model.messages.last().get('is_ephemeral')).toBe(false);
expect(view.model.messages.last().get('editable')).toBe(false);
......
......@@ -98,7 +98,7 @@ converse.plugins.add('converse-chatview', {
this.model.toJSON(),
vcard_json, {
'_converse': _converse,
'allow_contact_removal': _converse.allow_contact_removal,
'allow_contact_removal': api.settings.get('allow_contact_removal'),
'display_name': this.model.getDisplayName(),
'is_roster_contact': this.model.contact !== undefined,
'removeContact': ev => this.removeContact(ev),
......@@ -133,7 +133,7 @@ converse.plugins.add('converse-chatview', {
removeContact (ev) {
if (ev && ev.preventDefault) { ev.preventDefault(); }
if (!_converse.allow_contact_removal) { return; }
if (!api.settings.get('allow_contact_removal')) { return; }
const result = confirm(__("Are you sure you want to remove this contact?"));
if (result === true) {
this.modal.hide();
......
......@@ -251,7 +251,7 @@ converse.plugins.add('converse-controlbox', {
this.insertBrandHeading();
}
this.loginpanel.initPopovers();
if (_converse.auto_focus) {
if (api.settings.get('auto_focus')) {
this.loginpanel.el.querySelector('#converse-login-jid').focus();
}
return this;
......@@ -384,7 +384,7 @@ converse.plugins.add('converse-controlbox', {
'EXTERNAL': _converse.EXTERNAL,
'LOGIN': _converse.LOGIN,
'PREBIND': _converse.PREBIND,
'auto_login': _converse.auto_login,
'auto_login': api.settings.get('auto_login'),
'authentication': api.settings.get("authentication"),
'connection_status': connection_status,
'conn_feedback_class': feedback_class,
......
This diff is collapsed.
......@@ -11,6 +11,8 @@ import { _converse, api, converse } from "@converse/headless/converse-core";
const { Strophe, sizzle } = converse.env;
const u = converse.env.utils;
const supports_html5_notification = "Notification" in window;
converse.plugins.add('converse-notification', {
......@@ -20,7 +22,6 @@ converse.plugins.add('converse-notification', {
/* The initialize function gets called as soon as the plugin is
* loaded by converse.js's plugin machinery.
*/
_converse.supports_html5_notification = "Notification" in window;
api.settings.extend({
notify_all_room_messages: false,
......@@ -37,7 +38,7 @@ converse.plugins.add('converse-notification', {
_converse.shouldNotifyOfGroupMessage = function (message) {
/* Is this a group message worthy of notification?
*/
let notify_all = _converse.notify_all_room_messages;
let notify_all = api.settings.get('notify_all_room_messages');
const jid = message.getAttribute('from'),
resource = Strophe.getResourceFromJid(jid),
room_jid = Strophe.getBareJidFromJid(jid),
......@@ -85,7 +86,7 @@ converse.plugins.add('converse-notification', {
return !u.isOnlyChatStateNotification(message) &&
!u.isOnlyMessageDeliveryReceipt(message) &&
!is_me &&
(_converse.show_desktop_notifications === 'all' || _converse.isMessageToHiddenChat(message));
(api.settings.get('show_desktop_notifications') === 'all' || _converse.isMessageToHiddenChat(message));
};
......@@ -95,13 +96,13 @@ converse.plugins.add('converse-notification', {
* @method _converse#playSoundNotification
*/
_converse.playSoundNotification = function () {
if (_converse.play_sounds && window.Audio !== undefined) {
const audioOgg = new Audio(_converse.sounds_path+"msg_received.ogg");
if (api.settings.get('play_sounds') && window.Audio !== undefined) {
const audioOgg = new Audio(api.settings.get('sounds_path')+"msg_received.ogg");
const canPlayOgg = audioOgg.canPlayType('audio/ogg');
if (canPlayOgg === 'probably') {
return audioOgg.play();
}
const audioMp3 = new Audio(_converse.sounds_path+"msg_received.mp3");
const audioMp3 = new Audio(api.settings.get('sounds_path')+"msg_received.mp3");
const canPlayMp3 = audioMp3.canPlayType('audio/mp3');
if (canPlayMp3 === 'probably') {
audioMp3.play();
......@@ -114,9 +115,8 @@ converse.plugins.add('converse-notification', {
};
_converse.areDesktopNotificationsEnabled = function () {
return _converse.supports_html5_notification &&
_converse.show_desktop_notifications &&
return supports_html5_notification &&
api.settings.get('show_desktop_notifications') &&
Notification.permission === "granted";
};
......@@ -171,11 +171,11 @@ converse.plugins.add('converse-notification', {
const n = new Notification(title, {
'body': body,
'lang': _converse.locale,
'icon': _converse.notification_icon,
'icon': api.settings.get('notification_icon'),
'requireInteraction': !_converse.notification_delay
});
if (_converse.notification_delay) {
setTimeout(n.close.bind(n), _converse.notification_delay);
if (api.settings.get('notification_delay')) {
setTimeout(n.close.bind(n), api.settings.get('notification_delay'));
}
n.onclick = function (event) {
event.preventDefault();
......@@ -241,7 +241,7 @@ converse.plugins.add('converse-notification', {
* Will show an HTML5 notification to indicate that the chat
* status has changed.
*/
if (_converse.areDesktopNotificationsEnabled() && _converse.show_chat_state_notifications) {
if (_converse.areDesktopNotificationsEnabled() && api.settings.get('show_chat_state_notifications')) {
_converse.showChatStateNotification(contact);
}
};
......@@ -279,7 +279,7 @@ converse.plugins.add('converse-notification', {
};
_converse.requestPermission = function () {
if (_converse.supports_html5_notification && !['denied', 'granted'].includes(Notification.permission)) {
if (supports_html5_notification && !['denied', 'granted'].includes(Notification.permission)) {
// Ask user to enable HTML5 notifications
Notification.requestPermission();
}
......
......@@ -4,7 +4,7 @@
* @license Mozilla Public License (MPLv2)
* @description A plugin which restricts Converse to only one chat.
*/
import { converse } from "@converse/headless/converse-core";
import { api, converse } from "@converse/headless/converse-core";
converse.plugins.add('converse-singleton', {
......@@ -17,17 +17,17 @@ converse.plugins.add('converse-singleton', {
/* The initialize function gets called as soon as the plugin is
* loaded by converse.js's plugin machinery.
*/
this._converse.api.settings.extend({
api.settings.extend({
'allow_logout': false, // No point in logging out when we have auto_login as true.
'allow_muc_invitations': false, // Doesn't make sense to allow because only
// roster contacts can be invited
'hide_muc_server': true
});
const { _converse } = this;
if (!Array.isArray(_converse.auto_join_rooms) && !Array.isArray(_converse.auto_join_private_chats)) {
if (!Array.isArray(api.settings.get('auto_join_rooms')) &&
!Array.isArray(api.settings.get('auto_join_private_chats'))) {
throw new Error("converse-singleton: auto_join_rooms must be an Array");
}
if (_converse.auto_join_rooms.length > 1 || _converse.auto_join_private_chats.length > 1) {
if (api.settings.get('auto_join_rooms').length > 1 || api.settings.get('auto_join_private_chats').length > 1) {
throw new Error("It doesn't make sense to have singleton set to true and " +
"auto_join_rooms or auto_join_private_chats set to more then one, " +
"since only one chat room may be open at any time.");
......
......@@ -180,7 +180,7 @@ converse.plugins.add('converse-chat', {
getMessageText () {
if (this.get('is_encrypted')) {
return this.get('plaintext') ||
(_converse.loglevel === 'debug' ? __('Unencryptable OMEMO message') : null);
(api.settings.get('loglevel') === 'debug' ? __('Unencryptable OMEMO message') : null);
}
return this.get('message');
},
......@@ -521,7 +521,7 @@ converse.plugins.add('converse-chat', {
}
const room_jids = _converse.auto_join_rooms.map(s => isObject(s) ? s.jid : s);
const auto_join = api.settings.get('auto_join_private_chats').concat(room_jids);
if (api.settings.get("singleton") && !auto_join.includes(attrs.jid) && !_converse.auto_join_on_invite) {
if (api.settings.get("singleton") && !auto_join.includes(attrs.jid) && !api.settings.get('auto_join_on_invite')) {
const msg = `${attrs.jid} is not allowed because singleton is true and it's not being auto_joined`;
log.warn(msg);
return msg;
......
......@@ -197,7 +197,7 @@ converse.plugins.add('converse-muc', {
return log.warn(`invalid jid "${jid}" provided in url fragment`);
}
await api.waitUntil('roomsAutoJoined');
if (_converse.allow_bookmarks) {
if (api.settings.get('allow_bookmarks')) {
await api.waitUntil('bookmarksInitialized');
}
api.rooms.open(jid);
......@@ -483,7 +483,7 @@ converse.plugins.add('converse-muc', {
// Looks like we haven't restored occupants from cache, so we clear it.
this.occupants.clearStore();
}
if (_converse.clear_messages_on_reconnection) {
if (api.settings.get('clear_messages_on_reconnection')) {
await this.clearMessages();
}
},
......@@ -1049,13 +1049,13 @@ converse.plugins.add('converse-muc', {
* @method _converse.ChatRoom#sendChatState
*/
sendChatState () {
if (!_converse.send_chat_state_notifications ||
if (!api.settings.get('send_chat_state_notifications') ||
!this.get('chat_state') ||
this.session.get('connection_status') !== converse.ROOMSTATUS.ENTERED ||
this.features.get('moderated') && this.getOwnRole() === 'visitor') {
return;
}
const allowed = _converse.send_chat_state_notifications;
const allowed = api.settings.get('send_chat_state_notifications');
if (Array.isArray(allowed) && !allowed.includes(this.get('chat_state'))) {
return;
}
......@@ -2739,7 +2739,7 @@ converse.plugins.add('converse-muc', {
window.addEventListener(_converse.unloadevent, () => {
const using_websocket = api.connection.isType('websocket');
if (using_websocket &&
(!_converse.enable_smacks || !_converse.session.get('smacks_stream_id'))) {
(!api.settings.get('enable_smacks') || !_converse.session.get('smacks_stream_id'))) {
// For non-SMACKS websocket connections, or non-resumeable
// connections, we disconnect all chatrooms when the page unloads.
// See issue #1111
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment