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

OMEMO-encrypted MUC logging functionality #94

Merged
merged 11 commits into from
Aug 13, 2021
Merged

OMEMO-encrypted MUC logging functionality #94

merged 11 commits into from
Aug 13, 2021

Conversation

kssytsrk
Copy link
Contributor

Fixes #93. The changes have been made to the OMEMO plugin to log messages in groupchats, Conference Logger-style, and to the Conference Logger plugin for it to not log "placeholders" of encrypted messages ("You received a message encrypted with OMEMO but your client doesn't support OMEMO or its support is currently disabled.").

Comment on lines 241 to 246
QStringList List = from.split("/");
QString room = List.takeFirst();
if (!List.isEmpty()) {
from = List.join("/");
}
if (from != m_mucNicks[room]) {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
QStringList List = from.split("/");
QString room = List.takeFirst();
if (!List.isEmpty()) {
from = List.join("/");
}
if (from != m_mucNicks[room]) {
QString room = from.section('/', 0, 0);
QString nickname = from.section('/', 1);
if (nickname != m_mucNicks.value(room)) {

prevent empty insertions if for some reason room is not in the map.

QString Text = body.text();
QString MyJid = m_accountInfo->getJid(account);
MyJid = MyJid.replace("@", "_at_");
logMuc(room, from, MyJid, Text, Stamp);
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
logMuc(room, from, MyJid, Text, Stamp);
logMuc(room, nickname, MyJid, Text, Stamp);

taking into account my previous suggestion

// get all MUC nicks of the current account for groupchat logging
// functionality
else {
QStringList room_nick = xml.attribute("to").split("/");
Copy link
Member

Choose a reason for hiding this comment

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

I believe this thing may interfere with some non-muc presences. Like for example when we send a direct presence to a single contact.
Please at least add FIXME here.

// functionality
else {
QStringList room_nick = xml.attribute("to").split("/");
m_mucNicks.insert(room_nick[0], room_nick[1]);
Copy link
Member

Choose a reason for hiding this comment

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

Seems like we never clean it.
from the first glance it may look like a memory leak. But if it's rather a small cache for Psi life time, likely it's fine.
And I'd rather also use sections here to avoid side effects splitting by "/"

@@ -330,6 +358,22 @@ bool OMEMOPlugin::encryptMessageElement(int account, QDomElement &message)
return false;
}

// logging functionality for OMEMO-encrypted groupchats
if (message.attribute("type") == "groupchat") {
Copy link
Member

Choose a reason for hiding this comment

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

Please prefer wrapping string literals with QLatin1String. This way we improve performance by avoiding string conversion from "maybe unicode" to "unicode".

QLatin1String("groupchat")

// logging functionality for OMEMO-encrypted groupchats
if (message.attribute("type") == "groupchat") {
QString room = message.attribute("to");
QString from = m_mucNicks[room];
Copy link
Member

Choose a reason for hiding this comment

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

m_mucNicks.value(room)

will avoid invalid empty nickname insertion if room is not there.
Also it may be necessary to do some initialization if it's not there.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay, but wouldn't .value() also return an empty string if the room is not there (unless the second parameter of defaultValue is specified, but I'm not sure what kind of default value would be good for this)? Qt docs say so, although I might be misunderstanding it.

Copy link
Member

Choose a reason for hiding this comment

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

It will return empty string. that's correct.
Since nickname can't be empty, you can check for emptiness and maybe do some initialization if empty.

Imagine a case where you enable OMEMO plugin already after joining. So you missed the initial presence and have to live with this somehow. (drop everything encrypted / force rejoin / ask user what to do)

Copy link
Member

Choose a reason for hiding this comment

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

I'd go with the easiest way improving the stuff with consequent MRs :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay, so I changed the behavior to logging the full jid instead of the nick in case the nick is empty. Would that be fine for now? Can't think of any elegant solution to the problem yet

Copy link
Member

Choose a reason for hiding this comment

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

yep. should be good for now.
but technically all the MUC info has to be available somewhere in Psi including nicks.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Well, there is a mucNicks() function in ContactInfoAccessingHost, but that just gives a list of nicks from a MUC (without the real jids), so I suppose the realJid() function could be ran on each of the nicks until the one associated with the needed account is found... But that would probably be slow, especially if the MUC is big (although I strongly doubt that there exist big OMEMO-encrypted MUCs, as that's very uncomfortable since everyone seems to have to have everyone else in their roster to encrypt all messages). Not sure what other options are there to fix this.

Copy link
Member

Choose a reason for hiding this comment

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

It's fine to modify plugin interfaces if anything is needed.
We didn't release any stable plugins sdk yet. So it's Ok to change it.
I think after the coming release we can think about some stabilization of the plugins API.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh, okay. I'll see what can be done, would be great to remove the presence tracking hack as a whole

Copy link
Member

Choose a reason for hiding this comment

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

Thanks!

@kssytsrk
Copy link
Contributor Author

Also, should I add a line into changelog.txt (of OMEMO plugin or/and Conference Plugin) about these changes or are they too minor to mention?

@Ri0n
Copy link
Member

Ri0n commented Aug 13, 2021

Also, should I add a line into changelog.txt (of OMEMO plugin or/and Conference Plugin) about these changes or are they too minor to mention?

please add. you can also bump the plugin version.

@Ri0n Ri0n requested a review from stigger August 13, 2021 20:13
@Neustradamus
Copy link
Contributor

@kssytsrk: Thanks a lot for your contributions!

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.

[Conference Logger, OMEMO] Logging in OMEMO-encrypted conferences not working correctly
4 participants