`_converse.api.alert.show` is now `_converse.api.show`

Instead of taking an integer for the `type`, "info", "warn" or "error" should be passed in.
This commit is contained in:
JC Brand 2019-10-31 14:42:28 +01:00
parent 17dfa3d7ba
commit 23797dee21
8 changed files with 56 additions and 59 deletions

View File

@ -35,6 +35,8 @@
- The `show_only_online_users` setting has been removed.
- The order of certain events have now changed: `statusInitialized` is now triggered after `initialized` and `connected` and `reconnected`.
- `_converse.api.alert.show` is now `_converse.api.show` and instead of taking
an integer for the `type`, "info", "warn" or "error" should be passed in.
## 5.0.4 (2019-10-08)
- New config option [allow_message_corrections](https://conversejs.org/docs/html/configuration.html#allow-message-corrections)

View File

@ -207,13 +207,10 @@ converse.plugins.add('converse-chatview', {
() => this.model.contact.destroy(),
(err) => {
_converse.log(err, Strophe.LogLevel.ERROR);
_converse.api.alert.show(
Strophe.LogLevel.ERROR,
__('Error'),
[__('Sorry, there was an error while trying to remove %1$s as a contact.',
this.model.contact.getDisplayName())
]
)
_converse.api.alert('error', __('Error'), [
__('Sorry, there was an error while trying to remove %1$s as a contact.',
this.model.contact.getDisplayName())
]);
}
);
}

View File

@ -9,10 +9,11 @@
import "backbone.vdomview";
import bootstrap from "bootstrap.native";
import converse from "@converse/headless/converse-core";
import { isString } from "lodash";
import tpl_alert from "templates/alert.html";
import tpl_alert_modal from "templates/alert_modal.html";
const { Strophe, Backbone, sizzle, _ } = converse.env;
const { Backbone, sizzle } = converse.env;
const u = converse.env.utils;
@ -106,35 +107,40 @@ converse.plugins.add('converse-modal', {
let alert;
Object.assign(_converse.api, {
'alert': {
show (type, title, messages) {
if (_.isString(messages)) {
messages = [messages];
}
if (type === Strophe.LogLevel.ERROR) {
type = 'alert-danger';
} else if (type === Strophe.LogLevel.INFO) {
type = 'alert-info';
} else if (type === Strophe.LogLevel.WARN) {
type = 'alert-warning';
}
if (alert === undefined) {
const model = new Backbone.Model({
'title': title,
'messages': messages,
'type': type
})
alert = new _converse.Alert({'model': model});
} else {
alert.model.set({
'title': title,
'messages': messages,
'type': type
});
}
alert.show();
/**
* Show an alert modal to the user.
* @method _converse.api.alert
* @param { ('info'|'warn'|'error') } type - The type of alert.
* @returns { String } title - The header text for the alert.
* @returns { (String[]|String) } messages - The alert text to show to the user.
*/
alert (type, title, messages) {
if (isString(messages)) {
messages = [messages];
}
if (type === 'error') {
type = 'alert-danger';
} else if (type === 'info') {
type = 'alert-info';
} else if (type === 'warn') {
type = 'alert-warning';
}
if (alert === undefined) {
const model = new Backbone.Model({
'title': title,
'messages': messages,
'type': type
})
alert = new _converse.Alert({'model': model});
} else {
alert.model.set({
'title': title,
'messages': messages,
'type': type
});
}
alert.show();
}
});
}

View File

@ -123,7 +123,7 @@ converse.plugins.add('converse-omemo', {
const { _converse } = this.__super__,
{ __ } = _converse;
_converse.log(err, Strophe.LogLevel.ERROR);
_converse.api.alert.show(
_converse.api.alert(
Strophe.LogLevel.ERROR,
__('Error'), [__('Sorry, an error occurred while trying to remove the devices.')]
)
@ -413,10 +413,10 @@ converse.plugins.add('converse-omemo', {
err_msgs.push(__("Unable to send an encrypted message due to an unexpected error."));
err_msgs.push(e.iq.outerHTML);
}
_converse.api.alert.show(Strophe.LogLevel.ERROR, __('Error'), err_msgs);
_converse.api.alert('error', __('Error'), err_msgs);
_converse.log(e, Strophe.LogLevel.ERROR);
} else if (e.user_facing) {
_converse.api.alert.show(Strophe.LogLevel.ERROR, __('Error'), [e.message]);
_converse.api.alert('error', __('Error'), [e.message]);
_converse.log(e, Strophe.LogLevel.ERROR);
} else {
throw e;
@ -470,7 +470,7 @@ converse.plugins.add('converse-omemo', {
this.model.contact.getDisplayName()
)];
}
return _converse.api.alert.show(Strophe.LogLevel.ERROR, __('Error'), messages);
return _converse.api.alert('error', __('Error'), messages);
}
ev.preventDefault();
this.model.save({'omemo_active': !this.model.get('omemo_active')});

View File

@ -103,13 +103,10 @@ converse.plugins.add('converse-profile', {
.then(() => _converse.api.vcard.update(this.model.vcard, true))
.catch((err) => {
_converse.log(err, Strophe.LogLevel.FATAL);
_converse.api.alert.show(
Strophe.LogLevel.ERROR,
__('Error'), [
__("Sorry, an error happened while trying to save your profile data."),
__("You can check your browser's developer console for any error output.")
]
)
_converse.api.show('error', __('Error'), [
__("Sorry, an error happened while trying to save your profile data."),
__("You can check your browser's developer console for any error output.")
]);
});
this.modal.hide();
},

View File

@ -505,11 +505,9 @@ converse.plugins.add('converse-rosterview', {
}
} catch (e) {
_converse.log(e, Strophe.LogLevel.ERROR);
_converse.api.alert.show(
Strophe.LogLevel.ERROR,
__('Error'),
_converse.api.alert('error', __('Error'),
[__('Sorry, there was an error while trying to remove %1$s as a contact.', this.model.getDisplayName())]
)
);
}
},

View File

@ -174,10 +174,9 @@ converse.plugins.add('converse-bookmarks', {
onBookmarkError (iq, options) {
_converse.log("Error while trying to add bookmark", Strophe.LogLevel.ERROR);
_converse.log(iq);
_converse.api.alert.show(
Strophe.LogLevel.ERROR,
__('Error'), [__("Sorry, something went wrong while trying to save your bookmark.")]
)
_converse.api.alert(
'error', __('Error'), [__("Sorry, something went wrong while trying to save your bookmark.")]
);
this.findWhere({'jid': options.jid}).destroy();
},
@ -234,9 +233,7 @@ converse.plugins.add('converse-bookmarks', {
onBookmarksReceivedError (deferred, iq) {
if (iq === null) {
_converse.log('Error: timeout while fetching bookmarks', Strophe.LogLevel.ERROR);
_converse.api.alert.show(
Strophe.LogLevel.ERROR,
__('Timeout Error'),
_converse.api.alert('error', __('Timeout Error'),
[__("The server did not return your bookmarks within the allowed time. "+
"You can reload the page to request them again.")]
);

View File

@ -1516,7 +1516,7 @@ converse.plugins.add('converse-chatboxes', {
return chat;
} else if (Array.isArray(jids)) {
return Promise.all(
jids.map(j => _converse.api.chats.create(j, attrs).then(c => c ? c.maybeShow(force) : null))
jids.map(j => _converse.api.chats.create(j, attrs).then(c => c && c.maybeShow(force)))
.filter(c => c)
);
}