Make messages' time format configurable (#797)

Fixes #675 

* Made time format configurable

* Made changes to values of time_format

* Removed user restrictions on time format

* Added documentation for time-format config

* Edited changes.md

* Edited config doc

* Modified time-format explanation

* Added link to moment

* Added test to check rendered time

* Edited CHANGES and removeunncessary lines from time format checking spec

* Removed unncessary spaces
This commit is contained in:
Soumit Bose 2017-03-12 16:02:38 +05:30 committed by JC Brand
parent 9df3715ac8
commit 2c5ecd7120
5 changed files with 33 additions and 1 deletions

View File

@ -4,6 +4,7 @@
- #585 Duplicate contact created due to JID case sensivity [saganshul]
- #628 Fixes the bug in displaying chat status during private chat. [saganshul]
- #797 Time format made configurable. [smitbose]
- #806 The `_converse.listen` API event listeners aren't triggered. [jcbrand]
- #807 Error: Plugin "converse-dragresize" tried to override HeadlinesBoxView but it's not found. [jcbrand]

View File

@ -1067,6 +1067,17 @@ If set to ``false``, this feature is disabled.
If set to ``a resource name``, converse.js will synchronize only with a client that has that particular resource assigned to it.
time_format
-----------
* Default: ``HH:MM``
Examples: ``HH:MM``, ``hh:mm``, ``hh:mm a``.
This option makes the time format for the time shown, for each message, configurable. Converse uses `moment.js <https://momentjs.com/>`_
for showing time. This option allows the configuration of the format in which `moment` will display the time for the messages. For detailed
description of time-format options available for `moment` you can check this `link <https://momentjs.com/docs/#/parsing/string-format/>`_.
use_otr_by_default
------------------

View File

@ -1240,6 +1240,25 @@
});
}));
it("will render the message time as configured", mock.initConverse(function (_converse) {
test_utils.createContacts(_converse, 'current');
_converse.time_format = 'hh:mm';
var contact_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@localhost';
test_utils.openChatBoxFor(_converse, contact_jid);
var view = _converse.chatboxviews.get(contact_jid);
var message = 'This message is sent from this chatbox';
test_utils.sendMessage(view, message);
var chatbox = _converse.chatboxes.get(contact_jid);
expect(chatbox.messages.models.length, 1);
var msg_object = chatbox.messages.models[0];
var msg_time_author = view.$el.find('.chat-content').find('.chat-message')
.last().find('.chat-msg-author.chat-msg-me').text();
var msg_time_rendered = msg_time_author.split(" ",1);
var msg_time = moment(msg_object.get('time')).format(_converse.time_format);
expect(msg_time_rendered[0]).toBe(msg_time);
}));
});
describe("A Chat Status Notification", function () {

View File

@ -348,7 +348,7 @@
_.extend(this.getExtraMessageTemplateAttributes(attrs), {
'msgid': attrs.msgid,
'sender': attrs.sender,
'time': msg_time.format('hh:mm'),
'time': msg_time.format(_converse.time_format),
'isodate': msg_time.format(),
'username': username,
'extra_classes': this.getExtraMessageClasses(attrs)

View File

@ -267,6 +267,7 @@
whitelisted_plugins: [],
xhr_custom_status: false,
xhr_custom_status_url: '',
time_format: 'HH:MM',
};
_.assignIn(this, this.default_settings);
// Allow only whitelisted configuration attributes to be overwritten