handlematrix: bridge message edits
This commit is contained in:
@@ -65,6 +65,7 @@ var discordCaps = &event.RoomFeatures{
|
||||
ID: capID(),
|
||||
Reply: event.CapLevelFullySupported,
|
||||
Reaction: event.CapLevelFullySupported,
|
||||
Edit: event.CapLevelFullySupported,
|
||||
Delete: event.CapLevelFullySupported,
|
||||
Formatting: event.FormattingFeatureMap{
|
||||
event.FmtBold: event.CapLevelFullySupported,
|
||||
@@ -137,7 +138,6 @@ var discordCaps = &event.RoomFeatures{
|
||||
LocationMessage: event.CapLevelUnsupported,
|
||||
MaxTextLength: MaxTextLength,
|
||||
// TODO: Support threads.
|
||||
// TODO: Support editing.
|
||||
}
|
||||
|
||||
func (dc *DiscordClient) GetCapabilities(ctx context.Context, portal *bridgev2.Portal) *event.RoomFeatures {
|
||||
|
||||
@@ -18,6 +18,7 @@ package connector
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/bwmarrin/discordgo"
|
||||
@@ -72,8 +73,28 @@ func (d *DiscordClient) HandleMatrixMessage(ctx context.Context, msg *bridgev2.M
|
||||
}
|
||||
|
||||
func (d *DiscordClient) HandleMatrixEdit(ctx context.Context, msg *bridgev2.MatrixEdit) error {
|
||||
//TODO implement me
|
||||
panic("implement me")
|
||||
log := zerolog.Ctx(ctx).With().Str("action", "matrix message edit").Logger()
|
||||
ctx = log.WithContext(ctx)
|
||||
|
||||
content, _ := d.connector.MsgConv.ConvertMatrixMessageContent(
|
||||
ctx,
|
||||
msg.Portal,
|
||||
msg.Content,
|
||||
// Disregard link previews for now. Discord generally allows you to
|
||||
// remove individual link previews from a message though.
|
||||
[]string{},
|
||||
)
|
||||
|
||||
_, err := d.Session.ChannelMessageEdit(
|
||||
discordid.ParsePortalID(msg.Portal.ID),
|
||||
discordid.ParseMessageID(msg.EditTarget.ID),
|
||||
content,
|
||||
)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to send message edit to discord: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (d *DiscordClient) PreHandleMatrixReaction(ctx context.Context, reaction *bridgev2.MatrixReaction) (bridgev2.MatrixReactionPreResponse, error) {
|
||||
|
||||
@@ -112,7 +112,7 @@ func (mc *MessageConverter) ToDiscord(
|
||||
content := msg.Content
|
||||
|
||||
convertMatrix := func() {
|
||||
req.Content, req.AllowedMentions = mc.convertMatrixMessageContent(ctx, msg.Portal, content, parseAllowedLinkPreviews(msg.Event.Content.Raw))
|
||||
req.Content, req.AllowedMentions = mc.ConvertMatrixMessageContent(ctx, msg.Portal, content, parseAllowedLinkPreviews(msg.Event.Content.Raw))
|
||||
if content.MsgType == event.MsgEmote {
|
||||
req.Content = fmt.Sprintf("_%s_", req.Content)
|
||||
}
|
||||
@@ -176,7 +176,7 @@ func (mc *MessageConverter) ToDiscord(
|
||||
return &req, nil
|
||||
}
|
||||
|
||||
func (mc *MessageConverter) convertMatrixMessageContent(ctx context.Context, portal *bridgev2.Portal, content *event.MessageEventContent, allowedLinkPreviews []string) (string, *discordgo.MessageAllowedMentions) {
|
||||
func (mc *MessageConverter) ConvertMatrixMessageContent(ctx context.Context, portal *bridgev2.Portal, content *event.MessageEventContent, allowedLinkPreviews []string) (string, *discordgo.MessageAllowedMentions) {
|
||||
allowedMentions := &discordgo.MessageAllowedMentions{
|
||||
Parse: []discordgo.AllowedMentionType{},
|
||||
Users: []string{},
|
||||
|
||||
Reference in New Issue
Block a user