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

Adding global timestamp option to messages. #242

Closed
wants to merge 1 commit into from
Closed

Adding global timestamp option to messages. #242

wants to merge 1 commit into from

Conversation

scr267
Copy link

@scr267 scr267 commented Aug 26, 2017

This is a feature that I needed - Quite simply when the server is started with the --timestamp flag, all messages including user prompts will have a timestamps added.

@shazow
Copy link
Owner

shazow commented Aug 26, 2017

@za267 That's cool that you made a feature for your server. :)

One thing to keep in mind is that history message replay will break the time.Now() (historic messages will appear to have been sent when they're rendered).

This isn't how I would implement this feature for our version of ssh-chat, but I hope it's working for you! If you're interested in implementing a feature to be merged, pleased open an issue to discuss design/requirements first.

@shazow
Copy link
Owner

shazow commented Aug 26, 2017

If you want a super quick-and-dirty way to add timestamps, you could prepend the current timestamp right before it gets sent to the user's screen in this function: https://github.com/shazow/ssh-chat/blob/master/chat/message/user.go#L168

@scr267
Copy link
Author

scr267 commented Aug 26, 2017

Ah, good to know - I'll open a feature next time, possibly in the near future :) And I'll take a look at the function you point to on Line 168 of user.go.

As you mention, I did notice that the timestamps were not quite accurate... meaning that the timestamp is generated during rendering instead of when it is actually sent. I was having a conundrum with that bit. Initially I wanted to see if it was possible to have a user option that could enable/disable timestamps. If the user entered /ts for example, it would trigger a boolean. Anyway it only partially worked because the prompts are sent in a different manner than the messages, and I absolutely needed both of these to have it.

Ah well... back to the drawing board. Cheers!

@scr267 scr267 closed this Aug 26, 2017
@shazow
Copy link
Owner

shazow commented Aug 26, 2017

Messages already have a timestamp you can use, no need to make your own: https://github.com/shazow/ssh-chat/blob/master/chat/message/message.go#L14

@scr267
Copy link
Author

scr267 commented Aug 27, 2017

I didn't notice it in the code... Do you think any of this code can be reused to add a timestamp to the prompts?

@shazow
Copy link
Owner

shazow commented Aug 27, 2017

Which code? From the PR? You're definitely welcome to use it for your server but I'd want a different approach to merge it in here. :)

@scr267
Copy link
Author

scr267 commented Aug 27, 2017

I'll test with the function you mention. I'm just wondering how I might add timestamps to the "prompt" line. EG: own messages.

@shazow
Copy link
Owner

shazow commented Aug 28, 2017

Ah, you'll need to update the prompt every minute or somesuch: https://github.com/shazow/ssh-chat/blob/master/host.go#L175

@scr267
Copy link
Author

scr267 commented Aug 28, 2017

I'm going to open up a proper feature request...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants