From e233198b2ab0f7d922cf2c49d1ba38980beb3040 Mon Sep 17 00:00:00 2001 From: Armin Felder <armin.felder@osalliance.com> Date: Tue, 27 Nov 2018 16:58:20 +0100 Subject: [PATCH] some optimizations, more constness, mor compiler flags --- CustomModels/channelmodel.cpp | 2 - CustomModels/emojismodel.cpp | 2 +- ddpRequests/ddploginrequest.cpp | 3 +- ddpRequests/rocketchatsubscribeusernotify.cpp | 2 +- repos/abstractbaserepository.cpp | 5 +- repos/abstractbaserepository.h | 6 ++- repos/channelrepository.cpp | 9 ++++ repos/channelrepository.h | 2 + repos/emojirepo.cpp | 2 +- repos/emojirepo.h | 2 +- repos/entities/emoji.cpp | 51 ++++++++++--------- repos/entities/emoji.h | 14 ++--- repos/entities/loginmethod.cpp | 20 ++++---- repos/entities/loginmethod.h | 20 ++++---- repos/entities/rocketchatattachment.cpp | 6 +-- repos/entities/rocketchatattachment.h | 6 +-- repos/entities/rocketchatchannel.cpp | 43 ++++++++-------- repos/entities/rocketchatchannel.h | 28 +++++----- repos/entities/rocketchatmessage.cpp | 24 ++++----- repos/entities/rocketchatmessage.h | 24 ++++----- repos/entities/rocketchatuser.cpp | 10 ++-- repos/entities/rocketchatuser.h | 10 ++-- repos/entities/tempfile.cpp | 6 +-- repos/entities/tempfile.h | 8 +-- repos/messagerepository.cpp | 29 +++++------ repos/messagerepository.h | 6 +-- rocketchatserver.cpp | 2 +- 27 files changed, 179 insertions(+), 163 deletions(-) diff --git a/CustomModels/channelmodel.cpp b/CustomModels/channelmodel.cpp index dec1e91..b671917 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 2b246fa..0ac3b3d 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 3897b1d..35c0b42 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 9c3148b..236d2e6 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 e1e5992..c0d8a7d 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 bc7115a..2c644f0 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 03216e0..610bf73 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 7f9445c..f3e0f67 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 04a577c..c26d480 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 2731183..b7722bc 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 560f5b4..9d4e183 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 1a830a3..86d6d71 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 b01f00f..3c0375a 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 416b64c..383b1c5 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 33e5af2..cc34122 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 0970e41..97d6d11 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 0a827e6..2e6ba7b 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 eff3dd7..771df52 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 9dc0db0..87ef37e 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 26959ea..e37ae3b 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 a90c578..2f0c178 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 c7c5ebe..cd0f3b8 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 d43820b..f7ca930 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 0dd0f60..94263dc 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 10e14d6..10b4ad2 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 0712c5e..80b672b 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 aecb780..aede290 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 ); } -- GitLab