mirror of
https://github.com/Nheko-Reborn/nheko.git
synced 2024-11-25 12:38:48 +03:00
Reset user colors on theme change (in qml timeline)
This commit is contained in:
parent
2895162971
commit
6bdc75d073
12 changed files with 20 additions and 89 deletions
|
@ -23,7 +23,7 @@ RowLayout {
|
||||||
Reply {
|
Reply {
|
||||||
visible: model.replyTo
|
visible: model.replyTo
|
||||||
modelData: chat.model.getDump(model.replyTo)
|
modelData: chat.model.getDump(model.replyTo)
|
||||||
userColor: chat.model.userColor(modelData.userId, colors.window)
|
userColor: timelineManager.userColor(modelData.userId, colors.window)
|
||||||
}
|
}
|
||||||
|
|
||||||
// actual message content
|
// actual message content
|
||||||
|
|
|
@ -218,7 +218,7 @@ Item {
|
||||||
Text {
|
Text {
|
||||||
id: userName
|
id: userName
|
||||||
text: chat.model.escapeEmoji(modelData.userName)
|
text: chat.model.escapeEmoji(modelData.userName)
|
||||||
color: chat.model.userColor(modelData.userId, colors.window)
|
color: timelineManager.userColor(modelData.userId, colors.window)
|
||||||
textFormat: Text.RichText
|
textFormat: Text.RichText
|
||||||
|
|
||||||
MouseArea {
|
MouseArea {
|
||||||
|
@ -283,7 +283,7 @@ Item {
|
||||||
anchors.bottom: parent.bottom
|
anchors.bottom: parent.bottom
|
||||||
|
|
||||||
modelData: chat.model ? chat.model.getDump(timelineManager.replyingEvent) : {}
|
modelData: chat.model ? chat.model.getDump(timelineManager.replyingEvent) : {}
|
||||||
userColor: chat.model ? chat.model.userColor(modelData.userId, colors.window) : colors.window
|
userColor: timelineManager.userColor(modelData.userId, colors.window)
|
||||||
}
|
}
|
||||||
|
|
||||||
ImageButton {
|
ImageButton {
|
||||||
|
|
|
@ -34,7 +34,7 @@ Item {
|
||||||
roleValue: MtxEvent.EmoteMessage
|
roleValue: MtxEvent.EmoteMessage
|
||||||
NoticeMessage {
|
NoticeMessage {
|
||||||
formatted: chat.model.escapeEmoji(modelData.userName) + " " + model.data.formattedBody
|
formatted: chat.model.escapeEmoji(modelData.userName) + " " + model.data.formattedBody
|
||||||
color: chat.model.userColor(modelData.userId, colors.window)
|
color: timelineManager.userColor(modelData.userId, colors.window)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
DelegateChoice {
|
DelegateChoice {
|
||||||
|
|
|
@ -19,7 +19,7 @@ Rectangle {
|
||||||
anchors.bottom: replyContainer.bottom
|
anchors.bottom: replyContainer.bottom
|
||||||
width: 4
|
width: 4
|
||||||
|
|
||||||
color: chat.model ? chat.model.userColor(reply.modelData.userId, colors.window) : colors.window
|
color: timelineManager.userColor(reply.modelData.userId, colors.window)
|
||||||
}
|
}
|
||||||
|
|
||||||
Column {
|
Column {
|
||||||
|
|
|
@ -2186,7 +2186,6 @@ Cache::roomMembers(const std::string &room_id)
|
||||||
|
|
||||||
QHash<QString, QString> Cache::DisplayNames;
|
QHash<QString, QString> Cache::DisplayNames;
|
||||||
QHash<QString, QString> Cache::AvatarUrls;
|
QHash<QString, QString> Cache::AvatarUrls;
|
||||||
QHash<QString, QString> Cache::UserColors;
|
|
||||||
|
|
||||||
QString
|
QString
|
||||||
Cache::displayName(const QString &room_id, const QString &user_id)
|
Cache::displayName(const QString &room_id, const QString &user_id)
|
||||||
|
@ -2218,16 +2217,6 @@ Cache::avatarUrl(const QString &room_id, const QString &user_id)
|
||||||
return QString();
|
return QString();
|
||||||
}
|
}
|
||||||
|
|
||||||
QString
|
|
||||||
Cache::userColor(const QString &user_id)
|
|
||||||
{
|
|
||||||
if (UserColors.contains(user_id)) {
|
|
||||||
return UserColors[user_id];
|
|
||||||
}
|
|
||||||
|
|
||||||
return QString();
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
void
|
||||||
Cache::insertDisplayName(const QString &room_id,
|
Cache::insertDisplayName(const QString &room_id,
|
||||||
const QString &user_id,
|
const QString &user_id,
|
||||||
|
@ -2258,24 +2247,6 @@ Cache::removeAvatarUrl(const QString &room_id, const QString &user_id)
|
||||||
AvatarUrls.remove(fmt);
|
AvatarUrls.remove(fmt);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
|
||||||
Cache::insertUserColor(const QString &user_id, const QString &color_name)
|
|
||||||
{
|
|
||||||
UserColors.insert(user_id, color_name);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
Cache::removeUserColor(const QString &user_id)
|
|
||||||
{
|
|
||||||
UserColors.remove(user_id);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
Cache::clearUserColors()
|
|
||||||
{
|
|
||||||
UserColors.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
void
|
||||||
to_json(json &j, const RoomInfo &info)
|
to_json(json &j, const RoomInfo &info)
|
||||||
{
|
{
|
||||||
|
@ -2425,12 +2396,6 @@ avatarUrl(const QString &room_id, const QString &user_id)
|
||||||
return instance_->avatarUrl(room_id, user_id);
|
return instance_->avatarUrl(room_id, user_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
QString
|
|
||||||
userColor(const QString &user_id)
|
|
||||||
{
|
|
||||||
return instance_->userColor(user_id);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
void
|
||||||
removeDisplayName(const QString &room_id, const QString &user_id)
|
removeDisplayName(const QString &room_id, const QString &user_id)
|
||||||
{
|
{
|
||||||
|
@ -2441,11 +2406,6 @@ removeAvatarUrl(const QString &room_id, const QString &user_id)
|
||||||
{
|
{
|
||||||
instance_->removeAvatarUrl(room_id, user_id);
|
instance_->removeAvatarUrl(room_id, user_id);
|
||||||
}
|
}
|
||||||
void
|
|
||||||
removeUserColor(const QString &user_id)
|
|
||||||
{
|
|
||||||
instance_->removeUserColor(user_id);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
void
|
||||||
insertDisplayName(const QString &room_id, const QString &user_id, const QString &display_name)
|
insertDisplayName(const QString &room_id, const QString &user_id, const QString &display_name)
|
||||||
|
@ -2457,17 +2417,6 @@ insertAvatarUrl(const QString &room_id, const QString &user_id, const QString &a
|
||||||
{
|
{
|
||||||
instance_->insertAvatarUrl(room_id, user_id, avatar_url);
|
instance_->insertAvatarUrl(room_id, user_id, avatar_url);
|
||||||
}
|
}
|
||||||
void
|
|
||||||
insertUserColor(const QString &user_id, const QString &color_name)
|
|
||||||
{
|
|
||||||
instance_->insertUserColor(user_id, color_name);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
clearUserColors()
|
|
||||||
{
|
|
||||||
instance_->clearUserColors();
|
|
||||||
}
|
|
||||||
|
|
||||||
//! Load saved data for the display names & avatars.
|
//! Load saved data for the display names & avatars.
|
||||||
void
|
void
|
||||||
|
|
|
@ -43,25 +43,16 @@ QString
|
||||||
displayName(const QString &room_id, const QString &user_id);
|
displayName(const QString &room_id, const QString &user_id);
|
||||||
QString
|
QString
|
||||||
avatarUrl(const QString &room_id, const QString &user_id);
|
avatarUrl(const QString &room_id, const QString &user_id);
|
||||||
QString
|
|
||||||
userColor(const QString &user_id);
|
|
||||||
|
|
||||||
void
|
void
|
||||||
removeDisplayName(const QString &room_id, const QString &user_id);
|
removeDisplayName(const QString &room_id, const QString &user_id);
|
||||||
void
|
void
|
||||||
removeAvatarUrl(const QString &room_id, const QString &user_id);
|
removeAvatarUrl(const QString &room_id, const QString &user_id);
|
||||||
void
|
|
||||||
removeUserColor(const QString &user_id);
|
|
||||||
|
|
||||||
void
|
void
|
||||||
insertDisplayName(const QString &room_id, const QString &user_id, const QString &display_name);
|
insertDisplayName(const QString &room_id, const QString &user_id, const QString &display_name);
|
||||||
void
|
void
|
||||||
insertAvatarUrl(const QString &room_id, const QString &user_id, const QString &avatar_url);
|
insertAvatarUrl(const QString &room_id, const QString &user_id, const QString &avatar_url);
|
||||||
void
|
|
||||||
insertUserColor(const QString &user_id, const QString &color_name);
|
|
||||||
|
|
||||||
void
|
|
||||||
clearUserColors();
|
|
||||||
|
|
||||||
//! Load saved data for the display names & avatars.
|
//! Load saved data for the display names & avatars.
|
||||||
void
|
void
|
||||||
|
|
|
@ -51,11 +51,9 @@ public:
|
||||||
static std::string displayName(const std::string &room_id, const std::string &user_id);
|
static std::string displayName(const std::string &room_id, const std::string &user_id);
|
||||||
static QString displayName(const QString &room_id, const QString &user_id);
|
static QString displayName(const QString &room_id, const QString &user_id);
|
||||||
static QString avatarUrl(const QString &room_id, const QString &user_id);
|
static QString avatarUrl(const QString &room_id, const QString &user_id);
|
||||||
static QString userColor(const QString &user_id);
|
|
||||||
|
|
||||||
static void removeDisplayName(const QString &room_id, const QString &user_id);
|
static void removeDisplayName(const QString &room_id, const QString &user_id);
|
||||||
static void removeAvatarUrl(const QString &room_id, const QString &user_id);
|
static void removeAvatarUrl(const QString &room_id, const QString &user_id);
|
||||||
static void removeUserColor(const QString &user_id);
|
|
||||||
|
|
||||||
static void insertDisplayName(const QString &room_id,
|
static void insertDisplayName(const QString &room_id,
|
||||||
const QString &user_id,
|
const QString &user_id,
|
||||||
|
@ -63,9 +61,6 @@ public:
|
||||||
static void insertAvatarUrl(const QString &room_id,
|
static void insertAvatarUrl(const QString &room_id,
|
||||||
const QString &user_id,
|
const QString &user_id,
|
||||||
const QString &avatar_url);
|
const QString &avatar_url);
|
||||||
static void insertUserColor(const QString &user_id, const QString &color_name);
|
|
||||||
|
|
||||||
static void clearUserColors();
|
|
||||||
|
|
||||||
//! Load saved data for the display names & avatars.
|
//! Load saved data for the display names & avatars.
|
||||||
void populateMembers();
|
void populateMembers();
|
||||||
|
@ -484,7 +479,6 @@ private:
|
||||||
|
|
||||||
static QHash<QString, QString> DisplayNames;
|
static QHash<QString, QString> DisplayNames;
|
||||||
static QHash<QString, QString> AvatarUrls;
|
static QHash<QString, QString> AvatarUrls;
|
||||||
static QHash<QString, QString> UserColors;
|
|
||||||
|
|
||||||
OlmSessionStorage session_storage;
|
OlmSessionStorage session_storage;
|
||||||
};
|
};
|
||||||
|
|
|
@ -115,9 +115,6 @@ MainWindow::MainWindow(QWidget *parent)
|
||||||
|
|
||||||
connect(
|
connect(
|
||||||
userSettingsPage_, SIGNAL(trayOptionChanged(bool)), trayIcon_, SLOT(setVisible(bool)));
|
userSettingsPage_, SIGNAL(trayOptionChanged(bool)), trayIcon_, SLOT(setVisible(bool)));
|
||||||
connect(userSettingsPage_, &UserSettingsPage::themeChanged, this, []() {
|
|
||||||
cache::clearUserColors();
|
|
||||||
});
|
|
||||||
connect(
|
connect(
|
||||||
userSettingsPage_, &UserSettingsPage::themeChanged, chat_page_, &ChatPage::themeChanged);
|
userSettingsPage_, &UserSettingsPage::themeChanged, chat_page_, &ChatPage::themeChanged);
|
||||||
connect(trayIcon_,
|
connect(trayIcon_,
|
||||||
|
|
|
@ -196,9 +196,6 @@ TimelineModel::TimelineModel(TimelineViewManager *manager, QString room_id, QObj
|
||||||
if (idx >= 0)
|
if (idx >= 0)
|
||||||
emit dataChanged(index(idx, 0), index(idx, 0));
|
emit dataChanged(index(idx, 0), index(idx, 0));
|
||||||
});
|
});
|
||||||
|
|
||||||
connect(
|
|
||||||
ChatPage::instance(), &ChatPage::themeChanged, this, [this]() { userColors.clear(); });
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QHash<int, QByteArray>
|
QHash<int, QByteArray>
|
||||||
|
@ -650,15 +647,6 @@ TimelineModel::addBackwardsEvents(const mtx::responses::Messages &msgs)
|
||||||
prev_batch_token_ = QString::fromStdString(msgs.end);
|
prev_batch_token_ = QString::fromStdString(msgs.end);
|
||||||
}
|
}
|
||||||
|
|
||||||
QColor
|
|
||||||
TimelineModel::userColor(QString id, QColor background)
|
|
||||||
{
|
|
||||||
if (!userColors.contains(id))
|
|
||||||
userColors.insert(
|
|
||||||
id, QColor(utils::generateContrastingHexColor(id, background.name())));
|
|
||||||
return userColors.value(id);
|
|
||||||
}
|
|
||||||
|
|
||||||
QString
|
QString
|
||||||
TimelineModel::displayName(QString id) const
|
TimelineModel::displayName(QString id) const
|
||||||
{
|
{
|
||||||
|
@ -1446,7 +1434,8 @@ TimelineModel::formatTypingUsers(const std::vector<QString> &users, QColor bg)
|
||||||
|
|
||||||
auto formatUser = [this, bg](const QString &user_id) -> QString {
|
auto formatUser = [this, bg](const QString &user_id) -> QString {
|
||||||
auto uncoloredUsername = escapeEmoji(displayName(user_id).toHtmlEscaped());
|
auto uncoloredUsername = escapeEmoji(displayName(user_id).toHtmlEscaped());
|
||||||
QString prefix = QString("<font color=\"%1\">").arg(userColor(user_id, bg).name());
|
QString prefix =
|
||||||
|
QString("<font color=\"%1\">").arg(manager_->userColor(user_id, bg).name());
|
||||||
|
|
||||||
// color only parts that don't have a font already specified
|
// color only parts that don't have a font already specified
|
||||||
QString coloredUsername;
|
QString coloredUsername;
|
||||||
|
|
|
@ -165,7 +165,6 @@ public:
|
||||||
bool canFetchMore(const QModelIndex &) const override;
|
bool canFetchMore(const QModelIndex &) const override;
|
||||||
void fetchMore(const QModelIndex &) override;
|
void fetchMore(const QModelIndex &) override;
|
||||||
|
|
||||||
Q_INVOKABLE QColor userColor(QString id, QColor background);
|
|
||||||
Q_INVOKABLE QString displayName(QString id) const;
|
Q_INVOKABLE QString displayName(QString id) const;
|
||||||
Q_INVOKABLE QString avatarUrl(QString id) const;
|
Q_INVOKABLE QString avatarUrl(QString id) const;
|
||||||
Q_INVOKABLE QString formatDateSeparator(QDate date) const;
|
Q_INVOKABLE QString formatDateSeparator(QDate date) const;
|
||||||
|
@ -248,7 +247,6 @@ private:
|
||||||
bool paginationInProgress = false;
|
bool paginationInProgress = false;
|
||||||
bool isProcessingPending = false;
|
bool isProcessingPending = false;
|
||||||
|
|
||||||
QHash<QString, QColor> userColors;
|
|
||||||
QString currentId;
|
QString currentId;
|
||||||
std::vector<QString> typingUsers_;
|
std::vector<QString> typingUsers_;
|
||||||
|
|
||||||
|
|
|
@ -18,6 +18,8 @@ Q_DECLARE_METATYPE(mtx::events::collections::TimelineEvents)
|
||||||
void
|
void
|
||||||
TimelineViewManager::updateColorPalette()
|
TimelineViewManager::updateColorPalette()
|
||||||
{
|
{
|
||||||
|
userColors.clear();
|
||||||
|
|
||||||
if (settings->theme() == "light") {
|
if (settings->theme() == "light") {
|
||||||
QPalette lightActive(/*windowText*/ QColor("#333"),
|
QPalette lightActive(/*windowText*/ QColor("#333"),
|
||||||
/*button*/ QColor("#333"),
|
/*button*/ QColor("#333"),
|
||||||
|
@ -53,6 +55,15 @@ TimelineViewManager::updateColorPalette()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QColor
|
||||||
|
TimelineViewManager::userColor(QString id, QColor background)
|
||||||
|
{
|
||||||
|
if (!userColors.contains(id))
|
||||||
|
userColors.insert(
|
||||||
|
id, QColor(utils::generateContrastingHexColor(id, background.name())));
|
||||||
|
return userColors.value(id);
|
||||||
|
}
|
||||||
|
|
||||||
TimelineViewManager::TimelineViewManager(QSharedPointer<UserSettings> userSettings, QWidget *parent)
|
TimelineViewManager::TimelineViewManager(QSharedPointer<UserSettings> userSettings, QWidget *parent)
|
||||||
: imgProvider(new MxcImageProvider())
|
: imgProvider(new MxcImageProvider())
|
||||||
, colorImgProvider(new ColorImageProvider())
|
, colorImgProvider(new ColorImageProvider())
|
||||||
|
|
|
@ -40,6 +40,7 @@ public:
|
||||||
Q_INVOKABLE TimelineModel *activeTimeline() const { return timeline_; }
|
Q_INVOKABLE TimelineModel *activeTimeline() const { return timeline_; }
|
||||||
Q_INVOKABLE bool isInitialSync() const { return isInitialSync_; }
|
Q_INVOKABLE bool isInitialSync() const { return isInitialSync_; }
|
||||||
Q_INVOKABLE void openImageOverlay(QString mxcUrl, QString eventId) const;
|
Q_INVOKABLE void openImageOverlay(QString mxcUrl, QString eventId) const;
|
||||||
|
Q_INVOKABLE QColor userColor(QString id, QColor background);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void clearRoomMessageCount(QString roomid);
|
void clearRoomMessageCount(QString roomid);
|
||||||
|
@ -118,4 +119,5 @@ private:
|
||||||
QString replyingEvent_;
|
QString replyingEvent_;
|
||||||
|
|
||||||
QSharedPointer<UserSettings> settings;
|
QSharedPointer<UserSettings> settings;
|
||||||
|
QHash<QString, QColor> userColors;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue