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