msgconv: port most of attachment and text message bridging

* Created a separate discordid package to avoid import cycles.
* Implemented attachment bridging. We still need to implement direct
  media, but this will do for now.
* Corrected how encrypted files (e.g. embed images and attachments) were
  bridged. Previously, the URL field would be empty.

Still a lot of missing pieces. Thoughts:

* Mentions to roles and custom emoji are not rendered properly. We need
  to maintain our own DB.
* We might not need the "attachments" leaf package anymore? It's just
  there to avoid an import cycle.

Bridging actual events (i.e. wiring up discordgo's event handlers) is
probably next.
This commit is contained in:
Skip R
2025-11-26 18:09:00 -08:00
parent 86e18c1f7d
commit b5e6db06f8
10 changed files with 629 additions and 111 deletions

View File

@@ -27,6 +27,7 @@ import (
"github.com/bwmarrin/discordgo"
"github.com/rs/zerolog"
"go.mau.fi/mautrix-discord/pkg/discordid"
"maunium.net/go/mautrix/bridgev2"
"maunium.net/go/mautrix/bridgev2/database"
"maunium.net/go/mautrix/bridgev2/networkid"
@@ -221,6 +222,14 @@ func makeChannelAvatar(ch *discordgo.Channel) *bridgev2.Avatar {
}
}
func (d *DiscordClient) makeEventSender(user *discordgo.User) bridgev2.EventSender {
return bridgev2.EventSender{
IsFromMe: user.ID == d.Session.State.User.ID,
SenderLogin: networkid.UserLoginID(user.ID),
Sender: networkid.UserID(user.ID),
}
}
func (d *DiscordClient) syncChannel(_ context.Context, ch *discordgo.Channel, selfIsInChannel bool) {
isGroup := len(ch.RecipientIDs) > 1
@@ -253,7 +262,7 @@ func (d *DiscordClient) syncChannel(_ context.Context, ch *discordgo.Channel, se
d.connector.Bridge.QueueRemoteEvent(d.UserLogin, &DiscordChatResync{
channel: ch,
portalKey: MakePortalKey(ch, d.UserLogin.ID, true),
portalKey: discordid.MakePortalKey(ch, d.UserLogin.ID, true),
info: &bridgev2.ChatInfo{
Name: &ch.Name,
Members: &members,