Skip to content

Commit eb3364f

Browse files
committed
handlematrix: implement DeleteChatHandlingNetworkAPI
1 parent dba863c commit eb3364f

File tree

2 files changed

+36
-2
lines changed

2 files changed

+36
-2
lines changed

pkg/connector/capabilities.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ func (wa *WhatsAppConnector) GetCapabilities() *bridgev2.NetworkGeneralCapabilit
5050
}
5151

5252
func (wa *WhatsAppConnector) GetBridgeInfoVersion() (info, caps int) {
53-
return 1, 4
53+
return 1, 5
5454
}
5555

5656
const WAMaxFileSize = 2000 * 1024 * 1024
@@ -65,7 +65,7 @@ func supportedIfFFmpeg() event.CapabilitySupportLevel {
6565
}
6666

6767
func capID() string {
68-
base := "fi.mau.whatsapp.capabilities.2025_08_25+1"
68+
base := "fi.mau.whatsapp.capabilities.2025_10_07"
6969
if ffmpeg.Supported() {
7070
return base + "+ffmpeg"
7171
}
@@ -176,6 +176,7 @@ var whatsappCaps = &event.RoomFeatures{
176176
ReadReceipts: true,
177177
TypingNotifications: true,
178178
DisappearingTimer: waDisappearingCap,
179+
DeleteChat: true,
179180
}
180181

181182
var whatsappCAGCaps *event.RoomFeatures

pkg/connector/handlematrix.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ var (
4545
_ bridgev2.MuteHandlingNetworkAPI = (*WhatsAppClient)(nil)
4646
_ bridgev2.TagHandlingNetworkAPI = (*WhatsAppClient)(nil)
4747
_ bridgev2.MarkedUnreadHandlingNetworkAPI = (*WhatsAppClient)(nil)
48+
_ bridgev2.DeleteChatHandlingNetworkAPI = (*WhatsAppClient)(nil)
4849
)
4950

5051
func (wa *WhatsAppClient) HandleMatrixPollStart(ctx context.Context, msg *bridgev2.MatrixPollStart) (*bridgev2.MatrixMessageResponse, error) {
@@ -625,3 +626,35 @@ func (wa *WhatsAppClient) HandleMarkedUnread(ctx context.Context, msg *bridgev2.
625626
}
626627
return wa.Client.SendAppState(ctx, appstate.BuildMarkChatAsRead(chatJID, msg.Content.Unread, lastTS, lastKey))
627628
}
629+
630+
func (wa *WhatsAppClient) HandleMatrixDeleteChat(ctx context.Context, msg *bridgev2.MatrixDeleteChat) error {
631+
chatJID, err := waid.ParsePortalID(msg.Portal.ID)
632+
if err != nil {
633+
return err
634+
}
635+
messages, err := wa.Main.Bridge.DB.Message.GetLastNInPortal(ctx, msg.Portal.PortalKey, 1)
636+
if err != nil {
637+
return fmt.Errorf("failed to get last message in portal: %w", err)
638+
}
639+
if len(messages) < 1 {
640+
return fmt.Errorf("failed to delete chat: no messages found")
641+
}
642+
message := messages[0]
643+
lastTS := messages[0].Timestamp
644+
parsed, err := waid.ParseMessageID(message.ID)
645+
if err != nil {
646+
return fmt.Errorf("failed to parse last message ID: %w", err)
647+
}
648+
fromMe := parsed.Sender.ToNonAD() == wa.JID.ToNonAD() || parsed.Sender.ToNonAD() == wa.GetStore().GetLID().ToNonAD()
649+
var participant *string
650+
if chatJID.Server == types.GroupServer {
651+
participant = ptr.Ptr(parsed.Sender.String())
652+
}
653+
lastKey := &waCommon.MessageKey{
654+
RemoteJID: ptr.Ptr(chatJID.String()),
655+
FromMe: &fromMe,
656+
ID: &parsed.ID,
657+
Participant: participant,
658+
}
659+
return wa.Client.SendAppState(ctx, appstate.BuildDeleteChat(chatJID, lastTS, lastKey))
660+
}

0 commit comments

Comments
 (0)