diff --git a/CustomModels/messagemodel.cpp b/CustomModels/messagemodel.cpp index 476234fc8287172c224f0e0c924c44ed62e91fd9..48940773bfe0355163e8fe586a0d59510c118132 100644 --- a/CustomModels/messagemodel.cpp +++ b/CustomModels/messagemodel.cpp @@ -101,6 +101,10 @@ QVariant MessagesModel::data( const QModelIndex &index, int role ) const return mBlockedUsers.contains( messageAtIndex->getAuthorId() ); } + if ( role == id ) { + return messageAtIndex->getId(); + } + qWarning() << "MessagesModel data not found for row"; return QVariant(); } @@ -188,6 +192,7 @@ QHash<int, QByteArray> MessagesModel::roleNames() const roles[formattedTime] = QByteArrayLiteral( "formattedTime" ); roles[messageType] = QByteArrayLiteral( "messageType" ); roles[blocked] = QByteArrayLiteral( "blocked" ); + roles[id] = QByteArrayLiteral( "id" ); return roles; } diff --git a/CustomModels/messagemodel.h b/CustomModels/messagemodel.h index 820c984199394eee6b0a14000809ee1f29b253e8..5b16434631e96af69bd135e0318ffff10a822f25 100644 --- a/CustomModels/messagemodel.h +++ b/CustomModels/messagemodel.h @@ -51,7 +51,8 @@ class MessagesModel : public QAbstractListModel formattedTime, messageType, authorId, - blocked + blocked, + id }; MessagesModel(); QVariant data( const QModelIndex &index, int role = Qt::DisplayRole ) const; diff --git a/rocketchat.cpp b/rocketchat.cpp index fcde95002fb5ea34d68229f7dcfc299e9f24bc70..58720120de354ad916fc09505fdefab10c0cc8c8 100755 --- a/rocketchat.cpp +++ b/rocketchat.cpp @@ -234,6 +234,11 @@ void RocketChat::hideChannel( const QString &pChannelId ) QMetaObject::invokeMethod( mServerMap.first(), "hideChannel", Q_ARG( QString, pChannelId ) ); } +void RocketChat::reportAbusiveContent( const QString &pMessageId, const QString &pAuthor ) +{ + QMetaObject::invokeMethod( mServerMap.first(), "reportAbusiveContent", Q_ARG( QString, pMessageId ), Q_ARG( QString, pAuthor ) ); +} + bool RocketChat::newServerByDomain( const QString &domain ) { newServerMutex.lock(); diff --git a/rocketchat.h b/rocketchat.h index 70c40827ed8b49ea2d94e887bd050f17fbf1dfe9..ef41f290d09c28d30ef70f49120eb8d2b5667a04 100755 --- a/rocketchat.h +++ b/rocketchat.h @@ -129,6 +129,8 @@ class RocketChat : public QObject Q_INVOKABLE void hideChannel( const QString &pChannelId ); + Q_INVOKABLE void reportAbusiveContent( const QString &pMessageId, const QString &pAuthor ); + void registerServer( RocketChatServerData *pServer ); diff --git a/rocketchatserver.cpp b/rocketchatserver.cpp index f28b51ce49a0fa243f6bb7d97e7bac2aa785c17f..237289e881132e2c174999fa46d73c4554e3186c 100755 --- a/rocketchatserver.cpp +++ b/rocketchatserver.cpp @@ -1715,6 +1715,11 @@ void RocketChatServerData::hideChannel( const QString &pId ) mChannelService->hideRoom( pId ); } +void RocketChatServerData::reportAbusiveContent( const QString &pMessageId, const QString &pAuthor ) +{ + mChannelService->reportContent( pMessageId, pAuthor ); +} + QList<QSharedPointer<RocketChatUser> > RocketChatServerData::getUserOfChannel( const QString &pChannelId ) { QList<QSharedPointer<RocketChatUser>> users; diff --git a/rocketchatserver.h b/rocketchatserver.h index e52f9dc74ccd750d3d3e033cbf9e9d85d43f15ac..8f1570759500efa0a54dc799db1e6d585c545acc 100755 --- a/rocketchatserver.h +++ b/rocketchatserver.h @@ -204,6 +204,8 @@ class RocketChatServerData : public QObject void hideChannel( const QString &pId ); + void reportAbusiveContent( const QString &pMessageId, const QString &pAuthor ); + public: QString getServerId() const; diff --git a/services/rocketchatchannelservice.cpp b/services/rocketchatchannelservice.cpp index 673a712ca3fe81b3aec0ab3e56e817ec25449742..8e57fad90c31103c3e5fad4711f55044869c9643 100755 --- a/services/rocketchatchannelservice.cpp +++ b/services/rocketchatchannelservice.cpp @@ -333,6 +333,40 @@ void RocketChatChannelService::hideRoom( const QString &pId ) deleteChannel( pId ); } +void RocketChatChannelService::reportContent( const QString &pMessageId, const QString &pAuthorId ) +{ + QJsonArray params = {QStringLiteral( "abuse" )}; + QSharedPointer<DDPMethodRequest> request( new DDPMethodRequest( QStringLiteral( "createDirectMessage" ), params ) ); + std::function<void ( QJsonObject, MeteorDDP * )> success = [ = ]( QJsonObject pResponse, MeteorDDP * pDdp ) { + if ( Q_LIKELY( pResponse.contains( QStringLiteral( "result" ) ) ) ) { + QJsonObject result = pResponse[QStringLiteral( "result" )].toObject(); + + if ( Q_LIKELY( result.contains( QStringLiteral( "rid" ) ) ) ) { + QString rid = result[QStringLiteral( "rid" )].toString(); + QSharedPointer<DDPSubscriptionRequest> subRoom( new DDPSubscriptionRequest( QStringLiteral( "room" ), {"d" + QStringLiteral( "abuse" )} ) ); + QSharedPointer<RocketChatSubscribeChannelRequest> subMessages( new RocketChatSubscribeChannelRequest( rid ) ); + QSharedPointer<RocketChatChannel> channel = createChannelObject( rid, QStringLiteral( "abuse" ), "d" ); + + if ( !channel.isNull() ) { + + emit channelsLoaded( {channel}, true ); + pDdp->sendRequest( subRoom ); + pDdp->sendRequest( subMessages ); + emit directChannelReady( rid ); + QString message = QStringLiteral( "Report message with id:" ) + pMessageId + QStringLiteral( " from user with id:" ) + pAuthorId; + QSharedPointer<RocketChatMessage> reportMessage( new RocketChatMessage( rid, message ) ); + mMessageService->sendMessage( reportMessage ); + } + } + } + + pDdp->unsetResponseBinding( request->getFrame() ); + + }; + request->setSuccess( success ); + mServer->sendDdprequest( request ); +} + void RocketChatChannelService::openPrivateChannelWith( QString pUsername ) { QJsonArray params = {pUsername}; diff --git a/services/rocketchatchannelservice.h b/services/rocketchatchannelservice.h index 36c4dd54965480717e05641351f230ce0dbb55bc..d8ccf0d8d0e628f488bf98a79d6c37292a22c9a5 100755 --- a/services/rocketchatchannelservice.h +++ b/services/rocketchatchannelservice.h @@ -80,6 +80,8 @@ class RocketChatChannelService : public QObject void hideRoom( const QString &pId ); + void reportContent( const QString &pMessageId, const QString &pAuthorId ); + ~RocketChatChannelService();