diff --git a/.clang-format b/.clang-format index 1c4340a6..a145fa69 100644 --- a/.clang-format +++ b/.clang-format @@ -5,7 +5,9 @@ IncludeCategories: - Regex: '^"config\.h"' Priority: -1 # The main header for a source file automatically gets category 0 - - Regex: '.*' + - Regex: '^<[^.]*>' Priority: 1 - - Regex: '^<.*\.h>' + - Regex: '^<.*>' Priority: 2 + - Regex: '.*' + Priority: 3 diff --git a/examples/count-bot/main.cpp b/examples/count-bot/main.cpp index d12803d3..d167d6b5 100644 --- a/examples/count-bot/main.cpp +++ b/examples/count-bot/main.cpp @@ -23,9 +23,9 @@ void processNewMessageEvent(shared_ptr ct, LOG(INFO) << "New Message Event: " << endl; LOG(INFO) << " From: " << para.getPal()->GetKey().ToString() << endl; for (auto& chip : para.dtlist) { - LOG(INFO) << " Message: " << chip.ToString() << endl; + LOG(INFO) << " Message: " << chip->ToString() << endl; ostringstream oss; - oss << "your message has " << chip.data.size() << " bytes."; + oss << "your message has " << chip->data.size() << " bytes."; ct->SendMessage(para.getPal(), oss.str()); } } diff --git a/src/api/iptux-core/CoreThread.h b/src/api/iptux-core/CoreThread.h index eee5c853..6d632036 100644 --- a/src/api/iptux-core/CoreThread.h +++ b/src/api/iptux-core/CoreThread.h @@ -1,16 +1,15 @@ #ifndef IPTUX_CORETHREAD_H #define IPTUX_CORETHREAD_H -#include "iptux-core/Models.h" #include #include #include -#include #include - +#include #include - +#include "iptux-core/Const.h" #include "iptux-core/Event.h" +#include "iptux-core/Models.h" #include "iptux-core/ProgramData.h" #include "iptux-core/TransFileModel.h" @@ -126,13 +125,22 @@ class CoreThread { * @return false if send failed */ bool SendMessage(CPPalInfo pal, const std::string& message); - bool SendMessage(CPPalInfo pal, const ChipData& chipData); + bool SendMessage(CPPalInfo pal, + enum GroupMsgOption opttype, + std::shared_ptr chipData); bool SendMsgPara(std::shared_ptr msgPara); + bool SendMsgPara(CPPalInfo pal, + enum GroupMsgOption opttype, + std::shared_ptr msgPara); void AsyncSendMsgPara(std::shared_ptr msgPara); void SendUnitMessage(const PalKey& palKey, uint32_t opttype, const std::string& message); + void SendUnitMessage(const PalKey& palKey, + enum GroupMsgOption opttype, + std::shared_ptr msgPara); void SendGroupMessage(const PalKey& palKey, const std::string& message); + void SendGroupMessage(const PalKey& palKey, std::shared_ptr msgPara); bool SendAskShared(PPalInfo pal); bool SendAskSharedWithPassword(const PalKey& palKey, diff --git a/src/api/iptux-core/Models.h b/src/api/iptux-core/Models.h index 94cb1a3e..887eedbd 100644 --- a/src/api/iptux-core/Models.h +++ b/src/api/iptux-core/Models.h @@ -197,8 +197,15 @@ using PFileInfo = std::shared_ptr; */ class ChipData { public: + static std::shared_ptr newTxtMsg(const std::string& text); + static std::shared_ptr newImgMsg(const std::string& picPath, + bool deleteFileAfterSent = true); + + private: explicit ChipData(const std::string& data); ChipData(MessageContentType type, const std::string& data); + + public: ~ChipData(); std::string ToString() const; @@ -226,9 +233,9 @@ class MsgPara { CPPalInfo getPal() const { return pal; } - MessageSourceType stype; ///< 来源类型 - GroupBelongType btype; ///< 所属类型 - std::vector dtlist; ///< 数据链表 * + MessageSourceType stype; ///< 来源类型 + GroupBelongType btype; ///< 所属类型 + std::vector> dtlist; ///< 数据链表 * private: CPPalInfo pal; ///< 好友数据信息(来自好友*) }; diff --git a/src/iptux-core/Const.h b/src/iptux-core/Const.h index c54814d0..9b7bbf12 100644 --- a/src/iptux-core/Const.h +++ b/src/iptux-core/Const.h @@ -13,10 +13,12 @@ const int MAX_PHOTOSIZE = 300; const int MAX_UDPLEN = 8192; const int MAX_SHAREDFILE = 10000; -const uint32_t IPTUX_REGULAROPT = 0x00000100UL; -const uint32_t IPTUX_SEGMENTOPT = 0x00000200UL; -const uint32_t IPTUX_GROUPOPT = 0x00000300UL; -const uint32_t IPTUX_BROADCASTOPT = 0x00000400UL; +enum GroupMsgOption { + IPTUX_REGULAROPT = 0x00000100UL, + IPTUX_SEGMENTOPT = 0x00000200UL, + IPTUX_GROUPOPT = 0x00000300UL, + IPTUX_BROADCASTOPT = 0x00000400UL, +}; } // namespace iptux -#endif \ No newline at end of file +#endif diff --git a/src/iptux-core/CoreThread.cpp b/src/iptux-core/CoreThread.cpp index 400b5a03..859cef03 100644 --- a/src/iptux-core/CoreThread.cpp +++ b/src/iptux-core/CoreThread.cpp @@ -1,6 +1,5 @@ #include "config.h" #include "iptux-core/CoreThread.h" - #include #include #include @@ -8,14 +7,13 @@ #include #include #include - #include #include #include #include #include - #include "iptux-core/Exception.h" +#include "iptux-core/Models.h" #include "iptux-core/internal/Command.h" #include "iptux-core/internal/RecvFileData.h" #include "iptux-core/internal/SendFile.h" @@ -477,12 +475,13 @@ bool CoreThread::SendMessage(CPPalInfo palInfo, const string& message) { return true; } -bool CoreThread::SendMessage(CPPalInfo pal, const ChipData& chipData) { - auto ptr = chipData.data.c_str(); - switch (chipData.type) { +bool CoreThread::SendMessage(CPPalInfo pal, + enum GroupMsgOption option, + shared_ptr chipData) { + switch (chipData->type) { case MessageContentType::STRING: /* 文本类型 */ - return SendMessage(pal, chipData.data); + return SendMessage(pal, chipData->data); case MESSAGE_CONTENT_TYPE_PICTURE: /* 图片类型 */ int sock; @@ -491,12 +490,9 @@ bool CoreThread::SendMessage(CPPalInfo pal, const ChipData& chipData) { strerror(errno)); return false; } - Command(*this).SendSublayer(sock, pal, IPTUX_MSGPICOPT, ptr); + Command(*this).SendSublayer(sock, pal, IPTUX_MSGPICOPT, + chipData->data.c_str()); close(sock); // 关闭网络套接口 - /*/* 删除此图片 */ - if (chipData.GetDeleteFileAfterSent()) { - unlink(ptr); // 此文件已无用处 - } return true; default: g_assert_not_reached(); @@ -504,9 +500,15 @@ bool CoreThread::SendMessage(CPPalInfo pal, const ChipData& chipData) { } bool CoreThread::SendMsgPara(shared_ptr para) { + return SendMsgPara(para->getPal(), IPTUX_REGULAROPT, para); +} + +bool CoreThread::SendMsgPara(CPPalInfo pal, + enum GroupMsgOption option, + shared_ptr para) { for (int i = 0; i < int(para->dtlist.size()); ++i) { - if (!SendMessage(para->getPal(), para->dtlist[i])) { - LOG_ERROR("send message failed: %s", para->dtlist[i].ToString().c_str()); + if (!SendMessage(pal, para->dtlist[i])) { + LOG_ERROR("send message failed: %s", para->dtlist[i]->ToString().c_str()); return false; } } @@ -709,6 +711,13 @@ void CoreThread::SendUnitMessage(const PalKey& palKey, Command(*this).SendUnitMsg(udpSock, GetPal(palKey), opttype, message.c_str()); } +void CoreThread::SendUnitMessage(const PalKey& palKey, + enum GroupMsgOption opttype, + std::shared_ptr msgPara) { + auto pal = ((const CoreThread*)this)->GetPal(palKey); + SendMsgPara(pal, msgPara); +} + void CoreThread::SendGroupMessage(const PalKey& palKey, const std::string& message) { Command(*this).SendGroupMsg(udpSock, GetPal(palKey), message.c_str()); diff --git a/src/iptux-core/CoreThreadTest.cpp b/src/iptux-core/CoreThreadTest.cpp index 8cf35495..2df40ed3 100644 --- a/src/iptux-core/CoreThreadTest.cpp +++ b/src/iptux-core/CoreThreadTest.cpp @@ -83,7 +83,7 @@ TEST(CoreThread, SendMessage_ChipData) { CoreThread* thread = new CoreThread(core); auto pal = make_shared("127.0.0.1", 2425); thread->AttachPalToList(pal); - ChipData chipData("hello world"); + auto chipData = ChipData::newTxtMsg("hello world"); EXPECT_TRUE(thread->SendMessage(pal, chipData)); delete thread; } @@ -95,7 +95,7 @@ TEST(CoreThread, SendMsgPara) { CoreThread* thread = new CoreThread(core); PPalInfo pal = make_shared("127.0.0.1", 2425); thread->AttachPalToList(pal); - ChipData chipData("hello world"); + auto chipData = ChipData::newTxtMsg("hello world"); auto para = make_shared(pal); para->dtlist.push_back(std::move(chipData)); EXPECT_TRUE(thread->SendMsgPara(para)); @@ -179,7 +179,7 @@ TEST(CoreThread, FullCase) { } auto event2 = dynamic_pointer_cast(event); - ASSERT_EQ(event2->getMsgPara().dtlist[0].ToString(), + ASSERT_EQ(event2->getMsgPara().dtlist[0]->ToString(), "ChipData(MessageContentType::STRING, hello world)"); { lock_guard l(thread2EventsMutex); @@ -204,8 +204,7 @@ TEST(CoreThread, FullCase) { thread1->SendAskShared(pal2InThread1); // send picture - ChipData chipData(MessageContentType::PICTURE, testDataPath("iptux.png")); - chipData.SetDeleteFileAfterSent(false); + auto chipData = ChipData::newImgMsg(testDataPath("iptux.png"), false); thread1->SendMessage(pal2InThread1, chipData); // WARNING: does not work as expected, the message will be sent from // 127.0.0.2(expect 127.0.0.1) while(thread2Events.size() != 2) { diff --git a/src/iptux-core/Models.cpp b/src/iptux-core/Models.cpp index 8de2dd3d..ef42e0dc 100644 --- a/src/iptux-core/Models.cpp +++ b/src/iptux-core/Models.cpp @@ -26,6 +26,8 @@ using namespace std; namespace iptux { +// MARK: PalInfo + PalInfo::PalInfo(in_addr ipv4, uint16_t port) : segdes(NULL), photo(NULL), sign(NULL), packetn(0), rpacketn(0) { this->ipv4_ = ipv4; @@ -120,6 +122,8 @@ string PalInfo::toString() const { int(rpacketn), compatible, online, changed, in_blacklist); } +// MARK: FileInfo + FileInfo::FileInfo() : fileid(0), packetn(0), @@ -160,6 +164,17 @@ void FileInfo::ensureFilesizeFilled() { filesize = afs.ftwsize(filepath); } +bool FileInfo::operator==(const FileInfo& rhs) const { + const FileInfo& lhs = *this; + return lhs.fileid == rhs.fileid && lhs.packetn == rhs.packetn && + lhs.fileattr == rhs.fileattr && lhs.filesize == rhs.filesize && + lhs.finishedsize == rhs.finishedsize && + lhs.filectime == rhs.filectime && lhs.filemtime == rhs.filemtime && + lhs.filenum == rhs.filenum; +} + +// MARK: MsgPara + MsgPara::MsgPara(CPPalInfo pal) : stype(MessageSourceType::PAL), btype(GROUP_BELONG_TYPE_REGULAR), @@ -171,14 +186,65 @@ string MsgPara::getSummary() const { if (this->dtlist.empty()) { return _("Empty Message"); } - return this->dtlist[0].getSummary(); + return this->dtlist[0]->getSummary(); +} + +// MARK: ChipData + +shared_ptr ChipData::newTxtMsg(const std::string& text) { + return shared_ptr(new ChipData(text)); +} + +shared_ptr ChipData::newImgMsg(const std::string& text, + bool deleteFileAfterSent) { + auto res = + shared_ptr(new ChipData(MessageContentType::PICTURE, text)); + res->deleteFileAfterSent = deleteFileAfterSent; + return res; } ChipData::ChipData(const string& data) : type(MessageContentType::STRING), data(data) {} ChipData::ChipData(MessageContentType type, const string& data) : type(type), data(data) {} -ChipData::~ChipData() {} +ChipData::~ChipData() { + if (type == MessageContentType::PICTURE && deleteFileAfterSent) { + g_unlink(data.c_str()); + } +} + +string ChipData::ToString() const { + ostringstream oss; + oss << "ChipData("; + switch (type) { + case MessageContentType::STRING: + oss << "MessageContentType::STRING"; + break; + case MessageContentType::PICTURE: + oss << "MessageContentType::PICTURE"; + break; + default: + g_assert_not_reached(); + } + oss << ", "; + oss << data; + oss << ")"; + return oss.str(); +} + +string ChipData::getSummary() const { + switch (type) { + case MessageContentType::STRING: + return data; + case MessageContentType::PICTURE: + return _("Received an image"); + default: + g_assert_not_reached(); + } + return ""; +} + +// MARK: NetSegment NetSegment::NetSegment() {} @@ -223,36 +289,7 @@ NetSegment NetSegment::fromJsonValue(Json::Value& value) { return res; } -string ChipData::ToString() const { - ostringstream oss; - oss << "ChipData("; - switch (type) { - case MessageContentType::STRING: - oss << "MessageContentType::STRING"; - break; - case MessageContentType::PICTURE: - oss << "MessageContentType::PICTURE"; - break; - default: - g_assert_not_reached(); - } - oss << ", "; - oss << data; - oss << ")"; - return oss.str(); -} - -string ChipData::getSummary() const { - switch (type) { - case MessageContentType::STRING: - return data; - case MessageContentType::PICTURE: - return _("Received an image"); - default: - g_assert_not_reached(); - } - return ""; -} +// MARK: PalKey PalKey::PalKey(in_addr ipv4, int port) : ipv4(ipv4), port(port) {} @@ -268,13 +305,4 @@ string PalKey::ToString() const { return stringFormat("%s:%d", inAddrToString(ipv4).c_str(), port); } -bool FileInfo::operator==(const FileInfo& rhs) const { - const FileInfo& lhs = *this; - return lhs.fileid == rhs.fileid && lhs.packetn == rhs.packetn && - lhs.fileattr == rhs.fileattr && lhs.filesize == rhs.filesize && - lhs.finishedsize == rhs.finishedsize && - lhs.filectime == rhs.filectime && lhs.filemtime == rhs.filemtime && - lhs.filenum == rhs.filenum; -} - } // namespace iptux diff --git a/src/iptux-core/ModelsTest.cpp b/src/iptux-core/ModelsTest.cpp index d9dba76f..e7e18a80 100644 --- a/src/iptux-core/ModelsTest.cpp +++ b/src/iptux-core/ModelsTest.cpp @@ -50,13 +50,14 @@ TEST(NetSegment, ContainIP) { } TEST(ChipData, ToString) { - EXPECT_EQ(ChipData("").ToString(), "ChipData(MessageContentType::STRING, )"); + EXPECT_EQ(ChipData::newTxtMsg("")->ToString(), + "ChipData(MessageContentType::STRING, )"); } TEST(ChipData, getSummary) { - EXPECT_EQ(ChipData("").getSummary(), ""); - EXPECT_EQ(ChipData("foobar").getSummary(), "foobar"); - EXPECT_EQ(ChipData(MessageContentType::PICTURE, "foobar").getSummary(), + EXPECT_EQ(ChipData::newTxtMsg("")->getSummary(), ""); + EXPECT_EQ(ChipData::newTxtMsg("foobar")->getSummary(), "foobar"); + EXPECT_EQ(ChipData::newImgMsg("foobar", false)->getSummary(), "Received an image"); } @@ -72,12 +73,12 @@ TEST(MsgPara, getSummary) { auto pal = make_shared("127.0.0.1", 2425); MsgPara msg(pal); EXPECT_EQ(msg.getSummary(), "Empty Message"); - msg.dtlist.push_back(ChipData("foobar")); + msg.dtlist.push_back(ChipData::newTxtMsg("foobar")); EXPECT_EQ(msg.getSummary(), "foobar"); - msg.dtlist.push_back(ChipData("foobar2")); + msg.dtlist.push_back(ChipData::newTxtMsg("foobar2")); EXPECT_EQ(msg.getSummary(), "foobar"); msg.dtlist.clear(); - msg.dtlist.push_back(ChipData(MessageContentType::PICTURE, "foobar")); + msg.dtlist.push_back(ChipData::newImgMsg("foobar", false)); EXPECT_EQ(msg.getSummary(), "Received an image"); } diff --git a/src/iptux-core/internal/Command.cpp b/src/iptux-core/internal/Command.cpp index a4fd25c0..23294fb1 100644 --- a/src/iptux-core/internal/Command.cpp +++ b/src/iptux-core/internal/Command.cpp @@ -487,7 +487,7 @@ void Command::FeedbackError(CPPalInfo pal, para.stype = MessageSourceType::ERROR; para.btype = btype; - ChipData chip(MESSAGE_CONTENT_TYPE_STRING, error); + auto chip = ChipData::newTxtMsg(error); para.dtlist.push_back(std::move(chip)); /* 交给某人处理吧 */ coreThread.InsertMessage(std::move(para)); diff --git a/src/iptux-core/internal/TcpData.cpp b/src/iptux-core/internal/TcpData.cpp index 84b3e9a0..5dd22466 100644 --- a/src/iptux-core/internal/TcpData.cpp +++ b/src/iptux-core/internal/TcpData.cpp @@ -221,8 +221,7 @@ void TcpData::RecvMsgPic(PalInfo* pal, const char* path) { /* 构建消息封装包 */ para.stype = MessageSourceType::PAL; para.btype = GROUP_BELONG_TYPE_REGULAR; - ChipData chip(MESSAGE_CONTENT_TYPE_PICTURE, path); - para.dtlist.push_back(chip); + para.dtlist.push_back(ChipData::newImgMsg(path, false)); /* 交给某人处理吧 */ coreThread->InsertMessage(std::move(para)); diff --git a/src/iptux-core/internal/UdpData.cpp b/src/iptux-core/internal/UdpData.cpp index 20942a32..05202914 100644 --- a/src/iptux-core/internal/UdpData.cpp +++ b/src/iptux-core/internal/UdpData.cpp @@ -24,6 +24,7 @@ #include #include "iptux-core/CoreThread.h" +#include "iptux-core/Models.h" #include "iptux-core/internal/Command.h" #include "iptux-core/internal/CommandMode.h" #include "iptux-core/internal/RecvFile.h" @@ -515,7 +516,7 @@ void UdpData::InsertMessage(PPalInfo pal, /* 构建消息封装包 */ para.stype = MessageSourceType::PAL; para.btype = btype; - ChipData chip(MESSAGE_CONTENT_TYPE_STRING, msg); + auto chip = ChipData::newTxtMsg(msg); para.dtlist.push_back(std::move(chip)); /* 交给某人处理吧 */ diff --git a/src/iptux/DialogBase.cpp b/src/iptux/DialogBase.cpp index a24f820c..abfbfe7f 100644 --- a/src/iptux/DialogBase.cpp +++ b/src/iptux/DialogBase.cpp @@ -391,17 +391,13 @@ bool DialogBase::SendEnclosureMsg() { return true; } -/** - * 回馈消息. - * @param msg 消息 - */ -void DialogBase::FeedbackMsg(const gchar* msg) { - MsgPara para(this->app->getMe()); +void DialogBase::FeedbackMsg(shared_ptr msgPara) { + MsgPara para(grpinf->getMembers()[0]); + para.stype = MessageSourceType::SELF; para.btype = grpinf->getType(); + para.dtlist = msgPara->dtlist; - ChipData chip(msg); - para.dtlist.push_back(std::move(chip)); grpinf->addMsgPara(para); } diff --git a/src/iptux/DialogBase.h b/src/iptux/DialogBase.h index e424882c..080806a0 100644 --- a/src/iptux/DialogBase.h +++ b/src/iptux/DialogBase.h @@ -57,7 +57,7 @@ class DialogBase : public SessionAbstract, public sigc::trackable { bool SendEnclosureMsg(); virtual bool SendTextMsg() = 0; /* TODO: Group SendTextMsg need add Picture */ - void FeedbackMsg(const gchar* msg); + void FeedbackMsg(std::shared_ptr msgPara); virtual void BroadcastEnclosureMsg(const std::vector& files) = 0; // 回调部分 diff --git a/src/iptux/DialogGroup.cpp b/src/iptux/DialogGroup.cpp index 53fb9d49..73224060 100644 --- a/src/iptux/DialogGroup.cpp +++ b/src/iptux/DialogGroup.cpp @@ -11,11 +11,10 @@ // #include "config.h" #include "DialogGroup.h" - #include #include - #include "iptux-core/Const.h" +#include "iptux-core/Models.h" #include "iptux-utils/output.h" #include "iptux-utils/utils.h" #include "iptux/DialogPeer.h" @@ -425,12 +424,12 @@ void DialogGroup::BroadcastEnclosureMsg(const vector& files) { * 向选中的好友广播文本消息. * @param msg 文本消息 */ -void DialogGroup::BroadcastTextMsg(const gchar* msg) { +void DialogGroup::broadcastTextMsg(shared_ptr para) { GtkWidget* widget; GtkTreeModel* model; GtkTreeIter iter; gboolean active; - uint32_t opttype; + enum GroupMsgOption opttype; PalInfo* pal; /* 考察是否有成员 */ @@ -459,9 +458,9 @@ void DialogGroup::BroadcastTextMsg(const gchar* msg) { opttype = IPTUX_REGULAROPT; break; } - app->getCoreThread()->SendUnitMessage(pal->GetKey(), opttype, msg); + app->getCoreThread()->SendUnitMessage(pal->GetKey(), opttype, para); } else { - app->getCoreThread()->SendGroupMessage(pal->GetKey(), msg); + app->getCoreThread()->SendGroupMessage(pal->GetKey(), para); } } } while (gtk_tree_model_iter_next(model, &iter)); @@ -597,30 +596,16 @@ void DialogGroup::MembertreeItemActivated(GtkWidget* treeview, } bool DialogGroup::SendTextMsg() { - GtkWidget* textview; - GtkTextBuffer* buffer; - GtkTextIter start, end; - gchar* msg; - - /* 考察缓冲区内是否存在数据 */ - textview = GTK_WIDGET(g_datalist_get_data(&widset, "input-textview-widget")); - gtk_widget_grab_focus(textview); // 为下一次任务做准备 - buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(textview)); - gtk_text_buffer_get_bounds(buffer, &start, &end); - if (gtk_text_iter_equal(&start, &end)) + gtk_widget_grab_focus(GTK_WIDGET(inputTextviewWidget)); // 为下一次任务做准备 + if (grpinf->isInputEmpty()) { return false; + } - /* 获取数据并发送 */ - msg = gtk_text_buffer_get_text(buffer, &start, &end, FALSE); - gtk_text_buffer_delete(buffer, &start, &end); - FeedbackMsg(msg); - BroadcastTextMsg(msg); - - MsgPara msgpara(this->app->getMe()); - msgpara.stype = MessageSourceType::SELF; - app->getLogSystem()->communicateLog(&msgpara, "[STRING]%s", msg); - g_free(msg); + shared_ptr msgpara = grpinf->genMsgParaFromInput(); + grpinf->clearInputBuffer(); + FeedbackMsg(msgpara); + broadcastTextMsg(msgpara); return true; } diff --git a/src/iptux/DialogGroup.h b/src/iptux/DialogGroup.h index 726276b5..0dab7904 100644 --- a/src/iptux/DialogGroup.h +++ b/src/iptux/DialogGroup.h @@ -57,11 +57,11 @@ class DialogGroup : public DialogBase { bool SendTextMsg() override; void BroadcastEnclosureMsg(const std::vector& files) override; - void BroadcastTextMsg(const gchar* msg); + void broadcastTextMsg(std::shared_ptr para); std::string GetTitle(); static GtkWidget* CreatePopupMenu(GtkTreeModel* model); - //回调处理部分 + // 回调处理部分 private: static void onUIChanged(DialogGroup& self); static gint MemberTreeCompareByNameFunc(GtkTreeModel* model, diff --git a/src/iptux/DialogPeer.cpp b/src/iptux/DialogPeer.cpp index b41395e6..89d177be 100644 --- a/src/iptux/DialogPeer.cpp +++ b/src/iptux/DialogPeer.cpp @@ -401,27 +401,12 @@ bool DialogPeer::SendTextMsg() { return true; } -/** - * 回馈消息. - * @param dtlist 数据链表 - * @note 请不要修改链表(dtlist)中的数据 - */ -void DialogPeer::FeedbackMsg(shared_ptr msgPara) { - MsgPara para(grpinf->getMembers()[0]); - - para.stype = MessageSourceType::SELF; - para.btype = grpinf->getType(); - para.dtlist = msgPara->dtlist; - - grpinf->addMsgPara(para); -} - /** * 封装消息. * @param dtlist 数据链表 * @return 消息封装包 */ -MsgPara* DialogPeer::PackageMsg(const std::vector& dtlist) { +MsgPara* DialogPeer::PackageMsg(const vector>& dtlist) { MsgPara* para; auto g_cthrd = app->getCoreThread(); diff --git a/src/iptux/DialogPeer.h b/src/iptux/DialogPeer.h index 041c9665..8069cfe0 100644 --- a/src/iptux/DialogPeer.h +++ b/src/iptux/DialogPeer.h @@ -13,11 +13,11 @@ #ifndef IPTUX_DIALOGPEER_H #define IPTUX_DIALOGPEER_H +#include #include "iptux-core/IptuxConfig.h" #include "iptux-core/Models.h" #include "iptux/Application.h" #include "iptux/DialogBase.h" -#include namespace iptux { @@ -64,8 +64,7 @@ class DialogPeer : public DialogBase { void BroadcastEnclosureMsg(const std::vector& files) override; bool SendTextMsg() override; - void FeedbackMsg(std::shared_ptr msgPara); - MsgPara* PackageMsg(const std::vector& dtlist); + MsgPara* PackageMsg(const std::vector>& dtlist); void refreshSendAction(); std::string GetTitle(); diff --git a/src/iptux/DialogPeerTest.cpp b/src/iptux/DialogPeerTest.cpp index c338ebcc..20591bde 100644 --- a/src/iptux/DialogPeerTest.cpp +++ b/src/iptux/DialogPeerTest.cpp @@ -43,13 +43,12 @@ TEST(DialogPeer, Constructor) { g_object_unref(pixbuf); MsgPara msg(pal); - msg.dtlist.push_back(ChipData("helloworld")); + msg.dtlist.push_back(ChipData::newTxtMsg("helloworld")); grpinf->addMsgPara(msg); msg = MsgPara(pal); - msg.dtlist.push_back( - ChipData(MessageContentType::PICTURE, testDataPath("iptux.png"))); + msg.dtlist.push_back(ChipData::newImgMsg(testDataPath("iptux.png"), false)); grpinf->addMsgPara(msg); DestroyApplication(app); diff --git a/src/iptux/UiModels.cpp b/src/iptux/UiModels.cpp index c9ec4f6f..b1fa569c 100644 --- a/src/iptux/UiModels.cpp +++ b/src/iptux/UiModels.cpp @@ -477,7 +477,7 @@ shared_ptr GroupInfo::genMsgParaFromInput() const { GdkPixbuf* pixbuf; char buf[7]; gchar* chipmsg; - std::vector dtlist; + std::vector> dtlist; gtk_text_buffer_get_start_iter(inputBuffer, &start); ostringstream oss; @@ -487,8 +487,8 @@ shared_ptr GroupInfo::genMsgParaFromInput() const { break; if (ig_unichar_is_atomic(c)) { if (!oss.str().empty()) { - ChipData chip(MESSAGE_CONTENT_TYPE_STRING, oss.str()); - dtlist.push_back(std::move(chip)); + auto chip = ChipData::newTxtMsg(oss.str()); + dtlist.push_back(chip); oss.str(""); } pixbuf = gtk_text_iter_get_pixbuf(&start); @@ -501,7 +501,7 @@ shared_ptr GroupInfo::genMsgParaFromInput() const { g_error_free(error); } else { /* 新建一个碎片数据(图片),并加入数据链表 */ - ChipData chip(MESSAGE_CONTENT_TYPE_PICTURE, chipmsg); + auto chip = ChipData::newImgMsg(chipmsg, false); dtlist.push_back(std::move(chip)); } } else { @@ -511,7 +511,7 @@ shared_ptr GroupInfo::genMsgParaFromInput() const { gtk_text_iter_forward_char(&start); } if (!oss.str().empty()) { - ChipData chip(MESSAGE_CONTENT_TYPE_STRING, oss.str()); + auto chip = ChipData::newTxtMsg(oss.str()); dtlist.push_back(std::move(chip)); } @@ -762,7 +762,7 @@ void GroupInfo::_addMsgPara(const MsgPara& para, time_t now) { time(&last_activity_); for (size_t i = 0; i < para.dtlist.size(); ++i) { - const ChipData* chipData = ¶.dtlist[i]; + auto chipData = para.dtlist[i]; data = chipData->data.c_str(); switch (chipData->type) { case MESSAGE_CONTENT_TYPE_STRING: diff --git a/src/iptux/UiModelsTest.cpp b/src/iptux/UiModelsTest.cpp index 00235c1c..f306004a 100644 --- a/src/iptux/UiModelsTest.cpp +++ b/src/iptux/UiModelsTest.cpp @@ -101,7 +101,7 @@ TEST(GroupInfo, addMsgPara) { gi.buffer = gtk_text_buffer_new(nullptr); MsgPara msg(cpal); - msg.dtlist.push_back(ChipData("helloworld")); + msg.dtlist.push_back(ChipData::newTxtMsg("helloworld")); time_t now = 1716533706; setenv("TZ", "GMT", 1); @@ -112,8 +112,7 @@ TEST(GroupInfo, addMsgPara) { "(06:55:06) palname:\nhelloworld\n"); msg = MsgPara(cpal); - msg.dtlist.push_back( - ChipData(MessageContentType::PICTURE, testDataPath("iptux.png"))); + msg.dtlist.push_back(ChipData::newImgMsg(testDataPath("iptux.png"), false)); gi._addMsgPara(msg, now + 1); ASSERT_EQ( igtk_text_get_all_text(gi.buffer), @@ -141,8 +140,8 @@ TEST(GroupInfo, genMsgParaFromInput) { gtk_text_buffer_insert(buffer, &end, "hello", -1); para = gi.genMsgParaFromInput(); ASSERT_EQ(para->dtlist.size(), 1u); - ASSERT_EQ(para->dtlist[0].type, MessageContentType::STRING); - ASSERT_EQ(para->dtlist[0].data, "hello"); + ASSERT_EQ(para->dtlist[0]->type, MessageContentType::STRING); + ASSERT_EQ(para->dtlist[0]->data, "hello"); GError* error = NULL; auto pixbuf = @@ -155,14 +154,14 @@ TEST(GroupInfo, genMsgParaFromInput) { gtk_text_buffer_insert_pixbuf(buffer, &end, pixbuf); para = gi.genMsgParaFromInput(); ASSERT_EQ(para->dtlist.size(), 2u); - ASSERT_EQ(para->dtlist[1].type, MessageContentType::PICTURE); + ASSERT_EQ(para->dtlist[1]->type, MessageContentType::PICTURE); gtk_text_buffer_get_end_iter(buffer, &end); gtk_text_buffer_insert(buffer, &end, "world", -1); para = gi.genMsgParaFromInput(); ASSERT_EQ(para->dtlist.size(), 3u); - ASSERT_EQ(para->dtlist[2].type, MessageContentType::STRING); - ASSERT_EQ(para->dtlist[2].data, "world"); + ASSERT_EQ(para->dtlist[2]->type, MessageContentType::STRING); + ASSERT_EQ(para->dtlist[2]->data, "world"); ASSERT_FALSE(gi.isInputEmpty()); gi.clearInputBuffer(); ASSERT_TRUE(gi.isInputEmpty());