Fix leaky abstraction of MUC
This commit is contained in:
parent
148516e0cc
commit
a033899946
@ -345,6 +345,23 @@
|
||||
|
||||
describe("A Chat Room", function () {
|
||||
|
||||
it("will specially mark messages in which you are mentioned", mock.initConverse(function (_converse) {
|
||||
test_utils.createContacts(_converse, 'current');
|
||||
test_utils.openAndEnterChatRoom(_converse, 'lounge', 'localhost', 'dummy');
|
||||
var view = _converse.chatboxviews.get('lounge@localhost');
|
||||
if (!view.$el.find('.chat-area').length) { view.renderChatArea(); }
|
||||
var message = 'dummy: Your attention is required';
|
||||
var nick = mock.chatroom_names[0],
|
||||
msg = $msg({
|
||||
from: 'lounge@localhost/'+nick,
|
||||
id: (new Date()).getTime(),
|
||||
to: 'dummy@localhost',
|
||||
type: 'groupchat'
|
||||
}).c('body').t(message).tree();
|
||||
_converse.chatboxes.onMessage(msg);
|
||||
expect(view.$el.find('.chat-message').hasClass('mentioned')).toBeTruthy();
|
||||
}));
|
||||
|
||||
it("can have spaces and special characters in its name", mock.initConverse(function (_converse) {
|
||||
test_utils.openChatRoom(_converse, 'lounge & leisure', 'localhost', 'dummy');
|
||||
var view = _converse.chatboxviews.get(
|
||||
|
@ -303,6 +303,10 @@
|
||||
return {};
|
||||
},
|
||||
|
||||
getExtraMessageClasses: function (attrs) {
|
||||
return attrs.delayed && 'delayed' || '';
|
||||
},
|
||||
|
||||
renderMessage: function (attrs) {
|
||||
/* Renders a chat message based on the passed in attributes.
|
||||
*
|
||||
@ -316,7 +320,6 @@
|
||||
text = attrs.message,
|
||||
match = text.match(/^\/(.*?)(?: (.*))?$/),
|
||||
fullname = this.model.get('fullname') || attrs.fullname,
|
||||
extra_classes = attrs.delayed && 'delayed' || '',
|
||||
template, username;
|
||||
|
||||
if ((match) && (match[1] === 'me')) {
|
||||
@ -330,12 +333,6 @@
|
||||
}
|
||||
this.$content.find('div.chat-event').remove();
|
||||
|
||||
// FIXME: leaky abstraction from MUC
|
||||
if (this.is_chatroom && attrs.sender === 'them' && (new RegExp("\\b"+this.model.get('nick')+"\\b")).test(text)) {
|
||||
// Add special class to mark groupchat messages in which we
|
||||
// are mentioned.
|
||||
extra_classes += ' mentioned';
|
||||
}
|
||||
if (text.length > 8000) {
|
||||
text = text.substring(0, 10) + '...';
|
||||
this.showStatusNotification(
|
||||
@ -351,7 +348,7 @@
|
||||
'time': msg_time.format('hh:mm'),
|
||||
'isodate': msg_time.format(),
|
||||
'username': username,
|
||||
'extra_classes': extra_classes
|
||||
'extra_classes': this.getExtraMessageClasses(attrs)
|
||||
})
|
||||
));
|
||||
$msg.find('.chat-msg-content').first()
|
||||
|
@ -433,6 +433,20 @@
|
||||
return this;
|
||||
},
|
||||
|
||||
getExtraMessageClasses: function (attrs) {
|
||||
var extra_classes = _converse.ChatBoxView.prototype
|
||||
.getExtraMessageClasses.apply(this, arguments);
|
||||
|
||||
if (this.is_chatroom && attrs.sender === 'them' &&
|
||||
(new RegExp("\\b"+this.model.get('nick')+"\\b")).test(attrs.message)
|
||||
) {
|
||||
// Add special class to mark groupchat messages
|
||||
// in which we are mentioned.
|
||||
extra_classes += ' mentioned';
|
||||
}
|
||||
return extra_classes;
|
||||
},
|
||||
|
||||
getToolbarOptions: function () {
|
||||
return _.extend(
|
||||
_converse.ChatBoxView.prototype.getToolbarOptions.apply(this, arguments),
|
||||
|
Loading…
Reference in New Issue
Block a user