Skip to content

Commit

Permalink
issue event get context by org locale
Browse files Browse the repository at this point in the history
  • Loading branch information
chengjoey committed Dec 30, 2021
1 parent 018087f commit 7fed6ea
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 15 deletions.
22 changes: 11 additions & 11 deletions modules/dop/services/issuestream/issue_stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,15 +143,6 @@ func (s *IssueStream) CreateIssueEvent(req *apistructs.IssueStreamCreateRequest)
}
var content string
var err error
if len(req.StreamTypes) == 0 {
content, err = getDefaultContentForMsgSending(req.StreamType, req.StreamParams)
} else {
content, err = s.groupEventContent(req.StreamTypes, req.StreamParams)
}
if err != nil {
logrus.Errorf("get issue %d content error: %v, content will be empty", req.IssueID, err)
}
logrus.Debugf("old issue content is: %s", content)
issue, err := s.db.GetIssue(req.IssueID)
if err != nil {
return err
Expand All @@ -174,6 +165,15 @@ func (s *IssueStream) CreateIssueEvent(req *apistructs.IssueStreamCreateRequest)
if err != nil {
return err
}
if len(req.StreamTypes) == 0 {
content, err = getDefaultContentForMsgSending(req.StreamType, req.StreamParams, orgModel.Locale)
} else {
content, err = s.groupEventContent(req.StreamTypes, req.StreamParams, orgModel.Locale)
}
if err != nil {
logrus.Errorf("get issue %d content error: %v, content will be empty", req.IssueID, err)
}
logrus.Debugf("old issue content is: %s", content)
ev := &apistructs.EventCreateRequest{
EventHeader: apistructs.EventHeader{
Event: bundle.IssueEvent,
Expand Down Expand Up @@ -215,11 +215,11 @@ func (s *IssueStream) filterReceiversByOperatorID(receivers []string, operatorID
return users
}

func (s *IssueStream) groupEventContent(streamTypes []apistructs.IssueStreamType, param apistructs.ISTParam) (string, error) {
func (s *IssueStream) groupEventContent(streamTypes []apistructs.IssueStreamType, param apistructs.ISTParam, locale string) (string, error) {
var content string
interval := ";"
for _, streamType := range streamTypes {
tmp, err := getDefaultContentForMsgSending(streamType, param)
tmp, err := getDefaultContentForMsgSending(streamType, param, locale)
if err != nil {
return "", err
}
Expand Down
9 changes: 7 additions & 2 deletions modules/dop/services/issuestream/issue_stream_template.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ func getIssueStreamTemplate(locale string, ist apistructs.IssueStreamType) (stri

// getIssueStreamTemplateForMsgSending get issue stream template for msg sending
func getIssueStreamTemplateForMsgSending(locale string, ist apistructs.IssueStreamType) (string, error) {
if locale == "" || locale == "zh-CN" {
locale = "zh"
}
if locale == "en-US" {
locale = "en"
}
templateContent, err := getIssueStreamTemplate(locale, ist)
if err != nil {
return "", err
Expand Down Expand Up @@ -70,8 +76,7 @@ func getDefaultContent(ist apistructs.IssueStreamType, param apistructs.ISTParam
}

// getDefaultContentForMsgSending get rendered msg for sending
func getDefaultContentForMsgSending(ist apistructs.IssueStreamType, param apistructs.ISTParam) (string, error) {
locale := "zh"
func getDefaultContentForMsgSending(ist apistructs.IssueStreamType, param apistructs.ISTParam, locale string) (string, error) {
ct, err := getIssueStreamTemplateForMsgSending(locale, ist)
if err != nil {
return "", err
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ func Test_getDefaultContentForMsgSending(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := getDefaultContentForMsgSending(tt.args.ist, tt.args.param)
got, err := getDefaultContentForMsgSending(tt.args.ist, tt.args.param, "zh")
if (err != nil) != tt.wantErr {
t.Errorf("getDefaultContentForMsgSending() error = %v, wantErr %v", err, tt.wantErr)
return
Expand Down
2 changes: 1 addition & 1 deletion modules/dop/services/issuestream/issue_stream_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func Test_filterReceiversByOperatorID(t *testing.T) {

func Test_groupEventContent(t *testing.T) {
svc := IssueStream{}
content, err := svc.groupEventContent([]apistructs.IssueStreamType{apistructs.ISTChangeContent}, apistructs.ISTParam{})
content, err := svc.groupEventContent([]apistructs.IssueStreamType{apistructs.ISTChangeContent}, apistructs.ISTParam{}, "zh")
assert.NoError(t, err)
assert.Equal(t, "内容发生变更", content)
}

0 comments on commit 7fed6ea

Please sign in to comment.