...
 
Commits (5)
......@@ -143,7 +143,7 @@ QVariant ChannelModel::data( const QModelIndex &index, int role ) const
bool ChannelModel::addChannel( const QSharedPointer<RocketChatChannel> &channel )
{
if ( !channel.isNull() && channel->getRoomId() != "" && !duplicateCheck.contains( channel->getRoomId() ) ) {
//connect( channel.data(), &RocketChatChannel::messageAdded, this, &ChannelModel::onNewerMessage, Qt::UniqueConnection );
connect( channel.data(), &RocketChatChannel::messageAdded, this, &ChannelModel::onNewerMessage, 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::channelDeleted, this, &ChannelModel::onDeleted, Qt::UniqueConnection );
......@@ -167,7 +167,9 @@ bool ChannelModel::addChannel( const QSharedPointer<RocketChatChannel> &channel
bool ChannelModel::addChannelsSlot(const QVector<QSharedPointer<RocketChatChannel> > &pChannels)
{
beginResetModel();
// beginResetModel();
int from =-1;
int to = -1;
for(const auto &channel: pChannels){
if ( !channel.isNull() && channel->getRoomId() != "" && !duplicateCheck.contains( channel->getRoomId() ) ) {
//connect( channel.data(), &RocketChatChannel::messageAdded, this, &ChannelModel::onNewerMessage, Qt::UniqueConnection );
......@@ -176,10 +178,22 @@ bool ChannelModel::addChannelsSlot(const QVector<QSharedPointer<RocketChatChanne
connect( channel.data(), &RocketChatChannel::channelDeleted, this, &ChannelModel::onDeleted, Qt::UniqueConnection );
connect(channel.data(), &RocketChatChannel::updatedChanged, this, &ChannelModel::onChannelOrderChanged);
duplicateCheck.insert( channel->getRoomId() );
channelList.insertSort( channel );
auto index = channelList.insertSort( channel );
if(from == -1){
from = index;
to = index;
}
if(index<from){
from = index;
}else if(index>to){
to = index;
}
}
}
endResetModel();
beginInsertRows( QModelIndex(), from, to );
endInsertRows();
// endResetModel();
return true;
}
......@@ -296,6 +310,9 @@ void ChannelModel::onDeleted( const QString &pId, bool deleted )
void ChannelModel::onChannelOrderChanged(const QString &pId, qint64 pTimestamp)
{
static int counter = 0;
counter++;
qDebug() << counter;
beginResetModel();
channelList.reOrder();
endResetModel();
......
......@@ -43,7 +43,7 @@ void MeteorDDP::init( const QString &pUri )
if ( unsecure ) {
protocol = QStringLiteral( "ws://" );
}
QUrl wsUri = QUrl( protocol + pUri + QStringLiteral( "/websocket" ) );
qDebug() << wsUri;
qDebug() << "meteor init" ;
......@@ -53,10 +53,10 @@ void MeteorDDP::init( const QString &pUri )
connect( &mWebsocket, &QWebSocket::connected, this, &MeteorDDP::onConnected, Qt::UniqueConnection );
connect( &mWebsocket, &QWebSocket::disconnected, this, &MeteorDDP::ddpDisconnected );
connect( this, &MeteorDDP::sendMessageSignal, this, &MeteorDDP::sendJson, Qt::UniqueConnection );
connect( &mWebsocket, QOverload<QAbstractSocket::SocketError>::of(&QWebSocket::error),
[=](QAbstractSocket::SocketError error){
qDebug()<<mWebsocket.errorString();
});
connect( &mWebsocket, QOverload<QAbstractSocket::SocketError>::of( &QWebSocket::error ),
[ = ]( QAbstractSocket::SocketError error ) {
qDebug() << mWebsocket.errorString();
} );
mWebsocket.open( wsUri );
QDateTime now = QDateTime::currentDateTime();
......@@ -231,46 +231,32 @@ void MeteorDDP::sendRequest( const QSharedPointer<DDPRequest> &pDdpRequest )
void MeteorDDP::resume()
{
qDebug() << "resuming ddp";
#if defined(Q_OS_ANDROID) || defined(Q_OS_LINUX) ||defined(Q_OS_WIN) || defined(Q_OS_OSX)
qDebug() << "websocket valid: " << mWebsocket.isValid();
QUrl wsUri = QUrl( QStringLiteral( "wss://" ) + mWebsocketUri + QStringLiteral( "/websocket" ) );
if ( mWebsocket.state() == QAbstractSocket::UnconnectedState ) {
qDebug() << "websocket valid: " << mWebsocket.isValid();
QUrl wsUri = QUrl( QStringLiteral( "wss://" ) + mWebsocketUri + QStringLiteral( "/websocket" ) );
if ( mWebsocket.state() == QAbstractSocket::UnconnectedState ) {
mWebsocket.open( wsUri );
} else if ( mWebsocket.state() != QAbstractSocket::ConnectingState ) {
auto const connection = new QMetaObject::Connection;
*connection = connect( &mWebsocket, &QWebSocket::disconnected, [ = ]() {
qDebug() << "websocket closed";
mWebsocket.open( wsUri );
} else if ( mWebsocket.state() != QAbstractSocket::ConnectingState ) {
auto const connection = new QMetaObject::Connection;
*connection = connect( &mWebsocket, &QWebSocket::disconnected, [ = ]() {
qDebug() << "websocket closed";
mWebsocket.open( wsUri );
QDateTime now = QDateTime::currentDateTime();
uint currentTime = now.toTime_t();
mLastPing = currentTime;
if ( connection != nullptr ) {
QObject::disconnect( *connection );
delete connection;
}
} );
mWebsocket.close();
}
if ( mWebsocket.state() == QAbstractSocket::UnconnectedState ) {
// connectWithServer();
}
QDateTime now = QDateTime::currentDateTime();
uint currentTime = now.toTime_t();
mLastPing = currentTime;
#else
qDebug() << "resuming ddp";
mWebsocket.close();
connect(&mWebsocket , &QWebSocket::disconnected, [&]() {
qDebug()<<"disconnected";
init( mWebsocketUri );
if ( connection != nullptr ) {
QObject::disconnect( *connection );
delete connection;
}
} );
mWebsocket.close();
}
#endif
if ( mWebsocket.state() == QAbstractSocket::UnconnectedState ) {
// connectWithServer();
}
}
void MeteorDDP::unsetResponseBinding( const QString &pId )
......
......@@ -35,8 +35,13 @@ int SortedVector<T>::insertSort( const QSharedPointer<T> &pointer )
return ( *first ) > ( *second );
} );
row = std::distance(this->begin(), elementSmallerThanNew);
this->insert( elementSmallerThanNew, pointer );
row = elementSmallerThanNew - this->begin();
if(row <0 || row>1000){
qDebug()<<elementSmallerThanNew;
qDebug()<<"error";
}
}
return row;
......
......@@ -25,9 +25,18 @@
#include <QVector>
#include <QSharedPointer>
#include <QMutex>
struct SortedVectorProperties
{
enum class sortOrder{
asc,
dsc
};
};
template<typename T> class SortedVector : public QVector<QSharedPointer<T>>
{
public:
int insertSort( const QSharedPointer<T> & );
int findInsertPosition( const QSharedPointer<T> & ) const;
int findPosition( const QSharedPointer<T> & ) const;
......
......@@ -371,9 +371,9 @@ 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);
if(mUpdatedAt != updatedAt && updatedAt != -1){
if(mUpdatedAt != -1 ){
emit updatedChanged(mRoomId,updatedAt);
}
mUpdatedAt = updatedAt;
}
......
......@@ -112,8 +112,8 @@ QVector<QSharedPointer<RocketChatChannel> > RocketChatChannelService::processCha
qint64 updatedAt = -1;
if ( currentChannelObject.contains( QStringLiteral( "_updatedAt" ) ) ) {
auto updatedObj = currentChannelObject[QStringLiteral( "_updatedAt" )].toObject();
if ( currentChannelObject.contains( QStringLiteral( "ls" ) ) ) {
auto updatedObj = currentChannelObject[QStringLiteral( "ls" )].toObject();
updatedAt = static_cast<qint64>( updatedObj[QStringLiteral( "$date" )].toDouble() );
}
......