feat: implement comprehensive bridge-agnostic user management system

This commit implements a complete multi-user bridge management system that allows bridges to control multiple users with async goroutine management and convenience methods for channel operations.

Key features:
- Bridge-agnostic BridgeUser interface with validation, identity, state management, channel operations, connection lifecycle, and goroutine lifecycle methods
- BridgeUserManager interface for user lifecycle management with bridge type identification
- XMPPUser implementation for XMPP bridge with XMPP client integration, connection monitoring, and room operations
- MattermostUser implementation for Mattermost bridge with API integration and channel management
- Updated Bridge interface to include GetUserManager() method
- Base UserManager implementation with generic user management logic
- Added Ping() and CheckChannelExists() methods to BridgeUser interface for health checking and room validation
- Updated bridge manager naming from Manager to BridgeManager for clarity

The system enables bridges to manage multiple users (like "Mattermost Bridge" user in XMPP) with proper state management, connection monitoring, and channel operations abstracted across different bridge protocols.

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

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Felipe M 2025-08-04 17:50:44 +02:00
parent ea1711e94c
commit db8037ffbf
No known key found for this signature in database
GPG key ID: 52E5D65FCF99808A
8 changed files with 949 additions and 94 deletions

View file

@ -1,6 +1,11 @@
package model
import "fmt"
import (
"context"
"fmt"
"github.com/mattermost/mattermost-plugin-bridge-xmpp/server/config"
)
type BridgeID string
@ -144,27 +149,59 @@ type Bridge interface {
// Ping actively tests the bridge connection health by sending a lightweight request.
Ping() error
// GetUserManager returns the user manager for this bridge.
GetUserManager() BridgeUserManager
}
// BridgeUser represents a user connected to any bridge service
type BridgeUser interface {
// Validation
Validate() error
// Identity (bridge-agnostic)
GetID() string
GetDisplayName() string
// State management
GetState() UserState
SetState(state UserState) error
// Channel operations (abstracted from rooms/channels/groups)
JoinChannel(channelID string) error
LeaveChannel(channelID string) error
SendMessageToChannel(channelID, message string) error
// Connection lifecycle
Connect() error
Disconnect() error
IsConnected() bool
Ping() error
// Channel existence check
CheckChannelExists(channelID string) (bool, error)
// Goroutine lifecycle
Start(ctx context.Context) error
Stop() error
}
// BridgeUserManager manages users for a specific bridge
type BridgeUserManager interface {
// CreateUser creates a new user in the bridge system.
CreateUser(userID string, userData any) error
// GetUser retrieves user data for a given user ID.
GetUser(userID string) (any, error)
// UpdateUser updates user data for a given user ID.
UpdateUser(userID string, userData any) error
// DeleteUser removes a user from the bridge system.
// User lifecycle
CreateUser(user BridgeUser) error
GetUser(userID string) (BridgeUser, error)
DeleteUser(userID string) error
// ListUsers returns a list of all users in the bridge system.
ListUsers() ([]string, error)
// HasUser checks if a user exists in the bridge system.
ListUsers() []BridgeUser
HasUser(userID string) bool
// OnUserStateChange is called when a user's state changes (e.g., online, away, offline).
OnUserStateChange(userID string, state UserState) error
// Manager lifecycle
Start(ctx context.Context) error
Stop() error
// Configuration updates
UpdateConfiguration(config *config.Configuration) error
// Bridge type identification
GetBridgeType() string
}