Skip to content
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

Merged
merged 1 commit into from
Jun 10, 2017
Merged

Show seconds in timestamp #1141

merged 1 commit into from
Jun 10, 2017

Conversation

bews
Copy link
Contributor

@bews bews commented May 6, 2017

Just a simple option in settings (disabled by default):

2017-05-06_21-46-37

Here how it looks:

2017-05-06_21-40-54

Related issue: #98

@MaxLeiter
Copy link
Member

not looking at code, am fan of feature 👍

@astorije astorije added this to the 2.4.0 milestone May 6, 2017
@astorije astorije added the Type: Feature Tickets that describe a desired feature or PRs that add them to the project. label May 6, 2017
@astorije
Copy link
Member

astorije commented May 6, 2017

I think it would be even better if we could set the date format ourself

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! 😃

@@ -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}}">
Copy link
Member

@xPaw xPaw May 7, 2017

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.

Copy link
Contributor Author

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?

Copy link
Member

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.

Copy link
Member

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.

Copy link
Member

@AlMcKinlay AlMcKinlay left a 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.

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");
Copy link
Member

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.

@@ -2,6 +2,6 @@

const moment = require("moment");

module.exports = function(time) {
return moment(time).format("HH:mm");
module.exports = function(time, seconds) {
Copy link
Member

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.

@@ -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}}">
Copy link
Member

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.

@@ -19,6 +19,7 @@ const options = $.extend({
notifyAllMessages: false,
part: true,
quit: true,
seconds: false,
Copy link
Member

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.

@bews
Copy link
Contributor Author

bews commented May 9, 2017

So, I refactored this thing and now there even less code 😄

Decided to keep the previous commit for now to compare.

Here how it looks after the changes:
2017-05-09_07-37-48

@@ -1,7 +1,9 @@
"use strict";

const moment = require("moment");
const options = require("../../options");
Copy link
Member

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.

Copy link
Contributor Author

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.

Copy link
Member

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.

Copy link
Member

@AlMcKinlay AlMcKinlay left a 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.

@@ -1,7 +1,9 @@
"use strict";

const moment = require("moment");
const options = require("../../options");
Copy link
Member

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.

@astorije
Copy link
Member

astorije commented May 9, 2017

@xPaw, any idea how we could make it work with existing messages? Sorry @YaManicKill but your suggestion is... ahem, less than ideal 😅
Each .msg line has a data-time, so we could recompute the timestamp from that and update the DOM for everything. Not ideal either.

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.

@AlMcKinlay
Copy link
Member

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.

@xPaw
Copy link
Member

xPaw commented May 13, 2017

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.

@astorije
Copy link
Member

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.

@AlMcKinlay
Copy link
Member

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.

@bews
Copy link
Contributor Author

bews commented May 15, 2017

Yep, will do that later.

bews added a commit to bews/lounge that referenced this pull request May 16, 2017
@bews
Copy link
Contributor Author

bews commented May 16, 2017

Done.

@xPaw
Copy link
Member

xPaw commented May 17, 2017

Do you want to update this PR to support 12h (am/pm) as well?

} 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));
Copy link
Member

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.

Copy link
Contributor Author

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.

Copy link
Member

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@AlMcKinlay
Copy link
Member

Do you want to update this PR to support 12h (am/pm) as well?

Let's leave that to another PR.

Copy link
Member

@AlMcKinlay AlMcKinlay left a 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.

@@ -62,7 +64,7 @@ settings.on("change", "input, select, textarea", function() {
"nick",
"part",
"quit",
"notifyAllMessages",
"notifyAllMessages"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Revert this line.

Copy link
Contributor Author

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");
Copy link
Member

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?

Copy link
Member

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.

@bews bews force-pushed the bews/dev-6-seconds branch from 0cb6a5f to 70c95e3 Compare June 10, 2017 11:26
@xPaw
Copy link
Member

xPaw commented Jun 10, 2017

Could you squash the commits? I will merge after that.

@bews bews force-pushed the bews/dev-6-seconds branch from 70c95e3 to fd983a7 Compare June 10, 2017 11:53
@bews
Copy link
Contributor Author

bews commented Jun 10, 2017

done

@xPaw xPaw merged commit 53ffcb5 into thelounge:master Jun 10, 2017
@xPaw xPaw modified the milestones: 2.3.2, 2.4.0 Jun 10, 2017
@xPaw xPaw mentioned this pull request Jun 10, 2017
@bews bews deleted the bews/dev-6-seconds branch June 10, 2017 17:32
amaranth pushed a commit to amaranth/lounge that referenced this pull request Jun 14, 2017
@AlMcKinlay AlMcKinlay mentioned this pull request Jun 23, 2017
15 tasks
matburnham pushed a commit to matburnham/lounge that referenced this pull request Sep 6, 2017
@astorije
Copy link
Member

Hey @bews, we have free sticker packs for our contributors now!
If you're interested, go fill the form at https://goo.gl/forms/f5usqAEp5DWoeXC92 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Feature Tickets that describe a desired feature or PRs that add them to the project.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants