Skip to content

Commit

Permalink
handle whatsapp messages deleted/revoked remotely
Browse files Browse the repository at this point in the history
  • Loading branch information
d99kris committed May 11, 2024
1 parent 8414ecc commit 4faef72
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 3 deletions.
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 "4.78"
#define NCHAT_VERSION "4.79"
5 changes: 5 additions & 0 deletions lib/wmchat/go/cgowm.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package main
// extern void WmNewMessageFileNotify(int p_ConnId, char* p_ChatId, char* p_MsgId, char* p_FilePath, int p_FileStatus, int p_Action);
// extern void WmNewMessageReactionNotify(int p_ConnId, char* p_ChatId, char* p_MsgId, char* p_SenderId, char* p_Text, int p_FromMe);
// extern void WmDeleteChatNotify(int p_ConnId, char* p_ChatId);
// extern void WmDeleteMessageNotify(int p_ConnId, char* p_ChatId, char* p_MsgId);
// extern void WmUpdateMuteNotify(int p_ConnId, char* p_ChatId, int p_IsMuted);
// extern void WmReinit(int p_ConnId);
// extern void WmSetProtocolUiControl(int p_ConnId, int p_IsTakeControl);
Expand Down Expand Up @@ -141,6 +142,10 @@ func CWmDeleteChatNotify(connId int, chatId string) {
C.WmDeleteChatNotify(C.int(connId), C.CString(chatId))
}

func CWmDeleteMessageNotify(connId int, chatId string, msgId string) {
C.WmDeleteMessageNotify(C.int(connId), C.CString(chatId), C.CString(msgId))
}

func CWmUpdateMuteNotify(connId int, chatId string, isMuted int) {
C.WmUpdateMuteNotify(C.int(connId), C.CString(chatId), C.int(isMuted))
}
Expand Down
9 changes: 8 additions & 1 deletion lib/wmchat/go/gowm.go
Original file line number Diff line number Diff line change
Expand Up @@ -1374,8 +1374,8 @@ func (handler *WmEventHandler) HandleProtocolMessage(messageInfo types.MessageIn
return
}

// handle message edit
if protocol.GetType() == waProto.ProtocolMessage_MESSAGE_EDIT {
// handle message edit
editedMsg := protocol.GetEditedMessage()
if editedMsg != nil {
newMessageInfo := messageInfo
Expand All @@ -1384,6 +1384,13 @@ func (handler *WmEventHandler) HandleProtocolMessage(messageInfo types.MessageIn
} else {
LOG_WARNING(fmt.Sprintf("get edited message failed"))
}
} else if protocol.GetType() == waProto.ProtocolMessage_REVOKE {
// handle message revoke
connId := handler.connId
chatId := messageInfo.Chat.String()
msgId := protocol.GetKey().GetId()
LOG_TRACE(fmt.Sprintf("Call CWmDeleteMessageNotify %s %s", chatId, msgId))
CWmDeleteMessageNotify(connId, chatId, msgId)
} else {
LOG_TRACE(fmt.Sprintf("ProtocolMessage %#v ignore", protocol.GetType()))
}
Expand Down
22 changes: 22 additions & 0 deletions lib/wmchat/src/wmchat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -930,6 +930,28 @@ void WmDeleteChatNotify(int p_ConnId, char* p_ChatId)
free(p_ChatId);
}

void WmDeleteMessageNotify(int p_ConnId, char* p_ChatId, char* p_MsgId)
{
WmChat* instance = WmChat::GetInstance(p_ConnId);
if (instance == nullptr) return;

{
std::shared_ptr<DeleteMessageNotify> deleteMessageNotify =
std::make_shared<DeleteMessageNotify>(instance->GetProfileId());
deleteMessageNotify->success = true;
deleteMessageNotify->chatId = std::string(p_ChatId);
deleteMessageNotify->msgId = std::string(p_MsgId);

std::shared_ptr<DeferNotifyRequest> deferNotifyRequest =
std::make_shared<DeferNotifyRequest>();
deferNotifyRequest->serviceMessage = deleteMessageNotify;
instance->SendRequest(deferNotifyRequest);
}

free(p_ChatId);
free(p_MsgId);
}

void WmUpdateMuteNotify(int p_ConnId, char* p_ChatId, int p_IsMuted)
{
WmChat* instance = WmChat::GetInstance(p_ConnId);
Expand Down
1 change: 1 addition & 0 deletions lib/wmchat/src/wmchat.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ void WmNewMessageFileNotify(int p_ConnId, char* p_ChatId, char* p_MsgId, char* p
void WmNewMessageReactionNotify(int p_ConnId, char* p_ChatId, char* p_MsgId, char* p_SenderId, char* p_Text,
int p_FromMe);
void WmDeleteChatNotify(int p_ConnId, char* p_ChatId);
void WmDeleteMessageNotify(int p_ConnId, char* p_ChatId, char* p_MsgId);
void WmUpdateMuteNotify(int p_ConnId, char* p_ChatId, int p_IsMuted);
void WmReinit(int p_ConnId);
void WmSetProtocolUiControl(int p_ConnId, int p_IsTakeControl);
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" "May 2024" "nchat v4.78" "User Commands"
.TH NCHAT "1" "May 2024" "nchat v4.79" "User Commands"
.SH NAME
nchat \- ncurses chat
.SH SYNOPSIS
Expand Down

0 comments on commit 4faef72

Please sign in to comment.