diff --git a/CustomModels/channelmodel.cpp b/CustomModels/channelmodel.cpp index b67191774dc7928b812fe1229152fc00ffaae104..dec1e9152b07bd67f9eeb2887e126b9e4d40d63f 100644 --- a/CustomModels/channelmodel.cpp +++ b/CustomModels/channelmodel.cpp @@ -230,6 +230,8 @@ void ChannelModel::onDataChanged( const QString &id, const QString &property ) auto roleKeys = roles.keys(); for ( const auto &roleKey : roleKeys ) { + QString test = roles[roleKey]; + if ( roles[roleKey] == property ) { emit dataChanged( index( pos ), index( pos ), {roleKey} ); } diff --git a/CustomModels/usermodel.cpp b/CustomModels/usermodel.cpp index 137059d3f314fe93a3e93b513924018f43024c6d..5dfd965859e81aa2439c7c427168ba8ba67159a0 100644 --- a/CustomModels/usermodel.cpp +++ b/CustomModels/usermodel.cpp @@ -22,6 +22,8 @@ #include "usermodel.h" +#include <QDateTime> + UserModel::UserModel( QObject *parent ): QAbstractListModel( parent ) { @@ -180,9 +182,16 @@ void UserModel::addUser( const QSharedPointer<RocketChatUser> &pUser ) { if ( !pUser.isNull() ) { mMutex.lock(); - mAllUsers.insert( pUser->getUserId(), pUser ); + + if ( !mAllUsers.contains( pUser->getUserId() ) ) { + mAllUsers.insert( pUser->getUserId(), pUser ); + connect( pUser.data(), &RocketChatUser::statusChanged, this, &UserModel::refreshUserList ); + } else { + auto oldUser = mAllUsers[pUser->getUserId()]; + oldUser->setStatus( pUser->getStatus() ); + } + mMutex.unlock(); - connect( pUser.data(), &RocketChatUser::statusChanged, this, &UserModel::refreshUserList ); } } diff --git a/rocketchatserver.cpp b/rocketchatserver.cpp index 0373ea078f896126ce59f9ab75d42e45416c5b28..9a69de177407261d422614671aaf6f15e62607fd 100755 --- a/rocketchatserver.cpp +++ b/rocketchatserver.cpp @@ -1187,9 +1187,11 @@ void RocketChatServerData::onDDPMessageReceived( const QJsonObject &pMessage ) QString msg = pMessage[QStringLiteral( "msg" )].toString(); QJsonObject fields = pMessage["fields"].toObject(); + //race condition regarding user insertion into model, fixed for now with mutex and merge in model auto user = userModel->getUserById( userId ); if ( !user.isNull() ) { + if ( msg == QStringLiteral( "added" ) || msg == QStringLiteral( "changed" ) ) { if ( fields.contains( QStringLiteral( "statusDefault" ) ) && userId == mUserId ) { @@ -1201,7 +1203,11 @@ void RocketChatServerData::onDDPMessageReceived( const QJsonObject &pMessage ) } if ( fields.contains( QStringLiteral( "name" ) ) ) { - user->setUserName( fields[QStringLiteral( "name" )].toString() ); + user->setName( fields[QStringLiteral( "name" )].toString() ); + } + + if ( fields.contains( QStringLiteral( "username" ) ) ) { + user->setUserName( fields[QStringLiteral( "username" )].toString() ); }