mirror of
https://github.com/Nheko-Reborn/nheko.git
synced 2024-11-26 04:58: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
|
||||
handle_to_device_messages(const std::vector<nlohmann::json> &msgs);
|
||||
|
||||
boost::optional<json>
|
||||
nlohmann::json
|
||||
try_olm_decryption(const std::string &sender_key,
|
||||
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);
|
||||
|
||||
if (payload) {
|
||||
nhlog::crypto()->info("decrypted olm payload: {}", payload.value().dump(2));
|
||||
create_inbound_megolm_session(msg.sender, msg.sender_key, payload.value());
|
||||
if (!payload.is_null()) {
|
||||
nhlog::crypto()->info("decrypted olm payload: {}", payload.dump(2));
|
||||
create_inbound_megolm_session(msg.sender, msg.sender_key, payload);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -184,7 +184,7 @@ encrypt_group_message(const std::string &room_id,
|
|||
return data;
|
||||
}
|
||||
|
||||
boost::optional<json>
|
||||
nlohmann::json
|
||||
try_olm_decryption(const std::string &sender_key, const mtx::events::msg::OlmCipherContent &msg)
|
||||
{
|
||||
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 {
|
||||
text = olm::client()->decrypt_message(session->get(), msg.type, msg.body);
|
||||
cache::client()->saveOlmSession(id, std::move(session.value()));
|
||||
|
||||
} catch (const olm_exception &e) {
|
||||
nhlog::crypto()->info("failed to decrypt olm message ({}, {}) with {}: {}",
|
||||
msg.type,
|
||||
|
|
|
@ -1,15 +1,14 @@
|
|||
#include "notifications/Manager.h"
|
||||
|
||||
#include <QImage>
|
||||
#include <QDebug>
|
||||
#include <QImage>
|
||||
#include <QtDBus/QDBusConnection>
|
||||
#include <QtDBus/QDBusMessage>
|
||||
#include <QtDBus/QDBusMetaType>
|
||||
#include <QtDBus/QDBusConnection>
|
||||
|
||||
NotificationsManager::NotificationsManager(QObject *parent) :
|
||||
QObject(parent),
|
||||
dbus(
|
||||
"org.freedesktop.Notifications",
|
||||
NotificationsManager::NotificationsManager(QObject *parent)
|
||||
: QObject(parent)
|
||||
, dbus("org.freedesktop.Notifications",
|
||||
"/org/freedesktop/Notifications",
|
||||
"org.freedesktop.Notifications",
|
||||
QDBusConnection::sessionBus(),
|
||||
|
@ -17,17 +16,13 @@ NotificationsManager::NotificationsManager(QObject *parent) :
|
|||
{
|
||||
qDBusRegisterMetaType<QImage>();
|
||||
|
||||
//connectSlot("ActionInvoked", SLOT(actionInvoked(uint, QString)));
|
||||
//connectSlot("NotificationClosed", SLOT(notificationClosed(uint, uint)));
|
||||
QDBusConnection::sessionBus().connect(
|
||||
"org.freedesktop.Notifications",
|
||||
QDBusConnection::sessionBus().connect("org.freedesktop.Notifications",
|
||||
"/org/freedesktop/Notifications",
|
||||
"org.freedesktop.Notifications",
|
||||
"ActionInvoked",
|
||||
this,
|
||||
SLOT(actionInvoked(uint, QString)));
|
||||
QDBusConnection::sessionBus().connect(
|
||||
"org.freedesktop.Notifications",
|
||||
QDBusConnection::sessionBus().connect("org.freedesktop.Notifications",
|
||||
"/org/freedesktop/Notifications",
|
||||
"org.freedesktop.Notifications",
|
||||
"NotificationClosed",
|
||||
|
@ -43,8 +38,8 @@ NotificationsManager::postNotification(const QString &roomid,
|
|||
const QString &text,
|
||||
const QImage &icon)
|
||||
{
|
||||
uint id = showNotification(roomname, sender+": "+text, icon);
|
||||
notificationIds[id] = roomEventId{roomid,eventid};
|
||||
uint id = showNotification(roomname, sender + ": " + text, icon);
|
||||
notificationIds[id] = roomEventId{roomid, eventid};
|
||||
}
|
||||
/**
|
||||
* This function is based on code from
|
||||
|
@ -53,29 +48,28 @@ NotificationsManager::postNotification(const QString &roomid,
|
|||
* Licensed under the GNU General Public License, version 3
|
||||
*/
|
||||
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;
|
||||
hints["image_data"] = image;
|
||||
QList<QVariant> argumentList;
|
||||
argumentList << "nheko"; //app_name
|
||||
argumentList << "nheko"; // app_name
|
||||
argumentList << (uint)0; // replace_id
|
||||
argumentList << ""; // app_icon
|
||||
argumentList << summary; // summary
|
||||
argumentList << text; // body
|
||||
argumentList << (QStringList("default")<<"reply"); // actions
|
||||
argumentList << (QStringList("default") << "reply"); // actions
|
||||
argumentList << hints; // hints
|
||||
argumentList << (int)0; // timeout in ms
|
||||
|
||||
static QDBusInterface notifyApp(
|
||||
"org.freedesktop.Notifications",
|
||||
static QDBusInterface notifyApp("org.freedesktop.Notifications",
|
||||
"/org/freedesktop/Notifications",
|
||||
"org.freedesktop.Notifications");
|
||||
QDBusMessage reply = notifyApp.callWithArgumentList(
|
||||
QDBus::AutoDetect,
|
||||
"Notify",
|
||||
argumentList);
|
||||
if(reply.type() == QDBusMessage::ErrorMessage) {
|
||||
QDBusMessage reply =
|
||||
notifyApp.callWithArgumentList(QDBus::AutoDetect, "Notify", argumentList);
|
||||
if (reply.type() == QDBusMessage::ErrorMessage) {
|
||||
qDebug() << "D-Bus Error:" << reply.errorMessage();
|
||||
return 0;
|
||||
} else {
|
||||
|
@ -109,8 +103,10 @@ NotificationsManager::notificationClosed(uint id, uint reason)
|
|||
*
|
||||
* Copyright 2010, David Sansome <me@davidsansome.com>
|
||||
*/
|
||||
QDBusArgument& operator<<(QDBusArgument& arg, const QImage& image) {
|
||||
if(image.isNull()) {
|
||||
QDBusArgument &
|
||||
operator<<(QDBusArgument &arg, const QImage &image)
|
||||
{
|
||||
if (image.isNull()) {
|
||||
arg.beginStructure();
|
||||
arg << 0 << 0 << 0 << false << 0 << 0 << QByteArray();
|
||||
arg.endStructure();
|
||||
|
@ -127,9 +123,9 @@ QDBusArgument& operator<<(QDBusArgument& arg, const QImage& image) {
|
|||
// ABGR -> GBAR
|
||||
QImage i(scaled.size(), scaled.format());
|
||||
for (int y = 0; y < i.height(); ++y) {
|
||||
QRgb* p = (QRgb*) scaled.scanLine(y);
|
||||
QRgb* q = (QRgb*) i.scanLine(y);
|
||||
QRgb* end = p + scaled.width();
|
||||
QRgb *p = (QRgb *)scaled.scanLine(y);
|
||||
QRgb *q = (QRgb *)i.scanLine(y);
|
||||
QRgb *end = p + scaled.width();
|
||||
while (p < end) {
|
||||
*q = qRgba(qGreen(*p), qBlue(*p), qAlpha(*p), qRed(*p));
|
||||
p++;
|
||||
|
@ -146,12 +142,14 @@ QDBusArgument& operator<<(QDBusArgument& arg, const QImage& image) {
|
|||
int channels = i.isGrayscale() ? 1 : (i.hasAlphaChannel() ? 4 : 3);
|
||||
arg << i.depth() / channels;
|
||||
arg << channels;
|
||||
arg << QByteArray(reinterpret_cast<const char*>(i.bits()), i.byteCount());
|
||||
arg << QByteArray(reinterpret_cast<const char *>(i.bits()), i.byteCount());
|
||||
arg.endStructure();
|
||||
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.
|
||||
Q_ASSERT(0);
|
||||
return arg;
|
||||
|
|
|
@ -27,43 +27,39 @@ init()
|
|||
}
|
||||
}
|
||||
|
||||
NotificationsManager::NotificationsManager(QObject *parent): QObject(parent)
|
||||
{
|
||||
|
||||
}
|
||||
NotificationsManager::NotificationsManager(QObject *parent)
|
||||
: QObject(parent)
|
||||
{}
|
||||
|
||||
void
|
||||
NotificationsManager::postNotification(const QString &, //roomid
|
||||
const QString &, //eventid
|
||||
const QString &roomname,
|
||||
NotificationsManager::postNotification(const QString &room_id,
|
||||
const QString &event_id,
|
||||
const QString &room_name,
|
||||
const QString &sender,
|
||||
const QString &text,
|
||||
const QImage &) //icon
|
||||
const QImage &icon)
|
||||
{
|
||||
Q_UNUSED(room_id)
|
||||
Q_UNUSED(event_id)
|
||||
Q_UNUSED(icon)
|
||||
|
||||
if (!isInitialized)
|
||||
init();
|
||||
|
||||
auto templ = WinToastTemplate(WinToastTemplate::ImageAndText02);
|
||||
if (roomname != sender)
|
||||
templ.setTextField(QString("%1 - %2").arg(sender).arg(roomname).toStdWString(),
|
||||
if (room_name != sender)
|
||||
templ.setTextField(QString("%1 - %2").arg(sender).arg(room_name).toStdWString(),
|
||||
WinToastTemplate::FirstLine);
|
||||
else
|
||||
templ.setTextField(QString("%1").arg(user).toStdWString(),
|
||||
templ.setTextField(QString("%1").arg(sender).toStdWString(),
|
||||
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
|
||||
// templ.setImagePath(L"C:/example.png");
|
||||
|
||||
WinToast::instance()->showToast(templ, new CustomHandler());
|
||||
}
|
||||
|
||||
//unused
|
||||
void
|
||||
NotificationsManager::actionInvoked(uint, QString)
|
||||
{
|
||||
}
|
||||
void NotificationsManager::actionInvoked(uint, QString) {}
|
||||
|
||||
void
|
||||
NotificationsManager::notificationClosed(uint, uint)
|
||||
{
|
||||
}
|
||||
void NotificationsManager::notificationClosed(uint, uint) {}
|
||||
|
|
Loading…
Reference in a new issue