relocate dbmeta models to discordid

While we're about to introduce more metadata structs, it seems like
mautrix-slack keeps these in slackid, so let's keep ours in discordid.
This commit is contained in:
Skip R
2026-01-09 17:08:33 -08:00
parent fdcfb2b083
commit 86544bc7af
4 changed files with 32 additions and 10 deletions

View File

@@ -49,7 +49,7 @@ type DiscordClient struct {
}
func (d *DiscordConnector) LoadUserLogin(ctx context.Context, login *bridgev2.UserLogin) error {
meta := login.Metadata.(*UserLoginMetadata)
meta := login.Metadata.(*discordid.UserLoginMetadata)
session, err := NewDiscordSession(ctx, meta.Token)
login.Save(ctx)
@@ -77,7 +77,7 @@ var _ bridgev2.NetworkAPI = (*DiscordClient)(nil)
//
// nil may be passed for meta, especially during provisioning where we need to
// connect to the Discord gateway, but don't have a UserLogin yet.
func (d *DiscordClient) SetUp(ctx context.Context, meta *UserLoginMetadata) {
func (d *DiscordClient) SetUp(ctx context.Context, meta *discordid.UserLoginMetadata) {
// TODO: Turn this into a factory function like `NewDiscordClient`.
log := zerolog.Ctx(ctx)

View File

@@ -17,19 +17,15 @@
package connector
import (
"github.com/bwmarrin/discordgo"
"maunium.net/go/mautrix/bridgev2/database"
)
type UserLoginMetadata struct {
Token string `json:"token"`
HeartbeatSession discordgo.HeartbeatSession `json:"heartbeat_session"`
}
"go.mau.fi/mautrix-discord/pkg/discordid"
)
func (d *DiscordConnector) GetDBMetaTypes() database.MetaTypes {
return database.MetaTypes{
UserLogin: func() any {
return &UserLoginMetadata{}
return &discordid.UserLoginMetadata{}
},
}
}

View File

@@ -25,6 +25,8 @@ import (
"maunium.net/go/mautrix/bridgev2"
"maunium.net/go/mautrix/bridgev2/database"
"maunium.net/go/mautrix/bridgev2/networkid"
"go.mau.fi/mautrix-discord/pkg/discordid"
)
// DiscordGenericLogin is embedded within each struct that implements
@@ -70,7 +72,7 @@ func (dl *DiscordGenericLogin) FinalizeCreatingLogin(ctx context.Context, token
dl.Session = session
ul, err := dl.User.NewLogin(ctx, &database.UserLogin{
ID: networkid.UserLoginID(user.ID),
Metadata: &UserLoginMetadata{
Metadata: &discordid.UserLoginMetadata{
Token: token,
HeartbeatSession: session.HeartbeatSession,
},

24
pkg/discordid/dbmeta.go Normal file
View File

@@ -0,0 +1,24 @@
// mautrix-discord - A Matrix-Discord puppeting bridge.
// Copyright (C) 2026 Tulir Asokan
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
package discordid
import "github.com/bwmarrin/discordgo"
type UserLoginMetadata struct {
Token string `json:"token"`
HeartbeatSession discordgo.HeartbeatSession `json:"heartbeat_session"`
}