Commit 39b3b8ed authored by armin's avatar armin
Browse files

Merge branch 'fasterChannelLoad' into 'master'

Faster channel load

See merge request !116
parents 98a7a3f3 a1a7bb1d
...@@ -147,6 +147,11 @@ bool ChannelModel::addChannel( const QSharedPointer<RocketChatChannel> &channel ...@@ -147,6 +147,11 @@ bool ChannelModel::addChannel( const QSharedPointer<RocketChatChannel> &channel
connect( channel.data(), &RocketChatChannel::unreadMessagesChanged, this, &ChannelModel::onUnreadMessageChanged, Qt::UniqueConnection ); connect( channel.data(), &RocketChatChannel::unreadMessagesChanged, this, &ChannelModel::onUnreadMessageChanged, Qt::UniqueConnection );
connect( channel.data(), &RocketChatChannel::dataChanged, this, &ChannelModel::onDataChanged, Qt::UniqueConnection ); connect( channel.data(), &RocketChatChannel::dataChanged, this, &ChannelModel::onDataChanged, Qt::UniqueConnection );
connect( channel.data(), &RocketChatChannel::channelDeleted, this, &ChannelModel::onDeleted, Qt::UniqueConnection ); connect( channel.data(), &RocketChatChannel::channelDeleted, this, &ChannelModel::onDeleted, Qt::UniqueConnection );
/* connect(channel.data(), &RocketChatChannel::updatedChanged, [model = this](const QString &id, qint64 pTimeStamp){
model->beginResetModel();
model->channelList.reOrder();
model->endResetModel();
});*/
duplicateCheck.insert( channel->getRoomId() ); duplicateCheck.insert( channel->getRoomId() );
int pos = channelList.findPosition( channel ); int pos = channelList.findPosition( channel );
if(pos <0){ if(pos <0){
...@@ -172,6 +177,11 @@ bool ChannelModel::addChannelsSlot(const QVector<QSharedPointer<RocketChatChanne ...@@ -172,6 +177,11 @@ bool ChannelModel::addChannelsSlot(const QVector<QSharedPointer<RocketChatChanne
connect( channel.data(), &RocketChatChannel::unreadMessagesChanged, this, &ChannelModel::onUnreadMessageChanged, Qt::UniqueConnection ); connect( channel.data(), &RocketChatChannel::unreadMessagesChanged, this, &ChannelModel::onUnreadMessageChanged, Qt::UniqueConnection );
connect( channel.data(), &RocketChatChannel::dataChanged, this, &ChannelModel::onDataChanged, Qt::UniqueConnection ); connect( channel.data(), &RocketChatChannel::dataChanged, this, &ChannelModel::onDataChanged, Qt::UniqueConnection );
connect( channel.data(), &RocketChatChannel::channelDeleted, this, &ChannelModel::onDeleted, Qt::UniqueConnection ); connect( channel.data(), &RocketChatChannel::channelDeleted, this, &ChannelModel::onDeleted, Qt::UniqueConnection );
/* connect(channel.data(), &RocketChatChannel::updatedChanged, [model=this](const QString &id, qint64 pTimeStamp){
model->beginResetModel();
// model->channelList.reOrder();
model->endResetModel();
});*/
duplicateCheck.insert( channel->getRoomId() ); duplicateCheck.insert( channel->getRoomId() );
channelList.insertSort( channel ); channelList.insertSort( channel );
} }
...@@ -291,6 +301,11 @@ void ChannelModel::onDeleted( const QString &pId, bool deleted ) ...@@ -291,6 +301,11 @@ void ChannelModel::onDeleted( const QString &pId, bool deleted )
} }
void ChannelModel::onChannelOrderChanged(const QString &pId, qint64 pTimestamp)
{
qDebug()<<"order changed 123";
}
void ChannelModel::addChannelSlot( const QSharedPointer<RocketChatChannel> &channel ) void ChannelModel::addChannelSlot( const QSharedPointer<RocketChatChannel> &channel )
{ {
addChannel( channel ); addChannel( channel );
...@@ -308,11 +323,29 @@ void ChannelModel::setType( const QString &value ) ...@@ -308,11 +323,29 @@ void ChannelModel::setType( const QString &value )
void ChannelModel::sortChanged() void ChannelModel::sortChanged()
{ {
static int counter = 0;
counter++;
qDebug()<<counter;
beginResetModel(); beginResetModel();
channelList.reOrder(); std::sort( channelList.begin(), channelList.end(), []( const QSharedPointer<RocketChatChannel> &channel1, const QSharedPointer<RocketChatChannel> &channel2 ) {
auto youngest1 = channel1->getYoungestMessage();
auto youngest2 = channel2->getYoungestMessage();
if ( !youngest1.isNull() && !youngest2.isNull() ) {
auto timestamp1 = youngest1->getTimestamp();
auto timestamp2 = youngest2->getTimestamp();
return timestamp2 < timestamp1;
}
if ( youngest1.isNull() && !youngest2.isNull() ) {
return false;
}
if ( youngest2.isNull() && !youngest1.isNull() ) {
return true;
}
return false;
} );
endResetModel(); endResetModel();
emit countChanged(); emit countChanged();
} }
......
...@@ -99,6 +99,8 @@ int SortedVector<T>::findPosition( const QSharedPointer<T> &pointer ) const ...@@ -99,6 +99,8 @@ int SortedVector<T>::findPosition( const QSharedPointer<T> &pointer ) const
template<typename T> template<typename T>
void SortedVector<T>::reOrder() void SortedVector<T>::reOrder()
{ {
std::sort(this->begin(),this->end()); std::sort(this->begin(),this->end(),[](const auto &first, const auto &second){
return first.get()>second.get();
});
} }
...@@ -25,7 +25,7 @@ ...@@ -25,7 +25,7 @@
FileUploader::FileUploader( QObject *parent, RocketChatServerData *pServer, const QUrl &pUri, const QString &pChannelId ): QObject( parent ), FileUploader::FileUploader( QObject *parent, RocketChatServerData *pServer, const QUrl &pUri, const QString &pChannelId ): QObject( parent ),
mUri( pUri ), mChannelId( pChannelId ), mServer( pServer ) mUri( pUri ), mChannelId( pChannelId ), mServer( pServer )
{ {
auto file = QSharedPointer<QFile>::create( pUri.path() ); auto file = QSharedPointer<QFile>::create( pUri.toLocalFile() );
if ( file->isOpen() ) { if ( file->isOpen() ) {
file->close(); file->close();
......
...@@ -366,9 +366,12 @@ qint64 RocketChatChannel::getUpdatedAt() const ...@@ -366,9 +366,12 @@ qint64 RocketChatChannel::getUpdatedAt() const
void RocketChatChannel::setUpdatedAt( const qint64 &updatedAt ) void RocketChatChannel::setUpdatedAt( const qint64 &updatedAt )
{ {
//skip signal the first time
if(mUpdatedAt != updatedAt){ if(mUpdatedAt != updatedAt){
if(mUpdatedAt != -1){
emit updatedChanged(mRoomId,mUpdatedAt);
}
mUpdatedAt = updatedAt; mUpdatedAt = updatedAt;
emit updatedChanged(mRoomId,mUpdatedAt);
} }
} }
......
...@@ -431,24 +431,27 @@ void RocketChat::openFileDialog( const QString &pChannelId ) ...@@ -431,24 +431,27 @@ void RocketChat::openFileDialog( const QString &pChannelId )
#ifdef Q_OS_ANDROID #ifdef Q_OS_ANDROID
openAndroidFileDialog( pChannelId ); openAndroidFileDialog( pChannelId );
#endif #endif
} }
void RocketChat::openFileExternally( const QString &pPath ) void RocketChat::openFileExternally( const QString &pPath )
{ {
#ifdef Q_OS_LINUX
Q_UNUSED( pPath ); #if defined( Q_OS_ANDROID)
#endif
#ifdef Q_OS_ANDROID
QString q = pPath; QString q = pPath;
QAndroidJniObject jniObject = QAndroidJniObject::fromString(q); QAndroidJniObject jniObject = QAndroidJniObject::fromString(q);
jstring j = jniObject.object<jstring>(); jstring j = jniObject.object<jstring>();
QtAndroid::androidActivity().callObjectMethod("openFile","(Ljava/lang/String;)Ljava/lang/String;",j); QtAndroid::androidActivity().callObjectMethod("openFile","(Ljava/lang/String;)Ljava/lang/String;",j);
#endif #elif defined(Q_OS_LINUX)
#ifdef Q_OS_IOS QDesktopServices::openUrl(pPath);
#elif defined (Q_OS_IOS)
emit openIOSFileDialog( pPath ); emit openIOSFileDialog( pPath );
#elif defined(Q_OS_WIN)
QDesktopServices::openUrl(pPath);
#elif defined(Q_OS_MACOS)
QDesktopServices::openUrl(pPath);
#endif #endif
} }
bool RocketChat::hasCameraPermission() bool RocketChat::hasCameraPermission()
......
...@@ -156,7 +156,7 @@ class RocketChat : public QObject ...@@ -156,7 +156,7 @@ class RocketChat : public QObject
int getUserStatus(); int getUserStatus();
protected: private:
QMutex newServerMutex; QMutex newServerMutex;
//TODO: switch from shared pointer to normal ones, to avoid these hacks //TODO: switch from shared pointer to normal ones, to avoid these hacks
......
...@@ -1489,16 +1489,16 @@ bool RocketChatServerData::isUserJoinMessage( const QJsonObject &pMessage ) cons ...@@ -1489,16 +1489,16 @@ bool RocketChatServerData::isUserJoinMessage( const QJsonObject &pMessage ) cons
void RocketChatServerData::handleStreamRoomMessage( const QJsonObject &pMessage ) void RocketChatServerData::handleStreamRoomMessage( const QJsonObject &pMessage )
{ {
if ( Q_LIKELY( pMessage.contains( QStringLiteral( "fields" ) ) ) ) { if ( Q_LIKELY( pMessage.contains( QStringLiteral( "fields" ) ) ) ) {
QJsonObject fields = pMessage[QStringLiteral( "fields" )].toObject(); auto fields = pMessage[QStringLiteral( "fields" )].toObject();
if ( Q_LIKELY( fields.contains( QStringLiteral( "args" ) ) ) ) { if ( Q_LIKELY( fields.contains( QStringLiteral( "args" ) ) ) ) {
QJsonArray args = fields[QStringLiteral( "args" )].toArray(); auto args = fields[QStringLiteral( "args" )].toArray();
for ( const auto currentArg : args ) { for ( const auto currentArg : args ) {
QJsonObject currentArgObj = currentArg.toObject(); auto currentArgObj = currentArg.toObject();
if ( Q_LIKELY( currentArgObj.contains( QStringLiteral( "rid" ) ) && currentArgObj.contains( QStringLiteral( "_id" ) ) ) ) { if ( Q_LIKELY( currentArgObj.contains( QStringLiteral( "rid" ) ) && currentArgObj.contains( QStringLiteral( "_id" ) ) ) ) {
QString roomId = currentArgObj[QStringLiteral( "rid" )].toString(); auto roomId = currentArgObj[QStringLiteral( "rid" )].toString();
auto message = mMessageService->parseMessage( currentArgObj, true ); auto message = mMessageService->parseMessage( currentArgObj, true );
if ( Q_LIKELY( mChannels->contains( roomId ) ) ) { if ( Q_LIKELY( mChannels->contains( roomId ) ) ) {
...@@ -1513,6 +1513,7 @@ void RocketChatServerData::handleStreamRoomMessage( const QJsonObject &pMessage ...@@ -1513,6 +1513,7 @@ void RocketChatServerData::handleStreamRoomMessage( const QJsonObject &pMessage
} }
} }
} }
} }
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment