From 9b522a6ad1651b1ffcc7e70cbc06366f35a839f8 Mon Sep 17 00:00:00 2001 From: MRXY001 Date: Sun, 23 May 2021 13:23:08 +0800 Subject: [PATCH] =?UTF-8?q?=E9=87=8D=E6=9E=84=E5=9B=9E=E5=A4=8D=E9=80=BB?= =?UTF-8?q?=E8=BE=91=EF=BC=8C=E5=85=A8=E9=83=BD=E6=94=BEservice=E4=B8=AD?= =?UTF-8?q?=E8=B0=83=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mainwindow.cpp | 47 +++------------------ web_service/cqhttpservice.cpp | 67 ++++++++++++++++++++++++------ web_service/cqhttpservice.h | 6 +++ widgets/settings/accountwidget.cpp | 6 --- 4 files changed, 67 insertions(+), 59 deletions(-) diff --git a/mainwindow.cpp b/mainwindow.cpp index 3781879..4bf13b3 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -217,15 +217,7 @@ void MainWindow::initService() connect(service, SIGNAL(signalMessage(const MsgBean&)), this, SLOT(autoReplyMessage(const MsgBean&))); - connect(sig, &SignalTransfer::loadGroupMembers, service, [=](qint64 groupId) { - MyJson json; - json.insert("action", "get_group_member_list"); - MyJson params; - params.insert("group_id", groupId); - json.insert("params", params); - json.insert("echo", "get_group_member_list:" + snum(groupId)); - service->sendMessage(json.toBa()); - }); + connect(sig, &SignalTransfer::loadGroupMembers, service, &CqhttpService::refreshGroupMembers); } void MainWindow::initKey() @@ -373,28 +365,10 @@ void MainWindow::createNotificationBanner(const MsgBean &msg) adjustUnderCardsTop(index, -(card->height() + us->bannerSpacing)); notificationCards.removeOne(card); }); - connect(card, &NotificationCard::signalReplyPrivate, this, [=](qint64 userId, const QString& message) { - MyJson json; - json.insert("action", "send_private_msg"); - MyJson params; - params.insert("user_id", userId); - params.insert("message", message); - json.insert("params", params); - json.insert("echo", "send_private_msg"); - service->sendMessage(json.toBa()); - emit sig->myReplyUser(userId, message); - }); - connect(card, &NotificationCard::signalReplyGroup, this, [=](qint64 groupId, const QString& message) { - MyJson json; - json.insert("action", "send_group_msg"); - MyJson params; - params.insert("group_id", groupId); - params.insert("message", message); - json.insert("params", params); - json.insert("echo", "send_group_msg"); - service->sendMessage(json.toBa()); - emit sig->myReplyGroup(groupId, message); - }); + connect(card, &NotificationCard::signalReplyPrivate, service, &CqhttpService::sendUserMsg); + + connect(card, &NotificationCard::signalReplyGroup, service, &CqhttpService::sendGroupMsg); + connect(card, &NotificationCard::signalCancelReply, this, [=]{ returnToPrevWindow(); }); @@ -614,15 +588,6 @@ void MainWindow::triggerAiReply(const MsgBean &msg, int retry) answer = us->aiReplyPrefix + answer + us->aiReplySuffix; } - json = MyJson(); - json.insert("action", "send_private_msg"); - MyJson params; - params.insert("user_id", msg.senderId); - params.insert("message", answer); - json.insert("params", params); - json.insert("echo", "send_private_msg"); - service->sendMessage(json.toBa()); - - emit sig->myReplyUser(msg.senderId, answer); + service->sendUserMsg(msg.senderId, answer); }); } diff --git a/web_service/cqhttpservice.cpp b/web_service/cqhttpservice.cpp index 50822c4..f439c0d 100644 --- a/web_service/cqhttpservice.cpp +++ b/web_service/cqhttpservice.cpp @@ -59,20 +59,10 @@ void CqhttpService::loopStarted() socket->sendTextMessage(json.toBa()); } // 获取好友列表 - { - MyJson json; - json.insert("action", "get_friend_list"); - json.insert("echo", "get_friend_list"); - socket->sendTextMessage(json.toBa()); - } + refreshFriends(); // 获取群列表 - { - MyJson json; - json.insert("action", "get_group_list"); - json.insert("echo", "get_group_list"); - socket->sendTextMessage(json.toBa()); - } + refreshGroups(); } void CqhttpService::openHost(QString host, QString token) @@ -305,3 +295,56 @@ void CqhttpService::parseGroupUpload(const MyJson &json) emit signalMessage(msg); qInfo() << "收到群文件消息:" << group_id << ac->groupNames.value(group_id) << user_id << ac->friendNames.value(user_id) << name << size << id; } + +void CqhttpService::refreshFriends() +{ + MyJson json; + json.insert("action", "get_friend_list"); + json.insert("echo", "get_friend_list"); + socket->sendTextMessage(json.toBa()); +} + +void CqhttpService::refreshGroups() +{ + MyJson json; + json.insert("action", "get_group_list"); + json.insert("echo", "get_group_list"); + socket->sendTextMessage(json.toBa()); +} + +void CqhttpService::refreshGroupMembers(qint64 groupId) +{ + MyJson json; + json.insert("action", "get_group_member_list"); + MyJson params; + params.insert("group_id", groupId); + json.insert("params", params); + json.insert("echo", "get_group_member_list:" + snum(groupId)); + sendMessage(json.toBa()); +} + +void CqhttpService::sendUserMsg(qint64 userId, const QString& message) +{ + MyJson json; + json.insert("action", "send_private_msg"); + MyJson params; + params.insert("user_id", userId); + params.insert("message", message); + json.insert("params", params); + json.insert("echo", "send_private_msg"); + sendMessage(json.toBa()); + emit sig->myReplyUser(userId, message); +} + +void CqhttpService::sendGroupMsg(qint64 groupId, const QString& message) +{ + MyJson json; + json.insert("action", "send_group_msg"); + MyJson params; + params.insert("group_id", groupId); + params.insert("message", message); + json.insert("params", params); + json.insert("echo", "send_group_msg"); + sendMessage(json.toBa()); + emit sig->myReplyGroup(groupId, message); +} diff --git a/web_service/cqhttpservice.h b/web_service/cqhttpservice.h index 755ccd8..63a5027 100644 --- a/web_service/cqhttpservice.h +++ b/web_service/cqhttpservice.h @@ -29,6 +29,12 @@ public slots: void sendMessage(const QString& text); void messageReceived(const QString &message); + void refreshFriends(); + void refreshGroups(); + void refreshGroupMembers(qint64 groupId); + void sendUserMsg(qint64 userId, const QString &message); + void sendGroupMsg(qint64 groupId, const QString &message); + private: void parseEchoMessage(const MyJson& json); void parsePrivateMessage(const MyJson& json); diff --git a/widgets/settings/accountwidget.cpp b/widgets/settings/accountwidget.cpp index 41214da..c6f16af 100644 --- a/widgets/settings/accountwidget.cpp +++ b/widgets/settings/accountwidget.cpp @@ -29,12 +29,6 @@ AccountWidget::~AccountWidget() void AccountWidget::resotreSettings() { QString host = us->host; - // 加密 - QRegularExpressionMatch match; - if (host.indexOf(QRegularExpression(":(\\d+)"), 0, &match) > -1) - host.replace(match.captured(1), repeatString("*", match.captured(1).length())); - if (host.indexOf(QRegularExpression("://(\\w+)"), 0, &match) > -1) - host.replace(match.captured(1), repeatString("*", match.captured(1).length())); ui->hostEdit->setText(host); QString token = us->accessToken;