chatview: Replace lodash methods with built-in ones
This commit is contained in:
parent
f9b09052eb
commit
8b1c17c12b
@ -11,7 +11,7 @@ import "backbone.nativeview";
|
||||
import "converse-chatboxviews";
|
||||
import "converse-message-view";
|
||||
import "converse-modal";
|
||||
import BrowserStorage from "backbone.browserStorage";
|
||||
import { debounce, get, isString } from "lodash";
|
||||
import { Overview } from "backbone.overview";
|
||||
import converse from "@converse/headless/converse-core";
|
||||
import tpl_chatbox from "templates/chatbox.html";
|
||||
@ -29,7 +29,8 @@ import tpl_toolbar_fileupload from "templates/toolbar_fileupload.html";
|
||||
import tpl_user_details_modal from "templates/user_details_modal.html";
|
||||
import xss from "xss/dist/xss";
|
||||
|
||||
const { $msg, Backbone, Strophe, _, sizzle, dayjs } = converse.env;
|
||||
|
||||
const { Backbone, Strophe, sizzle, dayjs } = converse.env;
|
||||
const u = converse.env.utils;
|
||||
|
||||
|
||||
@ -87,7 +88,7 @@ converse.plugins.add('converse-chatview', {
|
||||
initialize () {
|
||||
this.listenTo(this.model, 'change:status', this.onStatusMessageChanged);
|
||||
|
||||
this.debouncedRender = _.debounce(this.render, 50);
|
||||
this.debouncedRender = debounce(this.render, 50);
|
||||
if (this.model.vcard) {
|
||||
this.listenTo(this.model.vcard, 'change', this.debouncedRender);
|
||||
}
|
||||
@ -100,7 +101,7 @@ converse.plugins.add('converse-chatview', {
|
||||
},
|
||||
|
||||
render () {
|
||||
const vcard = _.get(this.model, 'vcard'),
|
||||
const vcard = get(this.model, 'vcard'),
|
||||
vcard_json = vcard ? vcard.toJSON() : {};
|
||||
this.el.innerHTML = tpl_chatbox_head(
|
||||
Object.assign(
|
||||
@ -157,12 +158,11 @@ converse.plugins.add('converse-chatview', {
|
||||
},
|
||||
|
||||
toHTML () {
|
||||
const vcard = _.get(this.model, 'vcard'),
|
||||
const vcard = get(this.model, 'vcard'),
|
||||
vcard_json = vcard ? vcard.toJSON() : {};
|
||||
return tpl_user_details_modal(Object.assign(
|
||||
this.model.toJSON(),
|
||||
vcard_json, {
|
||||
'_': _,
|
||||
'__': __,
|
||||
'view': this,
|
||||
'_converse': _converse,
|
||||
@ -204,9 +204,7 @@ converse.plugins.add('converse-chatview', {
|
||||
if (result === true) {
|
||||
this.modal.hide();
|
||||
this.model.contact.removeFromRoster(
|
||||
(iq) => {
|
||||
this.model.contact.destroy();
|
||||
},
|
||||
() => this.model.contact.destroy(),
|
||||
(err) => {
|
||||
_converse.log(err, Strophe.LogLevel.ERROR);
|
||||
_converse.api.alert.show(
|
||||
@ -281,8 +279,8 @@ converse.plugins.add('converse-chatview', {
|
||||
},
|
||||
|
||||
initDebounced () {
|
||||
this.scrollDown = _.debounce(this._scrollDown, 100);
|
||||
this.markScrolled = _.debounce(this._markScrolled, 100);
|
||||
this.scrollDown = debounce(this._scrollDown, 100);
|
||||
this.markScrolled = debounce(this._markScrolled, 100);
|
||||
},
|
||||
|
||||
render () {
|
||||
@ -302,7 +300,7 @@ converse.plugins.add('converse-chatview', {
|
||||
if (!_converse.show_toolbar) {
|
||||
return this;
|
||||
}
|
||||
const options = _.assign(
|
||||
const options = Object.assign(
|
||||
this.model.toJSON(),
|
||||
this.getToolbarOptions()
|
||||
);
|
||||
@ -324,11 +322,11 @@ converse.plugins.add('converse-chatview', {
|
||||
form_container.innerHTML = tpl_chatbox_message_form(
|
||||
Object.assign(this.model.toJSON(), {
|
||||
'message_limit': _converse.message_limit,
|
||||
'hint_value': _.get(this.el.querySelector('.spoiler-hint'), 'value'),
|
||||
'hint_value': get(this.el.querySelector('.spoiler-hint'), 'value'),
|
||||
'label_message': this.model.get('composing_spoiler') ? __('Hidden message') : __('Message'),
|
||||
'label_send': __('Send'),
|
||||
'label_spoiler_hint': __('Optional hint'),
|
||||
'message_value': _.get(this.el.querySelector('.chat-textarea'), 'value'),
|
||||
'message_value': get(this.el.querySelector('.chat-textarea'), 'value'),
|
||||
'show_send_button': _converse.show_send_button,
|
||||
'show_toolbar': _converse.show_toolbar,
|
||||
'unread_msgs': __('You have unread messages')
|
||||
@ -354,7 +352,7 @@ converse.plugins.add('converse-chatview', {
|
||||
this.user_details_modal.show(ev);
|
||||
},
|
||||
|
||||
toggleFileUpload (ev) {
|
||||
toggleFileUpload () {
|
||||
this.el.querySelector('input.fileupload').click();
|
||||
},
|
||||
|
||||
@ -555,10 +553,8 @@ converse.plugins.add('converse-chatview', {
|
||||
* them here, otherwise we get a null reference later
|
||||
* upon element insertion.
|
||||
*/
|
||||
const msg_dates = _.invokeMap(
|
||||
sizzle('.message:not(.chat-state-notification)', this.content),
|
||||
Element.prototype.getAttribute, 'data-isodate'
|
||||
);
|
||||
const sel = '.message:not(.chat-state-notification)';
|
||||
const msg_dates = sizzle(sel, this.content).map(e => e.getAttribute('data-isodate'));
|
||||
const cutoff_iso = cutoff.toISOString();
|
||||
msg_dates.push(cutoff_iso);
|
||||
msg_dates.sort();
|
||||
@ -890,13 +886,11 @@ converse.plugins.add('converse-chatview', {
|
||||
return this.editLaterMessage();
|
||||
}
|
||||
}
|
||||
if (_.includes([
|
||||
_converse.keycodes.SHIFT,
|
||||
if ([_converse.keycodes.SHIFT,
|
||||
_converse.keycodes.META,
|
||||
_converse.keycodes.META_RIGHT,
|
||||
_converse.keycodes.ESCAPE,
|
||||
_converse.keycodes.ALT]
|
||||
, ev.keyCode)) {
|
||||
_converse.keycodes.ALT].includes(ev.keyCode)) {
|
||||
return;
|
||||
}
|
||||
if (this.model.get('chat_state') !== _converse.COMPOSING) {
|
||||
@ -916,9 +910,8 @@ converse.plugins.add('converse-chatview', {
|
||||
|
||||
onEscapePressed (ev) {
|
||||
ev.preventDefault();
|
||||
const idx = this.model.messages.findLastIndex('correcting'),
|
||||
message = idx >=0 ? this.model.messages.at(idx) : null;
|
||||
|
||||
const idx = this.model.messages.findLastIndex('correcting');
|
||||
const message = idx >=0 ? this.model.messages.at(idx) : null;
|
||||
if (message) {
|
||||
message.save('correcting', false);
|
||||
}
|
||||
@ -989,7 +982,7 @@ converse.plugins.add('converse-chatview', {
|
||||
}
|
||||
}
|
||||
}
|
||||
message = message || _.findLast(this.getOwnMessages(), msg => msg.get('message'));
|
||||
message = message || this.getOwnMessages().reverse().find(m => m.get('message'));
|
||||
if (message) {
|
||||
this.insertIntoTextArea(message.get('message'), true, true);
|
||||
message.save('correcting', true);
|
||||
@ -1344,10 +1337,10 @@ converse.plugins.add('converse-chatview', {
|
||||
);
|
||||
return null;
|
||||
}
|
||||
if (_.isString(jids)) {
|
||||
if (isString(jids)) {
|
||||
return _converse.chatboxviews.get(jids);
|
||||
}
|
||||
return jids.map(jid => _converse.chatboxviews.get(jids));
|
||||
return jids.map(jid => _converse.chatboxviews.get(jid));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user