-
Notifications
You must be signed in to change notification settings - Fork 700
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Show seconds in timestamp #1141
Conversation
not looking at code, am fan of feature 👍 |
We have discussed this in other tickets, this is not something we will do as part of the main codebase (what a nice way to say "packages!" until we get to that 😅). I invite you to look for them for rationale, I'm on a connection that's too spotty to browser around, sorry. Essentially, 12/24h + show seconds checkboxes will cover 95-99% of use cases while not having to learn a syntax for that (in fact, most if not all OS settings offer the same) so checkboxes = ease of use. @bews, we should be able to get that out with the next release (v2.4.0) once reviewed, thanks! 😃 |
client/views/msg.tpl
Outdated
@@ -1,6 +1,6 @@ | |||
<div class="msg {{type}}{{#if self}} self{{/if}}{{#if highlight}} highlight{{/if}}" id="msg-{{id}}" data-time="{{time}}" data-from="{{from}}"> | |||
<span class="time tooltipped tooltipped-e" aria-label="{{localetime time}}"> | |||
{{tz time}} | |||
<span class="time tooltipped tooltipped-e {{#if seconds}}seconds{{/if}}" aria-label="{{localetime time}}"> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's better to set option classes on body
, like option-seconds
. How would this mix with 12h+seconds (01:11:11 PM) display anyway? Perhaps it's better to make it a flexible column, if possible.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How would this mix with 12h+seconds (01:11:11 PM) display anyway?
Is it a planned feature or I'm missing smth?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think he's just meaning as a future plan, trying to think about how this would interoperate with it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we cared about it updating correctly when we change the settings (currently if you change the settings only new messages will have the correct format) then we could set it on the body (or container) and then have both time formats rendered, and show/hide in css based on the parameter we set on the container. That doesn't reaaaaally work well if we end up having multiple settings, and maybe feels a bit overkill (it doubles the number of time spans we have, with half of them being hidden). Let's leave that for now, this is good enough for just now I think. This is a setting we should have had a long time ago, personally.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me, just a couple of small things. Thanks for this, @bews, this is well overdue, and generally a nice PR.
client/js/libs/handlebars/tz.js
Outdated
module.exports = function(time) { | ||
return moment(time).format("HH:mm"); | ||
module.exports = function(time, seconds) { | ||
return seconds ? moment(time).format("HH:mm:ss") : moment(time).format("HH:mm"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can I be a code pedant and request something like this:
const format = seconds ? "HH:mm:ss" : "HH:mm";
return moment(time).format(format);
I would also prefer if the formats were in constants somewhere, but I won't push that one too hard.
client/js/libs/handlebars/tz.js
Outdated
@@ -2,6 +2,6 @@ | |||
|
|||
const moment = require("moment"); | |||
|
|||
module.exports = function(time) { | |||
return moment(time).format("HH:mm"); | |||
module.exports = function(time, seconds) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's something a little bit weird about passing through seconds here, but I don't know what the better option would be, tbh. If we had control over requring these handlebars templates, then we could use the modules that we are creating, but webpack pulls them in itself, so we'll end up with differing settings, which isn't good. So, I guess this is just me moaning about the system rather than asking you to do anything.
client/views/msg.tpl
Outdated
@@ -1,6 +1,6 @@ | |||
<div class="msg {{type}}{{#if self}} self{{/if}}{{#if highlight}} highlight{{/if}}" id="msg-{{id}}" data-time="{{time}}" data-from="{{from}}"> | |||
<span class="time tooltipped tooltipped-e" aria-label="{{localetime time}}"> | |||
{{tz time}} | |||
<span class="time tooltipped tooltipped-e {{#if seconds}}seconds{{/if}}" aria-label="{{localetime time}}"> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we cared about it updating correctly when we change the settings (currently if you change the settings only new messages will have the correct format) then we could set it on the body (or container) and then have both time formats rendered, and show/hide in css based on the parameter we set on the container. That doesn't reaaaaally work well if we end up having multiple settings, and maybe feels a bit overkill (it doubles the number of time spans we have, with half of them being hidden). Let's leave that for now, this is good enough for just now I think. This is a setting we should have had a long time ago, personally.
client/js/options.js
Outdated
@@ -19,6 +19,7 @@ const options = $.extend({ | |||
notifyAllMessages: false, | |||
part: true, | |||
quit: true, | |||
seconds: false, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe change this to "showSeconds" because it makes sense here, but everywhere else (data.msg.seconds) it isn't clear exactly what it does.
client/js/libs/handlebars/tz.js
Outdated
@@ -1,7 +1,9 @@ | |||
"use strict"; | |||
|
|||
const moment = require("moment"); | |||
const options = require("../../options"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this happen to register options stuff twice? That code isn't so modular to be required multiple times afaik.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this happen to register options stuff twice?
Just checked - it doesn't.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So, I know for certain that node caches require, so that it only runs the stuff once, and you get the same object back if you require it multiple times. So that's exactly how the options module was designed, so that we can require it anywhere within the client code.
I'm not 100% sure on that with webpack, but if @bews says it works, then I guess it does.
I'll do some testing of this before. I thought it might not work just because the handlebars templates are included into webpack in a separate way, so I just assumed it wouldn't. If this works, it's definitely better than the old way.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll test this later to make sure I'm happy with how this works. But assuming it works the way I expect it to, it's ready to go. Hopefully I'll have some time today or tomorrow to check.
client/js/libs/handlebars/tz.js
Outdated
@@ -1,7 +1,9 @@ | |||
"use strict"; | |||
|
|||
const moment = require("moment"); | |||
const options = require("../../options"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So, I know for certain that node caches require, so that it only runs the stuff once, and you get the same object back if you require it multiple times. So that's exactly how the options module was designed, so that we can require it anywhere within the client code.
I'm not 100% sure on that with webpack, but if @bews says it works, then I guess it does.
I'll do some testing of this before. I thought it might not work just because the handlebars templates are included into webpack in a separate way, so I just assumed it wouldn't. If this works, it's definitely better than the old way.
@xPaw, any idea how we could make it work with existing messages? Sorry @YaManicKill but your suggestion is... ahem, less than ideal 😅 The more we move forward with client, the more I think our HTML should be the rendered view of a state we keep in JS. Right now the state is the DOM, and this has been biting us quite a bit. |
Well I guess here's a better (and still css related) options. Wrap the seconds in a span that is shown/hidden appropriately. So we always generate the format as "HH:mm:ss" but the ":ss" is inside another span. The only other way I can think of is going through them all to change the format when we change the setting. Which doesn't feel idea. |
Hiding seconds in Dom approach won't work if we want to also support 12H format. Re-rendering should be a couple lines of code. |
Agreed with @xPaw. Re-rendering is not going to be that expensive, and it's an option you change once and keep forever (or like, until your personal preferences change), not something you'd change every day. |
Yeah, fine, I guess you are right. Re-rendering all the times when the user changes the settings sounds like the best idea and won't be too difficult. @bews are you happy to add this to the PR? I'll be happy with the PR if that is done. |
Yep, will do that later. |
Done. |
Do you want to update this PR to support 12h (am/pm) as well? |
client/js/options.js
Outdated
} else if (name === "showSeconds") { | ||
var format = options.showSeconds ? constants.timeFormats.msgWithSeconds : constants.timeFormats.msgDefault; | ||
chat.find(".msg > .time").each(function() { | ||
$(this).text(moment($(this).parent().data("time")).format(format)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Call the TS helper here, then you don't need duplicate code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Call the TS helper here, then you don't need duplicate code.
TZ you mean? I can't, since it imports options
now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's a fix for that. Move the import into the function on the export (so it only gets callled when the function gets called) and then add the import for the helper here. It's a little less efficient, but there should be no cyclical dependency.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
Let's leave that to another PR. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me.
client/js/options.js
Outdated
@@ -62,7 +64,7 @@ settings.on("change", "input, select, textarea", function() { | |||
"nick", | |||
"part", | |||
"quit", | |||
"notifyAllMessages", | |||
"notifyAllMessages" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Revert this line.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
|
||
module.exports = function(time) { | ||
return moment(time).format("HH:mm"); | ||
const options = require("../../options"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did this require outside of the function not work?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, because otherwise we have a cyclical dependency, with options requiring this file.
Could you squash the commits? I will merge after that. |
done |
Show seconds in timestamp
Hey @bews, we have free sticker packs for our contributors now! |
Just a simple option in settings (disabled by default):
Here how it looks:
Related issue: #98