MUC: Include nicks from messages in the mentions auto-complete list
This commit is contained in:
parent
62ef18a027
commit
d361d1d0a3
@ -7,7 +7,9 @@
|
|||||||
} (this, function (jasmine, mock, test_utils) {
|
} (this, function (jasmine, mock, test_utils) {
|
||||||
"use strict";
|
"use strict";
|
||||||
const $pres = converse.env.$pres;
|
const $pres = converse.env.$pres;
|
||||||
|
const $msg = converse.env.$msg;
|
||||||
const Strophe = converse.env.Strophe;
|
const Strophe = converse.env.Strophe;
|
||||||
|
const u = converse.env.utils;
|
||||||
|
|
||||||
describe("The nickname autocomplete feature", function () {
|
describe("The nickname autocomplete feature", function () {
|
||||||
|
|
||||||
@ -19,6 +21,7 @@
|
|||||||
await test_utils.openAndEnterChatRoom(_converse, 'lounge@montague.lit', 'tom');
|
await test_utils.openAndEnterChatRoom(_converse, 'lounge@montague.lit', 'tom');
|
||||||
const view = _converse.chatboxviews.get('lounge@montague.lit');
|
const view = _converse.chatboxviews.get('lounge@montague.lit');
|
||||||
|
|
||||||
|
// Nicknames from presences
|
||||||
['dick', 'harry'].forEach((nick) => {
|
['dick', 'harry'].forEach((nick) => {
|
||||||
_converse.connection._dataRecv(test_utils.createRequest(
|
_converse.connection._dataRecv(test_utils.createRequest(
|
||||||
$pres({
|
$pres({
|
||||||
@ -33,6 +36,15 @@
|
|||||||
})));
|
})));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Nicknames from messages
|
||||||
|
const msg = $msg({
|
||||||
|
from: 'lounge@montague.lit/jane',
|
||||||
|
id: u.getUniqueId(),
|
||||||
|
to: 'romeo@montague.lit',
|
||||||
|
type: 'groupchat'
|
||||||
|
}).c('body').t('Hello world').tree();
|
||||||
|
await view.model.onMessage(msg);
|
||||||
|
|
||||||
// Test that pressing @ brings up all options
|
// Test that pressing @ brings up all options
|
||||||
const textarea = view.el.querySelector('textarea.chat-textarea');
|
const textarea = view.el.querySelector('textarea.chat-textarea');
|
||||||
const at_event = {
|
const at_event = {
|
||||||
@ -46,10 +58,11 @@
|
|||||||
textarea.value = '@';
|
textarea.value = '@';
|
||||||
view.onKeyUp(at_event);
|
view.onKeyUp(at_event);
|
||||||
|
|
||||||
expect(view.el.querySelectorAll('.suggestion-box__results li').length).toBe(3);
|
expect(view.el.querySelectorAll('.suggestion-box__results li').length).toBe(4);
|
||||||
expect(view.el.querySelector('.suggestion-box__results li:first-child').textContent).toBe('dick');
|
expect(view.el.querySelector('.suggestion-box__results li:first-child').textContent).toBe('dick');
|
||||||
expect(view.el.querySelector('.suggestion-box__results li:nth-child(2)').textContent).toBe('harry');
|
expect(view.el.querySelector('.suggestion-box__results li:nth-child(2)').textContent).toBe('harry');
|
||||||
expect(view.el.querySelector('.suggestion-box__results li:nth-child(3)').textContent).toBe('tom');
|
expect(view.el.querySelector('.suggestion-box__results li:nth-child(3)').textContent).toBe('jane');
|
||||||
|
expect(view.el.querySelector('.suggestion-box__results li:nth-child(4)').textContent).toBe('tom');
|
||||||
done();
|
done();
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
@ -845,7 +845,12 @@ converse.plugins.add('converse-muc-views', {
|
|||||||
},
|
},
|
||||||
|
|
||||||
getAutoCompleteList () {
|
getAutoCompleteList () {
|
||||||
return this.model.occupants.filter('nick').map(o => ({'label': o.get('nick'), 'value': `@${o.get('nick')}`}));
|
// Create an array of unique nicknames based on the occupants and messages.
|
||||||
|
const nicks = [...new Set([
|
||||||
|
...this.model.occupants.map(o => o.get('nick')),
|
||||||
|
...this.model.messages.map(m => m.get('nick'))
|
||||||
|
])].filter(n => n);
|
||||||
|
return nicks.map(nick => ({'label': nick, 'value': `@${nick}`}));
|
||||||
},
|
},
|
||||||
|
|
||||||
getAutoCompleteListItem(text, input) {
|
getAutoCompleteListItem(text, input) {
|
||||||
|
Loading…
Reference in New Issue
Block a user