Commit 52d8441f authored by armin's avatar armin
Browse files

ifix channelsorting

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