join/leave notification fixes.
* Don't show leave notification twice when someone leaves, joins and then leaves again * Add a test case for a member joining and then leaving
This commit is contained in:
parent
5316aad340
commit
cf75d37587
28
dist/converse.js
vendored
28
dist/converse.js
vendored
@ -68682,7 +68682,7 @@ var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_
|
|||||||
this.model.on('destroy', this.hide, this);
|
this.model.on('destroy', this.hide, this);
|
||||||
this.model.on('show', this.show, this);
|
this.model.on('show', this.show, this);
|
||||||
this.model.occupants.on('add', this.onOccupantAdded, this);
|
this.model.occupants.on('add', this.onOccupantAdded, this);
|
||||||
this.model.occupants.on('remove', this.showLeaveNotification, this);
|
this.model.occupants.on('remove', this.onOccupantRemoved, this);
|
||||||
this.model.occupants.on('change:show', this.showJoinOrLeaveNotification, this);
|
this.model.occupants.on('change:show', this.showJoinOrLeaveNotification, this);
|
||||||
this.model.occupants.on('change:role', this.informOfOccupantsRoleChange, this);
|
this.model.occupants.on('change:role', this.informOfOccupantsRoleChange, this);
|
||||||
this.model.occupants.on('change:affiliation', this.informOfOccupantsAffiliationChange, this);
|
this.model.occupants.on('change:affiliation', this.informOfOccupantsAffiliationChange, this);
|
||||||
@ -69706,6 +69706,12 @@ var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
onOccupantRemoved(occupant) {
|
||||||
|
if (occupant.get('show') === 'online') {
|
||||||
|
this.showLeaveNotification(occupant);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
showJoinOrLeaveNotification(occupant) {
|
showJoinOrLeaveNotification(occupant) {
|
||||||
if (_.includes(occupant.get('states'), '303')) {
|
if (_.includes(occupant.get('states'), '303')) {
|
||||||
return;
|
return;
|
||||||
@ -69772,11 +69778,13 @@ var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_
|
|||||||
|
|
||||||
const nick = occupant.get('nick'),
|
const nick = occupant.get('nick'),
|
||||||
stat = occupant.get('status'),
|
stat = occupant.get('status'),
|
||||||
last_el = this.content.lastElementChild;
|
last_el = this.content.lastElementChild,
|
||||||
|
data = _.get(last_el, 'dataset', {});
|
||||||
|
|
||||||
if (last_el && _.includes(_.get(last_el, 'classList', []), 'chat-info') && moment(last_el.getAttribute('data-isodate')).isSame(new Date(), "day") && _.get(last_el, 'dataset', {}).join === `"${nick}"`) {
|
if (last_el && _.includes(_.get(last_el, 'classList', []), 'chat-info') && moment(last_el.getAttribute('data-isodate')).isSame(new Date(), "day") && (data.join === `"${nick}"` || data.leavejoin === `"${nick}"`)) {
|
||||||
let message;
|
let message;
|
||||||
|
|
||||||
|
if (data.join === `"${nick}"`) {
|
||||||
if (_.isNil(stat)) {
|
if (_.isNil(stat)) {
|
||||||
message = __('%1$s has entered and left the groupchat', nick);
|
message = __('%1$s has entered and left the groupchat', nick);
|
||||||
} else {
|
} else {
|
||||||
@ -69792,6 +69800,20 @@ var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_
|
|||||||
const el = this.content.lastElementChild;
|
const el = this.content.lastElementChild;
|
||||||
setTimeout(() => u.addClass('fade-out', el), 5000);
|
setTimeout(() => u.addClass('fade-out', el), 5000);
|
||||||
setTimeout(() => el.parentElement && el.parentElement.removeChild(el), 5250);
|
setTimeout(() => el.parentElement && el.parentElement.removeChild(el), 5250);
|
||||||
|
} else if (data.leavejoin === `"${nick}"`) {
|
||||||
|
if (_.isNil(stat)) {
|
||||||
|
message = __('%1$s has left the groupchat', nick);
|
||||||
|
} else {
|
||||||
|
message = __('%1$s has left the groupchat. "%2$s"', nick, stat);
|
||||||
|
}
|
||||||
|
|
||||||
|
last_el.outerHTML = tpl_info({
|
||||||
|
'data': `data-leave="${nick}"`,
|
||||||
|
'isodate': moment().format(),
|
||||||
|
'extra_classes': 'chat-event',
|
||||||
|
'message': message
|
||||||
|
});
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
let message;
|
let message;
|
||||||
|
|
||||||
|
@ -421,14 +421,13 @@
|
|||||||
|
|
||||||
test_utils.openChatRoom(_converse, "coven", 'chat.shakespeare.lit', 'some1')
|
test_utils.openChatRoom(_converse, "coven", 'chat.shakespeare.lit', 'some1')
|
||||||
.then(() => {
|
.then(() => {
|
||||||
var view = _converse.chatboxviews.get('coven@chat.shakespeare.lit');
|
const view = _converse.chatboxviews.get('coven@chat.shakespeare.lit');
|
||||||
var $chat_content = $(view.el).find('.chat-content');
|
const $chat_content = $(view.el).find('.chat-content');
|
||||||
|
|
||||||
/* We don't show join/leave messages for existing occupants. We
|
/* We don't show join/leave messages for existing occupants. We
|
||||||
* know about them because we receive their presences before we
|
* know about them because we receive their presences before we
|
||||||
* receive our own.
|
* receive our own.
|
||||||
*/
|
*/
|
||||||
var presence = $pres({
|
let presence = $pres({
|
||||||
to: 'dummy@localhost/_converse.js-29092160',
|
to: 'dummy@localhost/_converse.js-29092160',
|
||||||
from: 'coven@chat.shakespeare.lit/oldguy'
|
from: 'coven@chat.shakespeare.lit/oldguy'
|
||||||
}).c('x', {xmlns: Strophe.NS.MUC_USER})
|
}).c('x', {xmlns: Strophe.NS.MUC_USER})
|
||||||
@ -609,8 +608,55 @@
|
|||||||
_converse.connection._dataRecv(test_utils.createRequest(presence));
|
_converse.connection._dataRecv(test_utils.createRequest(presence));
|
||||||
expect($chat_content[0].querySelectorAll('div.chat-info').length).toBe(5);
|
expect($chat_content[0].querySelectorAll('div.chat-info').length).toBe(5);
|
||||||
expect($chat_content.find('div.chat-info:last').html()).toBe("nomorenicks has entered the groupchat");
|
expect($chat_content.find('div.chat-info:last').html()).toBe("nomorenicks has entered the groupchat");
|
||||||
done();
|
|
||||||
|
|
||||||
|
// Test a member joining and leaving
|
||||||
|
presence = $pres({
|
||||||
|
to: 'dummy@localhost/_converse.js-290918392',
|
||||||
|
from: 'coven@chat.shakespeare.lit/insider'
|
||||||
|
}).c('x', {xmlns: Strophe.NS.MUC_USER})
|
||||||
|
.c('item', {
|
||||||
|
'affiliation': 'member',
|
||||||
|
'jid': 'insider@localhost/_converse.js-290929789',
|
||||||
|
'role': 'participant'
|
||||||
});
|
});
|
||||||
|
_converse.connection._dataRecv(test_utils.createRequest(presence));
|
||||||
|
expect($chat_content[0].querySelectorAll('div.chat-info').length).toBe(6);
|
||||||
|
|
||||||
|
/* <presence
|
||||||
|
* from='coven@chat.shakespeare.lit/thirdwitch'
|
||||||
|
* to='crone1@shakespeare.lit/desktop'
|
||||||
|
* type='unavailable'>
|
||||||
|
* <status>Disconnected: Replaced by new connection</status>
|
||||||
|
* <x xmlns='http://jabber.org/protocol/muc#user'>
|
||||||
|
* <item affiliation='member'
|
||||||
|
* jid='hag66@shakespeare.lit/pda'
|
||||||
|
* role='none'/>
|
||||||
|
* </x>
|
||||||
|
* </presence>
|
||||||
|
*/
|
||||||
|
presence = $pres({
|
||||||
|
to: 'dummy@localhost/_converse.js-29092160',
|
||||||
|
type: 'unavailable',
|
||||||
|
from: 'coven@chat.shakespeare.lit/insider'
|
||||||
|
})
|
||||||
|
.c('status', 'Disconnected: Replaced by new connection').up()
|
||||||
|
.c('x', {xmlns: Strophe.NS.MUC_USER})
|
||||||
|
.c('item', {
|
||||||
|
'affiliation': 'member',
|
||||||
|
'jid': 'insider@localhost/_converse.js-290929789',
|
||||||
|
'role': 'none'
|
||||||
|
});
|
||||||
|
_converse.connection._dataRecv(test_utils.createRequest(presence));
|
||||||
|
expect($chat_content.find('div.chat-info').length).toBe(6);
|
||||||
|
expect($chat_content.find('div.chat-info:last').html()).toBe(
|
||||||
|
'insider has entered and left the groupchat. '+
|
||||||
|
'"Disconnected: Replaced by new connection"');
|
||||||
|
|
||||||
|
expect(view.model.occupants.length).toBe(5);
|
||||||
|
expect(view.model.occupants.findWhere({'jid': 'insider@localhost'}).get('show')).toBe('offline');
|
||||||
|
done();
|
||||||
|
}).catch(_.partial(_converse.log, _, Strophe.LogLevel.FATAL))
|
||||||
}));
|
}));
|
||||||
|
|
||||||
it("shows a new day indicator if a join/leave message is received on a new day",
|
it("shows a new day indicator if a join/leave message is received on a new day",
|
||||||
|
@ -541,7 +541,7 @@
|
|||||||
this.model.on('show', this.show, this);
|
this.model.on('show', this.show, this);
|
||||||
|
|
||||||
this.model.occupants.on('add', this.onOccupantAdded, this);
|
this.model.occupants.on('add', this.onOccupantAdded, this);
|
||||||
this.model.occupants.on('remove', this.showLeaveNotification, this);
|
this.model.occupants.on('remove', this.onOccupantRemoved, this);
|
||||||
this.model.occupants.on('change:show', this.showJoinOrLeaveNotification, this);
|
this.model.occupants.on('change:show', this.showJoinOrLeaveNotification, this);
|
||||||
this.model.occupants.on('change:role', this.informOfOccupantsRoleChange, this);
|
this.model.occupants.on('change:role', this.informOfOccupantsRoleChange, this);
|
||||||
this.model.occupants.on('change:affiliation', this.informOfOccupantsAffiliationChange, this);
|
this.model.occupants.on('change:affiliation', this.informOfOccupantsAffiliationChange, this);
|
||||||
@ -1482,6 +1482,12 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
onOccupantRemoved (occupant) {
|
||||||
|
if (occupant.get('show') === 'online') {
|
||||||
|
this.showLeaveNotification(occupant);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
showJoinOrLeaveNotification (occupant) {
|
showJoinOrLeaveNotification (occupant) {
|
||||||
if (_.includes(occupant.get('states'), '303')) {
|
if (_.includes(occupant.get('states'), '303')) {
|
||||||
return;
|
return;
|
||||||
@ -1546,14 +1552,16 @@
|
|||||||
}
|
}
|
||||||
const nick = occupant.get('nick'),
|
const nick = occupant.get('nick'),
|
||||||
stat = occupant.get('status'),
|
stat = occupant.get('status'),
|
||||||
last_el = this.content.lastElementChild;
|
last_el = this.content.lastElementChild,
|
||||||
|
data = _.get(last_el, 'dataset', {});
|
||||||
|
|
||||||
if (last_el &&
|
if (last_el &&
|
||||||
_.includes(_.get(last_el, 'classList', []), 'chat-info') &&
|
_.includes(_.get(last_el, 'classList', []), 'chat-info') &&
|
||||||
moment(last_el.getAttribute('data-isodate')).isSame(new Date(), "day") &&
|
moment(last_el.getAttribute('data-isodate')).isSame(new Date(), "day") &&
|
||||||
_.get(last_el, 'dataset', {}).join === `"${nick}"`) {
|
(data.join === `"${nick}"` || data.leavejoin === `"${nick}"`)) {
|
||||||
|
|
||||||
let message;
|
let message;
|
||||||
|
if (data.join === `"${nick}"`) {
|
||||||
if (_.isNil(stat)) {
|
if (_.isNil(stat)) {
|
||||||
message = __('%1$s has entered and left the groupchat', nick);
|
message = __('%1$s has entered and left the groupchat', nick);
|
||||||
} else {
|
} else {
|
||||||
@ -1569,6 +1577,21 @@
|
|||||||
const el = this.content.lastElementChild;
|
const el = this.content.lastElementChild;
|
||||||
setTimeout(() => u.addClass('fade-out', el), 5000);
|
setTimeout(() => u.addClass('fade-out', el), 5000);
|
||||||
setTimeout(() => el.parentElement && el.parentElement.removeChild(el), 5250);
|
setTimeout(() => el.parentElement && el.parentElement.removeChild(el), 5250);
|
||||||
|
|
||||||
|
} else if (data.leavejoin === `"${nick}"`) {
|
||||||
|
if (_.isNil(stat)) {
|
||||||
|
message = __('%1$s has left the groupchat', nick);
|
||||||
|
} else {
|
||||||
|
message = __('%1$s has left the groupchat. "%2$s"', nick, stat);
|
||||||
|
}
|
||||||
|
last_el.outerHTML =
|
||||||
|
tpl_info({
|
||||||
|
'data': `data-leave="${nick}"`,
|
||||||
|
'isodate': moment().format(),
|
||||||
|
'extra_classes': 'chat-event',
|
||||||
|
'message': message
|
||||||
|
});
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
let message;
|
let message;
|
||||||
if (_.isNil(stat)) {
|
if (_.isNil(stat)) {
|
||||||
|
Loading…
Reference in New Issue
Block a user