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
connect( channel.data(), &RocketChatChannel::unreadMessagesChanged, this, &ChannelModel::onUnreadMessageChanged, 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::updatedChanged, [model = this](const QString &id, qint64 pTimeStamp){
model->beginResetModel();
model->channelList.reOrder();
model->endResetModel();
});*/
duplicateCheck.insert( channel->getRoomId() );
int pos = channelList.findPosition( channel );
if(pos <0){
......@@ -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::dataChanged, this, &ChannelModel::onDataChanged, 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() );
channelList.insertSort( channel );
}
......@@ -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 )
{
addChannel( channel );
......@@ -308,11 +323,29 @@ void ChannelModel::setType( const QString &value )
void ChannelModel::sortChanged()
{
static int counter = 0;
counter++;
qDebug()<<counter;
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();
emit countChanged();
}
......
......@@ -99,6 +99,8 @@ int SortedVector<T>::findPosition( const QSharedPointer<T> &pointer ) const
template<typename T>
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 @@
FileUploader::FileUploader( QObject *parent, RocketChatServerData *pServer, const QUrl &pUri, const QString &pChannelId ): QObject( parent ),
mUri( pUri ), mChannelId( pChannelId ), mServer( pServer )
{
auto file = QSharedPointer<QFile>::create( pUri.path() );
auto file = QSharedPointer<QFile>::create( pUri.toLocalFile() );
if ( file->isOpen() ) {
file->close();
......
......@@ -366,9 +366,12 @@ qint64 RocketChatChannel::getUpdatedAt() const
void RocketChatChannel::setUpdatedAt( const qint64 &updatedAt )
{
//skip signal the first time
if(mUpdatedAt != updatedAt){
if(mUpdatedAt != -1){
emit updatedChanged(mRoomId,mUpdatedAt);
}
mUpdatedAt = updatedAt;
emit updatedChanged(mRoomId,mUpdatedAt);
}
}
......
......@@ -431,24 +431,27 @@ void RocketChat::openFileDialog( const QString &pChannelId )
#ifdef Q_OS_ANDROID
openAndroidFileDialog( pChannelId );
#endif
}
void RocketChat::openFileExternally( const QString &pPath )
{
#ifdef Q_OS_LINUX
Q_UNUSED( pPath );
#endif
#ifdef Q_OS_ANDROID
#if defined( Q_OS_ANDROID)
QString q = pPath;
QAndroidJniObject jniObject = QAndroidJniObject::fromString(q);
jstring j = jniObject.object<jstring>();
QtAndroid::androidActivity().callObjectMethod("openFile","(Ljava/lang/String;)Ljava/lang/String;",j);
#endif
#ifdef Q_OS_IOS
#elif defined(Q_OS_LINUX)
QDesktopServices::openUrl(pPath);
#elif defined (Q_OS_IOS)
emit openIOSFileDialog( pPath );
#elif defined(Q_OS_WIN)
QDesktopServices::openUrl(pPath);
#elif defined(Q_OS_MACOS)
QDesktopServices::openUrl(pPath);
#endif
}
bool RocketChat::hasCameraPermission()
......
......@@ -156,7 +156,7 @@ class RocketChat : public QObject
int getUserStatus();
protected:
private:
QMutex newServerMutex;
//TODO: switch from shared pointer to normal ones, to avoid these hacks
......
......@@ -1489,16 +1489,16 @@ bool RocketChatServerData::isUserJoinMessage( const QJsonObject &pMessage ) cons
void RocketChatServerData::handleStreamRoomMessage( const QJsonObject &pMessage )
{
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" ) ) ) ) {
QJsonArray args = fields[QStringLiteral( "args" )].toArray();
auto args = fields[QStringLiteral( "args" )].toArray();
for ( const auto currentArg : args ) {
QJsonObject currentArgObj = currentArg.toObject();
auto currentArgObj = currentArg.toObject();
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 );
if ( Q_LIKELY( mChannels->contains( roomId ) ) ) {
......@@ -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