diff --git a/CustomModels/channelmodel.cpp b/CustomModels/channelmodel.cpp index dec1e9152b07bd67f9eeb2887e126b9e4d40d63f..b67191774dc7928b812fe1229152fc00ffaae104 100644 --- a/CustomModels/channelmodel.cpp +++ b/CustomModels/channelmodel.cpp @@ -230,8 +230,6 @@ 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/emojismodel.cpp b/CustomModels/emojismodel.cpp index 2b246fac9eb582a21ee01211cd7dc6180b8d5285..0ac3b3dc29fe67fcfda19aaea735797efbb2c1e8 100644 --- a/CustomModels/emojismodel.cpp +++ b/CustomModels/emojismodel.cpp @@ -105,7 +105,7 @@ void EmojisModel::addEmojisByCategory( const QString &pCategory, const QList<QSh mData[pCategory].reserve( 600 ); } - for ( const auto &element : pList ) { + for ( auto &element : pList ) { if ( !mDuplicateCheck.contains( element->getIdentifier() ) ) { mDuplicateCheck.insert( element->getIdentifier() ); mData[pCategory].append( std::move( element ) ); diff --git a/ddpRequests/ddploginrequest.cpp b/ddpRequests/ddploginrequest.cpp index 3897b1d9455ab33de27008762545039f69cfabdf..35c0b42c280336c517ca057820738f3899303ad5 100755 --- a/ddpRequests/ddploginrequest.cpp +++ b/ddpRequests/ddploginrequest.cpp @@ -60,8 +60,7 @@ DDPLoginRequest::DDPLoginRequest( const QString &pUsername, const QString &pPswH } //QByteArray hashArray = QCryptographicHash::hash( password.toUtf8(), QCryptographicHash::Sha256 ); - QString hash = pPswHash; - passwordObj[QStringLiteral( "digest" )] = hash; + passwordObj[QStringLiteral( "digest" )] = pPswHash; passwordObj[QStringLiteral( "algorithm" )] = QStringLiteral( "sha-256" ); loginData[QStringLiteral( "user" )] = user; loginData[QStringLiteral( "password" )] = passwordObj; diff --git a/ddpRequests/rocketchatsubscribeusernotify.cpp b/ddpRequests/rocketchatsubscribeusernotify.cpp index 9c3148b6b879ad0344049002afbd55c3e3eebe4c..236d2e692a20799b2c5a3ed7bd9a7b866985a76e 100755 --- a/ddpRequests/rocketchatsubscribeusernotify.cpp +++ b/ddpRequests/rocketchatsubscribeusernotify.cpp @@ -21,7 +21,7 @@ #include "rocketchatsubscribeusernotify.h" -RocketChatSubscribeUserNotify::RocketChatSubscribeUserNotify( const QString &pUsername ): DDPSubscriptionRequest() +RocketChatSubscribeUserNotify::RocketChatSubscribeUserNotify( const QString &pUsername ) { QJsonArray params = {pUsername, false}; buildRequest( QStringLiteral( "stream-notify-user" ), params ); diff --git a/repos/abstractbaserepository.cpp b/repos/abstractbaserepository.cpp index e1e5992c2ca6f84d5dfa065d990cfbb39e9ef257..c0d8a7d8637cf40c6261374308df6938791f6b44 100755 --- a/repos/abstractbaserepository.cpp +++ b/repos/abstractbaserepository.cpp @@ -46,7 +46,7 @@ void AbstractBaseRepository<T>::set( const QString &pId, const QSharedPointer<T> mElements[pId] = pElement; } template <typename T> -bool AbstractBaseRepository<T>::contains( const QString &pId ) +bool AbstractBaseRepository<T>::contains( const QString &pId ) const { return mElements.contains( pId ); } @@ -59,8 +59,9 @@ QSharedPointer<T> AbstractBaseRepository<T>::get( const QString &pId ) throw new std::logic_error( "Cannot find element with id:" + pId.toStdString() ); } + template <typename T> -QHash<QString, QSharedPointer<T> > AbstractBaseRepository<T>::getElements() const +const QHash<QString, QSharedPointer<T> > &AbstractBaseRepository<T>::getElements() const { return mElements; } diff --git a/repos/abstractbaserepository.h b/repos/abstractbaserepository.h index bc7115a490df3a5ccba5c57f6189ff6d0f7d87b4..2c644f059bce76f086ea8fd4943351bac12e1b4a 100755 --- a/repos/abstractbaserepository.h +++ b/repos/abstractbaserepository.h @@ -34,10 +34,12 @@ template<typename T> class AbstractBaseRepository bool add( const QString &pId, const QSharedPointer<T> & ); void remove( const QString &pId ); void set( const QString &pId, const QSharedPointer<T> & ); - bool contains( const QString &pId ) ; + bool contains( const QString &pId ) const; QSharedPointer<T> get( const QString &pId ); + const QSharedPointer<T> &get( const QString &pId ) const; QMap<QString, T> list(); - QHash<QString, QSharedPointer<T> > getElements() const; + const QMap<QString, T> &list() const; + const QHash<QString, QSharedPointer<T> > &getElements() const; int size(); /* T& operator [](QString pArgument){ return *mElements[pArgument]; diff --git a/repos/channelrepository.cpp b/repos/channelrepository.cpp index 03216e0dfb5d0d1b5cfff267837f2bb8cf275b71..610bf73a6d8c52d29dce000be980f1520d47cd1b 100755 --- a/repos/channelrepository.cpp +++ b/repos/channelrepository.cpp @@ -82,6 +82,15 @@ QSharedPointer<RocketChatChannel> ChannelRepository::getChannelByName( const QSt } } +const QSharedPointer<RocketChatChannel> &ChannelRepository::getChannelByName( const QString &pName ) const +{ + if ( mNameIndex.contains( pName ) ) { + return mNameIndex[pName]; + } else { + return nullptr; + } +} + unsigned long ChannelRepository::getYoungestMessageDate() const { long oldest = LONG_MAX; diff --git a/repos/channelrepository.h b/repos/channelrepository.h index 7f9445c0055857792cc70e0cb6255fb6dd4e0eaa..f3e0f679700985aea221f849034c9330f6b834db 100755 --- a/repos/channelrepository.h +++ b/repos/channelrepository.h @@ -46,6 +46,8 @@ class ChannelRepository : public QObject, public AbstractBaseRepository<RocketCh bool add( const QSharedPointer<RocketChatChannel> &pChannel ); void receiveTimestamp( const QString &pId, qint64 pTimestamp ); QSharedPointer<RocketChatChannel> getChannelByName( const QString &pName ); + const QSharedPointer<RocketChatChannel> &getChannelByName( const QString &pName ) const; + ~ChannelRepository(); private: QHash<QSharedPointer<RocketChatChannel>, qint64 > mChannelTimeIndex; diff --git a/repos/emojirepo.cpp b/repos/emojirepo.cpp index 04a577cf314862ff0c3de570e69b3506df639606..c26d48035ad64c9bbed0d63571a0a131c6f9b35b 100644 --- a/repos/emojirepo.cpp +++ b/repos/emojirepo.cpp @@ -48,7 +48,7 @@ bool EmojiRepo::add( const QString &pId, const QSharedPointer<Emoji> &pEmoji ) } } -QMap<int, QSharedPointer<Emoji> > EmojiRepo::emojisOrdered() const +const QMap<int, QSharedPointer<Emoji> > &EmojiRepo::emojisOrdered() const { return mEmojisOrdered; } diff --git a/repos/emojirepo.h b/repos/emojirepo.h index 2731183c09d631247f0cf81a5ef43f781bc15fce..b7722bc9c40481ba9eb6f123547903cb06cc12e4 100644 --- a/repos/emojirepo.h +++ b/repos/emojirepo.h @@ -37,7 +37,7 @@ class EmojiRepo : public QObject, public AbstractBaseRepository<Emoji> bool add( const QSharedPointer<Emoji> &pEmoji ); bool add( const QString &pId, const QSharedPointer<Emoji> &pEmoji ); - QMap<int, QSharedPointer<Emoji> > emojisOrdered() const; + const QMap<int, QSharedPointer<Emoji> > &emojisOrdered() const; private: QMap<int, QSharedPointer<Emoji> > mEmojisOrdered; diff --git a/repos/entities/emoji.cpp b/repos/entities/emoji.cpp index 560f5b4b8e4f2cf0a7a2424d88a69c001a081acc..9d4e1835aec6b7913010ac2e3cf39fff3850f3ca 100644 --- a/repos/entities/emoji.cpp +++ b/repos/entities/emoji.cpp @@ -23,41 +23,43 @@ Emoji::Emoji( QString name, QString extension, QString category ): mCategory( std::move( category ) ) { - - this->mIdentifier = ':' + name + ':'; - mName = name; - mExtension = extension; + mName = std::move( name ); + this->mIdentifier = ':' + mName + ':'; + mExtension = std::move( extension ); this->mType = QStringLiteral( "emoji" ); } Emoji::Emoji( QString name, QString category, QString filePath, QString html ): mCategory( std::move( category ) ) { - this->mIdentifier = name; - QFileInfo fileInfo( filePath ); - mFilePath = filePath; - mhtml = html; + mName = std::move( name ); + this->mIdentifier = ':' + mName + ':'; + mFilePath = std::move( filePath ); + QFileInfo fileInfo( mFilePath ); + mhtml = std::move( html ); mExtension = fileInfo.completeSuffix(); } Emoji::Emoji( QString name, QString category, QString filePath, QString html, QString unicode ): mCategory( std::move( category ) ), mUnicodeChar( std::move( unicode ) ) { - this->mIdentifier = name; - QFileInfo fileInfo( filePath ); - mFilePath = filePath; - mhtml = html; + mName = std::move( name ); + this->mIdentifier = ':' + mName + ':'; + mFilePath = std::move( filePath ); + QFileInfo fileInfo( mFilePath ); + mhtml = std::move( html ); mExtension = fileInfo.completeSuffix(); } Emoji::Emoji( QString name, QString category, QString filePath, QString html, QString unicode, int order ): mCategory( std::move( category ) ), mUnicodeChar( std::move( unicode ) ), mOrder( order ) { - this->mIdentifier = name; - QFileInfo fileInfo( filePath ); - mFilePath = filePath; + mName = std::move( name ); + this->mIdentifier = ':' + mName + ':'; + mFilePath = std::move( filePath ); + QFileInfo fileInfo( mFilePath ); mhtml = html; mExtension = fileInfo.completeSuffix(); } -QString Emoji::getIdentifier() const +const QString &Emoji::getIdentifier() const { return mIdentifier; } @@ -72,7 +74,12 @@ QVariantMap Emoji::toQVariantMap() return entry; } -QString Emoji::getHtml() const +Emoji::operator QVariantMap() +{ + return toQVariantMap(); +} + +const QString &Emoji::getHtml() const { return mhtml; } @@ -82,12 +89,12 @@ void Emoji::setHtml( const QString &value ) mhtml = value; } -QString Emoji::getExtension() const +const QString &Emoji::getExtension() const { return mExtension; } -QString Emoji::getName() const +const QString &Emoji::getName() const { return mName; } @@ -97,7 +104,7 @@ void Emoji::setName( const QString &name ) mName = name; } -QString Emoji::getUnicodeChar() const +const QString &Emoji::getUnicodeChar() const { return mUnicodeChar; } @@ -117,9 +124,7 @@ void Emoji::setOrder( int pOrder ) mOrder = pOrder; } - - -QString Emoji::getCategory() const +const QString &Emoji::getCategory() const { return mCategory; } diff --git a/repos/entities/emoji.h b/repos/entities/emoji.h index 1a830a3083dd4410f74f42c04e27c42b73074ab8..86d6d71e2c1a8e871f5d8948a632a261c8b0a419 100644 --- a/repos/entities/emoji.h +++ b/repos/entities/emoji.h @@ -34,24 +34,26 @@ class Emoji : public TempFile Emoji( QString name, QString category, QString file, QString html, QString unicode ); Emoji( QString name, QString category, QString file, QString html, QString unicode, int order ); - QString getIdentifier() const; + const QString &getIdentifier() const; QVariantMap toQVariantMap(); - QString getHtml() const; + operator QVariantMap(); + + const QString &getHtml() const; void setHtml( const QString &value ); - QString getExtension() const; + const QString &getExtension() const; - QString getName() const; + const QString &getName() const; void setName( const QString &name ); - QString getUnicodeChar() const; + const QString &getUnicodeChar() const; void setUnicodeChar( const QString &pUnicodeChar ); int getOrder() const; void setOrder( int pOrder ); - QString getCategory() const; + const QString &getCategory() const; void setCategory( const QString &category ); protected: diff --git a/repos/entities/loginmethod.cpp b/repos/entities/loginmethod.cpp index b01f00fa5592578c64686bd7f949714dabc6ad0e..3c0375ab0f87cdabdec03bc8d6fc963583e5162b 100644 --- a/repos/entities/loginmethod.cpp +++ b/repos/entities/loginmethod.cpp @@ -37,7 +37,7 @@ void LoginMethod::setType( const Type &type ) mType = type; } -QString LoginMethod::getRedirectPath() const +const QString &LoginMethod::getRedirectPath() const { return mRedirectUrl; } @@ -47,7 +47,7 @@ void LoginMethod::setRedirectPath( const QString &pUrl ) mRedirectUrl = pUrl; } -QString LoginMethod::getServerUrl() const +const QString &LoginMethod::getServerUrl() const { return mServerUrl; } @@ -57,7 +57,7 @@ void LoginMethod::setServerUrl( const QString &pServerUrl ) mServerUrl = pServerUrl; } -QString LoginMethod::getService() const +const QString &LoginMethod::getService() const { return mService; } @@ -67,7 +67,7 @@ void LoginMethod::setService( const QString &pService ) mService = pService; } -QString LoginMethod::getClientId() const +const QString &LoginMethod::getClientId() const { return mClientId; } @@ -77,7 +77,7 @@ void LoginMethod::setClientId( const QString &pClientId ) mClientId = pClientId; } -QString LoginMethod::getTokenPath() const +const QString &LoginMethod::getTokenPath() const { return mTokenPath; } @@ -87,7 +87,7 @@ void LoginMethod::setTokenPath( const QString &pTokenPath ) mTokenPath = pTokenPath; } -QString LoginMethod::getIdentityPath() const +const QString &LoginMethod::getIdentityPath() const { return mIdentityPath; } @@ -97,7 +97,7 @@ void LoginMethod::setIdentityPath( const QString &pIdentityPath ) mIdentityPath = pIdentityPath; } -QString LoginMethod::getAuthorizePath() const +const QString &LoginMethod::getAuthorizePath() const { return mAuthorizePath; } @@ -107,7 +107,7 @@ void LoginMethod::setAuthorizePath( const QString &pAuthorizationPath ) mAuthorizePath = pAuthorizationPath; } -QString LoginMethod::getCredentialToken() const +const QString &LoginMethod::getCredentialToken() const { return mCredentialToken; } @@ -134,7 +134,7 @@ QString LoginMethod::getAuthorizeUrl() const return mServerUrl + mAuthorizePath; } -QString LoginMethod::getRedirectUrl() const +const QString &LoginMethod::getRedirectUrl() const { return mRedirectUrl; } @@ -171,7 +171,7 @@ LoginMethod::operator QMap<QString, QVariant>() return toMap(); } -QString LoginMethod::getButtonLabelText() const +const QString &LoginMethod::getButtonLabelText() const { return mButtonLabelText; } diff --git a/repos/entities/loginmethod.h b/repos/entities/loginmethod.h index 416b64c383029d139a5360da610597982646e401..383b1c53efb08bf53abbdcafea3c39b88096f929 100644 --- a/repos/entities/loginmethod.h +++ b/repos/entities/loginmethod.h @@ -41,38 +41,38 @@ class LoginMethod LoginMethod::Type getType() const; void setType( const Type &pType ); - QString getRedirectPath() const; + const QString &getRedirectPath() const; void setRedirectPath( const QString &pUrl ); - QString getServerUrl() const; + const QString &getServerUrl() const; void setServerUrl( const QString &pServerUrl ); - QString getService() const; + const QString &getService() const; void setService( const QString &pService ); - QString getClientId() const; + const QString &getClientId() const; void setClientId( const QString &pClientId ); - QString getTokenPath() const; + const QString &getTokenPath() const; void setTokenPath( const QString &pTokenPath ); - QString getIdentityPath() const; + const QString &getIdentityPath() const; void setIdentityPath( const QString &pIdentityPath ); - QString getAuthorizePath() const; + const QString &getAuthorizePath() const; void setAuthorizePath( const QString &pAuthorizationPath ); - QString getCredentialToken() const; + const QString &getCredentialToken() const; void setCredentialToken( const QString &pCredentialToken ); - QString getButtonLabelText() const; + const QString &getButtonLabelText() const; void setButtonLabelText( const QString &pButtonLabelText ); QString getState() const; QString getAuthorizeUrl() const; - QString getRedirectUrl() const; + const QString &getRedirectUrl() const; QString getIdpUrl() const; diff --git a/repos/entities/rocketchatattachment.cpp b/repos/entities/rocketchatattachment.cpp index 33e5af2cab689ec0c9a092e1ef308f4b87a1a647..cc34122086d43938be19b01598e81dcbcd8c6a9e 100644 --- a/repos/entities/rocketchatattachment.cpp +++ b/repos/entities/rocketchatattachment.cpp @@ -28,17 +28,17 @@ RocketChatAttachment::RocketChatAttachment( const QString &pFileUrl, const QStri this->mTitle = pTitle; } -QString RocketChatAttachment::getUrl() const +const QString &RocketChatAttachment::getUrl() const { return mUrl; } -QString RocketChatAttachment::getType() const +const QString &RocketChatAttachment::getType() const { return mType; } -QString RocketChatAttachment::getTitle() const +const QString &RocketChatAttachment::getTitle() const { return mTitle; } diff --git a/repos/entities/rocketchatattachment.h b/repos/entities/rocketchatattachment.h index 0970e411ce4f87ca983731cfef27b1742cbebd5b..97d6d11b39316ccf77e2fcdd7b05751a4b6f92f3 100644 --- a/repos/entities/rocketchatattachment.h +++ b/repos/entities/rocketchatattachment.h @@ -30,9 +30,9 @@ class RocketChatAttachment : public QObject public: RocketChatAttachment( const QString &pFileUrl, const QString &pType, const QString &pTitle ); - QString getUrl() const; - QString getType() const; - QString getTitle() const; + const QString &getUrl() const; + const QString &getType() const; + const QString &getTitle() const; int getWidth() const; void setWidth( int pValue ); diff --git a/repos/entities/rocketchatchannel.cpp b/repos/entities/rocketchatchannel.cpp index 0a827e6552f8fa69683badf2ad982559287e3fef..2e6ba7bab4a5fa8e18e86f227c57d570fea2ca55 100755 --- a/repos/entities/rocketchatchannel.cpp +++ b/repos/entities/rocketchatchannel.cpp @@ -61,12 +61,12 @@ bool RocketChatChannel::addMessage( const ChatMessage &pMessage, bool nosignal ) return false; } -QHash<QString, QSharedPointer< RocketChatMessage >> RocketChatChannel::getMessages() const +const QHash<QString, QSharedPointer< RocketChatMessage >> &RocketChatChannel::getMessages() const { return mMessages.getElements(); } -QString RocketChatChannel::getRoomId() const +const QString &RocketChatChannel::getRoomId() const { return mRoomId; } @@ -76,7 +76,7 @@ void RocketChatChannel::setRoomId( const QString &pValue ) mRoomId = pValue; } -QString RocketChatChannel::getName() const +const QString &RocketChatChannel::getName() const { return mName; } @@ -100,7 +100,7 @@ bool RocketChatChannel::addUser( const QSharedPointer<RocketChatUser> &user ) return false; } -QMap<QString, QSharedPointer<RocketChatUser> > RocketChatChannel::getUsers() const +const QMap<QString, QSharedPointer<RocketChatUser> > &RocketChatChannel::getUsers() const { return mUsers; } @@ -128,13 +128,9 @@ ChatMessage RocketChatChannel::getYoungestMessage() return ChatMessage( nullptr ); } } -ChatMessage RocketChatChannel::getYoungestMessage() const +const ChatMessage &RocketChatChannel::getYoungestMessage() const { - if ( !mMessages.isEmpty() ) { - return mMessages.youngest(); - } else { - return ChatMessage( nullptr ); - } + return mMessages.youngest(); } ChatMessage RocketChatChannel::getOldestMessage() @@ -146,26 +142,29 @@ ChatMessage RocketChatChannel::getOldestMessage() } } +const ChatMessage &RocketChatChannel::getOldestMessage() const +{ + return mMessages.oldest(); +} + MessageRepository *RocketChatChannel::getMessageRepo() { return &mMessages; } -QList<QSharedPointer<RocketChatMessage>> RocketChatChannel::addMessages( const QList<QSharedPointer<RocketChatMessage>> &messagesList ) +void RocketChatChannel::addMessages( const QList<QSharedPointer<RocketChatMessage>> &messagesList ) { QList<QSharedPointer<RocketChatMessage>> newMessages; - for ( const auto ¤tMessage : messagesList ) { + for ( auto ¤tMessage : messagesList ) { if ( !currentMessage.isNull() ) { if ( addMessage( currentMessage ) ) { - newMessages.append( currentMessage ); + newMessages.append( std::move( currentMessage ) ); } } } emit messageAdded( getRoomId(), 0 ); - return newMessages; - } bool RocketChatChannel::getJoined() const @@ -190,7 +189,7 @@ void RocketChatChannel::setUnreadMessages( unsigned int value ) emit unreadMessagesChanged( mRoomId, value ); } -QString RocketChatChannel::getType() const +const QString &RocketChatChannel::getType() const { return mType; } @@ -206,7 +205,7 @@ void RocketChatChannel::setReadOnly( bool value ) mReadOnly = value; } -QStringList RocketChatChannel::getMuted() const +const QStringList &RocketChatChannel::getMuted() const { return mMuted; } @@ -256,7 +255,7 @@ void RocketChatChannel::setDeleted( bool deleted ) emit channelDeleted( this->getRoomId(), deleted ); } -QString RocketChatChannel::getOwnerName() const +const QString &RocketChatChannel::getOwnerName() const { return mOwnerName; } @@ -266,7 +265,7 @@ void RocketChatChannel::setOwnerName( const QString &pOwner ) mOwnerName = pOwner; } -QString RocketChatChannel::getOwnerId() const +const QString &RocketChatChannel::getOwnerId() const { return mOwnerId; } @@ -276,7 +275,7 @@ void RocketChatChannel::setOwnerId( const QString &ownerId ) mOwnerId = ownerId; } -QString RocketChatChannel::getUsername() const +const QString &RocketChatChannel::getUsername() const { return mUsername; } @@ -286,7 +285,7 @@ void RocketChatChannel::setUsername( const QString &username ) mUsername = username; } -QSharedPointer<RocketChatUser> RocketChatChannel::getChatPartner() const +const QSharedPointer<RocketChatUser> &RocketChatChannel::getChatPartner() const { return mChatPartner; } @@ -299,7 +298,7 @@ void RocketChatChannel::setChatPartner( const QSharedPointer<RocketChatUser> &ch } ); } -QString RocketChatChannel::getChatPartnerId() const +const QString &RocketChatChannel::getChatPartnerId() const { return mChatPartnerId; } diff --git a/repos/entities/rocketchatchannel.h b/repos/entities/rocketchatchannel.h index eff3dd7380dc99a90caaef8e7a8071fb9cb3c4bf..771df520635eb3c09716e7e3c6ea46366c759b23 100755 --- a/repos/entities/rocketchatchannel.h +++ b/repos/entities/rocketchatchannel.h @@ -73,25 +73,27 @@ class RocketChatChannel : public QObject void setJoined( bool pValue ); void setUnreadMessages( unsigned int pValue ); bool addUser( const QSharedPointer<RocketChatUser> &pUser ); - QList<QSharedPointer<RocketChatMessage>> addMessages( const QList<QSharedPointer<RocketChatMessage>> &pMessagesList ); + void addMessages( const QList<QSharedPointer<RocketChatMessage>> &pMessagesList ); - QHash<QString, QSharedPointer< RocketChatMessage >> getMessages() const; - QString getRoomId() const; - QString getName() const; - QMap<QString, QSharedPointer<RocketChatUser> > getUsers() const; + const QHash<QString, QSharedPointer< RocketChatMessage >> &getMessages() const; + const QString &getRoomId() const; + const QString &getName() const; + const QMap<QString, QSharedPointer<RocketChatUser> > &getUsers() const; ChatMessage getYoungestMessage(); - ChatMessage getYoungestMessage() const; + const ChatMessage &getYoungestMessage() const; ChatMessage getOldestMessage(); + const ChatMessage &getOldestMessage() const; + MessageRepository *getMessageRepo( void ); bool getJoined() const; unsigned int getUnreadMessages() const; - QString getType() const; + const QString &getType() const; bool getReadOnly() const; void setReadOnly( bool pValue ); - QStringList getMuted() const; + const QStringList &getMuted() const; void setMuted( const QStringList &pValue ); bool getArchived() const; @@ -111,19 +113,19 @@ class RocketChatChannel : public QObject bool getDeleted() const; void setDeleted( bool deleted ); - QString getOwnerName() const; + const QString &getOwnerName() const; void setOwnerName( const QString &pOwner ); - QString getOwnerId() const; + const QString &getOwnerId() const; void setOwnerId( const QString &ownerId ); - QString getUsername() const; + const QString &getUsername() const; void setUsername( const QString &username ); - QSharedPointer<RocketChatUser> getChatPartner() const; + const QSharedPointer<RocketChatUser> &getChatPartner() const; void setChatPartner( const QSharedPointer<RocketChatUser> &chatPartner ); - QString getChatPartnerId() const; + const QString &getChatPartnerId() const; void setChatPartnerId( const QString &chatPartnerId ); private: diff --git a/repos/entities/rocketchatmessage.cpp b/repos/entities/rocketchatmessage.cpp index 9dc0db065ba4d57d399105cbd5d0a835bb1bb71b..87ef37e23f403747b30f108e1f86fc1fe505e172 100755 --- a/repos/entities/rocketchatmessage.cpp +++ b/repos/entities/rocketchatmessage.cpp @@ -55,12 +55,12 @@ bool RocketChatMessage::isEmpty() const return empty; } -QJsonObject RocketChatMessage::getData() const +const QJsonObject &RocketChatMessage::getData() const { return data; } -QString RocketChatMessage::getRoomId() const +const QString &RocketChatMessage::getRoomId() const { return roomId; } @@ -70,12 +70,12 @@ void RocketChatMessage::setRoomId( const QString &value ) roomId = value; } -QString RocketChatMessage::getId() const +const QString &RocketChatMessage::getId() const { return id; } -QString RocketChatMessage::getAuthor() const +const QString &RocketChatMessage::getAuthor() const { return author; } @@ -85,7 +85,7 @@ void RocketChatMessage::setAuthor( const QString &value ) author = value; } -QString RocketChatMessage::getFormattedDate() const +const QString &RocketChatMessage::getFormattedDate() const { return formattedDate; } @@ -95,7 +95,7 @@ void RocketChatMessage::setFormattedDate( const QString &value ) formattedDate = value; } -QString RocketChatMessage::getFormattedTime() const +const QString &RocketChatMessage::getFormattedTime() const { return formattedTime; } @@ -105,7 +105,7 @@ void RocketChatMessage::setFormattedTime( const QString &value ) formattedTime = value; } -QString RocketChatMessage::getMessageString() const +const QString &RocketChatMessage::getMessageString() const { return messageString; @@ -117,7 +117,7 @@ void RocketChatMessage::setMessageString( const QString &value ) messageString = value; } -QString RocketChatMessage::getMessageType() +const QString &RocketChatMessage::getMessageType() { if ( messageType.length() == 0 ) { this->messageType = QStringLiteral( "textMessage" ); @@ -155,7 +155,7 @@ void RocketChatMessage::emojify( EmojiRepo *pEmojiRepo ) } } -QList<QSharedPointer<RocketChatAttachment> > RocketChatMessage::getAttachments() const +const QList<QSharedPointer<RocketChatAttachment> > &RocketChatMessage::getAttachments() const { return attachments; } @@ -175,7 +175,7 @@ void RocketChatMessage::setEmojiHash( const qint64 &pValue ) mEmojiHash = pValue; } -QString RocketChatMessage::getAuthorId() const +const QString &RocketChatMessage::getAuthorId() const { return authorId; } @@ -185,7 +185,7 @@ void RocketChatMessage::setAuthorId( const QString &value ) authorId = value; } -QString RocketChatMessage::getServer() const +const QString &RocketChatMessage::getServer() const { return server; } @@ -195,7 +195,7 @@ void RocketChatMessage::setServer( const QString &value ) server = value; } -QString RocketChatMessage::getRoomeTyp() const +const QString &RocketChatMessage::getRoomeTyp() const { return roomeTyp; } diff --git a/repos/entities/rocketchatmessage.h b/repos/entities/rocketchatmessage.h index 26959eaced38481eafbc6c1acacf61af7ebad682..e37ae3b6595c51d7db2ca0857bed2cec82734932 100755 --- a/repos/entities/rocketchatmessage.h +++ b/repos/entities/rocketchatmessage.h @@ -57,33 +57,33 @@ class RocketChatMessage qint64 getTimestamp() const; bool isEmpty() const; - QJsonObject getData() const; + const QJsonObject &getData() const; - QString getRoomId() const; + const QString &getRoomId() const; void setRoomId( const QString &value ); - QString getId() const; + const QString &getId() const; - QString getAuthor() const; + const QString &getAuthor() const; void setAuthor( const QString &value ); - QString getFormattedDate() const; + const QString &getFormattedDate() const; void setFormattedDate( const QString &value ); - QString getFormattedTime() const; + const QString &getFormattedTime() const; void setFormattedTime( const QString &value ); - QString getMessageString() const; + const QString &getMessageString() const; void setMessageString( const QString &value ); - QString getMessageType(); + const QString &getMessageType(); void setMessageType( const QString &value ); bool getOwnMessage() const; void setOwnMessage( bool value ); void emojify( EmojiRepo *pEmojiRepo ); - QList<QSharedPointer<RocketChatAttachment> > getAttachments() const; + const QList<QSharedPointer<RocketChatAttachment> > &getAttachments() const; void setAttachments( const QList<QSharedPointer<RocketChatAttachment> > &value ); @@ -91,13 +91,13 @@ class RocketChatMessage qint64 getEmojiHash() const; void setEmojiHash( const qint64 &pValue ); - QString getAuthorId() const; + const QString &getAuthorId() const; void setAuthorId( const QString &value ); - QString getServer() const; + const QString &getServer() const; void setServer( const QString &value ); - QString getRoomeTyp() const; + const QString &getRoomeTyp() const; void setRoomeTyp( const QString &value ); protected: diff --git a/repos/entities/rocketchatuser.cpp b/repos/entities/rocketchatuser.cpp index a90c578aeaa7a70a82f73abb0af1e140562e2ced..2f0c1784455e714add75dbc7c6c330e03e8307eb 100755 --- a/repos/entities/rocketchatuser.cpp +++ b/repos/entities/rocketchatuser.cpp @@ -27,7 +27,7 @@ RocketChatUser::RocketChatUser( QString pId ): mUserId( std::move( pId ) ) } -QString RocketChatUser::getUserName() const +const QString &RocketChatUser::getUserName() const { return mUserName; } @@ -37,7 +37,7 @@ void RocketChatUser::setUserName( const QString &pValue ) mUserName = pValue; } -QString RocketChatUser::getSurname() const +const QString &RocketChatUser::getSurname() const { return mSurname; } @@ -47,7 +47,7 @@ void RocketChatUser::setSurname( const QString &pValue ) mSurname = pValue; } -QString RocketChatUser::getLastname() const +const QString &RocketChatUser::getLastname() const { return mLastname; } @@ -57,7 +57,7 @@ void RocketChatUser::setLastname( const QString &pValue ) mLastname = pValue; } -QString RocketChatUser::getUserId() const +const QString &RocketChatUser::getUserId() const { return mUserId; } @@ -106,7 +106,7 @@ bool RocketChatUser::operator==( const RocketChatUser &lhs ) const return lhs.getUserId() == this->getUserId(); } -QString RocketChatUser::getName() const +const QString &RocketChatUser::getName() const { return mName; } diff --git a/repos/entities/rocketchatuser.h b/repos/entities/rocketchatuser.h index c7c5ebedd35abc3c1f6d33bc72c368a194ed5a8b..cd0f3b8345c550c9ba505bc438a0843ec204a875 100755 --- a/repos/entities/rocketchatuser.h +++ b/repos/entities/rocketchatuser.h @@ -39,16 +39,16 @@ class RocketChatUser : public QObject }; explicit RocketChatUser( QString pId ) ; - QString getUserName() const; + const QString &getUserName() const; void setUserName( const QString &pValue ); - QString getSurname() const; + const QString &getSurname() const; void setSurname( const QString &pValue ); - QString getLastname() const; + const QString &getLastname() const; void setLastname( const QString &pValue ); - QString getUserId() const; + const QString &getUserId() const; void setUserId( const QString &pValue ); status getStatus() const; @@ -58,7 +58,7 @@ class RocketChatUser : public QObject bool operator==( const RocketChatUser &lhs ) const; - QString getName() const; + const QString &getName() const; void setName( const QString &name ); private: diff --git a/repos/entities/tempfile.cpp b/repos/entities/tempfile.cpp index d43820b01f8e081f4e74d02269ad916cd5ec15bf..f7ca9309cefa7c6b9dbd018590d4d5dcd9a411c9 100644 --- a/repos/entities/tempfile.cpp +++ b/repos/entities/tempfile.cpp @@ -40,12 +40,12 @@ TempFile::TempFile() } -QFileInfo TempFile::getFileInfo() const +const QFileInfo &TempFile::getFileInfo() const { return mFileInfo; } -QString TempFile::getFilePath() const +const QString &TempFile::getFilePath() const { return mFilePath; } @@ -56,7 +56,7 @@ void TempFile::setFilePath( const QString &filePath ) } -QUrl TempFile::getUrl() const +const QUrl &TempFile::getUrl() const { return mUrl; } diff --git a/repos/entities/tempfile.h b/repos/entities/tempfile.h index 0dd0f603129b9b8caf393b390295fe96f20f7626..94263dc186b01dd63cdd13348b71dff438055c76 100644 --- a/repos/entities/tempfile.h +++ b/repos/entities/tempfile.h @@ -33,16 +33,16 @@ class TempFile TempFile( const QString &path, const QString &url ); - QString getFilePath() const; + const QString &getFilePath() const; void setFilePath( const QString &filePath ); - QString getType() const; + const QString &getType() const; void setType( const QString &value ); - QUrl getUrl() const; + const QUrl &getUrl() const; void setUrl( const QUrl &url ); - QFileInfo getFileInfo() const; + const QFileInfo &getFileInfo() const; protected: TempFile(); diff --git a/repos/messagerepository.cpp b/repos/messagerepository.cpp index 10e14d679c1b58896a6fa5277751d9a395896c38..10b4ad241ec35bd7933e111cc3eb897bcbd810f8 100755 --- a/repos/messagerepository.cpp +++ b/repos/messagerepository.cpp @@ -38,16 +38,14 @@ ChatMessage MessageRepository::youngest() return obj; } -ChatMessage MessageRepository::youngest() const +const ChatMessage &MessageRepository::youngest() const { - - ChatMessage obj; - - if ( Q_LIKELY( mTimestampIndex.size() ) ) { - obj = mTimestampIndex.last(); + if ( !mTimestampIndex.isEmpty() ) { + return mTimestampIndex.last(); + } else { + const auto obj = new ChatMessage(); + return *obj; } - - return obj; } ChatMessage MessageRepository::oldest() @@ -61,15 +59,14 @@ ChatMessage MessageRepository::oldest() return obj; } -ChatMessage MessageRepository::oldest() const +const ChatMessage &MessageRepository::oldest() const { - ChatMessage obj; - - if ( Q_LIKELY( mTimestampIndex.size() ) ) { - obj = mTimestampIndex.first(); + if ( !mTimestampIndex.isEmpty() ) { + return mTimestampIndex.first(); + } else { + const auto obj = new ChatMessage(); + return *obj; } - - return obj; } @@ -87,7 +84,7 @@ QVector<QSharedPointer<RocketChatMessage> > MessageRepository::messagesAsObjects return list; } -QMap<qint64, QSharedPointer<RocketChatMessage> > MessageRepository::timestampIndex() const +const QMap<qint64, QSharedPointer<RocketChatMessage> > &MessageRepository::timestampIndex() const { return mTimestampIndex; } diff --git a/repos/messagerepository.h b/repos/messagerepository.h index 0712c5ea58250e3709fb6e216ff25e434b190300..80b672b6e719982d3eed8370b7a6787697c800e0 100755 --- a/repos/messagerepository.h +++ b/repos/messagerepository.h @@ -37,12 +37,12 @@ class MessageRepository : public AbstractBaseRepository<RocketChatMessage> public: MessageRepository(); ChatMessage youngest(); - ChatMessage youngest() const; + const ChatMessage &youngest() const; ChatMessage oldest(); - ChatMessage oldest() const; + const ChatMessage &oldest() const; QVector<QSharedPointer<RocketChatMessage> > messagesAsObjects(); bool add( const QString &pId, const ChatMessage & ); - QMap<qint64, QSharedPointer<RocketChatMessage> > timestampIndex() const; + const QMap<qint64, QSharedPointer<RocketChatMessage> > ×tampIndex() const; void setTimestampIndex( const QMap<qint64, QSharedPointer<RocketChatMessage> > ×tampIndex ); protected: diff --git a/rocketchatserver.cpp b/rocketchatserver.cpp index aecb7801fad9ab1b9f1a9fafcaba9ed95be937f6..aede2901d5ea45fc1807a25c08cfdc33e848489c 100755 --- a/rocketchatserver.cpp +++ b/rocketchatserver.cpp @@ -180,7 +180,7 @@ void RocketChatServerData::loadEmojis() auto emojiList = mEmojiService->loadEmojisFromDb(); QMap<QString, QList<QSharedPointer<Emoji>>> emojisByCategory; - for ( const auto &emoji : emojiList ) { + for ( auto &emoji : emojiList ) { if ( mEmojiRepo != nullptr && !emoji.isNull() ) { mEmojiRepo->add( emoji->getIdentifier(), emoji ); }