From 0d3a5cbad11e2fb00931696182fc20e2e69e8836 Mon Sep 17 00:00:00 2001 From: Armin <armin.felder@osalliance.com> Date: Fri, 12 Jan 2018 15:34:50 +0100 Subject: [PATCH] added code to remove channel --- CustomModels/channelmodel.cpp | 19 +++++++++++++++++-- CustomModels/channelmodel.h | 2 +- repos/entities/rocketchatchannel.cpp | 2 +- repos/entities/rocketchatchannel.h | 2 +- 4 files changed, 20 insertions(+), 5 deletions(-) diff --git a/CustomModels/channelmodel.cpp b/CustomModels/channelmodel.cpp index 00debb8..749fd93 100644 --- a/CustomModels/channelmodel.cpp +++ b/CustomModels/channelmodel.cpp @@ -196,9 +196,24 @@ void ChannelModel::onDataChanged( const QString &id, const QString &property ) } } -void ChannelModel::onDeleted( bool ) +void ChannelModel::onDeleted( const QString &pId, bool deleted ) { - //TODO: implement + if ( channelList.contains( pId ) ) { + int idx = -1; + + for ( int i = 0; i < channelList.length(); i++ ) { + if ( channelList.at( i ).getRoomId() == pId ) { + idx = i; + break; + } + } + + if ( idx != -1 ) { + beginRemoveRows( QModelIndex(), idx, idx ); + channelList.remove( idx ); + endRemoveRows(); + } + } } void ChannelModel::addChannelSlot( const QSharedPointer<RocketChatChannel> &channel ) diff --git a/CustomModels/channelmodel.h b/CustomModels/channelmodel.h index 3f17751..03dd2a7 100644 --- a/CustomModels/channelmodel.h +++ b/CustomModels/channelmodel.h @@ -66,7 +66,7 @@ class ChannelModel : public QAbstractListModel void onNewerMessage( const QString &id, qint64 timestamp ); void onUnreadMessageChanged( const QString &id, int number ); void onDataChanged( const QString &id, const QString &property ); - void onDeleted( bool ); + void onDeleted( const QString &pId, bool deleted ); QTimer timer; signals: void countChanged( void ); diff --git a/repos/entities/rocketchatchannel.cpp b/repos/entities/rocketchatchannel.cpp index d45cc61..289310f 100755 --- a/repos/entities/rocketchatchannel.cpp +++ b/repos/entities/rocketchatchannel.cpp @@ -253,7 +253,7 @@ bool RocketChatChannel::getDeleted() const void RocketChatChannel::setDeleted( bool deleted ) { mDeleted = deleted; - emit channelDeleted( deleted ); + emit channelDeleted( this->getRoomId(), deleted ); } bool RocketChatChannel::getBlocked() const { diff --git a/repos/entities/rocketchatchannel.h b/repos/entities/rocketchatchannel.h index b516791..51df694 100755 --- a/repos/entities/rocketchatchannel.h +++ b/repos/entities/rocketchatchannel.h @@ -128,7 +128,7 @@ class RocketChatChannel : public QObject void messageListReceived( QString pChannelId, QList<ChatMessage> pMessages ); void messageAdded( QString id, qint64 timestamp ); void unreadMessagesChanged( QString id, int number ); - void channelDeleted( bool ); + void channelDeleted( const QString &pId, bool deleted ); void dataChanged( QString id, QString property ); }; -- GitLab