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

Add support for server-time #345

Merged
merged 3 commits into from
Jan 22, 2022
Merged

Conversation

progval
Copy link
Member

@progval progval commented Nov 21, 2021

https://ircv3.net/specs/extensions/server-time

This is used by servers and bouncers when replaying history.

This commit adds a new const GDateTime *time const SircMessageContext* parameter to all callback functions,
containing the time specified by the server if any, and NULL the current time otherwise.

I wrote this a while ago. In retrospect, I'm not sure it's a good solution to add a new
argument just for this; because such arguments would just accumulate with more
context info if Srain gets support for other specifications in the future (eg.
message-specific display names,
bot message tags,
message IDs and replies, etc.)

So I wonder if I should rewrite this PR to pass some sort of structure with
all the context info instead. Possibly pass all the tags directly.
What do you think?

EDIT: I replaced it with a structure

@SilverRainZ
Copy link
Member

Can use use a GVariantDict for such params?

@progval
Copy link
Member Author

progval commented Dec 6, 2021

Hmm, the possible items should be known at compile time so I don't think a dict is needed. Unless you want to add support for adding items via plugins in the future?

@SilverRainZ
Copy link
Member

If all items are known at compile time, how about adding a struct?

https://ircv3.net/specs/extensions/server-time

This adds a new `const SircMessageContext*` parameter to all callback functions,
which for now only contains the time specified by the server if any, and
the current time otherwise.
@progval
Copy link
Member Author

progval commented Dec 23, 2021

Hey, I finally found some free time to work on this. I rebased the PR on master and rewrote it to use an opaque structure.

@progval
Copy link
Member Author

progval commented Dec 23, 2021

By the way, the way I use to test this is to connect to irc.ergo.chat, join an existing room with some messages, and type /quote history #channelname.

It looks like this:

screenshot-2021-12-23_13-19-09

(HistServ is a pseudo-user used by Ergo to announce non-messages, when clients don't support the draft/event-playback capability)

@progval progval marked this pull request as ready for review December 23, 2021 13:49
src/sirc/sirc.c Outdated
g_return_if_fail(sirc->events->connect);
sirc->events->connect(sirc, "CONNECT");
if (!sirc->events->connect) {
sirc_message_context_free(context);
Copy link
Member

Choose a reason for hiding this comment

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

How about using g_auto for freeing context?

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh nice, thanks! I'll use g_autoptr (which seems to be the right one here)

Copy link
Member

Choose a reason for hiding this comment

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

There are other calls to sirc_message_context_free in the code, please check them : )

Copy link
Member Author

Choose a reason for hiding this comment

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

including a couple of memory leaks, oops

Copy link
Member

Choose a reason for hiding this comment

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

We need a memory-safey language :-P

time = g_date_time_new_now_local();
}

g_return_val_if_fail(time, NULL);
Copy link
Member

Choose a reason for hiding this comment

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

This check can be omitted, I think.

Copy link
Member Author

Choose a reason for hiding this comment

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

"This function will always succeed unless GLib is still being used after the year 9999."

fair enough

src/sirc/sirc_context.c Outdated Show resolved Hide resolved
src/sirc/sirc_event_hdr.c Outdated Show resolved Hide resolved
src/core/app_ui_event.c Outdated Show resolved Hide resolved
src/sirc/sirc.c Outdated
g_return_if_fail(sirc->events->connect);
sirc->events->connect(sirc, "CONNECT");
if (!sirc->events->connect) {
sirc_message_context_free(context);
Copy link
Member

Choose a reason for hiding this comment

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

There are other calls to sirc_message_context_free in the code, please check them : )

Copy link
Member

@SilverRainZ SilverRainZ left a comment

Choose a reason for hiding this comment

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

LGTM

@SilverRainZ SilverRainZ merged commit 2010802 into SrainApp:master Jan 22, 2022
@progval progval deleted the server-time branch January 22, 2022 14:09
@SilverRainZ SilverRainZ added this to the 1.4 milestone Jan 23, 2022
This was referenced Jan 28, 2022
@progval progval mentioned this pull request May 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants