feat: implement comprehensive loop prevention and architecture improvements

- Add comprehensive loop prevention at source level for all bridges:
  - XMPP bridge: Skip messages from own XMPP connection user
  - Mattermost bridge: Skip messages from bot user and remote users
- Remove cache from getOrCreateRemoteUser method for simplified user management
- Improve XMPP client architecture with direct handler delegation:
  - Add SetMessageHandler and GetJID methods to XMPP client
  - Move protocol normalization methods to client level
  - Implement handleIncomingXMPPMessage in XMPP bridge for business logic
- Fix message direction handling in XMPP message handler
- Add remote user invitation to shared channels via InviteRemoteToChannel API
- Clean up unused code and improve code formatting

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

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Felipe M 2025-08-06 17:16:52 +02:00
parent 11a32afc53
commit d9c0215b93
No known key found for this signature in database
GPG key ID: 52E5D65FCF99808A
6 changed files with 63 additions and 44 deletions

View file

@ -32,8 +32,8 @@ type xmppBridge struct {
kvstore kvstore.KVStore
bridgeClient *xmppClient.Client // Main bridge XMPP client connection
userManager pluginModel.BridgeUserManager
bridgeID string // Bridge identifier used for registration
remoteID string // Remote ID for shared channels
bridgeID string // Bridge identifier used for registration
remoteID string // Remote ID for shared channels
// Message handling
messageHandler *xmppMessageHandler
@ -181,7 +181,6 @@ func (b *xmppBridge) Start() error {
// Start connection monitor
go b.connectionMonitor()
b.logger.LogInfo("Mattermost to XMPP bridge started successfully")
return nil
}
@ -574,7 +573,6 @@ func (b *xmppBridge) GetUserManager() pluginModel.BridgeUserManager {
return b.userManager
}
// GetMessageChannel returns the channel for incoming messages from XMPP
func (b *xmppBridge) GetMessageChannel() <-chan *pluginModel.DirectionalMessage {
return b.incomingMessages
@ -638,6 +636,14 @@ func (b *xmppBridge) handleIncomingXMPPMessage(msg stanza.Message, t xmlstream.T
userID, displayName := b.bridgeClient.ExtractUserInfo(msg.From)
// Skip messages from our own XMPP user to prevent loops
if userID == b.bridgeClient.GetJID().String() {
b.logger.LogDebug("Skipping message from our own XMPP user to prevent loop",
"our_jid", b.bridgeClient.GetJID().String(),
"source_user_id", userID)
return nil
}
// Create bridge message
bridgeMessage := &pluginModel.BridgeMessage{
SourceBridge: b.bridgeID,