This is an automated email from the ASF dual-hosted git repository.

linkinstar pushed a commit to branch feat/1.3.0/notifiaction
in repository https://gitbox.apache.org/repos/asf/incubator-answer.git


The following commit(s) were added to refs/heads/feat/1.3.0/notifiaction by 
this push:
     new faf0b7e9 fix(notification): If receiver not set language, use site 
default language. #833
faf0b7e9 is described below

commit faf0b7e9ccf68799df95c4f4efef5a1e4c04bfb9
Author: LinkinStars <[email protected]>
AuthorDate: Wed Mar 13 17:08:02 2024 +0800

    fix(notification): If receiver not set language, use site default language. 
#833
---
 internal/service/notification/external_notification.go     |  8 ++++++++
 internal/service/notification/new_question_notification.go | 10 +++++++++-
 internal/service/notification_common/notification.go       | 10 ++++++++++
 3 files changed, 27 insertions(+), 1 deletion(-)

diff --git a/internal/service/notification/external_notification.go 
b/internal/service/notification/external_notification.go
index 58228884..1db83f0b 100644
--- a/internal/service/notification/external_notification.go
+++ b/internal/service/notification/external_notification.go
@@ -21,7 +21,9 @@ package notification
 
 import (
        "context"
+
        "github.com/apache/incubator-answer/internal/base/data"
+       "github.com/apache/incubator-answer/internal/base/translator"
        "github.com/apache/incubator-answer/internal/schema"
        "github.com/apache/incubator-answer/internal/service/activity_common"
        "github.com/apache/incubator-answer/internal/service/export"
@@ -71,6 +73,12 @@ func NewExternalNotificationService(
 func (ns *ExternalNotificationService) Handler(ctx context.Context, msg 
*schema.ExternalNotificationMsg) error {
        log.Debugf("try to send external notification %+v", msg)
 
+       // If receiver not set language, use site default language.
+       if len(msg.ReceiverLang) == 0 || msg.ReceiverLang == 
translator.DefaultLangOption {
+               if interfaceInfo, _ := 
ns.siteInfoService.GetSiteInterface(ctx); interfaceInfo != nil {
+                       msg.ReceiverLang = interfaceInfo.Language
+               }
+       }
        if msg.NewQuestionTemplateRawData != nil {
                return ns.handleNewQuestionNotification(ctx, msg)
        }
diff --git a/internal/service/notification/new_question_notification.go 
b/internal/service/notification/new_question_notification.go
index c079ac28..d4173397 100644
--- a/internal/service/notification/new_question_notification.go
+++ b/internal/service/notification/new_question_notification.go
@@ -25,6 +25,7 @@ import (
        "time"
 
        "github.com/apache/incubator-answer/internal/base/constant"
+       "github.com/apache/incubator-answer/internal/base/translator"
        "github.com/apache/incubator-answer/internal/schema"
        "github.com/apache/incubator-answer/pkg/display"
        "github.com/apache/incubator-answer/pkg/token"
@@ -229,7 +230,7 @@ func (ns *ExternalNotificationService) 
syncNewQuestionNotificationToPlugin(ctx c
 
                        if len(subscriberUserID) > 0 {
                                userInfo, _, _ := ns.userRepo.GetByUserID(ctx, 
subscriberUserID)
-                               if userInfo != nil {
+                               if userInfo != nil && len(userInfo.Language) > 
0 && userInfo.Language != translator.DefaultLangOption {
                                        newMsg.ReceiverLang = userInfo.Language
                                }
                        }
@@ -264,6 +265,13 @@ func (ns *ExternalNotificationService) 
newPluginQuestionNotification(
        if err != nil {
                return raw
        }
+       interfaceInfo, err := ns.siteInfoService.GetSiteInterface(ctx)
+       if err != nil {
+               return raw
+       }
+       if len(raw.ReceiverLang) == 0 || raw.ReceiverLang == 
translator.DefaultLangOption {
+               raw.ReceiverLang = interfaceInfo.Language
+       }
        raw.QuestionUrl = display.QuestionURL(
                seoInfo.Permalink, siteInfo.SiteUrl,
                msg.NewQuestionTemplateRawData.QuestionID, 
msg.NewQuestionTemplateRawData.QuestionTitle)
diff --git a/internal/service/notification_common/notification.go 
b/internal/service/notification_common/notification.go
index 2338023c..319403b2 100644
--- a/internal/service/notification_common/notification.go
+++ b/internal/service/notification_common/notification.go
@@ -24,6 +24,7 @@ import (
        "fmt"
        "time"
 
+       "github.com/apache/incubator-answer/internal/base/translator"
        "github.com/apache/incubator-answer/internal/service/siteinfo_common"
        
"github.com/apache/incubator-answer/internal/service/user_external_login"
        "github.com/apache/incubator-answer/pkg/display"
@@ -253,6 +254,11 @@ func (ns *NotificationCommon) syncNotificationToPlugin(ctx 
context.Context, objI
                log.Errorf("get site seo info failed: %v", err)
                return
        }
+       interfaceInfo, err := ns.siteInfoService.GetSiteInterface(ctx)
+       if err != nil {
+               log.Errorf("get site interface info failed: %v", err)
+               return
+       }
 
        objInfo.QuestionID = uid.DeShortID(objInfo.QuestionID)
        objInfo.AnswerID = uid.DeShortID(objInfo.AnswerID)
@@ -294,6 +300,10 @@ func (ns *NotificationCommon) syncNotificationToPlugin(ctx 
context.Context, objI
                if userInfo != nil {
                        pluginNotificationMsg.ReceiverLang = userInfo.Language
                }
+               // If receiver not set language, use site default language.
+               if len(pluginNotificationMsg.ReceiverLang) == 0 || 
pluginNotificationMsg.ReceiverLang == translator.DefaultLangOption {
+                       pluginNotificationMsg.ReceiverLang = 
interfaceInfo.Language
+               }
        }
 
        _ = plugin.CallNotification(func(fn plugin.Notification) error {

Reply via email to