xmpp: Encrypt to self

This commit is contained in:
PapaTutuWawa 2022-09-23 23:32:16 +02:00
parent 068d156da3
commit 30cfd67e28

View File

@ -416,10 +416,17 @@ class OmemoManager extends XmppManagerBase {
await completer.future; await completer.future;
} }
var newSessions = <OmemoBundle>[]; final newSessions = List<OmemoBundle>.empty(growable: true);
final result = await _findNewSessions(toJid, stanza.children); // Try to find new sessions for [toJid].
if (!result.isType<OmemoError>()) { final resultToJid = await _findNewSessions(toJid, stanza.children);
newSessions = result.get<List<OmemoBundle>>(); if (resultToJid.isType<List<OmemoBundle>>()) {
newSessions.addAll(resultToJid.get<List<OmemoBundle>>());
}
// Try to find new sessions for our own Jid.
final ownJid = getAttributes().getFullJID().toBare();
final resultOwnJid = await _findNewSessions(ownJid, stanza.children);
if (resultOwnJid.isType<List<OmemoBundle>>()) {
newSessions.addAll(resultOwnJid.get<List<OmemoBundle>>());
} }
final toEncrypt = List<XMLNode>.empty(growable: true); final toEncrypt = List<XMLNode>.empty(growable: true);
@ -438,8 +445,7 @@ class OmemoManager extends XmppManagerBase {
toEncrypt, toEncrypt,
[ [
JID.fromString(stanza.to!).toBare().toString(), JID.fromString(stanza.to!).toBare().toString(),
// TODO(PapaTutuWawa): Encrypt to self. ownJid.toString(),
//bareJid.toString(),
], ],
stanza.to!, stanza.to!,
newSessions, newSessions,
@ -469,6 +475,10 @@ class OmemoManager extends XmppManagerBase {
/// and don't try to build a new ratchet even though there are unacked ones. /// and don't try to build a new ratchet even though there are unacked ones.
/// The current logic is that chat states with no body ignore the "ack" state of the /// The current logic is that chat states with no body ignore the "ack" state of the
/// ratchets. /// ratchets.
///
/// This function may be overriden. By default, the ack status of the ratchet is ignored
/// if we're sending a message containing chatstates or chat markers and the message does
/// not contain a <body /> element.
@visibleForOverriding @visibleForOverriding
bool shouldIgnoreUnackedRatchets(List<XMLNode> children) { bool shouldIgnoreUnackedRatchets(List<XMLNode> children) {
return listContains( return listContains(