Commit 01713517 authored by armin's avatar armin
Browse files

Merge branch 'channelSortFix' into 'master'

ifix channelsorting

See merge request !127
parents 4f450b8d 52d8441f
...@@ -168,7 +168,7 @@ bool ChannelModel::addChannel( const QSharedPointer<RocketChatChannel> &channel ...@@ -168,7 +168,7 @@ bool ChannelModel::addChannel( const QSharedPointer<RocketChatChannel> &channel
} }
bool ChannelModel::addChannelsSlot( const QVector<QSharedPointer<RocketChatChannel> > &pChannels ) bool ChannelModel::addChannelsSlot( const QList<QSharedPointer<RocketChatChannel> > &pChannels )
{ {
// beginResetModel(); // beginResetModel();
int from = -1; int from = -1;
...@@ -299,16 +299,18 @@ void ChannelModel::onDeleted( const QString &pId, bool deleted ) ...@@ -299,16 +299,18 @@ void ChannelModel::onDeleted( const QString &pId, bool deleted )
Q_UNUSED( deleted ) Q_UNUSED( deleted )
int idx = -1; int idx = -1;
for ( int i = 0; i < channelList.length(); i++ ) { auto iter = channelList.begin();
if ( channelList.at( i )->getRoomId() == pId ) {
idx = i; for ( ; iter != channelList.end(); iter++ ) {
if ( ( *iter )->getRoomId() == pId ) {
break; break;
} }
} }
if ( idx != -1 ) { if ( iter != channelList.end() ) {
idx = static_cast<int>( std::distance( channelList.begin(), iter ) );
beginRemoveRows( QModelIndex(), idx, idx ); beginRemoveRows( QModelIndex(), idx, idx );
channelList.remove( idx ); channelList.erase( iter );
endRemoveRows(); endRemoveRows();
} }
......
...@@ -72,7 +72,7 @@ class ChannelModel : public QAbstractListModel ...@@ -72,7 +72,7 @@ class ChannelModel : public QAbstractListModel
void onUnreadMessageChanged( const QString &id, int number ); void onUnreadMessageChanged( const QString &id, int number );
void onDataChanged( const QString &id, const QString &property ); void onDataChanged( const QString &id, const QString &property );
void onDeleted( const QString &pId, bool deleted ); void onDeleted( const QString &pId, bool deleted );
void onChannelOrderChanged(const QString &pId, qint64 pTimestamp); void onChannelOrderChanged( const QString &pId, qint64 pTimestamp );
QTimer timer; QTimer timer;
signals: signals:
...@@ -80,8 +80,8 @@ class ChannelModel : public QAbstractListModel ...@@ -80,8 +80,8 @@ class ChannelModel : public QAbstractListModel
void unreadMessagesChanged( void ); void unreadMessagesChanged( void );
public slots: public slots:
void addChannelSlot(const QSharedPointer<RocketChatChannel> &); void addChannelSlot( const QSharedPointer<RocketChatChannel> & );
bool addChannelsSlot( const QVector<QSharedPointer<RocketChatChannel>> & ); bool addChannelsSlot( const QList<QSharedPointer<RocketChatChannel>> & );
}; };
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
#include "repos/entities/rocketchatchannel.h" #include "repos/entities/rocketchatchannel.h"
#include "container/sortedvector.h" #include "container/sortedvector.h"
typedef QVector<QSharedPointer<RocketChatChannel>> channelVector; typedef QList<QSharedPointer<RocketChatChannel>> channelVector;
class RoomSearchResultsModel: public QAbstractListModel class RoomSearchResultsModel: public QAbstractListModel
{ {
......
...@@ -77,7 +77,7 @@ std::tuple<int, int> SortedVector<T>::reOrder() ...@@ -77,7 +77,7 @@ std::tuple<int, int> SortedVector<T>::reOrder()
int from = -1; int from = -1;
int to = -1; int to = -1;
for ( int i = 0; i < this->size() - 1; i++ ) { for ( int i = 0; i < this->size() ; i++ ) {
if ( indices[i] != ( *this )[i] ) { if ( indices[i] != ( *this )[i] ) {
from = i; from = i;
break; break;
......
...@@ -32,7 +32,7 @@ struct SortedVectorProperties { ...@@ -32,7 +32,7 @@ struct SortedVectorProperties {
dsc dsc
}; };
}; };
template<typename T> class SortedVector : public QVector<QSharedPointer<T>> template<typename T> class SortedVector : public QList<QSharedPointer<T>>
{ {
public: public:
......
...@@ -59,10 +59,10 @@ bool ChannelRepository::add( const QSharedPointer<RocketChatChannel> &pChannel ) ...@@ -59,10 +59,10 @@ bool ChannelRepository::add( const QSharedPointer<RocketChatChannel> &pChannel )
return add( id, pChannel ); return add( id, pChannel );
} }
bool ChannelRepository::add(const QString &pType, const QVector<QSharedPointer<RocketChatChannel> > &pChannels) bool ChannelRepository::add( const QString &pType, const QList<QSharedPointer<RocketChatChannel> > &pChannels )
{ {
if(!pChannels.empty()){ if ( !pChannels.empty() ) {
for(const auto &elem: pChannels){ for ( const auto &elem : pChannels ) {
if ( !mElements.contains( elem->getRoomId() ) ) { if ( !mElements.contains( elem->getRoomId() ) ) {
mNameIndex[elem->getName()] = elem; mNameIndex[elem->getName()] = elem;
...@@ -71,13 +71,15 @@ bool ChannelRepository::add(const QString &pType, const QVector<QSharedPointer<R ...@@ -71,13 +71,15 @@ bool ChannelRepository::add(const QString &pType, const QVector<QSharedPointer<R
} }
} }
} }
if(pType == "p"){
auto result = QMetaObject::invokeMethod( mGroupsModel, "addChannelsSlot", Q_ARG( QVector<QSharedPointer<RocketChatChannel> >, pChannels) ); if ( pType == "p" ) {
}else if(pType == "c"){ auto result = QMetaObject::invokeMethod( mGroupsModel, "addChannelsSlot", Q_ARG( QList<QSharedPointer<RocketChatChannel> >, pChannels ) );
auto result = QMetaObject::invokeMethod( mChannelsModel, "addChannelsSlot", Q_ARG( QVector<QSharedPointer<RocketChatChannel> >, pChannels ) ); } else if ( pType == "c" ) {
}else if(pType == "d"){ auto result = QMetaObject::invokeMethod( mChannelsModel, "addChannelsSlot", Q_ARG( QList<QSharedPointer<RocketChatChannel> >, pChannels ) );
auto result = QMetaObject::invokeMethod( mDirectModel, "addChannelsSlot", Q_ARG( QVector<QSharedPointer<RocketChatChannel> >, pChannels ) ); } else if ( pType == "d" ) {
auto result = QMetaObject::invokeMethod( mDirectModel, "addChannelsSlot", Q_ARG( QList<QSharedPointer<RocketChatChannel> >, pChannels ) );
} }
return true; return true;
} }
......
...@@ -42,7 +42,7 @@ class ChannelRepository : public QObject, public AbstractBaseRepository<RocketCh ...@@ -42,7 +42,7 @@ class ChannelRepository : public QObject, public AbstractBaseRepository<RocketCh
explicit ChannelRepository( QObject *parent = nullptr ); explicit ChannelRepository( QObject *parent = nullptr );
bool add( const QString &id, const QSharedPointer<RocketChatChannel> & ); bool add( const QString &id, const QSharedPointer<RocketChatChannel> & );
bool add( const QSharedPointer<RocketChatChannel> &pChannel ); bool add( const QSharedPointer<RocketChatChannel> &pChannel );
bool add(const QString &pType, const QVector<QSharedPointer<RocketChatChannel>> &pChannels); bool add( const QString &pType, const QList<QSharedPointer<RocketChatChannel>> &pChannels );
QSharedPointer<RocketChatChannel> getChannelByName( const QString &pName ); QSharedPointer<RocketChatChannel> getChannelByName( const QString &pName );
const QSharedPointer<RocketChatChannel> getChannelByName( const QString &pName ) const; const QSharedPointer<RocketChatChannel> getChannelByName( const QString &pName ) const;
......
...@@ -355,6 +355,10 @@ void RocketChatChannel::setChatPartnerId( const QString &chatPartnerId ) ...@@ -355,6 +355,10 @@ void RocketChatChannel::setChatPartnerId( const QString &chatPartnerId )
QSharedPointer<TempFile> RocketChatChannel::getAvatarImg() const QSharedPointer<TempFile> RocketChatChannel::getAvatarImg() const
{ {
if ( mAvatarImg.isNull() ) {
}
return mAvatarImg; return mAvatarImg;
} }
......
...@@ -198,7 +198,7 @@ void RocketChatMessage::setRoomeTyp( const QString &value ) ...@@ -198,7 +198,7 @@ void RocketChatMessage::setRoomeTyp( const QString &value )
roomeTyp = value; roomeTyp = value;
} }
bool RocketChatMessage::inTimeIntervall(const qint64 newt,const qint64 oldt) bool RocketChatMessage::inTimeIntervall( const qint64 newt, const qint64 oldt )
{ {
return getTimestamp() >= oldt && getTimestamp() <= newt; return getTimestamp() >= oldt && getTimestamp() <= newt;
} }
...@@ -210,8 +210,13 @@ QSharedPointer<TempFile> RocketChatMessage::getAvatarImg() const ...@@ -210,8 +210,13 @@ QSharedPointer<TempFile> RocketChatMessage::getAvatarImg() const
void RocketChatMessage::setAvatarImg( const QSharedPointer<TempFile> &avatarImg ) void RocketChatMessage::setAvatarImg( const QSharedPointer<TempFile> &avatarImg )
{ {
if ( mAvatarImg != avatarImg ) { if ( mAvatarImg != avatarImg && !avatarImg.isNull() ) {
mAvatarImg = avatarImg; mAvatarImg = avatarImg;
emit dataChanged( id, "avatarImg" );
if ( mIntialized ) {
emit dataChanged( id, "avatarImg" );
}
mIntialized = true;
} }
} }
...@@ -94,11 +94,12 @@ class RocketChatMessage: public QObject ...@@ -94,11 +94,12 @@ class RocketChatMessage: public QObject
const QString &getRoomeTyp() const; const QString &getRoomeTyp() const;
void setRoomeTyp( const QString &value ); void setRoomeTyp( const QString &value );
bool inTimeIntervall(const qint64 newt,const qint64 oldt); bool inTimeIntervall( const qint64 newt, const qint64 oldt );
QSharedPointer<TempFile> getAvatarImg() const; QSharedPointer<TempFile> getAvatarImg() const;
void setAvatarImg( const QSharedPointer<TempFile> &avatarImg ); void setAvatarImg( const QSharedPointer<TempFile> &avatarImg );
protected: protected:
bool mIntialized = false;
QSharedPointer<TempFile> mAvatarImg; QSharedPointer<TempFile> mAvatarImg;
QSharedPointer<RocketChatUser> mAuthor; QSharedPointer<RocketChatUser> mAuthor;
bool empty = false; bool empty = false;
......
...@@ -57,7 +57,7 @@ void RocketChatServerData::init() ...@@ -57,7 +57,7 @@ void RocketChatServerData::init()
void RocketChatServerData::initDb() void RocketChatServerData::initDb()
{ {
qDebug()<<" "<<QThread::currentThreadId(); qDebug() << " " << QThread::currentThreadId();
mStorage = PersistanceLayer::instance(); mStorage = PersistanceLayer::instance();
connect( mStorage, &PersistanceLayer::ready, this, &RocketChatServerData::initConnections, Qt::UniqueConnection ); connect( mStorage, &PersistanceLayer::ready, this, &RocketChatServerData::initConnections, Qt::UniqueConnection );
...@@ -66,7 +66,7 @@ void RocketChatServerData::initDb() ...@@ -66,7 +66,7 @@ void RocketChatServerData::initDb()
void RocketChatServerData::initConnections() void RocketChatServerData::initConnections()
{ {
qDebug()<<" "<<QThread::currentThreadId(); qDebug() << " " << QThread::currentThreadId();
historyLoaded = [ = ]( QMultiMap<QString, QSharedPointer<RocketChatMessage>> *messages ) { historyLoaded = [ = ]( QMultiMap<QString, QSharedPointer<RocketChatMessage>> *messages ) {
if ( messages ) { if ( messages ) {
...@@ -503,9 +503,10 @@ QString RocketChatServerData::getUserId() const ...@@ -503,9 +503,10 @@ QString RocketChatServerData::getUserId() const
void RocketChatServerData::setUserId( const QString &userId ) void RocketChatServerData::setUserId( const QString &userId )
{ {
//TODO: do this differently //TODO: do this differently
auto users = Models::getUsersModel(); auto users = Models::getUsersModel();
if(users){
qDebug()<<" "<<QThread::currentThreadId(); if ( users ) {
qDebug() << " " << QThread::currentThreadId();
users->mMutex.lock(); users->mMutex.lock();
auto user = users->getUserById( userId ); auto user = users->getUserById( userId );
...@@ -522,6 +523,7 @@ void RocketChatServerData::setUserId( const QString &userId ) ...@@ -522,6 +523,7 @@ void RocketChatServerData::setUserId( const QString &userId )
emit userStatusChanged( static_cast<int>( user->getStatus() ) ); emit userStatusChanged( static_cast<int>( user->getStatus() ) );
} ); } );
} }
users->mMutex.unlock(); users->mMutex.unlock();
} }
...@@ -599,11 +601,12 @@ void RocketChatServerData::onUnreadCountChanged() ...@@ -599,11 +601,12 @@ void RocketChatServerData::onUnreadCountChanged()
number += channel->getUnreadMessages(); number += channel->getUnreadMessages();
} }
} }
if ( lastUnreadCount != number ) {
lastUnreadCount = number;
emit unreadCountChanged( QStringLiteral( "default" ), number );
} if ( lastUnreadCount != number ) {
lastUnreadCount = number;
emit unreadCountChanged( QStringLiteral( "default" ), number );
}
} }
...@@ -1180,10 +1183,10 @@ void RocketChatServerData::handleChannelMessage( const QJsonObject &pMessage ) ...@@ -1180,10 +1183,10 @@ void RocketChatServerData::handleChannelMessage( const QJsonObject &pMessage )
qint64 updatedAt = -1; qint64 updatedAt = -1;
if ( data.contains( "_updatedAt" ) ) { /*if ( data.contains( "_updatedAt" ) ) {
auto updatedObj = data["_updatedAt"].toObject(); auto updatedObj = data["_updatedAt"].toObject();
updatedAt = static_cast<qint64>( updatedObj["$date"].toDouble() ); updatedAt = static_cast<qint64>( updatedObj["$date"].toDouble() );
} }*/
auto type = data[QStringLiteral( "t" )].toString(); auto type = data[QStringLiteral( "t" )].toString();
bool blocked = false; bool blocked = false;
...@@ -1438,6 +1441,7 @@ void RocketChatServerData::onDDPMessageReceived( const QJsonObject &pMessage ) ...@@ -1438,6 +1441,7 @@ void RocketChatServerData::onDDPMessageReceived( const QJsonObject &pMessage )
auto result = QMetaObject::invokeMethod( userModel, "addUser", Q_ARG( User, newUser ) ); auto result = QMetaObject::invokeMethod( userModel, "addUser", Q_ARG( User, newUser ) );
Q_ASSERT( result ); Q_ASSERT( result );
} }
userModel->mMutex.unlock(); userModel->mMutex.unlock();
...@@ -1534,6 +1538,11 @@ void RocketChatServerData::handleStreamRoomMessage( const QJsonObject &pMessage ...@@ -1534,6 +1538,11 @@ void RocketChatServerData::handleStreamRoomMessage( const QJsonObject &pMessage
mChannels->get( roomId )->addMessage( message ); mChannels->get( roomId )->addMessage( message );
mMessageService->persistMessage( message ); mMessageService->persistMessage( message );
//TODO: fix RC server to make this hack unnecessary
if ( channel->getUpdatedAt() < message->getTimestamp() ) {
channel->setUpdatedAt( message->getTimestamp() );
}
if ( message->getMessageType() == "au" ) { if ( message->getMessageType() == "au" ) {
mChannelService->loadUsersOfChannel( channel ); mChannelService->loadUsersOfChannel( channel );
} }
...@@ -1714,7 +1723,7 @@ void RocketChatServerData::getServerSettings() ...@@ -1714,7 +1723,7 @@ void RocketChatServerData::getServerSettings()
sendDdprequest( request, true, true ); sendDdprequest( request, true, true );
} }
void RocketChatServerData::onChannelsLoaded( const QVector<QSharedPointer<RocketChatChannel>> &pChannels ) void RocketChatServerData::onChannelsLoaded( const QList<QSharedPointer<RocketChatChannel>> &pChannels )
{ {
Q_UNUSED( pChannels ); Q_UNUSED( pChannels );
qDebug() << "on channels loaded "; qDebug() << "on channels loaded ";
......
...@@ -217,7 +217,7 @@ class RocketChatServerData : public MessageListener ...@@ -217,7 +217,7 @@ class RocketChatServerData : public MessageListener
void setSetting( const QString &pKey, const QString &pValue ); void setSetting( const QString &pKey, const QString &pValue );
void getSetting( const QString &pKey ); void getSetting( const QString &pKey );
void deleteMessage(QString rid, QString id); void deleteMessage( QString rid, QString id );
void reconnect(); void reconnect();
public: public:
...@@ -298,7 +298,7 @@ class RocketChatServerData : public MessageListener ...@@ -298,7 +298,7 @@ class RocketChatServerData : public MessageListener
void onDDPAuthenticated(); void onDDPAuthenticated();
void onDDPMessageReceived( const QJsonObject &pMessage ); void onDDPMessageReceived( const QJsonObject &pMessage );
void onChannelsLoaded( const QVector<QSharedPointer<RocketChatChannel> > &pChannels ); void onChannelsLoaded( const QList<QSharedPointer<RocketChatChannel> > &pChannels );
void onLoggedIn(); void onLoggedIn();
bool isStreamRoomMessage( const QJsonObject &pMessage ) const; bool isStreamRoomMessage( const QJsonObject &pMessage ) const;
bool isUserJoinMessage( const QJsonObject &pMessage ) const; bool isUserJoinMessage( const QJsonObject &pMessage ) const;
...@@ -341,7 +341,7 @@ class RocketChatServerData : public MessageListener ...@@ -341,7 +341,7 @@ class RocketChatServerData : public MessageListener
void userStatusChanged( int status ); void userStatusChanged( int status );
void videoPath( const QString &path ); void videoPath( const QString &path );
void setting( const QString &pKey, const QString &pValue ); void setting( const QString &pKey, const QString &pValue );
void offline(void); void offline( void );
// MessageListener interface // MessageListener interface
public: public:
......
...@@ -222,7 +222,7 @@ QSharedPointer<RocketChatMessage> MessageService::parseMessage( const QJsonObjec ...@@ -222,7 +222,7 @@ QSharedPointer<RocketChatMessage> MessageService::parseMessage( const QJsonObjec
}; };
auto avatarUrl = "/avatar/" + author + ".jpg"; auto avatarUrl = "/avatar/" + author + ".jpg";
auto avatarRequest = QSharedPointer<FileRequest>::create( avatarUrl, "temp", then, true ); auto avatarRequest = QSharedPointer<FileRequest>::create( avatarUrl, "temp", then, true );
//mFileService->getFileRessource( avatarRequest ); mFileService->getFileRessource( avatarRequest );
message->setAuthor( author ); message->setAuthor( author );
message->setFormattedDate( formattedDate ); message->setFormattedDate( formattedDate );
......
...@@ -88,9 +88,9 @@ QSharedPointer<RocketChatChannel> RocketChatChannelService::createChannelObject( ...@@ -88,9 +88,9 @@ QSharedPointer<RocketChatChannel> RocketChatChannelService::createChannelObject(
} }
QVector<QSharedPointer<RocketChatChannel> > RocketChatChannelService::processChannelData( const QJsonArray &pChannelArray, bool pJoined, bool pUpdateOnly ) QList<QSharedPointer<RocketChatChannel> > RocketChatChannelService::processChannelData( const QJsonArray &pChannelArray, bool pJoined, bool pUpdateOnly )
{ {
QVector<QSharedPointer<RocketChatChannel> > vec; QList<QSharedPointer<RocketChatChannel> > vec;
if ( mServer ) { if ( mServer ) {
std::tuple<QString, QString> openChannelTupel = mStorage->getCurrentChannel(); std::tuple<QString, QString> openChannelTupel = mStorage->getCurrentChannel();
...@@ -112,8 +112,9 @@ QVector<QSharedPointer<RocketChatChannel> > RocketChatChannelService::processCha ...@@ -112,8 +112,9 @@ QVector<QSharedPointer<RocketChatChannel> > RocketChatChannelService::processCha
qint64 updatedAt = -1; qint64 updatedAt = -1;
if ( currentChannelObject.contains( QStringLiteral( "ls" ) ) ) { //don't ask ...
auto updatedObj = currentChannelObject[QStringLiteral( "ls" )].toObject(); if ( currentChannelObject.contains( QStringLiteral( "_updatedAt" ) ) ) {
auto updatedObj = currentChannelObject[QStringLiteral( "_updatedAt" )].toObject();
updatedAt = static_cast<qint64>( updatedObj[QStringLiteral( "$date" )].toDouble() ); updatedAt = static_cast<qint64>( updatedObj[QStringLiteral( "$date" )].toDouble() );
} }
...@@ -278,10 +279,10 @@ void RocketChatChannelService::loadJoinedChannelsFromDb() ...@@ -278,10 +279,10 @@ void RocketChatChannelService::loadJoinedChannelsFromDb()
QList<QVariantHash> roomsList = mStorage->getChannels(); QList<QVariantHash> roomsList = mStorage->getChannels();
if ( Q_LIKELY( !roomsList.isEmpty() ) ) { if ( Q_LIKELY( !roomsList.isEmpty() ) ) {
QVector<QSharedPointer<RocketChatChannel>> channels; QList<QSharedPointer<RocketChatChannel>> channels;
QVector<QSharedPointer<RocketChatChannel>> channelsP; QList<QSharedPointer<RocketChatChannel>> channelsP;
QVector<QSharedPointer<RocketChatChannel>> channelsD; QList<QSharedPointer<RocketChatChannel>> channelsD;
QVector<QSharedPointer<RocketChatChannel>> channelsC; QList<QSharedPointer<RocketChatChannel>> channelsC;
auto users = Models::getUsersModel(); auto users = Models::getUsersModel();
......
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
********************************************************************************************/ ********************************************************************************************/
#pragma once
#ifndef ROCKETCHATCHANNELFACTORY_H #ifndef ROCKETCHATCHANNELFACTORY_H
#define ROCKETCHATCHANNELFACTORY_H #define ROCKETCHATCHANNELFACTORY_H
...@@ -44,7 +45,7 @@ ...@@ -44,7 +45,7 @@
#include "CustomModels/models.h" #include "CustomModels/models.h"
typedef QVector<QSharedPointer<RocketChatChannel>> channelVector; typedef QList<QSharedPointer<RocketChatChannel>> channelVector;
typedef QVector<QSharedPointer<RocketChatUser>> userVector; typedef QVector<QSharedPointer<RocketChatUser>> userVector;
...@@ -106,7 +107,7 @@ class RocketChatChannelService : public QObject ...@@ -106,7 +107,7 @@ class RocketChatChannelService : public QObject
FileService *mFileService = nullptr; FileService *mFileService = nullptr;
MeteorDDP *mDdp; MeteorDDP *mDdp;
QVector<QSharedPointer<RocketChatChannel>> processChannelData( const QJsonArray &pChannelArray, bool pJoined, bool pUpdateOnly ); QList<QSharedPointer<RocketChatChannel>> processChannelData( const QJsonArray &pChannelArray, bool pJoined, bool pUpdateOnly );
MessageService *mMessageService; MessageService *mMessageService;
signals: signals:
......
Supports Markdown
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