2026-01-09 17:08:33 -08:00
|
|
|
// 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
|
|
|
|
|
|
2026-02-11 19:03:17 -08:00
|
|
|
import (
|
|
|
|
|
"github.com/bwmarrin/discordgo"
|
|
|
|
|
"maunium.net/go/mautrix/bridgev2/database"
|
|
|
|
|
)
|
2026-01-09 17:08:33 -08:00
|
|
|
|
2026-01-09 17:08:33 -08:00
|
|
|
type PortalMetadata struct {
|
|
|
|
|
// The ID of the Discord guild that the channel corresponding to this portal
|
|
|
|
|
// belongs to.
|
|
|
|
|
//
|
|
|
|
|
// For private channels (DMs and group DMs), this will be the zero value
|
|
|
|
|
// (an empty string).
|
|
|
|
|
GuildID string `json:"guild_id"`
|
2026-03-04 20:36:17 -08:00
|
|
|
|
|
|
|
|
// The type of Discord channel this portal corresponds to.
|
|
|
|
|
//
|
|
|
|
|
// This is omitted for guild space portals.
|
|
|
|
|
ChannelType *discordgo.ChannelType `json:"channel_type,omitempty"`
|
2026-01-09 17:08:33 -08:00
|
|
|
}
|
|
|
|
|
|
2026-01-09 17:08:33 -08:00
|
|
|
type UserLoginMetadata struct {
|
|
|
|
|
Token string `json:"token"`
|
|
|
|
|
HeartbeatSession discordgo.HeartbeatSession `json:"heartbeat_session"`
|
2026-02-05 21:05:04 -08:00
|
|
|
BridgedGuildIDs map[string]bool `json:"bridged_guild_ids,omitempty"`
|
2026-01-09 17:08:33 -08:00
|
|
|
}
|
2026-02-11 19:03:17 -08:00
|
|
|
|
|
|
|
|
var _ database.MetaMerger = (*UserLoginMetadata)(nil)
|
|
|
|
|
|
|
|
|
|
func (ulm *UserLoginMetadata) CopyFrom(incoming any) {
|
|
|
|
|
incomingMeta, ok := incoming.(*UserLoginMetadata)
|
|
|
|
|
if !ok || incomingMeta == nil {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if incomingMeta.Token != "" {
|
|
|
|
|
ulm.Token = incomingMeta.Token
|
|
|
|
|
}
|
|
|
|
|
ulm.HeartbeatSession = discordgo.NewHeartbeatSession()
|
|
|
|
|
|
|
|
|
|
// Retain the BridgedGuildIDs from the existing login.
|
|
|
|
|
}
|