From e030c9548cfcee25686917a68c506afb9d237689 Mon Sep 17 00:00:00 2001 From: Skip R Date: Wed, 17 Dec 2025 18:44:52 -0800 Subject: [PATCH] handlematrix: bridge outgoing reactions --- pkg/connector/capabilities.go | 5 +++-- pkg/connector/handlematrix.go | 34 +++++++++++++++++++++++++--------- 2 files changed, 28 insertions(+), 11 deletions(-) diff --git a/pkg/connector/capabilities.go b/pkg/connector/capabilities.go index b9c891f..aff026e 100644 --- a/pkg/connector/capabilities.go +++ b/pkg/connector/capabilities.go @@ -55,8 +55,9 @@ func capID() string { } var discordCaps = &event.RoomFeatures{ - ID: capID(), - Reply: event.CapLevelFullySupported, + ID: capID(), + Reply: event.CapLevelFullySupported, + Reaction: event.CapLevelFullySupported, Formatting: event.FormattingFeatureMap{ event.FmtBold: event.CapLevelFullySupported, event.FmtItalic: event.CapLevelFullySupported, diff --git a/pkg/connector/handlematrix.go b/pkg/connector/handlematrix.go index ab6d89f..c33017a 100644 --- a/pkg/connector/handlematrix.go +++ b/pkg/connector/handlematrix.go @@ -73,19 +73,35 @@ func (d *DiscordClient) HandleMatrixEdit(ctx context.Context, msg *bridgev2.Matr panic("implement me") } -func (d *DiscordClient) PreHandleMatrixReaction(ctx context.Context, msg *bridgev2.MatrixReaction) (bridgev2.MatrixReactionPreResponse, error) { - //TODO implement me - panic("implement me") +func (d *DiscordClient) PreHandleMatrixReaction(ctx context.Context, reaction *bridgev2.MatrixReaction) (bridgev2.MatrixReactionPreResponse, error) { + key := reaction.Content.RelatesTo.Key + // TODO: Handle custom emoji. + + return bridgev2.MatrixReactionPreResponse{ + SenderID: networkid.UserID(d.UserLogin.ID), + EmojiID: networkid.EmojiID(key), + }, nil } -func (d *DiscordClient) HandleMatrixReaction(ctx context.Context, msg *bridgev2.MatrixReaction) (reaction *database.Reaction, err error) { - //TODO implement me - panic("implement me") +func (d *DiscordClient) HandleMatrixReaction(ctx context.Context, reaction *bridgev2.MatrixReaction) (*database.Reaction, error) { + key := reaction.Content.RelatesTo.Key + portal := reaction.Portal + // TODO: Support guilds. + guildID := "" + + err := d.Session.MessageReactionAddUser(guildID, string(portal.ID), string(reaction.TargetMessage.ID), key) + return nil, err } -func (d *DiscordClient) HandleMatrixReactionRemove(ctx context.Context, msg *bridgev2.MatrixReactionRemove) error { - //TODO implement me - panic("implement me") +func (d *DiscordClient) HandleMatrixReactionRemove(ctx context.Context, removal *bridgev2.MatrixReactionRemove) error { + removing := removal.TargetReaction + emojiID := removing.EmojiID + channelID := string(removing.Room.ID) + // TODO: Support guilds. + guildID := "" + + err := d.Session.MessageReactionRemoveUser(guildID, channelID, string(removing.MessageID), string(emojiID), string(d.UserLogin.ID)) + return err } func (d *DiscordClient) HandleMatrixMessageRemove(ctx context.Context, msg *bridgev2.MatrixMessageRemove) error {