Commit graph

16 commits

Author SHA1 Message Date
Simon Ser 8f29ae41a2
Introduce internal message IDs
For now, these can be used as cursors in the logs. Future patches will
introduce functions that perform log queries with message IDs.

The IDs are state-less tokens containing all the required information to
refer to an on-disk log line: network name, entity name, date and byte
offset. The byte offset doesn't need to point to the first byte of the
line, any byte will do (note, this makes it so message IDs aren't
necessarily unique, we may want to change that in the future).

These internal message IDs are not exposed to clients because we don't
support upstream message IDs yet.
2020-08-20 20:05:01 +02:00
Simon Ser 9f26422592
Escape user/network/entity characters in log file path
ZNC replaces slashes and backslashes with a dashes.
2020-08-19 12:22:32 +02:00
Simon Ser c654d2bac4
Format CTCP ACTION messages in logs 2020-08-17 15:01:53 +02:00
Simon Ser 3d8ed90055
Parse NOTICE messages from logs 2020-08-17 13:55:22 +02:00
Simon Ser 745b3f67a0
Extract history loading into functions
These will get re-used for sending history to clients that don't support
the chathistory extension.
2020-08-11 15:58:50 +02:00
Simon Ser cd3eacdbfc
go fmt 2020-07-22 12:16:01 +02:00
Simon Ser dcfe206bda
Implement CHATHISTORY AFTER
References: https://todo.sr.ht/~emersion/soju/12
2020-07-15 17:47:57 +02:00
delthas f7894e612b Add support for downstream CHATHISTORY
This adds support for the WIP (at the time of this commit)
draft/chathistory extension, based on the draft at [1] and the
additional comments at [2].

This gets the history by parsing the chat logs, and is therefore only
enabled when the logs are enabled and the log path is configured.

Getting the history only from the logs adds some restrictions:
- we cannot get history by msgid (those are not logged)
- we cannot get the users masks (maybe they could be inferred from the
  JOIN etc, but it is not worth the effort and would not work every
  time)

The regular soju network history is not sent to clients that support
draft/chathistory, so that they can fetch what they need by manually
calling CHATHISTORY.

The only supported command is BEFORE for now, because that is the only
required command for an app that offers an "infinite history scrollback"
feature.

Regarding implementation, rather than reading the file from the end in
reverse, we simply start from the beginning of each log file, store each
PRIVMSG into a ring, then add the last lines of that ring into the
history we'll return later. The message parsing implementation must be
kept somewhat fast because an app could potentially request thousands of
messages in several files. Here we are using simple sscanf and indexOf
rather than regexps.

In case some log files do not contain any message (for example because
the user had not joined a channel at that time), we try up to a 100 days
of empty log files before giving up.

[1]: https://github.com/prawnsalad/ircv3-specifications/pull/3/files
[2]: https://github.com/ircv3/ircv3-specifications/pull/393/files#r350210018
2020-06-05 23:50:31 +02:00
Simon Ser 155f35bd84
Parse timestamp from message tags in messageLogger.Append 2020-04-08 10:19:33 +02:00
Simon Ser f2037c5d52
Make newMessageLogger take a *network instead of an *upstreamConn
There's no reason why messgeLogger needs access to the whole connection,
the network is enough.
2020-04-07 21:54:24 +02:00
Simon Ser 64b537d799
Extract logic to build log filepath into a function
This will get re-used when parsing logs.
2020-04-07 21:50:12 +02:00
Simon Ser 78b123be72
Log TOPIC messages
See [1].

[1]: 82c4ad8362/modules/log.cpp (L486)
2020-04-06 18:49:39 +02:00
Simon Ser c985b88559
Fix NOTICE log formatting
ZNC uses hyphens instead of angle brackets [1].

[1]: 82c4ad8362/modules/log.cpp (L495)
2020-04-06 18:45:30 +02:00
Simon Ser 3680facb1d
Use Network.GetName for logs path 2020-04-05 15:24:57 +02:00
Simon Ser 3d142cae9f
Add time tag to all messages 2020-04-03 20:48:23 +02:00
Simon Ser 27e0906450
Introduce messageLogger
This centralizes formatting related to message logging in a single
place.
2020-04-03 18:59:17 +02:00