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()) { if (user_mentions_popup_->isVisible()) {
user_mentions_popup_->hide(); user_mentions_popup_->hide();
} else { } else {
showNotificationsDialog(mentionsPos);
http::client()->notifications( http::client()->notifications(
1000, 1000,
"", "",
@ -525,13 +526,12 @@ ChatPage::ChatPage(QSharedPointer<UserSettings> userSettings, QWidget *parent)
connect(this, connect(this,
&ChatPage::highlightedNotifsRetrieved, &ChatPage::highlightedNotifsRetrieved,
this, this,
[this](const mtx::responses::Notifications &notif, const QPoint &widgetPos) { [this](const mtx::responses::Notifications &notif) {
try { try {
cache::client()->saveTimelineMentions(notif); cache::client()->saveTimelineMentions(notif);
} catch (const lmdb::error &e) { } catch (const lmdb::error &e) {
nhlog::db()->error("failed to save mentions: {}", e.what()); nhlog::db()->error("failed to save mentions: {}", e.what());
} }
showNotificationsDialog(notif, widgetPos);
}); });
connect(communitiesList_, connect(communitiesList_,
@ -1004,32 +1004,13 @@ ChatPage::sendDesktopNotifications(const mtx::responses::Notifications &res)
} }
void 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_; 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( notifDialog->setGeometry(
widgetPos.x() - (width() / 10), widgetPos.y() + 25, width() / 5, height() / 2); 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->raise();
notifDialog->showPopup(); notifDialog->showPopup();
} }

View file

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

View file

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

View file

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