feat(account-users): align inviter id

This commit is contained in:
2026-06-06 11:45:56 +08:00
parent fbc0bb833d
commit 2acd93831f
7 changed files with 43 additions and 18 deletions
+13 -13
View File
@@ -21,11 +21,11 @@ import (
// after_save (update_presence_in_redis on availability change),
// validates user_id uniqueness scoped to account_id
type AccountUserService struct {
repo *repository.AccountUserRepo
notificationRepo *repository.NotificationSettingRepo
accountRepo *repository.AccountRepo
userRepo *repository.UserRepo
eventBus *pubsub.EventBus
repo *repository.AccountUserRepo
notificationRepo *repository.NotificationSettingRepo
accountRepo *repository.AccountRepo
userRepo *repository.UserRepo
eventBus *pubsub.EventBus
}
// NewAccountUserService creates a new AccountUser service.
@@ -78,10 +78,10 @@ func (s *AccountUserService) AddUserToAccount(ctx context.Context, accountID uin
}
au := &model.AccountUser{
AccountID: accountID,
UserID: req.UserID,
Role: req.Role,
InvitedBy: req.InviterID,
AccountID: accountID,
UserID: req.UserID,
Role: req.Role,
InvitedBy: req.InviterID,
Availability: "offline", // 1:1 Chatwoot: default availability
AutoOffline: true, // 1:1 Chatwoot: default auto_offline
}
@@ -104,7 +104,7 @@ func (s *AccountUserService) AddUserToAccount(ctx context.Context, accountID uin
"account_id": accountID,
"user_id": req.UserID,
"role": req.Role,
"invited_by": req.InviterID,
"inviter_id": req.InviterID,
})
if err := s.eventBus.Publish(pubsub.TopicAccountUserCreated, payload); err != nil {
applogger.L().Errorf("Failed to publish AccountUserCreated event: %v", err)
@@ -211,8 +211,8 @@ func (s *AccountUserService) createDefaultNotificationSetting(ctx context.Contex
// 1:1 Chatwoot: email_conversation_assignment = bit 1 → 2
// push_conversation_assignment = bit 1 → 2
setting := &model.NotificationSetting{
UserID: userID,
AccountID: accountID,
UserID: userID,
AccountID: accountID,
EmailFlags: 2, // bit 1 = email_conversation_assignment
PushFlags: 2, // bit 1 = push_conversation_assignment
}
@@ -234,4 +234,4 @@ func (s *AccountUserService) SetAutoOffline(ctx context.Context, accountID, user
// FindOnlineAgents returns all online agents for an account.
func (s *AccountUserService) FindOnlineAgents(ctx context.Context, accountID uint) ([]model.AccountUser, error) {
return s.repo.FindOnlineAgentsByAccount(ctx, accountID)
}
}