chore: fix lint issues

This commit is contained in:
Felipe M 2025-08-06 18:25:25 +02:00
parent 17ea21a579
commit 7c37953c28
No known key found for this signature in database
GPG key ID: 52E5D65FCF99808A
20 changed files with 136 additions and 131 deletions

View file

@ -9,15 +9,16 @@ import (
"fmt"
"github.com/mattermost/mattermost/server/public/plugin"
"mellium.im/xmlstream"
"mellium.im/xmpp/stanza"
"github.com/mattermost/mattermost-plugin-bridge-xmpp/server/bridge"
"github.com/mattermost/mattermost-plugin-bridge-xmpp/server/config"
"github.com/mattermost/mattermost-plugin-bridge-xmpp/server/logger"
pluginModel "github.com/mattermost/mattermost-plugin-bridge-xmpp/server/model"
"github.com/mattermost/mattermost-plugin-bridge-xmpp/server/store/kvstore"
xmppClient "github.com/mattermost/mattermost-plugin-bridge-xmpp/server/xmpp"
"github.com/mattermost/mattermost/server/public/plugin"
"mellium.im/xmlstream"
"mellium.im/xmpp/stanza"
)
const (
@ -55,12 +56,12 @@ type xmppBridge struct {
}
// NewBridge creates a new XMPP bridge
func NewBridge(log logger.Logger, api plugin.API, kvstore kvstore.KVStore, cfg *config.Configuration, bridgeID, remoteID string) pluginModel.Bridge {
func NewBridge(log logger.Logger, api plugin.API, store kvstore.KVStore, cfg *config.Configuration, bridgeID, remoteID string) pluginModel.Bridge {
ctx, cancel := context.WithCancel(context.Background())
b := &xmppBridge{
logger: log,
api: api,
kvstore: kvstore,
kvstore: store,
ctx: ctx,
cancel: cancel,
channelMappings: make(map[string]string),
@ -87,7 +88,7 @@ func NewBridge(log logger.Logger, api plugin.API, kvstore kvstore.KVStore, cfg *
func (b *xmppBridge) createXMPPClient(cfg *config.Configuration) *xmppClient.Client {
// Create TLS config based on certificate verification setting
tlsConfig := &tls.Config{
InsecureSkipVerify: cfg.XMPPInsecureSkipVerify,
InsecureSkipVerify: cfg.XMPPInsecureSkipVerify, //nolint:gosec // Allow insecure TLS for testing environments
}
return xmppClient.NewClientWithTLS(
@ -154,19 +155,19 @@ func (b *xmppBridge) Start() error {
b.logger.LogDebug("Starting Mattermost to XMPP bridge")
b.configMu.RLock()
config := b.config
cfg := b.config
b.configMu.RUnlock()
if config == nil {
if cfg == nil {
return fmt.Errorf("bridge configuration not set")
}
if !config.EnableSync {
if !cfg.EnableSync {
b.logger.LogInfo("XMPP sync is disabled, bridge will not start")
return nil
}
b.logger.LogInfo("Starting Mattermost to XMPP bridge", "xmpp_server", config.XMPPServerURL, "username", config.XMPPUsername)
b.logger.LogInfo("Starting Mattermost to XMPP bridge", "xmpp_server", cfg.XMPPServerURL, "username", cfg.XMPPUsername)
// Connect to XMPP server
if err := b.connectToXMPP(); err != nil {
@ -340,10 +341,10 @@ func (b *xmppBridge) connectionMonitor() {
// handleReconnection attempts to reconnect to XMPP and rejoin rooms
func (b *xmppBridge) handleReconnection() {
b.configMu.RLock()
config := b.config
cfg := b.config
b.configMu.RUnlock()
if config == nil || !config.EnableSync {
if cfg == nil || !cfg.EnableSync {
return
}
@ -357,7 +358,7 @@ func (b *xmppBridge) handleReconnection() {
// Retry connection with exponential backoff
maxRetries := 3
for i := range maxRetries {
backoff := time.Duration(1<<uint(i)) * time.Second
backoff := time.Duration(1<<i) * time.Second
select {
case <-b.ctx.Done():
@ -604,6 +605,8 @@ func (b *xmppBridge) ID() string {
}
// handleIncomingXMPPMessage handles incoming XMPP messages and converts them to bridge messages
//
//nolint:gocritic // msg parameter must match external XMPP library handler signature
func (b *xmppBridge) handleIncomingXMPPMessage(msg stanza.Message, t xmlstream.TokenReadEncoder) error {
b.logger.LogDebug("XMPP bridge handling incoming message",
"from", msg.From.String(),

View file

@ -85,7 +85,7 @@ func (h *xmppMessageHandler) sendMessageToXMPP(msg *pluginModel.BridgeMessage) e
}
// Send the message
_, err = h.bridge.bridgeClient.SendMessage(req)
_, err = h.bridge.bridgeClient.SendMessage(&req)
if err != nil {
return fmt.Errorf("failed to send message to XMPP room: %w", err)
}
@ -144,7 +144,7 @@ func (r *xmppUserResolver) FormatUserMention(user *pluginModel.ExternalUser) str
func (r *xmppUserResolver) GetDisplayName(externalUserID string) string {
// For XMPP JIDs, extract the local part or resource as display name
// Format: user@domain/resource -> use resource or user
if len(externalUserID) == 0 {
if externalUserID == "" {
return "Unknown User"
}

View file

@ -15,6 +15,8 @@ import (
)
// XMPPUser represents an XMPP user that implements the BridgeUser interface
//
//nolint:revive // XMPPUser is clearer than User in this context
type XMPPUser struct {
// User identity
id string
@ -41,12 +43,12 @@ type XMPPUser struct {
}
// NewXMPPUser creates a new XMPP user
func NewXMPPUser(id, displayName, jid string, cfg *config.Configuration, logger logger.Logger) *XMPPUser {
func NewXMPPUser(id, displayName, jid string, cfg *config.Configuration, log logger.Logger) *XMPPUser {
ctx, cancel := context.WithCancel(context.Background())
// Create TLS config based on certificate verification setting
tlsConfig := &tls.Config{
InsecureSkipVerify: cfg.XMPPInsecureSkipVerify,
InsecureSkipVerify: cfg.XMPPInsecureSkipVerify, //nolint:gosec // Allow insecure TLS for testing environments
}
// Create XMPP client for this user
@ -57,7 +59,7 @@ func NewXMPPUser(id, displayName, jid string, cfg *config.Configuration, logger
cfg.GetXMPPResource(),
id, // Use user ID as remote ID
tlsConfig,
logger,
log,
)
return &XMPPUser{
@ -69,7 +71,7 @@ func NewXMPPUser(id, displayName, jid string, cfg *config.Configuration, logger
config: cfg,
ctx: ctx,
cancel: cancel,
logger: logger,
logger: log,
}
}
@ -171,7 +173,7 @@ func (u *XMPPUser) SendMessageToChannel(channelID, message string) error {
Message: message,
}
_, err := u.client.SendMessage(req)
_, err := u.client.SendMessage(&req)
if err != nil {
return fmt.Errorf("failed to send message to XMPP room %s: %w", channelID, err)
}