mirror of
https://github.com/Nheko-Reborn/nheko.git
synced 2024-11-22 19:08:58 +03:00
parent
290de548bb
commit
d6b61fbb14
7 changed files with 64 additions and 6 deletions
|
@ -68,6 +68,12 @@ public:
|
||||||
QString currentRoom() const { return current_room_; }
|
QString currentRoom() const { return current_room_; }
|
||||||
|
|
||||||
static ChatPage *instance() { return instance_; }
|
static ChatPage *instance() { return instance_; }
|
||||||
|
void readEvent(const QString &room_id, const QString &event_id)
|
||||||
|
{
|
||||||
|
client_->readEvent(room_id, event_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
QSharedPointer<UserSettings> userSettings() { return userSettings_; }
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void contentLoaded();
|
void contentLoaded();
|
||||||
|
|
|
@ -61,6 +61,12 @@ public:
|
||||||
save();
|
save();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
void setReadReceipts(bool state)
|
||||||
|
{
|
||||||
|
isReadReceiptsEnabled_ = state;
|
||||||
|
save();
|
||||||
|
}
|
||||||
|
|
||||||
void setTypingNotifications(bool state)
|
void setTypingNotifications(bool state)
|
||||||
{
|
{
|
||||||
isTypingNotificationsEnabled_ = state;
|
isTypingNotificationsEnabled_ = state;
|
||||||
|
@ -72,6 +78,7 @@ public:
|
||||||
bool isOrderingEnabled() const { return isOrderingEnabled_; }
|
bool isOrderingEnabled() const { return isOrderingEnabled_; }
|
||||||
bool isGroupViewEnabled() const { return isGroupViewEnabled_; }
|
bool isGroupViewEnabled() const { return isGroupViewEnabled_; }
|
||||||
bool isTypingNotificationsEnabled() const { return isTypingNotificationsEnabled_; }
|
bool isTypingNotificationsEnabled() const { return isTypingNotificationsEnabled_; }
|
||||||
|
bool isReadReceiptsEnabled() const { return isReadReceiptsEnabled_; }
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void groupViewStateChanged(bool state);
|
void groupViewStateChanged(bool state);
|
||||||
|
@ -82,6 +89,7 @@ private:
|
||||||
bool isOrderingEnabled_;
|
bool isOrderingEnabled_;
|
||||||
bool isGroupViewEnabled_;
|
bool isGroupViewEnabled_;
|
||||||
bool isTypingNotificationsEnabled_;
|
bool isTypingNotificationsEnabled_;
|
||||||
|
bool isReadReceiptsEnabled_;
|
||||||
};
|
};
|
||||||
|
|
||||||
class HorizontalLine : public QFrame
|
class HorizontalLine : public QFrame
|
||||||
|
@ -123,6 +131,7 @@ private:
|
||||||
Toggle *roomOrderToggle_;
|
Toggle *roomOrderToggle_;
|
||||||
Toggle *groupViewToggle_;
|
Toggle *groupViewToggle_;
|
||||||
Toggle *typingNotifications_;
|
Toggle *typingNotifications_;
|
||||||
|
Toggle *readReceipts_;
|
||||||
|
|
||||||
QComboBox *themeCombo_;
|
QComboBox *themeCombo_;
|
||||||
|
|
||||||
|
|
|
@ -26,6 +26,7 @@
|
||||||
#include <QStyleOption>
|
#include <QStyleOption>
|
||||||
|
|
||||||
#include "AvatarProvider.h"
|
#include "AvatarProvider.h"
|
||||||
|
#include "ChatPage.h"
|
||||||
#include "RoomInfoListItem.h"
|
#include "RoomInfoListItem.h"
|
||||||
#include "TimelineViewManager.h"
|
#include "TimelineViewManager.h"
|
||||||
#include "Utils.h"
|
#include "Utils.h"
|
||||||
|
@ -85,6 +86,12 @@ public:
|
||||||
QString eventId() const { return event_id_; }
|
QString eventId() const { return event_id_; }
|
||||||
void setEventId(const QString &event_id) { event_id_ = event_id; }
|
void setEventId(const QString &event_id) { event_id_ = event_id; }
|
||||||
void markReceived();
|
void markReceived();
|
||||||
|
void setRoomId(const QString &room_id) { room_id_ = room_id; }
|
||||||
|
void sendReadReceipt() const
|
||||||
|
{
|
||||||
|
if (!event_id_.isEmpty())
|
||||||
|
ChatPage::instance()->readEvent(room_id_, event_id_);
|
||||||
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void paintEvent(QPaintEvent *event) override;
|
void paintEvent(QPaintEvent *event) override;
|
||||||
|
@ -114,11 +121,13 @@ private:
|
||||||
|
|
||||||
QString replaceEmoji(const QString &body);
|
QString replaceEmoji(const QString &body);
|
||||||
QString event_id_;
|
QString event_id_;
|
||||||
|
QString room_id_;
|
||||||
|
|
||||||
DescInfo descriptionMsg_;
|
DescInfo descriptionMsg_;
|
||||||
|
|
||||||
QMenu *receiptsMenu_;
|
QMenu *contextMenu_;
|
||||||
QAction *showReadReceipts_;
|
QAction *showReadReceipts_;
|
||||||
|
QAction *markAsRead_;
|
||||||
|
|
||||||
QHBoxLayout *topLayout_;
|
QHBoxLayout *topLayout_;
|
||||||
//! The message and the timestamp/checkmark.
|
//! The message and the timestamp/checkmark.
|
||||||
|
|
|
@ -252,6 +252,7 @@ TimelineView::addUserMessage(const QString &url,
|
||||||
|
|
||||||
TimelineItem *view_item =
|
TimelineItem *view_item =
|
||||||
new TimelineItem(widget, local_user_, with_sender, scroll_widget_);
|
new TimelineItem(widget, local_user_, with_sender, scroll_widget_);
|
||||||
|
view_item->setRoomId(room_id_);
|
||||||
|
|
||||||
addTimelineItem(view_item);
|
addTimelineItem(view_item);
|
||||||
|
|
||||||
|
@ -272,6 +273,7 @@ TimelineItem *
|
||||||
TimelineView::createTimelineItem(const Event &event, bool withSender)
|
TimelineView::createTimelineItem(const Event &event, bool withSender)
|
||||||
{
|
{
|
||||||
TimelineItem *item = new TimelineItem(event, withSender, scroll_widget_);
|
TimelineItem *item = new TimelineItem(event, withSender, scroll_widget_);
|
||||||
|
item->setRoomId(room_id_);
|
||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -281,6 +283,7 @@ TimelineView::createTimelineItem(const Event &event, bool withSender)
|
||||||
{
|
{
|
||||||
auto eventWidget = new Widget(client_, event);
|
auto eventWidget = new Widget(client_, event);
|
||||||
auto item = new TimelineItem(eventWidget, event, withSender, scroll_widget_);
|
auto item = new TimelineItem(eventWidget, event, withSender, scroll_widget_);
|
||||||
|
item->setRoomId(room_id_);
|
||||||
|
|
||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,6 +38,7 @@ UserSettings::load()
|
||||||
isOrderingEnabled_ = settings.value("user/room_ordering", true).toBool();
|
isOrderingEnabled_ = settings.value("user/room_ordering", true).toBool();
|
||||||
isGroupViewEnabled_ = settings.value("user/group_view", true).toBool();
|
isGroupViewEnabled_ = settings.value("user/group_view", true).toBool();
|
||||||
isTypingNotificationsEnabled_ = settings.value("user/typing_notifications", true).toBool();
|
isTypingNotificationsEnabled_ = settings.value("user/typing_notifications", true).toBool();
|
||||||
|
isReadReceiptsEnabled_ = settings.value("user/read_receipts", true).toBool();
|
||||||
theme_ = settings.value("user/theme", "light").toString();
|
theme_ = settings.value("user/theme", "light").toString();
|
||||||
|
|
||||||
applyTheme();
|
applyTheme();
|
||||||
|
@ -86,6 +87,7 @@ UserSettings::save()
|
||||||
|
|
||||||
settings.setValue("room_ordering", isOrderingEnabled_);
|
settings.setValue("room_ordering", isOrderingEnabled_);
|
||||||
settings.setValue("typing_notifications", isTypingNotificationsEnabled_);
|
settings.setValue("typing_notifications", isTypingNotificationsEnabled_);
|
||||||
|
settings.setValue("read_receipts", isReadReceiptsEnabled_);
|
||||||
settings.setValue("group_view", isGroupViewEnabled_);
|
settings.setValue("group_view", isGroupViewEnabled_);
|
||||||
settings.setValue("theme", theme());
|
settings.setValue("theme", theme());
|
||||||
settings.endGroup();
|
settings.endGroup();
|
||||||
|
@ -166,6 +168,17 @@ UserSettingsPage::UserSettingsPage(QSharedPointer<UserSettings> settings, QWidge
|
||||||
typingLayout->addWidget(typingLabel);
|
typingLayout->addWidget(typingLabel);
|
||||||
typingLayout->addWidget(typingNotifications_, 0, Qt::AlignBottom | Qt::AlignRight);
|
typingLayout->addWidget(typingNotifications_, 0, Qt::AlignBottom | Qt::AlignRight);
|
||||||
|
|
||||||
|
auto receiptsLayout = new QHBoxLayout;
|
||||||
|
receiptsLayout->setContentsMargins(0, OptionMargin, 0, OptionMargin);
|
||||||
|
auto receiptsLabel = new QLabel(tr("Read receipts"), this);
|
||||||
|
readReceipts_ = new Toggle(this);
|
||||||
|
readReceipts_->setActiveColor(QColor("#38A3D8"));
|
||||||
|
readReceipts_->setInactiveColor(QColor("gray"));
|
||||||
|
receiptsLabel->setStyleSheet("font-size: 15px;");
|
||||||
|
|
||||||
|
receiptsLayout->addWidget(receiptsLabel);
|
||||||
|
receiptsLayout->addWidget(readReceipts_, 0, Qt::AlignBottom | Qt::AlignRight);
|
||||||
|
|
||||||
auto themeOptionLayout_ = new QHBoxLayout;
|
auto themeOptionLayout_ = new QHBoxLayout;
|
||||||
themeOptionLayout_->setContentsMargins(0, OptionMargin, 0, OptionMargin);
|
themeOptionLayout_->setContentsMargins(0, OptionMargin, 0, OptionMargin);
|
||||||
auto themeLabel_ = new QLabel(tr("Theme"), this);
|
auto themeLabel_ = new QLabel(tr("Theme"), this);
|
||||||
|
@ -194,6 +207,7 @@ UserSettingsPage::UserSettingsPage(QSharedPointer<UserSettings> settings, QWidge
|
||||||
mainLayout_->addLayout(groupViewLayout);
|
mainLayout_->addLayout(groupViewLayout);
|
||||||
mainLayout_->addWidget(new HorizontalLine(this));
|
mainLayout_->addWidget(new HorizontalLine(this));
|
||||||
mainLayout_->addLayout(typingLayout);
|
mainLayout_->addLayout(typingLayout);
|
||||||
|
mainLayout_->addLayout(receiptsLayout);
|
||||||
mainLayout_->addWidget(new HorizontalLine(this));
|
mainLayout_->addWidget(new HorizontalLine(this));
|
||||||
mainLayout_->addLayout(themeOptionLayout_);
|
mainLayout_->addLayout(themeOptionLayout_);
|
||||||
mainLayout_->addWidget(new HorizontalLine(this));
|
mainLayout_->addWidget(new HorizontalLine(this));
|
||||||
|
@ -223,6 +237,10 @@ UserSettingsPage::UserSettingsPage(QSharedPointer<UserSettings> settings, QWidge
|
||||||
settings_->setTypingNotifications(!isDisabled);
|
settings_->setTypingNotifications(!isDisabled);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
connect(readReceipts_, &Toggle::toggled, this, [this](bool isDisabled) {
|
||||||
|
settings_->setReadReceipts(!isDisabled);
|
||||||
|
});
|
||||||
|
|
||||||
connect(backBtn_, &QPushButton::clicked, this, [this]() {
|
connect(backBtn_, &QPushButton::clicked, this, [this]() {
|
||||||
settings_->save();
|
settings_->save();
|
||||||
emit moveBack();
|
emit moveBack();
|
||||||
|
@ -239,6 +257,7 @@ UserSettingsPage::showEvent(QShowEvent *)
|
||||||
roomOrderToggle_->setState(!settings_->isOrderingEnabled());
|
roomOrderToggle_->setState(!settings_->isOrderingEnabled());
|
||||||
groupViewToggle_->setState(!settings_->isGroupViewEnabled());
|
groupViewToggle_->setState(!settings_->isGroupViewEnabled());
|
||||||
typingNotifications_->setState(!settings_->isTypingNotificationsEnabled());
|
typingNotifications_->setState(!settings_->isTypingNotificationsEnabled());
|
||||||
|
readReceipts_->setState(!settings_->isReadReceiptsEnabled());
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
|
@ -21,7 +21,6 @@
|
||||||
#include <QTextEdit>
|
#include <QTextEdit>
|
||||||
|
|
||||||
#include "Avatar.h"
|
#include "Avatar.h"
|
||||||
#include "ChatPage.h"
|
|
||||||
#include "Config.h"
|
#include "Config.h"
|
||||||
|
|
||||||
#include "timeline/TimelineItem.h"
|
#include "timeline/TimelineItem.h"
|
||||||
|
@ -44,14 +43,19 @@ TimelineItem::init()
|
||||||
|
|
||||||
QFontMetrics fm(font_);
|
QFontMetrics fm(font_);
|
||||||
|
|
||||||
receiptsMenu_ = new QMenu(this);
|
contextMenu_ = new QMenu(this);
|
||||||
showReadReceipts_ = new QAction("Read receipts", this);
|
showReadReceipts_ = new QAction("Read receipts", this);
|
||||||
receiptsMenu_->addAction(showReadReceipts_);
|
markAsRead_ = new QAction("Mark as read", this);
|
||||||
|
contextMenu_->addAction(showReadReceipts_);
|
||||||
|
contextMenu_->addAction(markAsRead_);
|
||||||
|
|
||||||
connect(showReadReceipts_, &QAction::triggered, this, [this]() {
|
connect(showReadReceipts_, &QAction::triggered, this, [this]() {
|
||||||
if (!event_id_.isEmpty())
|
if (!event_id_.isEmpty())
|
||||||
ChatPage::instance()->showReadReceipts(event_id_);
|
ChatPage::instance()->showReadReceipts(event_id_);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
connect(markAsRead_, &QAction::triggered, this, [this]() { sendReadReceipt(); });
|
||||||
|
|
||||||
topLayout_ = new QHBoxLayout(this);
|
topLayout_ = new QHBoxLayout(this);
|
||||||
mainLayout_ = new QVBoxLayout;
|
mainLayout_ = new QVBoxLayout;
|
||||||
messageLayout_ = new QHBoxLayout;
|
messageLayout_ = new QHBoxLayout;
|
||||||
|
@ -360,6 +364,8 @@ TimelineItem::markReceived()
|
||||||
{
|
{
|
||||||
checkmark_->setText(CHECKMARK);
|
checkmark_->setText(CHECKMARK);
|
||||||
checkmark_->setAlignment(Qt::AlignTop);
|
checkmark_->setAlignment(Qt::AlignTop);
|
||||||
|
|
||||||
|
sendReadReceipt();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Only the body is displayed.
|
// Only the body is displayed.
|
||||||
|
@ -500,8 +506,8 @@ TimelineItem::setUserAvatar(const QImage &avatar)
|
||||||
void
|
void
|
||||||
TimelineItem::contextMenuEvent(QContextMenuEvent *event)
|
TimelineItem::contextMenuEvent(QContextMenuEvent *event)
|
||||||
{
|
{
|
||||||
if (receiptsMenu_)
|
if (contextMenu_)
|
||||||
receiptsMenu_->exec(event->globalPos());
|
contextMenu_->exec(event->globalPos());
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
|
@ -19,8 +19,10 @@
|
||||||
#include <QFileInfo>
|
#include <QFileInfo>
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
|
|
||||||
|
#include "ChatPage.h"
|
||||||
#include "Config.h"
|
#include "Config.h"
|
||||||
#include "FloatingButton.h"
|
#include "FloatingButton.h"
|
||||||
|
#include "UserSettingsPage.h"
|
||||||
#include "Utils.h"
|
#include "Utils.h"
|
||||||
|
|
||||||
#include "timeline/TimelineView.h"
|
#include "timeline/TimelineView.h"
|
||||||
|
@ -504,6 +506,7 @@ TimelineView::addUserMessage(mtx::events::MessageType ty, const QString &body)
|
||||||
|
|
||||||
TimelineItem *view_item =
|
TimelineItem *view_item =
|
||||||
new TimelineItem(ty, local_user_, body, with_sender, scroll_widget_);
|
new TimelineItem(ty, local_user_, body, with_sender, scroll_widget_);
|
||||||
|
view_item->setRoomId(room_id_);
|
||||||
|
|
||||||
addTimelineItem(view_item);
|
addTimelineItem(view_item);
|
||||||
|
|
||||||
|
@ -628,6 +631,9 @@ TimelineView::paintEvent(QPaintEvent *)
|
||||||
void
|
void
|
||||||
TimelineView::readLastEvent() const
|
TimelineView::readLastEvent() const
|
||||||
{
|
{
|
||||||
|
if (!ChatPage::instance()->userSettings()->isReadReceiptsEnabled())
|
||||||
|
return;
|
||||||
|
|
||||||
const auto eventId = getLastEventId();
|
const auto eventId = getLastEventId();
|
||||||
|
|
||||||
if (!eventId.isEmpty())
|
if (!eventId.isEmpty())
|
||||||
|
|
Loading…
Reference in a new issue