feat(wxwork): remove unused recipient fields from wxWorkNotifyConfig

This commit is contained in:
mlogclub
2026-04-21 17:36:05 +08:00
parent e5c9eba497
commit 8c31a9c444
4 changed files with 5 additions and 25 deletions
-4
View File
@@ -88,10 +88,6 @@ wxWork:
enabled: false
# 默认接收通知的成员ID列表;如业务目标用户已绑定企业微信身份,会优先发给目标用户。
toUsers: []
# 默认接收通知的部门ID列表。
toParties: []
# 默认接收通知的标签ID列表。
toTags: []
# 是否发送保密消息。
safe: false
# 是否开启重复消息检查。
-2
View File
@@ -22,8 +22,6 @@ type Config struct {
type WxWorkNotifyConfig struct {
Enabled bool `yaml:"enabled"`
ToUsers []string `yaml:"toUsers"`
ToParties []string `yaml:"toParties"`
ToTags []string `yaml:"toTags"`
Safe bool `yaml:"safe"`
EnableDuplicateCheck bool `yaml:"enableDuplicateCheck"`
DuplicateCheckInterval int `yaml:"duplicateCheckInterval"`
+3 -9
View File
@@ -22,9 +22,7 @@ type wxWorkMessageSender interface {
}
type wxWorkNotifyRecipients struct {
ToUsers []string
ToParties []string
ToTags []string
ToUsers []string
}
type wxWorkNotifyService struct {
@@ -79,8 +77,6 @@ func (s *wxWorkNotifyService) sendText(title, body string, recipients wxWorkNoti
req := wxmessage.SendTextRequest{
SendRequestCommon: &wxmessage.SendRequestCommon{
ToUser: strings.Join(recipients.ToUsers, "|"),
ToParty: strings.Join(recipients.ToParties, "|"),
ToTag: strings.Join(recipients.ToTags, "|"),
AgentID: strings.TrimSpace(cfg.AgentID),
Safe: cast.ToInt(cfg.Notify.Safe),
EnableDuplicateCheck: cast.ToInt(cfg.Notify.EnableDuplicateCheck),
@@ -117,9 +113,7 @@ func (s *wxWorkNotifyService) resolveRecipientsByUserIDs(userIDs []int64) wxWork
func (s *wxWorkNotifyService) defaultRecipients() wxWorkNotifyRecipients {
cfg := config.Current().WxWork.Notify
return wxWorkNotifyRecipients{
ToUsers: arrs.Distinct(cfg.ToUsers),
ToParties: arrs.Distinct(cfg.ToParties),
ToTags: arrs.Distinct(cfg.ToTags),
ToUsers: arrs.Distinct(cfg.ToUsers),
}
}
@@ -149,7 +143,7 @@ func (s *wxWorkNotifyService) normalizeDuplicateCheckInterval(value int) int {
}
func (r wxWorkNotifyRecipients) empty() bool {
return len(r.ToUsers) == 0 && len(r.ToParties) == 0 && len(r.ToTags) == 0
return len(r.ToUsers) == 0
}
func truncateRunes(value string, max int) string {
@@ -18,10 +18,8 @@ func TestWxWorkNotifyDefaultRecipients(t *testing.T) {
config.SetCurrent(&config.Config{
WxWork: config.WxWorkConfig{
Notify: config.WxWorkNotifyConfig{
Enabled: true,
ToUsers: []string{" user_a ", "user_a", ""},
ToParties: []string{"2", "2"},
ToTags: []string{"tag-1"},
Enabled: true,
ToUsers: []string{" user_a ", "user_a", ""},
},
},
})
@@ -31,12 +29,6 @@ func TestWxWorkNotifyDefaultRecipients(t *testing.T) {
if len(recipients.ToUsers) != 1 || recipients.ToUsers[0] != "user_a" {
t.Fatalf("unexpected users: %#v", recipients.ToUsers)
}
if len(recipients.ToParties) != 1 || recipients.ToParties[0] != "2" {
t.Fatalf("unexpected parties: %#v", recipients.ToParties)
}
if len(recipients.ToTags) != 1 || recipients.ToTags[0] != "tag-1" {
t.Fatalf("unexpected tags: %#v", recipients.ToTags)
}
}
func TestWxWorkNotifyNormalizeDuplicateCheckInterval(t *testing.T) {