Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#610 cant send image in group chat #637

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

lidaobing
Copy link
Member

@lidaobing lidaobing commented Jul 14, 2024

Summary by Sourcery

This pull request introduces the ability to send image messages in group chats by adding new methods to the ChipData class and refactoring message handling to use shared pointers. It also includes bug fixes for image message sending and updates to the test suite to cover the new functionality.

  • New Features:
    • Added support for sending image messages in group chats by introducing new methods in the ChipData class for creating text and image messages.
  • Bug Fixes:
    • Fixed an issue where image messages could not be sent in group chats by updating the message broadcasting and sending logic.
  • Enhancements:
    • Refactored message handling to use shared pointers for ChipData objects, improving memory management and consistency across the codebase.
    • Updated the MsgPara class to use a vector of shared pointers to ChipData, allowing for more flexible and safer message handling.
  • Tests:
    • Updated existing tests to use the new ChipData methods for creating text and image messages.
    • Added new test cases to verify the correct creation and handling of image messages.

@lidaobing lidaobing linked an issue Jul 14, 2024 that may be closed by this pull request
@lidaobing lidaobing marked this pull request as draft July 14, 2024 04:54
Copy link

sourcery-ai bot commented Jul 14, 2024

Reviewer's Guide by Sourcery

This pull request addresses the issue of sending images in group chats. The changes primarily involve refactoring the ChipData class to support image messages, updating message handling in various classes, and modifying tests to accommodate the new functionality.

File-Level Changes

Files Changes
src/iptux-core/Models.cpp
src/iptux-core/Models.h
src/iptux-core/CoreThread.cpp
src/iptux-core/CoreThread.h
Refactored ChipData class to support image messages and updated related methods in CoreThread.
src/iptux/DialogGroup.cpp
src/iptux/DialogGroup.h
src/iptux/DialogBase.cpp
src/iptux/DialogBase.h
Updated DialogGroup and DialogBase to handle shared_ptr<MsgPara> for broadcasting and feedback messages.
src/iptux/DialogPeer.cpp
src/iptux/DialogPeer.h
Refactored DialogPeer to use shared_ptr<ChipData> and removed redundant FeedbackMsg method.
src/iptux-core/ModelsTest.cpp
src/iptux/UiModelsTest.cpp
src/iptux-core/CoreThreadTest.cpp
src/iptux/DialogPeerTest.cpp
Updated tests to use new ChipData methods for text and image messages.
src/iptux-core/internal/TcpData.cpp
src/iptux-core/internal/UdpData.cpp
src/iptux-core/internal/Command.cpp
Updated internal message handling to use new ChipData methods.

Tips
  • Trigger a new Sourcery review by commenting @sourcery-ai review on the pull request.
  • Continue your discussion with Sourcery by replying directly to review comments.
  • You can change your review settings at any time by accessing your dashboard:
    • Enable or disable the Sourcery-generated pull request summary or reviewer's guide;
    • Change the review language;
  • You can always contact us if you have any questions or feedback.

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @lidaobing - I've reviewed your changes and found some issues that need to be addressed.

Blocking issues:

  • Potential null pointer dereference (link)
  • Null pointer check for chipData (link)
Here's what I looked at during the review
  • 🔴 General issues: 2 blocking issues, 6 other issues
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment to tell me if it was helpful.

Comment on lines +200 to +202
auto res =
shared_ptr<ChipData>(new ChipData(MessageContentType::PICTURE, text));
res->deleteFileAfterSent = deleteFileAfterSent;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: Consider using make_shared for shared_ptr creation

Using make_shared is generally more efficient and safer than using new with shared_ptr. It performs a single memory allocation for both the control block and the object.

Suggested change
auto res =
shared_ptr<ChipData>(new ChipData(MessageContentType::PICTURE, text));
res->deleteFileAfterSent = deleteFileAfterSent;
auto res = make_shared<ChipData>(MessageContentType::PICTURE, text);
res->deleteFileAfterSent = deleteFileAfterSent;

@@ -425,7 +426,7 @@ void DialogGroup::BroadcastEnclosureMsg(const vector<FileInfo*>& files) {
* 向选中的好友广播文本消息.
* @param msg 文本消息
*/
void DialogGroup::BroadcastTextMsg(const gchar* msg) {
void DialogGroup::broadcastTextMsg(shared_ptr<MsgPara> para) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick: Inconsistent naming convention

The method name broadcastTextMsg does not follow the camelCase convention used elsewhere in the codebase. Consider renaming it to BroadcastTextMsg for consistency.

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()) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue (bug_risk): Potential null pointer dereference

Ensure that grpinf is not null before calling isInputEmpty to avoid potential null pointer dereference.

/**
* 封装消息.
* @param dtlist 数据链表
* @return 消息封装包
*/
MsgPara* DialogPeer::PackageMsg(const std::vector<ChipData>& dtlist) {
MsgPara* DialogPeer::PackageMsg(const vector<shared_ptr<ChipData>>& dtlist) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion (performance): Consider using const reference for parameter

Consider passing const vector<shared_ptr<ChipData>>& dtlist as a const reference to avoid unnecessary copying.

Suggested change
MsgPara* DialogPeer::PackageMsg(const vector<shared_ptr<ChipData>>& dtlist) {
MsgPara* DialogPeer::PackageMsg(const std::vector<std::shared_ptr<ChipData>>& dtlist) {

auto ptr = chipData.data.c_str();
switch (chipData.type) {
bool CoreThread::SendMessage(CPPalInfo pal, shared_ptr<ChipData> chipData) {
switch (chipData->type) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue (bug_risk): Null pointer check for chipData

Ensure that chipData is not null before dereferencing it to avoid potential null pointer dereference.

Comment on lines +493 to +494
Command(*this).SendSublayer(sock, pal, IPTUX_MSGPICOPT,
chipData->data.c_str());
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue (bug_risk): Potential resource leak

Ensure that the socket is closed in case of an exception to avoid potential resource leaks.

*/
void DialogBase::FeedbackMsg(const gchar* msg) {
MsgPara para(this->app->getMe());
void DialogBase::FeedbackMsg(shared_ptr<MsgPara> msgPara) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick: Inconsistent naming convention

The method name FeedbackMsg does not follow the camelCase convention used elsewhere in the codebase. Consider renaming it to feedbackMsg for consistency.

@@ -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));
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion (performance): Consider using emplace_back

Consider using emplace_back instead of push_back to construct the object in place and avoid an unnecessary copy.

Suggested change
para.dtlist.push_back(ChipData::newImgMsg(path, false));
para.dtlist.emplace_back(ChipData::newImgMsg(path, false));

Copy link

github-actions bot commented Jul 14, 2024

Test Results

0 tests   - 66   0 ✅  - 66   0s ⏱️ -4s
0 suites  - 32   0 💤 ± 0 
0 files    -  1   0 ❌ ± 0 

Results for commit 0ece922. ± Comparison against base commit 403f421.

♻️ This comment has been updated with latest results.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Can't send image in group chat
1 participant