Merge branch 'Nheko-Reborn:master' into ignore-command

This commit is contained in:
Nep Nep 2023-12-17 21:35:01 -03:00 committed by GitHub
commit 7dbad2c648
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
13 changed files with 111 additions and 37 deletions

View file

@ -201,9 +201,14 @@ NhekoFixupPaletteEventFilter::eventFilter(QObject *obj, QEvent *event)
// reason?!?
if (event->type() == QEvent::ChildAdded &&
obj->metaObject()->className() == QStringLiteral("QQuickRootItem")) {
QSet<QWindow *> newWindows;
for (const auto window : QGuiApplication::topLevelWindows()) {
newWindows.insert(window);
if (m_postedWindows.contains(window))
continue;
QGuiApplication::postEvent(window, new QEvent(QEvent::ApplicationPaletteChange));
}
m_postedWindows.swap(newWindows);
}
return false;
}

View file

@ -45,6 +45,9 @@ public:
}
bool eventFilter(QObject *obj, QEvent *event) override;
private:
QSet<QWindow *> m_postedWindows;
};
class MainWindow : public QQuickView

View file

@ -24,11 +24,12 @@ SelfVerificationStatus::SelfVerificationStatus(QObject *o)
: QObject(o)
{
connect(ChatPage::instance(), &ChatPage::contentLoaded, this, [this] {
// We connect INSIDE a lambda, not A lambda...
connect(cache::client(),
&Cache::selfVerificationStatusChanged,
this,
&SelfVerificationStatus::invalidate,
Qt::UniqueConnection);
Qt::UniqueConnection); // clazy:exclude=lambda-unique-connection
cache::client()->markUserKeysOutOfDate({http::client()->user_id().to_string()});
});

View file

@ -93,8 +93,12 @@ public:
#if defined(Q_OS_WINDOWS)
private:
void
systemPostNotification(const QString &line1, const QString &line2, const QString &iconPath);
void systemPostNotification(const QString &roomid,
const QString &eventid,
const QString &line1,
const QString &line2,
const QString &iconPath,
const QString &bodyImagePath);
#endif
// these slots are platform specific (D-Bus only)

View file

@ -114,7 +114,8 @@ NotificationsManager::postNotification(const mtx::responses::Notification &notif
if (hasMarkup_) {
if (hasImages_ &&
mtx::accessors::msg_type(notification.event) == mtx::events::MessageType::Image) {
(mtx::accessors::msg_type(notification.event) == mtx::events::MessageType::Image ||
mtx::accessors::msg_type(notification.event) == mtx::events::MessageType::Image)) {
MxcImageProvider::download(
QString::fromStdString(mtx::accessors::url(notification.event))
.remove(QStringLiteral("mxc://")),

View file

@ -13,6 +13,7 @@
#include "Cache.h"
#include "EventAccessors.h"
#include "MxcImageProvider.h"
#include "Utils.h"
using namespace WinToastLib;
@ -20,10 +21,21 @@ using namespace WinToastLib;
class CustomHandler : public IWinToastHandler
{
public:
void toastActivated() const {}
CustomHandler(NotificationsManager *manager_, const QString &roomid_, const QString &eventid_)
: manager(manager_)
, roomid(roomid_)
, eventid(eventid_)
{
}
void toastActivated() const { manager->notificationClicked(roomid, eventid); }
void toastActivated(int) const {}
void toastFailed() const { std::wcout << L"Error showing current toast" << std::endl; }
void toastDismissed(WinToastDismissalReason) const {}
NotificationsManager *manager;
QString roomid;
QString eventid;
};
namespace {
@ -34,9 +46,9 @@ init()
{
isInitialized = true;
WinToast::instance()->setAppName(L"Nheko");
WinToast::instance()->setAppUserModelId(
WinToast::configureAUMI(L"NhekoReborn", L"in.nheko.Nheko"));
WinToast::instance()->setAppName(L"Nheko");
if (!WinToast::instance()->initialize())
std::wcout << "Your system is not compatible with toast notifications\n";
}
@ -52,6 +64,8 @@ NotificationsManager::postNotification(const mtx::responses::Notification &notif
const QImage &icon)
{
const auto room_name = QString::fromStdString(cache::singleRoomInfo(notification.room_id).name);
auto roomid = QString::fromStdString(notification.room_id);
auto eventid = QString::fromStdString(mtx::accessors::event_id(notification.event));
auto formatNotification = [this, notification] {
const auto template_ = getMessageTemplate(notification);
@ -61,20 +75,40 @@ NotificationsManager::postNotification(const mtx::responses::Notification &notif
}
return template_.arg(utils::stripReplyFallbacks(notification.event, {}, {}).quoted_body);
};
}();
auto iconPath = QStandardPaths::writableLocation(QStandardPaths::CacheLocation) + room_name +
"-room-avatar.png";
if (!icon.save(iconPath))
iconPath.clear();
systemPostNotification(room_name, formatNotification(), iconPath);
if (mtx::accessors::msg_type(notification.event) == mtx::events::MessageType::Image ||
mtx::accessors::msg_type(notification.event) == mtx::events::MessageType::Image) {
MxcImageProvider::download(
QString::fromStdString(mtx::accessors::url(notification.event))
.remove(QStringLiteral("mxc://")),
QSize(200, 80),
[this, roomid, eventid, room_name, formatNotification, iconPath](
QString, QSize, QImage, QString imgPath) {
if (imgPath.isEmpty())
systemPostNotification(
roomid, eventid, room_name, formatNotification, iconPath, "");
else
systemPostNotification(
roomid, eventid, room_name, formatNotification, iconPath, imgPath);
});
} else {
systemPostNotification(roomid, eventid, room_name, formatNotification, iconPath, "");
}
}
void
NotificationsManager::systemPostNotification(const QString &line1,
NotificationsManager::systemPostNotification(const QString &roomid,
const QString &eventid,
const QString &line1,
const QString &line2,
const QString &iconPath)
const QString &iconPath,
const QString &bodyImagePath)
{
if (!isInitialized)
init();
@ -85,8 +119,12 @@ NotificationsManager::systemPostNotification(const QString &line1,
if (!iconPath.isNull())
templ.setImagePath(iconPath.toStdWString());
if (!bodyImagePath.isNull())
templ.setHeroImagePath(bodyImagePath.toStdWString(), true);
WinToast::instance()->showToast(templ, new CustomHandler());
templ.setAudioPath(WinToastTemplate::IM);
WinToast::instance()->showToast(templ, new CustomHandler(this, roomid, eventid));
}
// clang-format off

View file

@ -271,11 +271,13 @@ RoomlistModel::addRoom(const QString &room_id, bool suppressInsertNotification)
{
if (!models.contains(room_id)) {
// ensure we get read status updates and are only connected once
// WORKAROUND(Nico): This is not a lambda, but clazy on alpine currently doesn't
// believe us...
connect(cache::client(),
&Cache::roomReadStatus,
this,
&RoomlistModel::updateReadStatus,
Qt::UniqueConnection);
Qt::UniqueConnection); // clazy:exclude=lambda-unique-connection
QSharedPointer<TimelineModel> newRoom(new TimelineModel(manager, room_id));
newRoom->setDecryptDescription(ChatPage::instance()->userSettings()->decryptSidebar());
@ -529,11 +531,13 @@ RoomlistModel::sync(const mtx::responses::Sync &sync_)
addRoom(qroomid);
const auto &room_model = models.value(qroomid);
// WORKAROUND(Nico): This is not a lambda, but clazy on alpine currently doesn't
// believe us
connect(room_model.data(),
&TimelineModel::newCallEvent,
ChatPage::instance()->callManager(),
&CallManager::syncEvent,
Qt::UniqueConnection);
Qt::UniqueConnection); // clazy:exclude=lambda-unique-connection
room_model->sync(room);