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

Parse and clean up quotes from XMPP #116

Open
ForNeVeR opened this issue Aug 10, 2020 · 0 comments
Open

Parse and clean up quotes from XMPP #116

ForNeVeR opened this issue Aug 10, 2020 · 0 comments

Comments

@ForNeVeR
Copy link
Member

ForNeVeR commented Aug 10, 2020

From time to time, we receive quoted messages from XMPP. Consider this excerpt from XMPP log:

[08:29:00] <тг> <@fvnever> Вон, тот же unclechu не отделяет в своих сообщениях цитату от ответа.
[13:44:32] <unclechu> » [08:29:00] <тг> <@fvnever> Вон, тот же unclechu не отделяет в своих сообщениях цитату от ответа.
пустой строкой? я просто пользуюсь встроенной фичей psi-plus для цитирования, он перед каждой строкой добавляет ». так что технически ответ отделён.
[13:44:58] <тг> <@fvnever> >> <unclechu>
>> » [08:29:00] <тг> <@fvnever> Вон, тот же unclechu не отделяет в своих сообщениях цитату от ответа.
>> пустой строкой? я просто пользуюсь встроенной фичей psi-plus для цитирования, он перед каждой строкой добавляет ». так что технически ответ отделён.
Ну я про это и говорил

(note there seem to be a separate newline at the beginning of the unclechu's message, but it's not visible in the HTML version of the log. Ah, standards…)

This quote-of-quote-of-quote train gets very old very quickly, and starts looking bad both in Telegram and in XMPP.

Also, we sometimes impose overquote limits on our messages, and, in cases like this, the only part of the message remaning intact is often the quote, and not the actual message itself.

On the other hand, when replying to a message with quote in Telegram, we never re-translate the quoted part again.

I propose that, when sending a response to an XMPP message, we should strip any quotations from it completely (similar to how we do it for Telegram replies).

For example, consider the same discussion with this feature turned on:

[08:29:00] <тг> <@fvnever> Вон, тот же unclechu не отделяет в своих сообщениях цитату от ответа.
[13:44:32] <unclechu> » [08:29:00] <тг> <@fvnever> Вон, тот же unclechu не отделяет в своих сообщениях цитату от ответа.
пустой строкой? я просто пользуюсь встроенной фичей psi-plus для цитирования, он перед каждой строкой добавляет ». так что технически ответ отделён.
[13:44:58] <тг> <@fvnever> >> <unclechu> пустой строкой? я просто пользуюсь встроенной фичей psi-plus для цитирования, он перед каждой строкой добавляет ». так что технически ответ отделён.
Ну я про это и говорил

Much betta, right?

So, here's the technical specification:

When re-translating a Telegram message to XMPP, we should check if this message is a reply to a message from our own bot. If so, then

  1. (We are already able to extract the XMPP nickname and add it to the message within <> braces, I won't repeat this part)
  2. If the message body (i.e. the part after the nickname) starts with any whitespace, delete it and replace with a single space.
    So, for example, "<user>\n \n test message" should turn into "<user> test message".
  3. While the first line of the message starts with a quotation prefix ¹, remove this line.
    This shouldn't be applied to the last line of the message.
    So, for example, "<user> >> foo\nbar" should turn into "<user> bar", but "<user> >> boo" should be left as-is.
  4. If any content was deleted during part 3, replace it with a single […]. So, "<user> >> foo\nbar" should become "<user> […] bar".
  5. After this, the remaining part of the message should be processed as usual (i.e. apply the quoting limits).

¹ Quotation prefix is either ">> ", "> ", or "» ".

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

No branches or pull requests

1 participant