More updates to mentions functionality

This commit is contained in:
Joseph Donofry 2019-08-19 18:11:38 -04:00
parent 52a2621776
commit bcdd97c85f
No known key found for this signature in database
GPG Key ID: E8A1D78EF044B0CB
4 changed files with 21 additions and 33 deletions

View File

@ -156,6 +156,7 @@ ChatPage::ChatPage(QSharedPointer<UserSettings> userSettings, QWidget *parent)
if (user_mentions_popup_->isVisible()) {
user_mentions_popup_->hide();
} else {
showNotificationsDialog(mentionsPos);
http::client()->notifications(
1000,
"",
@ -525,13 +526,12 @@ ChatPage::ChatPage(QSharedPointer<UserSettings> userSettings, QWidget *parent)
connect(this,
&ChatPage::highlightedNotifsRetrieved,
this,
[this](const mtx::responses::Notifications &notif, const QPoint &widgetPos) {
[this](const mtx::responses::Notifications &notif) {
try {
cache::client()->saveTimelineMentions(notif);
} catch (const lmdb::error &e) {
nhlog::db()->error("failed to save mentions: {}", e.what());
}
showNotificationsDialog(notif, widgetPos);
});
connect(communitiesList_,
@ -1004,32 +1004,13 @@ ChatPage::sendDesktopNotifications(const mtx::responses::Notifications &res)
}
void
ChatPage::showNotificationsDialog(const mtx::responses::Notifications &res, const QPoint &widgetPos)
ChatPage::showNotificationsDialog(const QPoint &widgetPos)
{
// TODO: Remove notifications from this function call.
Q_UNUSED(res);
auto notifDialog = user_mentions_popup_;
// for (const auto &item : res.notifications) {
// const auto event_id = QString::fromStdString(utils::event_id(item.event));
// try {
// const auto room_id = QString::fromStdString(item.room_id);
// const auto user_id = utils::event_sender(item.event);
// const auto body = utils::event_body(item.event);
// notifDialog->pushItem(event_id, user_id, body, room_id, current_room_);
// } catch (const lmdb::error &e) {
// nhlog::db()->warn("error while sending desktop notification: {}",
// e.what());
// }
// }
notifDialog->setGeometry(
widgetPos.x() - (width() / 10), widgetPos.y() + 25, width() / 5, height() / 2);
// notifDialog->move(widgetPos.x(), widgetPos.y());
// notifDialog->setFixedWidth(width() / 10);
// notifDialog->setFixedHeight(height() / 2);
notifDialog->raise();
notifDialog->showPopup();
}

View File

@ -210,7 +210,7 @@ private:
//! Send desktop notification for the received messages.
void sendDesktopNotifications(const mtx::responses::Notifications &);
void showNotificationsDialog(const mtx::responses::Notifications &, const QPoint &point);
void showNotificationsDialog(const QPoint &point);
QStringList generateTypingUsers(const QString &room_id,
const std::vector<std::string> &typing_users);

View File

@ -3,6 +3,7 @@
#include "Cache.h"
#include "ChatPage.h"
#include "Logging.h"
#include "UserMentions.h"
#include "timeline/TimelineItem.h"
@ -12,7 +13,7 @@ UserMentions::UserMentions(QWidget *parent)
: QWidget{parent}
{
setAttribute(Qt::WA_ShowWithoutActivating, true);
setWindowFlags(Qt::ToolTip | Qt::NoDropShadowWindowHint);
setWindowFlags(Qt::FramelessWindowHint | Qt::Popup);
tab_layout_ = new QTabWidget(this);
@ -66,12 +67,7 @@ void
UserMentions::initializeMentions(const QMap<QString, mtx::responses::Notifications> &notifs)
{
nhlog::ui()->debug("Initializing " + std::to_string(notifs.size()) + " notifications.");
for (auto widget : all_scroll_layout_->findChildren<QWidget *>()) {
delete widget;
}
for (auto widget : local_scroll_layout_->findChildren<QWidget *>()) {
delete widget;
}
for (const auto &item : notifs) {
for (const auto notif : item.notifications) {
const auto event_id = QString::fromStdString(utils::event_id(notif.event));
@ -98,10 +94,16 @@ UserMentions::initializeMentions(const QMap<QString, mtx::responses::Notificatio
void
UserMentions::showPopup()
{
for (auto widget : all_scroll_layout_->findChildren<QWidget *>()) {
delete widget;
}
for (auto widget : local_scroll_layout_->findChildren<QWidget *>()) {
delete widget;
}
auto notifs = cache::client()->getTimelineMentions();
initializeMentions(notifs);
show();
}

View File

@ -2,6 +2,8 @@
#include <mtx/responses.hpp>
#include <QApplication>
#include <QEvent>
#include <QMap>
#include <QScrollArea>
#include <QScrollBar>
@ -9,6 +11,9 @@
#include <QTabWidget>
#include <QVBoxLayout>
#include <QWidget>
#include <Qt>
#include "Logging.h"
namespace popups {
@ -18,8 +23,8 @@ class UserMentions : public QWidget
public:
UserMentions(QWidget *parent = nullptr);
void showPopup();
void initializeMentions(const QMap<QString, mtx::responses::Notifications> &notifs);
void showPopup();
private:
void pushItem(const QString &event_id,