Skip to content

Commit b034552

Browse files
committed
handlematrix: implement account data interfaces
1 parent b4a929b commit b034552

File tree

4 files changed

+63
-4
lines changed

4 files changed

+63
-4
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ require (
99
github.com/rs/zerolog v1.34.0
1010
go.mau.fi/util v0.9.2-0.20251001114608-d99877b9cc10
1111
go.mau.fi/webp v0.2.0
12-
go.mau.fi/whatsmeow v0.0.0-20250930215512-38f9aaa3ba7c
12+
go.mau.fi/whatsmeow v0.0.0-20251002120845-b3cd0a5002d4
1313
golang.org/x/image v0.31.0
1414
golang.org/x/net v0.44.0
1515
golang.org/x/sync v0.17.0

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,8 @@ go.mau.fi/util v0.9.2-0.20251001114608-d99877b9cc10 h1:EvX/di02gOriKN0xGDJuQ5mgi
8181
go.mau.fi/util v0.9.2-0.20251001114608-d99877b9cc10/go.mod h1:M0bM9SyaOWJniaHs9hxEzz91r5ql6gYq6o1q5O1SsjQ=
8282
go.mau.fi/webp v0.2.0 h1:QVMenHw7JDb4vall5sV75JNBQj9Hw4u8AKbi1QetHvg=
8383
go.mau.fi/webp v0.2.0/go.mod h1:VSg9MyODn12Mb5pyG0NIyNFhujrmoFSsZBs8syOZD1Q=
84-
go.mau.fi/whatsmeow v0.0.0-20250930215512-38f9aaa3ba7c h1:mlDr3/zLUCf8aylmGwds0mnAb4SNYimpb43ylQQlY3Q=
85-
go.mau.fi/whatsmeow v0.0.0-20250930215512-38f9aaa3ba7c/go.mod h1:dvltpCF0rOHbbur25DHbQ3Ovi747z2Pm11S2M7p1T74=
84+
go.mau.fi/whatsmeow v0.0.0-20251002120845-b3cd0a5002d4 h1:uysENrRsp3Ko6LjrOIsNnCT2l3lTibrUkp+CCx1IxG4=
85+
go.mau.fi/whatsmeow v0.0.0-20251002120845-b3cd0a5002d4/go.mod h1:dvltpCF0rOHbbur25DHbQ3Ovi747z2Pm11S2M7p1T74=
8686
go.mau.fi/zeroconfig v0.2.0 h1:e/OGEERqVRRKlgaro7E6bh8xXiKFSXB3eNNIud7FUjU=
8787
go.mau.fi/zeroconfig v0.2.0/go.mod h1:J0Vn0prHNOm493oZoQ84kq83ZaNCYZnq+noI1b1eN8w=
8888
golang.org/x/crypto v0.42.0 h1:chiH31gIWm57EkTXpwnqf8qeuMUi0yekh6mT2AvFlqI=

pkg/connector/client.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ func (wa *WhatsAppClient) Connect(ctx context.Context) {
197197
zerolog.Ctx(ctx).Err(err).Msg("Failed to update proxy")
198198
}
199199
wa.startLoops()
200-
wa.Client.BackgroundEventCtx = wa.Main.Bridge.BackgroundCtx
200+
wa.Client.BackgroundEventCtx = wa.UserLogin.Log.WithContext(wa.Main.Bridge.BackgroundCtx)
201201
if err := wa.Client.Connect(); err != nil {
202202
zerolog.Ctx(ctx).Err(err).Msg("Failed to connect to WhatsApp")
203203
state := status.BridgeState{

pkg/connector/handlematrix.go

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ import (
1515
"go.mau.fi/util/ptr"
1616
"go.mau.fi/util/variationselector"
1717
"go.mau.fi/whatsmeow"
18+
"go.mau.fi/whatsmeow/appstate"
19+
"go.mau.fi/whatsmeow/proto/waCommon"
1820
"go.mau.fi/whatsmeow/proto/waE2E"
1921
"go.mau.fi/whatsmeow/types"
2022
"golang.org/x/image/draw"
@@ -40,6 +42,9 @@ var (
4042
_ bridgev2.RoomNameHandlingNetworkAPI = (*WhatsAppClient)(nil)
4143
_ bridgev2.RoomTopicHandlingNetworkAPI = (*WhatsAppClient)(nil)
4244
_ bridgev2.RoomAvatarHandlingNetworkAPI = (*WhatsAppClient)(nil)
45+
_ bridgev2.MuteHandlingNetworkAPI = (*WhatsAppClient)(nil)
46+
_ bridgev2.TagHandlingNetworkAPI = (*WhatsAppClient)(nil)
47+
_ bridgev2.MarkedUnreadHandlingNetworkAPI = (*WhatsAppClient)(nil)
4348
)
4449

4550
func (wa *WhatsAppClient) HandleMatrixPollStart(ctx context.Context, msg *bridgev2.MatrixPollStart) (*bridgev2.MatrixMessageResponse, error) {
@@ -566,3 +571,57 @@ func convertRoomAvatar(data []byte) ([]byte, error) {
566571
}
567572
return buf.Bytes(), nil
568573
}
574+
575+
func (wa *WhatsAppClient) HandleMute(ctx context.Context, msg *bridgev2.MatrixMute) error {
576+
chatJID, err := waid.ParsePortalID(msg.Portal.ID)
577+
if err != nil {
578+
return err
579+
}
580+
mutedUntil := msg.Content.GetMutedUntilTime()
581+
muted := mutedUntil.After(time.Now())
582+
muteTS := ptr.Ptr(mutedUntil.UnixMilli())
583+
if !muted || mutedUntil == event.MutedForever {
584+
muteTS = nil
585+
}
586+
return wa.Client.SendAppState(ctx, appstate.BuildMuteAbs(chatJID, muted, muteTS))
587+
}
588+
589+
func (wa *WhatsAppClient) HandleRoomTag(ctx context.Context, msg *bridgev2.MatrixRoomTag) error {
590+
chatJID, err := waid.ParsePortalID(msg.Portal.ID)
591+
if err != nil {
592+
return err
593+
}
594+
_, isFavorite := msg.Content.Tags[event.RoomTagFavourite]
595+
return wa.Client.SendAppState(ctx, appstate.BuildPin(chatJID, isFavorite))
596+
}
597+
598+
func (wa *WhatsAppClient) HandleMarkedUnread(ctx context.Context, msg *bridgev2.MatrixMarkedUnread) error {
599+
chatJID, err := waid.ParsePortalID(msg.Portal.ID)
600+
if err != nil {
601+
return err
602+
}
603+
msgs, err := wa.Main.Bridge.DB.Message.GetLastNInPortal(ctx, msg.Portal.PortalKey, 1)
604+
if err != nil {
605+
return fmt.Errorf("failed to get last message in portal: %w", err)
606+
}
607+
var lastTS time.Time
608+
var lastKey *waCommon.MessageKey
609+
if len(msgs) == 1 {
610+
lastTS = msgs[0].Timestamp
611+
parsed, _ := waid.ParseMessageID(msgs[0].ID)
612+
if parsed != nil {
613+
fromMe := parsed.Sender.ToNonAD() == wa.JID.ToNonAD() || parsed.Sender.ToNonAD() == wa.GetStore().GetLID().ToNonAD()
614+
var participant *string
615+
if chatJID.Server == types.GroupServer {
616+
participant = ptr.Ptr(parsed.Sender.String())
617+
}
618+
lastKey = &waCommon.MessageKey{
619+
RemoteJID: ptr.Ptr(chatJID.String()),
620+
FromMe: &fromMe,
621+
ID: &parsed.ID,
622+
Participant: participant,
623+
}
624+
}
625+
}
626+
return wa.Client.SendAppState(ctx, appstate.BuildMarkChatAsRead(chatJID, msg.Content.Unread, lastTS, lastKey))
627+
}

0 commit comments

Comments
 (0)