mirror of
https://github.com/Nheko-Reborn/nheko.git
synced 2024-11-29 14:18:49 +03:00
Fix Windows build
This commit is contained in:
parent
888700743a
commit
c4613b210e
4 changed files with 114 additions and 121 deletions
|
@ -41,7 +41,7 @@ client();
|
||||||
void
|
void
|
||||||
handle_to_device_messages(const std::vector<nlohmann::json> &msgs);
|
handle_to_device_messages(const std::vector<nlohmann::json> &msgs);
|
||||||
|
|
||||||
boost::optional<json>
|
nlohmann::json
|
||||||
try_olm_decryption(const std::string &sender_key,
|
try_olm_decryption(const std::string &sender_key,
|
||||||
const mtx::events::msg::OlmCipherContent &content);
|
const mtx::events::msg::OlmCipherContent &content);
|
||||||
|
|
||||||
|
|
|
@ -90,9 +90,9 @@ handle_olm_message(const OlmMessage &msg)
|
||||||
|
|
||||||
auto payload = try_olm_decryption(msg.sender_key, cipher.second);
|
auto payload = try_olm_decryption(msg.sender_key, cipher.second);
|
||||||
|
|
||||||
if (payload) {
|
if (!payload.is_null()) {
|
||||||
nhlog::crypto()->info("decrypted olm payload: {}", payload.value().dump(2));
|
nhlog::crypto()->info("decrypted olm payload: {}", payload.dump(2));
|
||||||
create_inbound_megolm_session(msg.sender, msg.sender_key, payload.value());
|
create_inbound_megolm_session(msg.sender, msg.sender_key, payload);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -184,7 +184,7 @@ encrypt_group_message(const std::string &room_id,
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
boost::optional<json>
|
nlohmann::json
|
||||||
try_olm_decryption(const std::string &sender_key, const mtx::events::msg::OlmCipherContent &msg)
|
try_olm_decryption(const std::string &sender_key, const mtx::events::msg::OlmCipherContent &msg)
|
||||||
{
|
{
|
||||||
auto session_ids = cache::client()->getOlmSessions(sender_key);
|
auto session_ids = cache::client()->getOlmSessions(sender_key);
|
||||||
|
@ -203,7 +203,6 @@ try_olm_decryption(const std::string &sender_key, const mtx::events::msg::OlmCip
|
||||||
try {
|
try {
|
||||||
text = olm::client()->decrypt_message(session->get(), msg.type, msg.body);
|
text = olm::client()->decrypt_message(session->get(), msg.type, msg.body);
|
||||||
cache::client()->saveOlmSession(id, std::move(session.value()));
|
cache::client()->saveOlmSession(id, std::move(session.value()));
|
||||||
|
|
||||||
} catch (const olm_exception &e) {
|
} catch (const olm_exception &e) {
|
||||||
nhlog::crypto()->info("failed to decrypt olm message ({}, {}) with {}: {}",
|
nhlog::crypto()->info("failed to decrypt olm message ({}, {}) with {}: {}",
|
||||||
msg.type,
|
msg.type,
|
||||||
|
|
|
@ -1,15 +1,14 @@
|
||||||
#include "notifications/Manager.h"
|
#include "notifications/Manager.h"
|
||||||
|
|
||||||
#include <QImage>
|
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
#include <QImage>
|
||||||
|
#include <QtDBus/QDBusConnection>
|
||||||
#include <QtDBus/QDBusMessage>
|
#include <QtDBus/QDBusMessage>
|
||||||
#include <QtDBus/QDBusMetaType>
|
#include <QtDBus/QDBusMetaType>
|
||||||
#include <QtDBus/QDBusConnection>
|
|
||||||
|
|
||||||
NotificationsManager::NotificationsManager(QObject *parent) :
|
NotificationsManager::NotificationsManager(QObject *parent)
|
||||||
QObject(parent),
|
: QObject(parent)
|
||||||
dbus(
|
, dbus("org.freedesktop.Notifications",
|
||||||
"org.freedesktop.Notifications",
|
|
||||||
"/org/freedesktop/Notifications",
|
"/org/freedesktop/Notifications",
|
||||||
"org.freedesktop.Notifications",
|
"org.freedesktop.Notifications",
|
||||||
QDBusConnection::sessionBus(),
|
QDBusConnection::sessionBus(),
|
||||||
|
@ -17,17 +16,13 @@ NotificationsManager::NotificationsManager(QObject *parent) :
|
||||||
{
|
{
|
||||||
qDBusRegisterMetaType<QImage>();
|
qDBusRegisterMetaType<QImage>();
|
||||||
|
|
||||||
//connectSlot("ActionInvoked", SLOT(actionInvoked(uint, QString)));
|
QDBusConnection::sessionBus().connect("org.freedesktop.Notifications",
|
||||||
//connectSlot("NotificationClosed", SLOT(notificationClosed(uint, uint)));
|
|
||||||
QDBusConnection::sessionBus().connect(
|
|
||||||
"org.freedesktop.Notifications",
|
|
||||||
"/org/freedesktop/Notifications",
|
"/org/freedesktop/Notifications",
|
||||||
"org.freedesktop.Notifications",
|
"org.freedesktop.Notifications",
|
||||||
"ActionInvoked",
|
"ActionInvoked",
|
||||||
this,
|
this,
|
||||||
SLOT(actionInvoked(uint, QString)));
|
SLOT(actionInvoked(uint, QString)));
|
||||||
QDBusConnection::sessionBus().connect(
|
QDBusConnection::sessionBus().connect("org.freedesktop.Notifications",
|
||||||
"org.freedesktop.Notifications",
|
|
||||||
"/org/freedesktop/Notifications",
|
"/org/freedesktop/Notifications",
|
||||||
"org.freedesktop.Notifications",
|
"org.freedesktop.Notifications",
|
||||||
"NotificationClosed",
|
"NotificationClosed",
|
||||||
|
@ -53,7 +48,9 @@ NotificationsManager::postNotification(const QString &roomid,
|
||||||
* Licensed under the GNU General Public License, version 3
|
* Licensed under the GNU General Public License, version 3
|
||||||
*/
|
*/
|
||||||
uint
|
uint
|
||||||
NotificationsManager::showNotification(const QString summary, const QString text, const QImage image)
|
NotificationsManager::showNotification(const QString summary,
|
||||||
|
const QString text,
|
||||||
|
const QImage image)
|
||||||
{
|
{
|
||||||
QVariantMap hints;
|
QVariantMap hints;
|
||||||
hints["image_data"] = image;
|
hints["image_data"] = image;
|
||||||
|
@ -67,14 +64,11 @@ NotificationsManager::showNotification(const QString summary, const QString text
|
||||||
argumentList << hints; // hints
|
argumentList << hints; // hints
|
||||||
argumentList << (int)0; // timeout in ms
|
argumentList << (int)0; // timeout in ms
|
||||||
|
|
||||||
static QDBusInterface notifyApp(
|
static QDBusInterface notifyApp("org.freedesktop.Notifications",
|
||||||
"org.freedesktop.Notifications",
|
|
||||||
"/org/freedesktop/Notifications",
|
"/org/freedesktop/Notifications",
|
||||||
"org.freedesktop.Notifications");
|
"org.freedesktop.Notifications");
|
||||||
QDBusMessage reply = notifyApp.callWithArgumentList(
|
QDBusMessage reply =
|
||||||
QDBus::AutoDetect,
|
notifyApp.callWithArgumentList(QDBus::AutoDetect, "Notify", argumentList);
|
||||||
"Notify",
|
|
||||||
argumentList);
|
|
||||||
if (reply.type() == QDBusMessage::ErrorMessage) {
|
if (reply.type() == QDBusMessage::ErrorMessage) {
|
||||||
qDebug() << "D-Bus Error:" << reply.errorMessage();
|
qDebug() << "D-Bus Error:" << reply.errorMessage();
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -109,7 +103,9 @@ NotificationsManager::notificationClosed(uint id, uint reason)
|
||||||
*
|
*
|
||||||
* Copyright 2010, David Sansome <me@davidsansome.com>
|
* Copyright 2010, David Sansome <me@davidsansome.com>
|
||||||
*/
|
*/
|
||||||
QDBusArgument& operator<<(QDBusArgument& arg, const QImage& image) {
|
QDBusArgument &
|
||||||
|
operator<<(QDBusArgument &arg, const QImage &image)
|
||||||
|
{
|
||||||
if (image.isNull()) {
|
if (image.isNull()) {
|
||||||
arg.beginStructure();
|
arg.beginStructure();
|
||||||
arg << 0 << 0 << 0 << false << 0 << 0 << QByteArray();
|
arg << 0 << 0 << 0 << false << 0 << 0 << QByteArray();
|
||||||
|
@ -151,7 +147,9 @@ QDBusArgument& operator<<(QDBusArgument& arg, const QImage& image) {
|
||||||
return arg;
|
return arg;
|
||||||
}
|
}
|
||||||
|
|
||||||
const QDBusArgument& operator>>(const QDBusArgument& arg, QImage&) {
|
const QDBusArgument &
|
||||||
|
operator>>(const QDBusArgument &arg, QImage &)
|
||||||
|
{
|
||||||
// This is needed to link but shouldn't be called.
|
// This is needed to link but shouldn't be called.
|
||||||
Q_ASSERT(0);
|
Q_ASSERT(0);
|
||||||
return arg;
|
return arg;
|
||||||
|
|
|
@ -27,43 +27,39 @@ init()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
NotificationsManager::NotificationsManager(QObject *parent): QObject(parent)
|
NotificationsManager::NotificationsManager(QObject *parent)
|
||||||
{
|
: QObject(parent)
|
||||||
|
{}
|
||||||
}
|
|
||||||
|
|
||||||
void
|
void
|
||||||
NotificationsManager::postNotification(const QString &, //roomid
|
NotificationsManager::postNotification(const QString &room_id,
|
||||||
const QString &, //eventid
|
const QString &event_id,
|
||||||
const QString &roomname,
|
const QString &room_name,
|
||||||
const QString &sender,
|
const QString &sender,
|
||||||
const QString &text,
|
const QString &text,
|
||||||
const QImage &) //icon
|
const QImage &icon)
|
||||||
{
|
{
|
||||||
|
Q_UNUSED(room_id)
|
||||||
|
Q_UNUSED(event_id)
|
||||||
|
Q_UNUSED(icon)
|
||||||
|
|
||||||
if (!isInitialized)
|
if (!isInitialized)
|
||||||
init();
|
init();
|
||||||
|
|
||||||
auto templ = WinToastTemplate(WinToastTemplate::ImageAndText02);
|
auto templ = WinToastTemplate(WinToastTemplate::ImageAndText02);
|
||||||
if (roomname != sender)
|
if (room_name != sender)
|
||||||
templ.setTextField(QString("%1 - %2").arg(sender).arg(roomname).toStdWString(),
|
templ.setTextField(QString("%1 - %2").arg(sender).arg(room_name).toStdWString(),
|
||||||
WinToastTemplate::FirstLine);
|
WinToastTemplate::FirstLine);
|
||||||
else
|
else
|
||||||
templ.setTextField(QString("%1").arg(user).toStdWString(),
|
templ.setTextField(QString("%1").arg(sender).toStdWString(),
|
||||||
WinToastTemplate::FirstLine);
|
WinToastTemplate::FirstLine);
|
||||||
templ.setTextField(QString("%1").arg(msg).toStdWString(), WinToastTemplate::SecondLine);
|
templ.setTextField(QString("%1").arg(text).toStdWString(), WinToastTemplate::SecondLine);
|
||||||
// TODO: implement room or user avatar
|
// TODO: implement room or user avatar
|
||||||
// templ.setImagePath(L"C:/example.png");
|
// templ.setImagePath(L"C:/example.png");
|
||||||
|
|
||||||
WinToast::instance()->showToast(templ, new CustomHandler());
|
WinToast::instance()->showToast(templ, new CustomHandler());
|
||||||
}
|
}
|
||||||
|
|
||||||
//unused
|
void NotificationsManager::actionInvoked(uint, QString) {}
|
||||||
void
|
|
||||||
NotificationsManager::actionInvoked(uint, QString)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
void NotificationsManager::notificationClosed(uint, uint) {}
|
||||||
NotificationsManager::notificationClosed(uint, uint)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in a new issue