refactor: standardize bridge-agnostic terminology and remove unused kvstore functions
- Replace "Room" with "Channel" in bridge-agnostic contexts throughout codebase - Update BridgeRoomID → BridgeChannelID in model structs and all references - Change error messages to use consistent "Channel" terminology for user-facing text - Update log keys: bridge_room_id → bridge_channel_id for consistency - Clean up kvstore constants file by removing unused functions and constants: - Removed BuildXMPPUserKey, BuildMattermostUserKey, BuildGhostUserKey - Removed BuildXMPPEventPostKey, BuildXMPPReactionKey functions - Removed unused constants: KeyPrefixXMPPUser, KeyPrefixMattermostUser, etc. - Keep only actively used BuildChannelMapKey and ExtractIdentifierFromChannelMapKey - Preserve XMPP-specific "Room" terminology in appropriate contexts (client methods, JIDs) 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
eb852662f7
commit
4c6aeb2392
8 changed files with 94 additions and 150 deletions
|
@ -264,7 +264,7 @@ func (m *BridgeManager) CreateChannelMapping(req model.CreateChannelMappingReque
|
|||
return fmt.Errorf("invalid mapping request: %w", err)
|
||||
}
|
||||
|
||||
m.logger.LogDebug("Creating channel mapping", "channel_id", req.ChannelID, "bridge_name", req.BridgeName, "bridge_room_id", req.BridgeRoomID, "user_id", req.UserID, "team_id", req.TeamID)
|
||||
m.logger.LogDebug("Creating channel mapping", "channel_id", req.ChannelID, "bridge_name", req.BridgeName, "bridge_channel_id", req.BridgeChannelID, "user_id", req.UserID, "team_id", req.TeamID)
|
||||
|
||||
// Get the specific bridge
|
||||
bridge, err := m.GetBridge(req.BridgeName)
|
||||
|
@ -279,41 +279,41 @@ func (m *BridgeManager) CreateChannelMapping(req model.CreateChannelMappingReque
|
|||
}
|
||||
|
||||
// NEW: Check if room already mapped to another channel
|
||||
existingChannelID, err := bridge.GetChannelMapping(req.BridgeRoomID)
|
||||
existingChannelID, err := bridge.GetChannelMapping(req.BridgeChannelID)
|
||||
if err != nil {
|
||||
m.logger.LogError("Failed to check room mapping", "bridge_room_id", req.BridgeRoomID, "error", err)
|
||||
return fmt.Errorf("failed to check room mapping: %w", err)
|
||||
m.logger.LogError("Failed to check channel mapping", "bridge_channel_id", req.BridgeChannelID, "error", err)
|
||||
return fmt.Errorf("failed to check channel mapping: %w", err)
|
||||
}
|
||||
if existingChannelID != "" {
|
||||
m.logger.LogWarn("Room already mapped to another channel",
|
||||
"bridge_room_id", req.BridgeRoomID,
|
||||
m.logger.LogWarn("Channel already mapped to another channel",
|
||||
"bridge_channel_id", req.BridgeChannelID,
|
||||
"existing_channel_id", existingChannelID,
|
||||
"requested_channel_id", req.ChannelID)
|
||||
return fmt.Errorf("room '%s' is already mapped to channel '%s'", req.BridgeRoomID, existingChannelID)
|
||||
return fmt.Errorf("channel '%s' is already mapped to channel '%s'", req.BridgeChannelID, existingChannelID)
|
||||
}
|
||||
|
||||
// NEW: Check if room exists on target bridge
|
||||
roomExists, err := bridge.ChannelMappingExists(req.BridgeRoomID)
|
||||
channelExists, err := bridge.ChannelMappingExists(req.BridgeChannelID)
|
||||
if err != nil {
|
||||
m.logger.LogError("Failed to check room existence", "bridge_room_id", req.BridgeRoomID, "error", err)
|
||||
return fmt.Errorf("failed to check room existence: %w", err)
|
||||
m.logger.LogError("Failed to check channel existence", "bridge_channel_id", req.BridgeChannelID, "error", err)
|
||||
return fmt.Errorf("failed to check channel existence: %w", err)
|
||||
}
|
||||
if !roomExists {
|
||||
m.logger.LogWarn("Room does not exist on bridge",
|
||||
"bridge_room_id", req.BridgeRoomID,
|
||||
if !channelExists {
|
||||
m.logger.LogWarn("Channel does not exist on bridge",
|
||||
"bridge_channel_id", req.BridgeChannelID,
|
||||
"bridge_name", req.BridgeName)
|
||||
return fmt.Errorf("room '%s' does not exist on %s bridge", req.BridgeRoomID, req.BridgeName)
|
||||
return fmt.Errorf("channel '%s' does not exist on %s bridge", req.BridgeChannelID, req.BridgeName)
|
||||
}
|
||||
|
||||
m.logger.LogDebug("Room validation passed",
|
||||
"bridge_room_id", req.BridgeRoomID,
|
||||
m.logger.LogDebug("Channel validation passed",
|
||||
"bridge_channel_id", req.BridgeChannelID,
|
||||
"bridge_name", req.BridgeName,
|
||||
"room_exists", roomExists,
|
||||
"channel_exists", channelExists,
|
||||
"already_mapped", false)
|
||||
|
||||
// Create the channel mapping on the receiving bridge
|
||||
if err = bridge.CreateChannelMapping(req.ChannelID, req.BridgeRoomID); err != nil {
|
||||
m.logger.LogError("Failed to create channel mapping", "channel_id", req.ChannelID, "bridge_name", req.BridgeName, "bridge_room_id", req.BridgeRoomID, "error", err)
|
||||
if err = bridge.CreateChannelMapping(req.ChannelID, req.BridgeChannelID); err != nil {
|
||||
m.logger.LogError("Failed to create channel mapping", "channel_id", req.ChannelID, "bridge_name", req.BridgeName, "bridge_channel_id", req.BridgeChannelID, "error", err)
|
||||
return fmt.Errorf("failed to create channel mapping for bridge '%s': %w", req.BridgeName, err)
|
||||
}
|
||||
|
||||
|
@ -324,19 +324,19 @@ func (m *BridgeManager) CreateChannelMapping(req model.CreateChannelMappingReque
|
|||
}
|
||||
|
||||
// Create the channel mapping in the Mattermost bridge
|
||||
if err = mattermostBridge.CreateChannelMapping(req.ChannelID, req.BridgeRoomID); err != nil {
|
||||
m.logger.LogError("Failed to create channel mapping in Mattermost bridge", "channel_id", req.ChannelID, "bridge_name", req.BridgeName, "bridge_room_id", req.BridgeRoomID, "error", err)
|
||||
if err = mattermostBridge.CreateChannelMapping(req.ChannelID, req.BridgeChannelID); err != nil {
|
||||
m.logger.LogError("Failed to create channel mapping in Mattermost bridge", "channel_id", req.ChannelID, "bridge_name", req.BridgeName, "bridge_channel_id", req.BridgeChannelID, "error", err)
|
||||
return fmt.Errorf("failed to create channel mapping in Mattermost bridge: %w", err)
|
||||
}
|
||||
|
||||
// Share the channel using Mattermost's shared channels API
|
||||
if err = m.shareChannel(req); err != nil {
|
||||
m.logger.LogError("Failed to share channel", "channel_id", req.ChannelID, "bridge_room_id", req.BridgeRoomID, "error", err)
|
||||
m.logger.LogError("Failed to share channel", "channel_id", req.ChannelID, "bridge_channel_id", req.BridgeChannelID, "error", err)
|
||||
// Don't fail the entire operation if sharing fails, but log the error
|
||||
m.logger.LogWarn("Channel mapping created but sharing failed - channel may not sync properly")
|
||||
}
|
||||
|
||||
m.logger.LogInfo("Successfully created channel mapping", "channel_id", req.ChannelID, "bridge_name", req.BridgeName, "bridge_room_id", req.BridgeRoomID)
|
||||
m.logger.LogInfo("Successfully created channel mapping", "channel_id", req.ChannelID, "bridge_name", req.BridgeName, "bridge_channel_id", req.BridgeChannelID)
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -403,9 +403,9 @@ func (m *BridgeManager) shareChannel(req model.CreateChannelMappingRequest) erro
|
|||
TeamId: req.TeamID,
|
||||
Home: true,
|
||||
ReadOnly: false,
|
||||
ShareName: model.SanitizeShareName(fmt.Sprintf("bridge-%s", req.BridgeRoomID)),
|
||||
ShareDisplayName: fmt.Sprintf("Bridge: %s", req.BridgeRoomID),
|
||||
SharePurpose: fmt.Sprintf("Shared channel bridged to %s", req.BridgeRoomID),
|
||||
ShareName: model.SanitizeShareName(fmt.Sprintf("bridge-%s", req.BridgeChannelID)),
|
||||
ShareDisplayName: fmt.Sprintf("Bridge: %s", req.BridgeChannelID),
|
||||
SharePurpose: fmt.Sprintf("Shared channel bridged to %s", req.BridgeChannelID),
|
||||
ShareHeader: "test header",
|
||||
CreatorId: req.UserID,
|
||||
RemoteId: m.remoteID,
|
||||
|
|
|
@ -163,7 +163,7 @@ func (c *Handler) executeMapCommand(args *model.CommandArgs, fields []string) *m
|
|||
mappingReq := pluginModel.CreateChannelMappingRequest{
|
||||
ChannelID: channelID,
|
||||
BridgeName: "xmpp",
|
||||
BridgeRoomID: roomJID,
|
||||
BridgeChannelID: roomJID,
|
||||
UserID: args.UserId,
|
||||
TeamID: args.TeamId,
|
||||
}
|
||||
|
@ -292,7 +292,7 @@ func (c *Handler) formatMappingError(operation, roomJID string, err error) *mode
|
|||
case strings.Contains(errorMsg, "already mapped to channel"):
|
||||
return &model.CommandResponse{
|
||||
ResponseType: model.CommandResponseTypeEphemeral,
|
||||
Text: fmt.Sprintf(`❌ **Room Already Mapped**
|
||||
Text: fmt.Sprintf(`❌ **Channel Already Mapped**
|
||||
|
||||
The XMPP room **%s** is already connected to another channel.
|
||||
|
||||
|
@ -305,7 +305,7 @@ The XMPP room **%s** is already connected to another channel.
|
|||
case strings.Contains(errorMsg, "does not exist"):
|
||||
return &model.CommandResponse{
|
||||
ResponseType: model.CommandResponseTypeEphemeral,
|
||||
Text: fmt.Sprintf(`❌ **Room Not Found**
|
||||
Text: fmt.Sprintf(`❌ **Channel Not Found**
|
||||
|
||||
The XMPP room **%s** doesn't exist or isn't accessible.
|
||||
|
||||
|
|
|
@ -22,7 +22,7 @@ const (
|
|||
type CreateChannelMappingRequest struct {
|
||||
ChannelID string // Mattermost channel ID
|
||||
BridgeName string // Name of the bridge (e.g., "xmpp")
|
||||
BridgeRoomID string // Remote room/channel ID (e.g., JID for XMPP)
|
||||
BridgeChannelID string // Remote room/channel ID (e.g., JID for XMPP)
|
||||
UserID string // ID of user who triggered the mapping creation
|
||||
TeamID string // Team ID where the channel belongs
|
||||
}
|
||||
|
@ -35,8 +35,8 @@ func (r CreateChannelMappingRequest) Validate() error {
|
|||
if r.BridgeName == "" {
|
||||
return fmt.Errorf("bridgeName cannot be empty")
|
||||
}
|
||||
if r.BridgeRoomID == "" {
|
||||
return fmt.Errorf("bridgeRoomID cannot be empty")
|
||||
if r.BridgeChannelID == "" {
|
||||
return fmt.Errorf("bridgeChannelID cannot be empty")
|
||||
}
|
||||
if r.UserID == "" {
|
||||
return fmt.Errorf("userID cannot be empty")
|
||||
|
@ -132,13 +132,13 @@ type Bridge interface {
|
|||
// Stop stops the bridge
|
||||
Stop() error
|
||||
|
||||
// CreateChannelMapping creates a mapping between a Mattermost channel ID and an bridge room ID.
|
||||
// CreateChannelMapping creates a mapping between a Mattermost channel ID and a bridge channel ID.
|
||||
CreateChannelMapping(channelID, roomJID string) error
|
||||
|
||||
// GetChannelMapping retrieves the bridge room ID for a given Mattermost channel ID.
|
||||
// GetChannelMapping retrieves the bridge channel ID for a given Mattermost channel ID.
|
||||
GetChannelMapping(channelID string) (string, error)
|
||||
|
||||
// DeleteChannelMapping removes a mapping between a Mattermost channel ID and a bridge room ID.
|
||||
// DeleteChannelMapping removes a mapping between a Mattermost channel ID and a bridge channel ID.
|
||||
DeleteChannelMapping(channelID string) error
|
||||
|
||||
// ChannelMappingExists checks if a room/channel exists on the remote service.
|
||||
|
|
|
@ -7,72 +7,17 @@ import "strings"
|
|||
// to ensure consistency and avoid key conflicts.
|
||||
|
||||
const (
|
||||
// CurrentKVStoreVersion is the current version requiring migrations
|
||||
CurrentKVStoreVersion = 2
|
||||
// KeyPrefixXMPPUser is the prefix for XMPP user ID -> Mattermost user ID mappings
|
||||
KeyPrefixXMPPUser = "xmpp_user_"
|
||||
// KeyPrefixMattermostUser is the prefix for Mattermost user ID -> XMPP user ID mappings
|
||||
KeyPrefixMattermostUser = "mattermost_user_"
|
||||
|
||||
// KeyPrefixChannelMap is the prefix for bridge-agnostic channel mappings
|
||||
KeyPrefixChannelMap = "channel_map_"
|
||||
|
||||
// KeyPrefixGhostUser is the prefix for Mattermost user ID -> XMPP ghost user ID cache
|
||||
KeyPrefixGhostUser = "ghost_user_"
|
||||
// KeyPrefixGhostRoom is the prefix for ghost user room membership tracking
|
||||
KeyPrefixGhostRoom = "ghost_room_"
|
||||
|
||||
// KeyPrefixXMPPEventPost is the prefix for XMPP event ID -> Mattermost post ID mappings
|
||||
KeyPrefixXMPPEventPost = "xmpp_event_post_"
|
||||
// KeyPrefixXMPPReaction is the prefix for XMPP reaction event ID -> reaction info mappings
|
||||
KeyPrefixXMPPReaction = "xmpp_reaction_"
|
||||
|
||||
// KeyStoreVersion is the key for tracking the current KV store schema version
|
||||
KeyStoreVersion = "kv_store_version"
|
||||
|
||||
// KeyPrefixLegacyDMMapping was the old prefix for DM mappings
|
||||
KeyPrefixLegacyDMMapping = "dm_mapping_"
|
||||
// KeyPrefixLegacyXMPPDMMapping was the old prefix for XMPP DM mappings
|
||||
KeyPrefixLegacyXMPPDMMapping = "xmpp_dm_mapping_"
|
||||
)
|
||||
|
||||
// Helper functions for building KV store keys
|
||||
|
||||
// BuildXMPPUserKey creates a key for XMPP user -> Mattermost user mapping
|
||||
func BuildXMPPUserKey(xmppUserID string) string {
|
||||
return KeyPrefixXMPPUser + xmppUserID
|
||||
}
|
||||
|
||||
// BuildMattermostUserKey creates a key for Mattermost user -> XMPP user mapping
|
||||
func BuildMattermostUserKey(mattermostUserID string) string {
|
||||
return KeyPrefixMattermostUser + mattermostUserID
|
||||
}
|
||||
|
||||
// BuildChannelMapKey creates a bridge-agnostic key for channel mappings
|
||||
func BuildChannelMapKey(bridgeName, identifier string) string {
|
||||
return KeyPrefixChannelMap + bridgeName + "_" + identifier
|
||||
}
|
||||
|
||||
// BuildGhostUserKey creates a key for ghost user cache
|
||||
func BuildGhostUserKey(mattermostUserID string) string {
|
||||
return KeyPrefixGhostUser + mattermostUserID
|
||||
}
|
||||
|
||||
// BuildGhostRoomKey creates a key for ghost user room membership
|
||||
func BuildGhostRoomKey(mattermostUserID, roomID string) string {
|
||||
return KeyPrefixGhostRoom + mattermostUserID + "_" + roomID
|
||||
}
|
||||
|
||||
// BuildXMPPEventPostKey creates a key for XMPP event -> post mapping
|
||||
func BuildXMPPEventPostKey(xmppEventID string) string {
|
||||
return KeyPrefixXMPPEventPost + xmppEventID
|
||||
}
|
||||
|
||||
// BuildXMPPReactionKey creates a key for XMPP reaction storage
|
||||
func BuildXMPPReactionKey(reactionEventID string) string {
|
||||
return KeyPrefixXMPPReaction + reactionEventID
|
||||
}
|
||||
|
||||
// ExtractIdentifierFromChannelMapKey extracts the identifier from a bridge-agnostic channel map key
|
||||
func ExtractIdentifierFromChannelMapKey(key, bridgeName string) string {
|
||||
expectedPrefix := KeyPrefixChannelMap + bridgeName + "_"
|
||||
|
|
|
@ -155,7 +155,6 @@ func (c *Client) SetServerDomain(domain string) {
|
|||
|
||||
// Connect establishes connection to the XMPP server
|
||||
func (c *Client) Connect() error {
|
||||
|
||||
if c.session != nil {
|
||||
return nil // Already connected
|
||||
}
|
||||
|
|
Reference in a new issue