Shifted fetching of global username fom timeline model to user profile

This commit is contained in:
Jedi18 2021-01-29 00:09:11 +05:30
parent 3b82b2ff97
commit fa7ad4f234
4 changed files with 34 additions and 21 deletions

View File

@ -22,7 +22,6 @@
#include "TimelineViewManager.h" #include "TimelineViewManager.h"
#include "Utils.h" #include "Utils.h"
#include "dialogs/RawMessage.h" #include "dialogs/RawMessage.h"
#include <mtx/responses.hpp>
Q_DECLARE_METATYPE(QModelIndex) Q_DECLARE_METATYPE(QModelIndex)
@ -261,17 +260,6 @@ TimelineModel::TimelineModel(TimelineViewManager *manager, QString room_id, QObj
connect(&events, &EventStore::updateFlowEventId, this, [this](std::string event_id) { connect(&events, &EventStore::updateFlowEventId, this, [this](std::string event_id) {
this->updateFlowEventId(event_id); this->updateFlowEventId(event_id);
}); });
const auto userid = utils::localUser().toStdString();
http::client()->get_profile(
userid, [this](const mtx::responses::Profile &res, mtx::http::RequestErr err) {
if (err) {
nhlog::net()->warn("failed to retrieve own profile info");
return;
}
globalUsername = QString::fromStdString(res.display_name);
});
} }
QHash<int, QByteArray> QHash<int, QByteArray>
@ -814,8 +802,7 @@ void
TimelineModel::openUserProfile(QString userid, bool global) TimelineModel::openUserProfile(QString userid, bool global)
{ {
if (global) { if (global) {
emit openProfile( emit openProfile(new UserProfile("", utils::localUser(), manager_, this));
new UserProfile("", utils::localUser(), manager_, this, globalUsername));
} else { } else {
emit openProfile(new UserProfile(room_id_, userid, manager_, this)); emit openProfile(new UserProfile(room_id_, userid, manager_, this));
} }

View File

@ -317,7 +317,6 @@ private:
mutable EventStore events; mutable EventStore events;
QString room_id_; QString room_id_;
QString globalUsername;
bool decryptDescription = true; bool decryptDescription = true;
bool m_paginationInProgress = false; bool m_paginationInProgress = false;

View File

@ -8,18 +8,17 @@
#include "timeline/TimelineModel.h" #include "timeline/TimelineModel.h"
#include "timeline/TimelineViewManager.h" #include "timeline/TimelineViewManager.h"
#include <mtx/responses/common.hpp> #include <mtx/responses/common.hpp>
#include <mtx/responses.hpp>
UserProfile::UserProfile(QString roomid, UserProfile::UserProfile(QString roomid,
QString userid, QString userid,
TimelineViewManager *manager_, TimelineViewManager *manager_,
TimelineModel *parent, TimelineModel *parent)
QString globalUsername)
: QObject(parent) : QObject(parent)
, roomid_(roomid) , roomid_(roomid)
, userid_(userid) , userid_(userid)
, manager(manager_) , manager(manager_)
, model(parent) , model(parent)
, globalUsername(globalUsername)
{ {
fetchDeviceList(this->userid_); fetchDeviceList(this->userid_);
@ -47,6 +46,23 @@ UserProfile::UserProfile(QString roomid,
} }
deviceList_.reset(deviceList_.deviceList_); deviceList_.reset(deviceList_.deviceList_);
}); });
connect(this,
&UserProfile::globalUsernameRetrieved,
this,
&UserProfile::setGlobalUsername,
Qt::QueuedConnection);
http::client()->get_profile(
userid_.toStdString(),
[this](const mtx::responses::Profile &res, mtx::http::RequestErr err) {
if (err) {
nhlog::net()->warn("failed to retrieve own profile info");
return;
}
emit globalUsernameRetrieved(QString::fromStdString(res.display_name));
});
} }
QHash<int, QByteArray> QHash<int, QByteArray>
@ -286,3 +302,10 @@ UserProfile::isUsernameEditingAllowed() const
{ {
return usernameEditing; return usernameEditing;
} }
void
UserProfile::setGlobalUsername(const QString& globalUser)
{
globalUsername = globalUser;
emit displayNameChanged();
}

View File

@ -79,7 +79,7 @@ private:
class UserProfile : public QObject class UserProfile : public QObject
{ {
Q_OBJECT Q_OBJECT
Q_PROPERTY(QString displayName READ displayName CONSTANT) Q_PROPERTY(QString displayName READ displayName NOTIFY displayNameChanged)
Q_PROPERTY(QString userid READ userid CONSTANT) Q_PROPERTY(QString userid READ userid CONSTANT)
Q_PROPERTY(QString avatarUrl READ avatarUrl CONSTANT) Q_PROPERTY(QString avatarUrl READ avatarUrl CONSTANT)
Q_PROPERTY(DeviceInfoModel *deviceList READ deviceList CONSTANT) Q_PROPERTY(DeviceInfoModel *deviceList READ deviceList CONSTANT)
@ -94,8 +94,7 @@ public:
UserProfile(QString roomid, UserProfile(QString roomid,
QString userid, QString userid,
TimelineViewManager *manager_, TimelineViewManager *manager_,
TimelineModel *parent = nullptr, TimelineModel *parent = nullptr);
QString globalUsername = "");
DeviceInfoModel *deviceList(); DeviceInfoModel *deviceList();
@ -121,6 +120,11 @@ public:
signals: signals:
void userStatusChanged(); void userStatusChanged();
void usernameEditingChanged(); void usernameEditingChanged();
void displayNameChanged();
void globalUsernameRetrieved(const QString& globalUser);
protected slots:
void setGlobalUsername(const QString &globalUser);
private: private:
QString roomid_, userid_; QString roomid_, userid_;