Commit de6ecbf0 authored by JC Brand's avatar JC Brand

Render messages via a new MessageView view

updates #161
parent 264e6830
...@@ -4,8 +4,8 @@ ...@@ -4,8 +4,8 @@
## New Features ## New Features
- files can now be sent via http-file-upload (XEP-0363) - #161 XEP-0363: HTTP File Upload
- mp4 and mp3 files will now be playable directly in chat. - mp4 and mp3 files will now be playable directly in chat
## 4.0.0 (Unreleased) ## 4.0.0 (Unreleased)
......
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
var u = converse.env.utils; var u = converse.env.utils;
return describe("Chatboxes", function () { return describe("Chatboxes", function () {
describe("A Chatbox", function () { describe("A Chatbox", function () {
it("has a /help command to show the available commands", it("has a /help command to show the available commands",
...@@ -239,7 +240,6 @@ ...@@ -239,7 +240,6 @@
}); });
})); }));
it("can be saved to, and retrieved from, browserStorage", it("can be saved to, and retrieved from, browserStorage",
mock.initConverseWithPromises( mock.initConverseWithPromises(
null, ['rosterGroupsFetched'], {}, null, ['rosterGroupsFetched'], {},
...@@ -654,6 +654,8 @@ ...@@ -654,6 +654,8 @@
return chatbox.get('fullname') === mock.cur_names[0]; return chatbox.get('fullname') === mock.cur_names[0];
}, 100); }, 100);
}).then(function () { }).then(function () {
var author_el = chatboxview.el.querySelector('.chat-msg-author');
expect( _.includes(author_el.textContent, 'Max Frankfurter')).toBeTruthy();
done(); done();
}); });
})); }));
......
...@@ -77,6 +77,7 @@ require.config({ ...@@ -77,6 +77,7 @@ require.config({
"converse-headline": "src/converse-headline", "converse-headline": "src/converse-headline",
"converse-http-file-upload":"src/converse-http-file-upload", "converse-http-file-upload":"src/converse-http-file-upload",
"converse-mam": "src/converse-mam", "converse-mam": "src/converse-mam",
"converse-message-view": "src/converse-message-view",
"converse-minimize": "src/converse-minimize", "converse-minimize": "src/converse-minimize",
"converse-modal": "src/converse-modal", "converse-modal": "src/converse-modal",
"converse-muc": "src/converse-muc", "converse-muc": "src/converse-muc",
......
// Converse.js (A browser based XMPP chat client) // Converse.js
// http://conversejs.org // http://conversejs.org
// //
// Copyright (c) 2012-2017, Jan-Carel Brand <jc@opkode.com> // Copyright (c) 2012-2018, the Converse.js developers
// Licensed under the Mozilla Public License (MPLv2) // Licensed under the Mozilla Public License (MPLv2)
//
/*global define */
(function (root, factory) { (function (root, factory) {
define([ define([
...@@ -106,6 +104,7 @@ ...@@ -106,6 +104,7 @@
this.messages = new _converse.Messages(); this.messages = new _converse.Messages();
this.messages.browserStorage = new Backbone.BrowserStorage[_converse.message_storage]( this.messages.browserStorage = new Backbone.BrowserStorage[_converse.message_storage](
b64_sha1(`converse.messages${this.get('jid')}${_converse.bare_jid}`)); b64_sha1(`converse.messages${this.get('jid')}${_converse.bare_jid}`));
this.messages.chatbox = this;
this.save({ this.save({
// The chat_state will be set to ACTIVE once the chat box is opened // The chat_state will be set to ACTIVE once the chat box is opened
......
This diff is collapsed.
// Converse.js (A browser based XMPP chat client) // Converse.js
// http://conversejs.org // https://conversejs.org
// //
// Copyright (c) 2012-2017, Jan-Carel Brand <jc@opkode.com> // Copyright (c) 2012-2018, the Converse.js developers
// Licensed under the Mozilla Public License (MPLv2) // Licensed under the Mozilla Public License (MPLv2)
//
/*global Backbone, define, window, JSON */
(function (root, factory) { (function (root, factory) {
define(["sizzle", define(["sizzle",
"es6-promise", "es6-promise",
...@@ -80,6 +79,7 @@ ...@@ -80,6 +79,7 @@
'converse-headline', 'converse-headline',
'converse-http-file-upload', 'converse-http-file-upload',
'converse-mam', 'converse-mam',
'converse-message-view',
'converse-minimize', 'converse-minimize',
'converse-modal', 'converse-modal',
'converse-muc', 'converse-muc',
......
...@@ -34,7 +34,6 @@ ...@@ -34,7 +34,6 @@
'click .upload-file': 'toggleFileUpload', 'click .upload-file': 'toggleFileUpload',
'change input.fileupload': 'onFileSelection' 'change input.fileupload': 'onFileSelection'
}, },
toggleFileUpload (ev) { toggleFileUpload (ev) {
this.el.querySelector('input.fileupload').click(); this.el.querySelector('input.fileupload').click();
......
...@@ -90,11 +90,11 @@ ...@@ -90,11 +90,11 @@
msg_content.innerHTML = u.addEmoji( msg_content.innerHTML = u.addEmoji(
_converse, emojione, u.addHyperlinks(xss.filterXSS(text, {'whiteList': {}})) _converse, emojione, u.addHyperlinks(xss.filterXSS(text, {'whiteList': {}}))
); );
if (msg_content.textContent.endsWith('mp4')) { if (msg_content.textContent.endsWith('mp4')) {
msg_content.innerHTML = u.renderMovieURLs(msg_content); msg_content.innerHTML = u.renderMovieURLs(msg_content);
} else if (msg_content.textContent.endsWith('mp3')) { } else if (msg_content.textContent.endsWith('mp3')) {
msg_content.innerHTML = u.renderAudioURLs(msg_content); msg_content.innerHTML = u.renderAudioURLs(msg_content);
} else { } else {
u.renderImageURLs(msg_content).then(() => { u.renderImageURLs(msg_content).then(() => {
this.model.collection.trigger('rendered'); this.model.collection.trigger('rendered');
......
// Converse.js
// http://conversejs.org
//
// Copyright (c) 2018, the Converse.js developers
// Licensed under the Mozilla Public License (MPLv2)
(function (root, factory) { (function (root, factory) {
if (typeof define === 'function' && define.amd) { if (typeof define === 'function' && define.amd) {
define([ define([
......
...@@ -515,6 +515,8 @@ ...@@ -515,6 +515,8 @@
this.markScrolled = _.debounce(this._markScrolled, 100); this.markScrolled = _.debounce(this._markScrolled, 100);
this.model.messages.on('add', this.onMessageAdded, this); this.model.messages.on('add', this.onMessageAdded, this);
this.model.messages.on('rendered', this.scrollDown, this);
this.model.on('change:affiliation', this.renderHeading, this); this.model.on('change:affiliation', this.renderHeading, this);
this.model.on('change:chat_state', this.sendChatState, this); this.model.on('change:chat_state', this.sendChatState, this);
this.model.on('change:connection_status', this.afterConnected, this); this.model.on('change:connection_status', this.afterConnected, this);
...@@ -654,19 +656,6 @@ ...@@ -654,19 +656,6 @@
} }
}, },
getExtraMessageClasses (attrs) {
let extra_classes = _converse.ChatBoxView.prototype
.getExtraMessageClasses.apply(this, arguments);
if (this.is_chatroom && attrs.sender === 'them' &&
this.model.isUserMentioned(attrs.message)) {
// Add special class to mark groupchat messages
// in which we are mentioned.
extra_classes += ' mentioned';
}
return extra_classes;
},
getToolbarOptions () { getToolbarOptions () {
return _.extend( return _.extend(
_converse.ChatBoxView.prototype.getToolbarOptions.apply(this, arguments), _converse.ChatBoxView.prototype.getToolbarOptions.apply(this, arguments),
......
<div class="message chat-message {{{o.extra_classes}}}" data-isodate="{{{o.isodate}}}" data-msgid="{{{o.msgid}}}"> <div class="message chat-message {{{o.extra_classes}}}" data-isodate="{{{o.isodate}}}" data-msgid="{{{o.msgid}}}">
<span class="chat-msg-author chat-msg-{{{o.sender}}}">{{{o.time}}} {{{o.username}}}:&nbsp;</span> <span class="chat-msg-author chat-msg-{{{o.sender}}}">{{{o.time}}} {{{o.username}}}:&nbsp;</span>
<div class="spoiler-hint"><!-- message gets added here via renderMessage --></div> <div class="spoiler-hint">{{{o.spoiler_hint}}}</div>
<a class="icon-eye toggle-spoiler" data-toggle-state="closed" href="#">{{{o.label_show}}}</a> <a class="icon-eye toggle-spoiler" data-toggle-state="closed" href="#">{{{o.label_show}}}</a>
<div class="chat-msg-content spoiler collapsed"><!-- message gets added here via renderMessage --></div> <div class="chat-msg-content spoiler collapsed"><!-- message gets added here via renderMessage --></div>
</div> </div>
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment