[polari] chatView: Insert timestamps after inactivity
- From: Florian Müllner <fmuellner src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [polari] chatView: Insert timestamps after inactivity
- Date: Wed, 13 Nov 2013 20:51:09 +0000 (UTC)
commit 95494c861054ab11625b184096f0fc8a5f33f0ab
Author: Florian Müllner <fmuellner gnome org>
Date: Tue Nov 12 16:56:55 2013 +0100
chatView: Insert timestamps after inactivity
The time a message was sent/received is useful information, but
clutters the interface when repeated for every single message.
So rather than doing that (or chickening out by making it a user
option), only insert a timestamp after some time of inactivity,
which should allow to provide a good enough indication of when
a message was sent without the cluttering.
https://bugzilla.gnome.org/show_bug.cgi?id=712248
src/chatView.js | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 63 insertions(+), 0 deletions(-)
---
diff --git a/src/chatView.js b/src/chatView.js
index 6efd35b..d54eec5 100644
--- a/src/chatView.js
+++ b/src/chatView.js
@@ -13,6 +13,9 @@ const MAX_NICK_CHARS = 8;
const IGNORE_STATUS_TIME = 5;
const TP_CURRENT_TIME = GLib.MAXUINT32;
+const TIMESTAMP_INTERVAL = 300; // seconds of inactivity after which to
+ // insert a timestamp
+
const INDICATOR_OFFSET = 5; // TODO: should be based on line spacing
// Workaround for GtkTextView growing horizontally over time when
@@ -75,6 +78,7 @@ const ChatView = new Lang.Class({
this._room = room;
this._lastNick = null;
+ this._lastTimestamp = 0;
this._active = false;
this._toplevelFocus = false;
this._joinTime = GLib.DateTime.new_now_utc().to_unix();
@@ -146,6 +150,11 @@ const ChatView = new Lang.Class({
left_margin: 0,
indent: 0,
justification: Gtk.Justification.RIGHT },
+ { name: 'timestamp',
+ left_margin: 0,
+ indent: 0,
+ weight: Pango.Weight.BOLD,
+ justification: Gtk.Justification.RIGHT },
{ name: 'action',
left_margin: 0 },
{ name: 'url',
@@ -178,6 +187,8 @@ const ChatView = new Lang.Class({
foreground_rgba: selectedColor },
{ name: 'status',
foreground_rgba: dimColor },
+ { name: 'timestamp',
+ foreground_rgba: dimColor },
{ name: 'action',
foreground_rgba: dimColor },
{ name: 'url',
@@ -421,6 +432,42 @@ const ChatView = new Lang.Class({
this._insertWithTagName(text, 'status');
},
+ _formatTimestamp: function(timestamp) {
+ let date = GLib.DateTime.new_from_unix_local(timestamp);
+ let now = GLib.DateTime.new_now_local();
+
+ let daysAgo = now.difference(date) / GLib.TIME_SPAN_DAY;
+
+ let format;
+ // Show only the hour if date is on today
+ if(daysAgo < 1){
+ format = "%H:%M";
+ }
+ // Show the word "Yesterday" and time if date is on yesterday
+ else if(daysAgo <2){
+ /* Translators: this is the word "Yesterday" followed by a time string. i.e. "Yesterday, 14:30"*/
+ // xgettext:no-c-format
+ format = _("Yesterday, %H:%M");
+ }
+ // Show a week day and time if date is in the last week
+ else if (daysAgo < 7) {
+ /* Translators: this is the week day name followed by a time string. i.e. "Monday, 14:30*/
+ // xgettext:no-c-format
+ format = _("%A, %H:%M");
+
+ } else if (date.get_year() == now.get_year()) {
+ /* Translators: this is the month name and day number followed by a time string. i.e. "May 25,
14:30"*/
+ // xgettext:no-c-format
+ format = _("%B %d, %H:%M");
+ } else {
+ /* Translators: this is the month name, day number, year number followed by a time string. i.e.
"May 25 2012, 14:30"*/
+ // xgettext:no-c-format
+ format = _("%B %d %Y, %H:%M");
+ }
+
+ return date.format(format);
+ },
+
_insertMessage: function(room, message) {
let nick = message.sender.alias;
let [text, flags] = message.to_text();
@@ -428,6 +475,22 @@ const ChatView = new Lang.Class({
let isAction = message.get_message_type() == Tp.ChannelTextMessageType.ACTION;
let needsGap = nick != this._lastNick || isAction;
+ let timestamp = message.get_sent_timestamp();
+ if (!timestamp)
+ timestamp = message.get_received_timestamp();
+
+ if (timestamp - TIMESTAMP_INTERVAL > this._lastTimestamp) {
+ this._ensureNewLine();
+
+ let iter = this._view.buffer.get_end_iter();
+ let tags = [this._lookupTag('timestamp')];
+ if (needsGap)
+ tags.push(this._lookupTag('gap'));
+ needsGap = false;
+ this._insertWithTags(this._formatTimestamp(timestamp), tags);
+ }
+ this._lastTimestamp = timestamp;
+
this._ensureNewLine();
if (nick.length > this._maxNickChars) {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]