Skip to content
Snippets Groups Projects
Commit 7dcc7d49 authored by ubermanu's avatar ubermanu
Browse files

Merge remote-tracking branch 'origin/beta' into 161_new_converse_rai

parents 918f0780 d4548a8b
No related branches found
No related tags found
2 merge requests!115161 new converse rai,!113History, Reply to messages and RAI
# CHANGELOG
This file contains the changes applied to the sources of converse<br>
The current build version of converse is: `v7.0.3dev`<br>
If the converse sources have to be updated, apply these changes again, or fix them using plugins
### 2021-03-12
* Added the `fa-reply` icon into the icons svg (icons.js)
### 2021-03-02
* Fixed the date separator format for French language
### 2021-02-18
* Added support for custom HTTP headers in file upload
* Allowed the preview of webp images in messages
* Disabled the image modal in messages
### 2021-02-15
* Escaped an error on undefined `ev.target` when scrolling a chat view
* Fixed missing default avatar by updating its image type to webp
### 2021-02-08
* Disabled the user modal on avatars (in messages)
### 2021-02-04
* Fixed @ mention on new lines
### 2021-01-25
* Updated the default avatar image
This diff is collapsed.
/**
* Forces the loading of the real number of messages (or more)
* from the setting `archived_messages_page_size`.
* Updates the history behavior of chat boxes.
*/
converse.plugins.add('sib-mam-history', {
converse.plugins.add('sib-history-improved', {
dependencies: [
'converse-mam',
],
overrides: {
ChatRoomView: {
events: {
'wheel .chat-content__messages': 'onScrolledUp',
},
},
ChatBoxView: {
events: {
'wheel .chat-content__messages': 'onScrolledUp',
},
/**
* Fetch the old messages if there is no scroll available.
* @param {WheelEvent} ev
*/
onScrolledUp(ev) {
const { api } = this.__super__._converse;
const { utils } = converse.env;
const scrollable = this.msgs_container.clientHeight < this.msgs_container.scrollHeight;
if (ev.deltaY < 0 && !scrollable) {
api.trigger('chatBoxScrolledUp', this);
utils.safeSave(this.model, {
scrolled: true,
scrollTop: 0,
});
}
},
},
ChatBox: {
/**
* Disable this event handler.
* Causes the history to be fetched twice for private chats.
*/
afterMessagesFetched() {
},
},
},
initialize() {
const { api } = this._converse;
const _converse = this._converse;
const { api } = _converse;
const { log } = converse.env;
let counter = 0;
// Forces the loading of the real number of messages (or more)
// from the setting `archived_messages_page_size`.
api.listen.on('MAMResult', async data => {
const max = +api.settings.get('archived_messages_page_size');
......@@ -22,22 +63,27 @@ converse.plugins.add('sib-mam-history', {
// Stop if there are less messages available than the page size
// Stop if the counter registers more messages than the max value
if (!max || messages.length < max || counter >= max) {
log.debug(`Chatbox has enough messages or cannot get more, count: ${counter}`);
counter = 0;
return;
}
log.debug(`Chatbox needs more messages, count: ${counter}`);
const is_groupchat = data.chatbox.get('type') === converse.CHATROOMS_TYPE;
const oldest_message = messages.pop();
const oldest_message = messages[0] || null;
if (oldest_message) {
const by_jid = is_groupchat ? data.chatbox.get('jid') : converse.bare_jid;
const by_jid = is_groupchat ? data.chatbox.get('jid') : _converse.bare_jid;
const stanza_id = oldest_message && oldest_message['stanza_id '.concat(by_jid)];
if (stanza_id) {
log.debug(`Loading messages before stanza: ${stanza_id}`);
await data.chatbox.fetchArchivedMessages({
'before': stanza_id,
});
} else {
log.debug(`Loading messages before time: ${oldest_message['time']}`);
await data.chatbox.fetchArchivedMessages({
'end': oldest_message['time'],
});
......
/**
* Allow mentions on mobile phones.
* Register a new event handler for the textarea InputEvent.
* Note: The chatroom should already have an event for it.
*/
converse.plugins.add('sib-mention-mobile', {
overrides: {
ChatRoomView: {
/**
* @param {InputEvent} ev
*/
inputChanged(ev) {
this.__super__.inputChanged.apply(this, arguments);
this.mention_auto_complete.onInput(ev);
},
},
AutoComplete: {
/**
* @param {InputEvent} ev
*/
onInput(ev) {
if (this.ac_triggers.includes(ev.data)) {
this.auto_completing = true;
}
},
},
},
});
/**
* Add an action button to reply to a message.
* TODO: Add settings to handle this plugin
*/
converse.plugins.add('sib-reply-to-message', {
initialize() {
const _converse = this._converse;
const { api, __ } = _converse;
const { utils, _ } = converse.env;
function removeQuotedMessages(text) {
return text.replace(/^>.*(\n)?/gm, '');
}
api.listen.on('getMessageActionButtons', (el, buttons) => {
buttons.push({
'i18n_text': __('Reply'),
'handler': ev => {
const chat_textarea = utils.ancestor(el, '.chatbox')?.querySelector('.chat-textarea');
chat_textarea.value = '';
// Add the previous message without quoted messages (to avoid blockquotes into blockquotes)
const message = _.truncate(removeQuotedMessages(el.model.get('message')), { length: 100 });
if (message.length > 0) {
chat_textarea.value += `${message.replace(/^/gm, '>')}\n`;
}
// Add mention to the initial author for MUCs
// Do not add the mention if you were the author of the original message
const nickname = el.model.get('nick');
if (el.model.get('type') === 'groupchat' && el.model.get('sender') !== 'me' && nickname.length) {
chat_textarea.value += `@${nickname} `;
}
chat_textarea.focus();
},
'button_class': 'chat-msg__action-reply',
'icon_class': 'fa fa-reply',
'name': 'reply',
});
return buttons;
});
},
});
......@@ -9,8 +9,10 @@ import './plugins/converse-rai.js';
import './plugins/sib-chat-navigation.js';
import './plugins/sib-custom-hats.js';
import './plugins/sib-disconnected.js';
import './plugins/sib-mam-history.js';
import './plugins/sib-history-improved.js';
import './plugins/sib-mention-mobile.js';
import './plugins/sib-remove-notifications.js';
import './plugins/sib-reply-to-message.js';
import './plugins/sib-scroll-down-on-focus.js';
import './plugins/sib-subscribe-to-rai.js';
......@@ -225,8 +227,10 @@ export const SolidXMPPChat = {
'sib-connected',
'sib-custom-hats',
'sib-disconnected',
'sib-mam-history',
'sib-history-improved',
'sib-mention-mobile',
'sib-remove-notifications',
'sib-reply-to-message',
'sib-scroll-down-on-focus',
'sib-subscribe-to-rai',
],
......
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