2016-03-09 09:14:09 +01:00
|
|
|
// Converse.js (A browser based XMPP chat client)
|
|
|
|
// http://conversejs.org
|
|
|
|
//
|
2017-02-13 15:37:17 +01:00
|
|
|
// Copyright (c) 2012-2017, Jan-Carel Brand <jc@opkode.com>
|
2016-03-09 09:14:09 +01:00
|
|
|
// Licensed under the Mozilla Public License (MPLv2)
|
|
|
|
//
|
2016-12-19 08:46:48 +01:00
|
|
|
/*global define */
|
2016-03-09 09:14:09 +01:00
|
|
|
|
|
|
|
(function (root, factory) {
|
2017-02-13 15:37:17 +01:00
|
|
|
define([
|
2017-02-14 15:08:39 +01:00
|
|
|
"converse-core",
|
2017-02-19 10:58:30 +01:00
|
|
|
"tpl!chatbox",
|
|
|
|
"converse-chatview",
|
2016-03-13 17:16:53 +01:00
|
|
|
], factory);
|
2017-02-19 10:58:30 +01:00
|
|
|
}(this, function (converse, tpl_chatbox) {
|
2016-03-09 09:14:09 +01:00
|
|
|
"use strict";
|
2016-12-20 11:42:20 +01:00
|
|
|
var _ = converse.env._,
|
2016-12-20 11:42:20 +01:00
|
|
|
utils = converse.env.utils;
|
2016-03-20 00:03:00 +01:00
|
|
|
|
2016-12-19 08:02:49 +01:00
|
|
|
converse.plugins.add('converse-headline', {
|
2016-12-20 11:42:20 +01:00
|
|
|
|
2016-03-20 00:03:00 +01:00
|
|
|
overrides: {
|
|
|
|
// Overrides mentioned here will be picked up by converse.js's
|
|
|
|
// plugin architecture they will replace existing methods on the
|
|
|
|
// relevant objects or classes.
|
|
|
|
//
|
|
|
|
// New functions which don't exist yet can also be added.
|
2016-05-28 10:55:03 +02:00
|
|
|
|
2016-03-20 00:03:00 +01:00
|
|
|
ChatBoxViews: {
|
|
|
|
onChatBoxAdded: function (item) {
|
2016-12-20 11:42:20 +01:00
|
|
|
var _converse = this.__super__._converse;
|
2016-03-20 00:03:00 +01:00
|
|
|
var view = this.get(item.get('id'));
|
|
|
|
if (!view && item.get('type') === 'headline') {
|
2016-12-20 10:30:20 +01:00
|
|
|
view = new _converse.HeadlinesBoxView({model: item});
|
2016-03-20 00:03:00 +01:00
|
|
|
this.add(item.get('id'), view);
|
|
|
|
return view;
|
|
|
|
} else {
|
2016-08-31 12:06:17 +02:00
|
|
|
return this.__super__.onChatBoxAdded.apply(this, arguments);
|
2016-03-20 00:03:00 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2016-03-09 09:14:09 +01:00
|
|
|
initialize: function () {
|
|
|
|
/* The initialize function gets called as soon as the plugin is
|
|
|
|
* loaded by converse.js's plugin machinery.
|
|
|
|
*/
|
2016-12-20 11:42:20 +01:00
|
|
|
var _converse = this._converse,
|
|
|
|
__ = _converse.__;
|
|
|
|
|
2016-12-20 10:30:20 +01:00
|
|
|
_converse.HeadlinesBoxView = _converse.ChatBoxView.extend({
|
2016-03-20 00:03:00 +01:00
|
|
|
className: 'chatbox headlines',
|
|
|
|
|
|
|
|
events: {
|
|
|
|
'click .close-chatbox-button': 'close',
|
|
|
|
'click .toggle-chatbox-button': 'minimize',
|
2016-12-19 08:46:48 +01:00
|
|
|
'keypress textarea.chat-textarea': 'keyPressed'
|
2016-03-20 00:03:00 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
initialize: function () {
|
2016-03-31 11:17:39 +02:00
|
|
|
this.disable_mam = true; // Don't do MAM queries for this box
|
2016-03-20 00:03:00 +01:00
|
|
|
this.model.messages.on('add', this.onMessageAdded, this);
|
|
|
|
this.model.on('show', this.show, this);
|
|
|
|
this.model.on('destroy', this.hide, this);
|
|
|
|
this.model.on('change:minimized', this.onMinimizedChanged, this);
|
2016-06-22 15:54:22 +02:00
|
|
|
this.render().fetchMessages().insertIntoDOM().hide();
|
2016-12-20 10:30:20 +01:00
|
|
|
_converse.emit('chatBoxInitialized', this);
|
2016-03-20 00:03:00 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
render: function () {
|
|
|
|
this.$el.attr('id', this.model.get('box_id'))
|
2017-02-19 10:58:30 +01:00
|
|
|
.html(tpl_chatbox(
|
2016-03-20 00:03:00 +01:00
|
|
|
_.extend(this.model.toJSON(), {
|
2016-12-20 10:30:20 +01:00
|
|
|
show_toolbar: _converse.show_toolbar,
|
2016-03-20 00:03:00 +01:00
|
|
|
show_textarea: false,
|
|
|
|
title: this.model.get('fullname'),
|
2016-05-28 10:55:03 +02:00
|
|
|
unread_msgs: __('You have unread messages'),
|
2016-03-20 00:03:00 +01:00
|
|
|
info_close: __('Close this box'),
|
|
|
|
label_personal_message: ''
|
|
|
|
}
|
|
|
|
)
|
|
|
|
)
|
|
|
|
);
|
|
|
|
this.$content = this.$el.find('.chat-content');
|
2016-12-20 10:30:20 +01:00
|
|
|
_converse.emit('chatBoxOpened', this);
|
2016-10-17 13:07:19 +02:00
|
|
|
utils.refreshWebkit();
|
2016-03-20 00:03:00 +01:00
|
|
|
return this;
|
2016-03-31 11:17:39 +02:00
|
|
|
}
|
2016-03-20 00:03:00 +01:00
|
|
|
});
|
|
|
|
|
2016-12-20 11:42:20 +01:00
|
|
|
var onHeadlineMessage = function (message) {
|
2017-02-24 15:03:26 +01:00
|
|
|
/* Handler method for all incoming messages of type "headline". */
|
2016-12-20 11:42:20 +01:00
|
|
|
var from_jid = message.getAttribute('from');
|
|
|
|
if (utils.isHeadlineMessage(message)) {
|
2017-02-24 15:03:26 +01:00
|
|
|
if (_.includes(from_jid, '@') && !_converse.allow_non_roster_messaging) {
|
|
|
|
return;
|
|
|
|
}
|
2016-12-20 11:42:20 +01:00
|
|
|
_converse.chatboxes.create({
|
|
|
|
'id': from_jid,
|
|
|
|
'jid': from_jid,
|
|
|
|
'fullname': from_jid,
|
|
|
|
'type': 'headline'
|
|
|
|
}).createMessage(message, undefined, message);
|
|
|
|
_converse.emit('message', message);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
};
|
|
|
|
|
2016-03-20 00:03:00 +01:00
|
|
|
var registerHeadlineHandler = function () {
|
2016-12-20 10:30:20 +01:00
|
|
|
_converse.connection.addHandler(
|
2016-03-21 11:40:52 +01:00
|
|
|
onHeadlineMessage, null, 'message');
|
2016-03-20 00:03:00 +01:00
|
|
|
};
|
2016-12-20 10:30:20 +01:00
|
|
|
_converse.on('connected', registerHeadlineHandler);
|
|
|
|
_converse.on('reconnected', registerHeadlineHandler);
|
2016-03-09 09:14:09 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}));
|