Skip to content
Snippets Groups Projects
Commit eb4b96ec authored by Armin Felder's avatar Armin Felder
Browse files

sa

parent 01db702c
No related branches found
No related tags found
1 merge request!69Improved emoji loading
This commit is part of merge request !69. Comments created here will be created in the context of that merge request.
#include "emojismodel.h"
#include <QDebug>
EmojisModel::EmojisModel()
{
......@@ -91,6 +92,10 @@ void EmojisModel::addEmoji( const QSharedPointer<Emoji> &pEmoji )
void EmojisModel::addEmojisByCategory( const QString &pCategory, const QList<QSharedPointer<Emoji> > &pList )
{
static int counter = 0;
qDebug() << "called: " << counter++;
qDebug() << "category: " << pCategory;
if ( mCurrentCategory == pCategory ) {
beginResetModel();
}
......@@ -102,8 +107,8 @@ void EmojisModel::addEmojisByCategory( const QString &pCategory, const QList<QSh
for ( const auto &element : pList ) {
if ( !mDuplicateCheck.contains( element->getIdentifier() ) ) {
mData[pCategory].append( element );
mDuplicateCheck.insert( element->getIdentifier() );
mData[pCategory].append( std::move( element ) );
}
}
......
......@@ -249,7 +249,7 @@ void MeteorDDP::resume()
if ( mWsClient->isDisconnected() ) {
mWsClient->open( wsUri );
} else if ( !mWsClient->isConnecting() ) {
QMetaObject::Connection *const connection = new QMetaObject::Connection;
auto const connection = new QMetaObject::Connection;
*connection = connect( mWsClient, &Websocket::closed, [ = ]() {
qDebug() << "websocket closed";
mWsClient->open( wsUri );
......
......@@ -192,9 +192,6 @@ void RocketChatServerData::loadEmojis()
for ( const auto &emoji : emojiList ) {
if ( mEmojiRepo != nullptr && !emoji.isNull() ) {
mEmojiRepo->add( emoji->getIdentifier(), emoji );
// if(emoji->getCategory() == "custom"){
// mCustomEmojisHash = Utils::hash(mCustomEmojis);
// }
}
auto category = emoji->getCategory();
......@@ -204,13 +201,13 @@ void RocketChatServerData::loadEmojis()
emojisByCategory[category].reserve( 500 );
}
emojisByCategory[category].append( emoji );
emojisByCategory[category].append( std::move( emoji ) );
}
auto keys = emojisByCategory.keys();
for ( const auto &key : keys ) {
QMetaObject::invokeMethod( emojiModel, "addEmojisByCategory", Q_ARG( QString, key ), Q_ARG( QList<QSharedPointer<Emoji>>, emojisByCategory[key] ) );
QMetaObject::invokeMethod( emojiModel, "addEmojisByCategory", Q_ARG( QString, key ), Q_ARG( QList<QSharedPointer<Emoji>>, std::move( emojisByCategory[key] ) ) );
}
}
......@@ -1713,51 +1710,52 @@ void RocketChatServerData::sendMessage( const QString &pMessage, const QString &
void RocketChatServerData::getCustomEmojis()
{
std::function<void ( QList<QSharedPointer<Emoji>> )> success = [ = ]( QList<QSharedPointer<Emoji>> pEmojiList ) {
auto emojiModel = Models::getEmojisModel();
std::function<void ( QList<QSharedPointer<Emoji>> )> success = [ = ]( const QList<QSharedPointer<Emoji>> &pEmojiList ) {
if ( pEmojiList.size() ) {
if ( !pEmojiList.isEmpty() ) {
auto emojiModel = Models::getEmojisModel();
mStorage->transaction();
QList<QSharedPointer<Emoji>> newEmojis;
for ( const auto &emoji : pEmojiList ) {
if ( !emoji.isNull() ) {
mEmojiService->persistEmoji( emoji );
if ( !mEmojiRepo->contains( emoji->getIdentifier() ) ) {
mEmojiService->persistEmoji( emoji );
mEmojiRepo->add( emoji->getIdentifier(), emoji );
newEmojis.append( std::move( emoji ) );
}
}
}
QMetaObject::invokeMethod( emojiModel, "addEmojisByCategory", Q_ARG( QString, "custom" ), Q_ARG( QList<QSharedPointer<Emoji>>, pEmojiList ) );
if ( !newEmojis.isEmpty() ) {
QMetaObject::invokeMethod( emojiModel, "addEmojisByCategory", Q_ARG( QString, "custom" ), Q_ARG( QList<QSharedPointer<Emoji>>, std::move( newEmojis ) ) );
}
mStorage->commit();
}
//emit customEmojisReceived( getEmojisByCategory() );
QSharedPointer<RocketChatSubscribeRoomsChanged> notifyRoomsChanged( new RocketChatSubscribeRoomsChanged( this->mUserId ) );
QSharedPointer<RocketChatSubscribeUserNotify> notifySubSubscription( new RocketChatSubscribeUserNotify( this->mUserId ) );
QSharedPointer<RocketChatNotifyNoticesRequest> notifyNoticeSubSubscription( new RocketChatNotifyNoticesRequest( this->mUserId ) );
QSharedPointer<RocketChatSubScriptionChangedRequest> noitfySubscriptionsSubscription( new RocketChatSubScriptionChangedRequest( this->mUserId ) );
QSharedPointer<RocketChatSubscribeActiveUsers> activeUsersSubscription( new RocketChatSubscribeActiveUsers() );
QSharedPointer<RocketChatSubscribeUserData> userData( new RocketChatSubscribeUserData() );
sendDdprequest( notifySubSubscription, true );
sendDdprequest( notifyNoticeSubSubscription, true );
sendDdprequest( noitfySubscriptionsSubscription, true );
sendDdprequest( activeUsersSubscription, true );
sendDdprequest( notifyRoomsChanged, true );
sendDdprequest( userData, true );
onLoggedIn();
sendUnsentMessages();
getServerSettings();
emit registerForPush();
qDebug() << "ddp authenticated";
this->initialised = 1;
this->initialised = true;
};
QSharedPointer<RocketChatSubscribeRoomsChanged> notifyRoomsChanged( new RocketChatSubscribeRoomsChanged( this->mUserId ) );
QSharedPointer<RocketChatSubscribeUserNotify> notifySubSubscription( new RocketChatSubscribeUserNotify( this->mUserId ) );
QSharedPointer<RocketChatNotifyNoticesRequest> notifyNoticeSubSubscription( new RocketChatNotifyNoticesRequest( this->mUserId ) );
QSharedPointer<RocketChatSubScriptionChangedRequest> noitfySubscriptionsSubscription( new RocketChatSubScriptionChangedRequest( this->mUserId ) );
QSharedPointer<RocketChatSubscribeActiveUsers> activeUsersSubscription( new RocketChatSubscribeActiveUsers() );
QSharedPointer<RocketChatSubscribeUserData> userData( new RocketChatSubscribeUserData() );
sendDdprequest( notifySubSubscription, true );
sendDdprequest( notifyNoticeSubSubscription, true );
sendDdprequest( noitfySubscriptionsSubscription, true );
sendDdprequest( activeUsersSubscription, true );
sendDdprequest( notifyRoomsChanged, true );
sendDdprequest( userData, true );
sendUnsentMessages();
getServerSettings();
emit registerForPush();
mEmojiService->loadCustomEmojis( success );
}
......@@ -1786,7 +1784,7 @@ void RocketChatServerData::uploadFile( const QString &pChannelId, const QString
file.close();
}
FileUploader *uploader = new FileUploader( this, uri, pChannelId );
auto uploader = new FileUploader( this, uri, pChannelId );
std::function<void( void )> success = [ = ]() {
emit fileUploadFinished( uploader->getFileId() );
delete uploader;
......
......@@ -46,7 +46,7 @@ void EmojiService::loadCustomEmojis( const std::function<void ( QList<QSharedPoi
DdpCallback success = [ = ]( const QJsonObject & pResponse, MeteorDDP * pDdp ) {
Q_UNUSED( pDdp );
QJsonArray result = pResponse[QStringLiteral( "result" )].toArray();
EmojiData *data = new EmojiData( result );
auto data = new EmojiData( result );
data->success = pSuccess;
handleCustomEmojisReceived( data );
};
......@@ -66,8 +66,8 @@ QList<QSharedPointer<Emoji>> EmojiService::loadEmojisFromDb()
emojiList.reserve( 3000 );
for ( const auto &current : emojiData ) {
auto parsedEmojis = parseEmoji( current );
emojiList.append( parsedEmojis );
auto parsedEmojis = parseEmoji( std::move( current ) );
emojiList.append( std::move( parsedEmojis ) );
}
return emojiList;
......@@ -141,7 +141,7 @@ QSharedPointer<Emoji> EmojiService::parseEmoji( const QHash<QString, QString> &p
QString unicode = pEmojiData[QStringLiteral( "unicode" )];
int order = pEmojiData[QStringLiteral( "sort_order" )].toInt();
QSharedPointer<Emoji> emoji( new Emoji( name, catgeory, filePath, html, unicode, order ) );
QSharedPointer<Emoji> emoji( new Emoji( std::move( name ), std::move( catgeory ), std::move( filePath ), std::move( html ), std::move( unicode ), order ) );
return emoji;
}
......@@ -151,7 +151,7 @@ QSharedPointer<Emoji> EmojiService::parseEmoji( const QJsonObject &pEmojiData )
QString extension = pEmojiData[QStringLiteral( "extension" )].toString();
QString category = pEmojiData[QStringLiteral( "category" )].toString();
QSharedPointer<Emoji> emoji( new Emoji( name, extension, category ) );
QSharedPointer<Emoji> emoji( new Emoji( std::move( name ), std::move( extension ), std::move( category ) ) );
return emoji;
}
......@@ -166,7 +166,7 @@ EmojiData::EmojiData( const QJsonArray &data )
this->emojiCounter = data.count();
}
QJsonArray EmojiData::getEmojiData() const
const QJsonArray &EmojiData::getEmojiData() const
{
return emojiData;
}
......@@ -38,7 +38,7 @@ class EmojiData
{
public:
EmojiData( const QJsonArray &data );
QJsonArray getEmojiData() const;
const QJsonArray &getEmojiData() const;
QAtomicInt emojiCounter = 0;
QAtomicInt emojisProcessed = 0;
QJsonArray emojiData = {};
......
......@@ -281,7 +281,7 @@ void MessageService::loadHistoryFromServer( const QSharedPointer<LoadHistoryRequ
QSharedPointer<QSet<QString>> duplicateCheck( new QSet<QString> );
if ( requests.length() ) {
QMultiMap<QString, ChatMessage> *list = new QMultiMap<QString, ChatMessage>;
auto list = new QMultiMap<QString, ChatMessage>;
//loop over all channels
for ( const auto &currentChannelRequest : requests ) {
......@@ -373,7 +373,7 @@ void MessageService::loadHistoryFromServer( const QSharedPointer<LoadHistoryServ
QMultiMap<QString, ChatMessage> *MessageService::loadHistoryFromDb(
const QSharedPointer<LoadHistoryServiceRequest> &pRequest )
{
QMultiMap<QString, ChatMessage> *channelMap = new QMultiMap<QString, ChatMessage>;
auto channelMap = new QMultiMap<QString, ChatMessage>;
if ( !pRequest.isNull() ) {
QStringList channelIds = pRequest->getChannelIds();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment