mattermost-plugin-bridge-xmpp/server/store/kvstore/constants.go
Felipe Martin d159c668c2
feat: implement production-ready MUC operations and comprehensive testing
- Implement proper XMPP MUC operations using mellium.im/xmpp/muc package
- Add session readiness checking to prevent blocking on room joins
- Create comprehensive bridge manager architecture with lifecycle management
- Add complete channel mapping functionality with KV store persistence
- Remove defensive logger nil checks as requested by user
- Enhance XMPP client doctor with MUC testing (join/wait/leave workflow)
- Add detailed dev server documentation for test room creation
- Implement timeout protection for all MUC operations
- Add proper error handling with fmt.Errorf instead of pkg/errors
- Successfully tested: MUC join in ~21ms, 5s wait, clean leave operation

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-08-01 13:47:15 +02:00

87 lines
3.4 KiB
Go

package kvstore
// KV Store key prefixes and constants
// This file centralizes all KV store key patterns used throughout the plugin
// 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_"
// KeyPrefixChannelMapping is the prefix for Mattermost channel ID -> XMPP room mappings
KeyPrefixChannelMapping = "channel_mapping_"
// KeyPrefixRoomMapping is the prefix for XMPP room identifier -> Mattermost channel ID mappings
KeyPrefixRoomMapping = "xmpp_room_mapping_"
// 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 (migrated to channel_mapping_)
KeyPrefixLegacyDMMapping = "dm_mapping_"
// KeyPrefixLegacyXMPPDMMapping was the old prefix for XMPP DM mappings (migrated to room_mapping_)
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
}
// BuildChannelMappingKey creates a key for channel -> room mapping
func BuildChannelMappingKey(channelID string) string {
return KeyPrefixChannelMapping + channelID
}
// BuildRoomMappingKey creates a key for room -> channel mapping
func BuildRoomMappingKey(roomIdentifier string) string {
return KeyPrefixRoomMapping + roomIdentifier
}
// 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
}
// ExtractChannelIDFromKey extracts the channel ID from a channel mapping key
func ExtractChannelIDFromKey(key string) string {
if len(key) <= len(KeyPrefixChannelMapping) {
return ""
}
return key[len(KeyPrefixChannelMapping):]
}