mirror of
https://codeberg.org/Mercury-IM/Smack
synced 2025-09-09 18:29:45 +02:00
Improve MamManager API
This commit is contained in:
parent
d958b42eff
commit
9161ba9e7d
8 changed files with 794 additions and 392 deletions
|
@ -325,16 +325,16 @@ public final class OmemoManager extends Manager {
|
|||
* Return a list of all OMEMO messages that were found in the MAM query result, that could be successfully decrypted.
|
||||
* Normal cleartext messages are also added to this list.
|
||||
*
|
||||
* @param mamQueryResult mamQueryResult
|
||||
* @param mamQuery The MAM query
|
||||
* @return list of decrypted OmemoMessages
|
||||
* @throws InterruptedException Exception
|
||||
* @throws XMPPException.XMPPErrorException Exception
|
||||
* @throws SmackException.NotConnectedException Exception
|
||||
* @throws SmackException.NoResponseException Exception
|
||||
*/
|
||||
public List<ClearTextMessage> decryptMamQueryResult(MamManager.MamQueryResult mamQueryResult) throws InterruptedException, XMPPException.XMPPErrorException, SmackException.NotConnectedException, SmackException.NoResponseException {
|
||||
public List<ClearTextMessage> decryptMamQueryResult(MamManager.MamQuery mamQuery) throws InterruptedException, XMPPException.XMPPErrorException, SmackException.NotConnectedException, SmackException.NoResponseException {
|
||||
List<ClearTextMessage> l = new ArrayList<>();
|
||||
l.addAll(getOmemoService().decryptMamQueryResult(this, mamQueryResult));
|
||||
l.addAll(getOmemoService().decryptMamQueryResult(this, mamQuery));
|
||||
return l;
|
||||
}
|
||||
|
||||
|
|
|
@ -54,7 +54,6 @@ import org.jivesoftware.smack.util.Async;
|
|||
import org.jivesoftware.smackx.carbons.CarbonCopyReceivedListener;
|
||||
import org.jivesoftware.smackx.carbons.CarbonManager;
|
||||
import org.jivesoftware.smackx.carbons.packet.CarbonExtension;
|
||||
import org.jivesoftware.smackx.forward.packet.Forwarded;
|
||||
import org.jivesoftware.smackx.mam.MamManager;
|
||||
import org.jivesoftware.smackx.muc.MultiUserChat;
|
||||
import org.jivesoftware.smackx.muc.MultiUserChatManager;
|
||||
|
@ -1127,21 +1126,21 @@ public abstract class OmemoService<T_IdKeyPair, T_IdKey, T_PreKey, T_SigPreKey,
|
|||
* @throws SmackException.NotConnectedException
|
||||
* @throws SmackException.NoResponseException
|
||||
*/
|
||||
List<ClearTextMessage> decryptMamQueryResult(OmemoManager omemoManager, MamManager.MamQueryResult mamQueryResult)
|
||||
List<ClearTextMessage> decryptMamQueryResult(OmemoManager omemoManager, MamManager.MamQuery mamQuery)
|
||||
throws InterruptedException, XMPPException.XMPPErrorException, SmackException.NotConnectedException, SmackException.NoResponseException {
|
||||
List<ClearTextMessage> result = new ArrayList<>();
|
||||
for (Forwarded f : mamQueryResult.forwardedMessages) {
|
||||
if (OmemoManager.stanzaContainsOmemoElement(f.getForwardedStanza())) {
|
||||
for (Message message : mamQuery.getMessages()) {
|
||||
if (OmemoManager.stanzaContainsOmemoElement(message)) {
|
||||
// Decrypt OMEMO messages
|
||||
try {
|
||||
result.add(processLocalMessage(omemoManager, f.getForwardedStanza().getFrom().asBareJid(), (Message) f.getForwardedStanza()));
|
||||
result.add(processLocalMessage(omemoManager, message.getFrom().asBareJid(), message));
|
||||
} catch (NoRawSessionException | CorruptedOmemoKeyException | CryptoFailedException e) {
|
||||
LOGGER.log(Level.WARNING, "decryptMamQueryResult failed to decrypt message from "
|
||||
+ f.getForwardedStanza().getFrom() + " due to corrupted session/key: " + e.getMessage());
|
||||
+ message.getFrom() + " due to corrupted session/key: " + e.getMessage());
|
||||
}
|
||||
} else {
|
||||
// Wrap cleartext messages
|
||||
Message m = (Message) f.getForwardedStanza();
|
||||
Message m = message;
|
||||
result.add(new ClearTextMessage(m.getBody(), m,
|
||||
new OmemoMessageInformation(null, null, OmemoMessageInformation.CARBON.NONE, false)));
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue