blob: 32a108a8fa96e3085cf23597196cfa75a131f993 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
// SPDX-FileCopyrightText: 2021 Carl Schwan <carlschwan@kde.org>
//
// SPDX-License-Identifier: LGPL-2.1-or-later
#include "olm/qolmsession.h"
using namespace Quotient;
std::optional<OlmMessage> fromTypeAndCipthertext(size_t messageType, const QByteArray &ciphertext)
{
if (messageType == OLM_MESSAGE_TYPE_PRE_KEY) {
return PreKeyMessage { ciphertext };
} else if (messageType == OLM_MESSAGE_TYPE_MESSAGE) {
return Message { ciphertext };
}
return std::nullopt;
}
std::pair<OlmMessageType, QByteArray> toPair(const OlmMessage &message)
{
return std::visit([](auto &arg) {
using T = std::decay_t<decltype(arg)>;
if constexpr (std::is_same_v<T, Message>) {
return std::make_pair<OlmMessageType, QByteArray>(MessageType, QByteArray(arg.message));
} else if constexpr (std::is_same_v<T, PreKeyMessage>) {
return std::make_pair<OlmMessageType, QByteArray>(PreKeyType, QByteArray(arg.message));
}
}, message);
}
|