Skip to content

Commit

Permalink
fixes #148 - add whatsapp support for group admin deletion of message…
Browse files Browse the repository at this point in the history
…s sent by others
  • Loading branch information
d99kris committed Nov 11, 2023
1 parent 4b71a18 commit 02f91fc
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 7 deletions.
1 change: 1 addition & 0 deletions lib/common/src/protocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ class DeleteMessageRequest : public RequestMessage
public:
virtual MessageType GetMessageType() const { return DeleteMessageRequestType; }
std::string chatId;
std::string senderId; // only needed for wmchat
std::string msgId;
};

Expand Down
2 changes: 1 addition & 1 deletion lib/common/src/version.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@

#pragma once

#define NCHAT_VERSION "3.96"
#define NCHAT_VERSION "3.97"
4 changes: 2 additions & 2 deletions lib/wmchat/go/cgowm.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ func CWmMarkMessageRead(connId int, chatId *C.char, msgId *C.char) int {
}

//export CWmDeleteMessage
func CWmDeleteMessage(connId int, chatId *C.char, msgId *C.char) int {
return WmDeleteMessage(connId, C.GoString(chatId), C.GoString(msgId))
func CWmDeleteMessage(connId int, chatId *C.char, senderId *C.char, msgId *C.char) int {
return WmDeleteMessage(connId, C.GoString(chatId), C.GoString(senderId), C.GoString(msgId))
}

//export CWmDeleteChat
Expand Down
5 changes: 3 additions & 2 deletions lib/wmchat/go/gowm.go
Original file line number Diff line number Diff line change
Expand Up @@ -1946,7 +1946,7 @@ func WmMarkMessageRead(connId int, chatId string, msgId string) int {
return 0
}

func WmDeleteMessage(connId int, chatId string, msgId string) int {
func WmDeleteMessage(connId int, chatId string, senderId string, msgId string) int {

LOG_TRACE("delete message " + strconv.Itoa(connId) + ", " + chatId + ", " + msgId)

Expand All @@ -1961,7 +1961,8 @@ func WmDeleteMessage(connId int, chatId string, msgId string) int {

// delete message
chatJid, _ := types.ParseJID(chatId)
_, err := client.RevokeMessage(chatJid, msgId)
senderJid, _ := types.ParseJID(senderId)
_, err := client.SendMessage(context.Background(), chatJid, client.BuildRevoke(chatJid, senderJid, msgId))

// log any error
if err != nil {
Expand Down
2 changes: 2 additions & 0 deletions lib/wmchat/src/wmchat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -427,9 +427,11 @@ void WmChat::PerformRequest(std::shared_ptr<RequestMessage> p_RequestMessage)
std::shared_ptr<DeleteMessageRequest> deleteMessageRequest =
std::static_pointer_cast<DeleteMessageRequest>(p_RequestMessage);
std::string chatId = deleteMessageRequest->chatId;
std::string senderId = deleteMessageRequest->senderId;
std::string msgId = deleteMessageRequest->msgId;

int rv = CWmDeleteMessage(m_ConnId, const_cast<char*>(chatId.c_str()),
const_cast<char*>(senderId.c_str()),
const_cast<char*>(msgId.c_str()));
Status::Clear(Status::FlagUpdating);

Expand Down
2 changes: 1 addition & 1 deletion src/nchat.1
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
.\" DO NOT MODIFY THIS FILE! It was generated by help2man.
.TH NCHAT "1" "November 2023" "nchat v3.96" "User Commands"
.TH NCHAT "1" "November 2023" "nchat v3.97" "User Commands"
.SH NAME
nchat \- ncurses chat
.SH SYNOPSIS
Expand Down
15 changes: 14 additions & 1 deletion src/uimodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -992,9 +992,22 @@ void UiModel::DeleteMessage()
return;
}

std::string msgId = *it;
std::string senderId;
const std::string msgId = *it;
const std::unordered_map<std::string, ChatMessage>& messages = m_Messages[profileId][chatId];
auto mit = messages.find(msgId);
if (mit != messages.end())
{
senderId = mit->second.senderId;
}
else
{
LOG_WARNING("error finding message");
}

std::shared_ptr<DeleteMessageRequest> deleteMessageRequest = std::make_shared<DeleteMessageRequest>();
deleteMessageRequest->chatId = chatId;
deleteMessageRequest->senderId = senderId;
deleteMessageRequest->msgId = msgId;
SendProtocolRequest(profileId, deleteMessageRequest);
}
Expand Down

0 comments on commit 02f91fc

Please sign in to comment.