Merge remote-tracking branch 'github/feat/1.1.0/report' into feat/1.1.0/context

This commit is contained in:
LinkinStars 2023-06-02 12:17:15 +08:00
commit aeaeb4b127
5 changed files with 34 additions and 13 deletions

View File

@ -7,7 +7,3 @@ const (
AvatarTypeGravatar = "gravatar" AvatarTypeGravatar = "gravatar"
AvatarTypeCustom = "custom" AvatarTypeCustom = "custom"
) )
var (
DefaultSiteURL = ""
)

View File

@ -184,9 +184,9 @@ func (tc *TemplateController) QuestionInfoeRdirect(ctx *gin.Context, siteInfo *s
titleIsAnswerID = true titleIsAnswerID = true
} }
} }
siteInfo = tc.SiteInfo(ctx)
url = fmt.Sprintf("%s/questions/%s", siteInfo.General.SiteUrl, id) url = fmt.Sprintf("%s/questions/%s", siteInfo.General.SiteUrl, id)
if siteInfo.SiteSeo.PermaLink == schema.PermaLinkQuestionID { if siteInfo.SiteSeo.PermaLink == schema.PermaLinkQuestionID || siteInfo.SiteSeo.PermaLink == schema.PermaLinkQuestionIDByShortID {
if len(ctx.Request.URL.Query()) > 0 { if len(ctx.Request.URL.Query()) > 0 {
url = fmt.Sprintf("%s?%s", url, ctx.Request.URL.RawQuery) url = fmt.Sprintf("%s?%s", url, ctx.Request.URL.RawQuery)
} }

View File

@ -27,6 +27,7 @@ import (
"github.com/answerdev/answer/internal/service/revision_common" "github.com/answerdev/answer/internal/service/revision_common"
tagcommon "github.com/answerdev/answer/internal/service/tag_common" tagcommon "github.com/answerdev/answer/internal/service/tag_common"
usercommon "github.com/answerdev/answer/internal/service/user_common" usercommon "github.com/answerdev/answer/internal/service/user_common"
"github.com/answerdev/answer/pkg/converter"
"github.com/answerdev/answer/pkg/encryption" "github.com/answerdev/answer/pkg/encryption"
"github.com/answerdev/answer/pkg/htmltext" "github.com/answerdev/answer/pkg/htmltext"
"github.com/answerdev/answer/pkg/uid" "github.com/answerdev/answer/pkg/uid"
@ -566,9 +567,12 @@ func (qs *QuestionService) UpdateQuestionInviteUser(ctx context.Context, req *sc
for _, item := range req.InviteUser { for _, item := range req.InviteUser {
_, ok := inviteUserInfoList[item] _, ok := inviteUserInfoList[item]
if ok { if ok {
//The inviter can't be himself.
if req.UserID != inviteUserInfoList[item].ID {
inviteUserIDs = append(inviteUserIDs, inviteUserInfoList[item].ID) inviteUserIDs = append(inviteUserIDs, inviteUserInfoList[item].ID)
} }
} }
}
inviteUserStr := "" inviteUserStr := ""
inviteUserByte, err := json.Marshal(inviteUserIDs) inviteUserByte, err := json.Marshal(inviteUserIDs)
if err != nil { if err != nil {
@ -585,7 +589,17 @@ func (qs *QuestionService) UpdateQuestionInviteUser(ctx context.Context, req *sc
if saveerr != nil { if saveerr != nil {
return saveerr return saveerr
} }
go qs.notificationInviteUser(ctx, inviteUserIDs, originQuestion.ID, originQuestion.Title, req.UserID) //send notification
oldInviteUserIDsStr := originQuestion.InviteUserID
oldInviteUserIDs := make([]string, 0)
if oldInviteUserIDsStr != "" {
err = json.Unmarshal([]byte(oldInviteUserIDsStr), &oldInviteUserIDs)
if err == nil {
needSendNotificationUserIDs := converter.ArrayNotInArray(oldInviteUserIDs, inviteUserIDs)
go qs.notificationInviteUser(ctx, needSendNotificationUserIDs, originQuestion.ID, originQuestion.Title, req.UserID)
}
}
return nil return nil
} }

View File

@ -126,11 +126,7 @@ func (s *SiteInfoService) SaveSiteGeneral(ctx context.Context, req schema.SiteGe
Content: string(content), Content: string(content),
Status: 1, Status: 1,
} }
err = s.siteInfoRepo.SaveByType(ctx, constant.SiteTypeGeneral, data) return s.siteInfoRepo.SaveByType(ctx, constant.SiteTypeGeneral, data)
if err == nil {
constant.DefaultSiteURL = req.SiteUrl
}
return
} }
func (s *SiteInfoService) SaveSiteInterface(ctx context.Context, req schema.SiteInterfaceReq) (err error) { func (s *SiteInfoService) SaveSiteInterface(ctx context.Context, req schema.SiteInterfaceReq) (err error) {

15
pkg/converter/array.go Normal file
View File

@ -0,0 +1,15 @@
package converter
func ArrayNotInArray(original []string, search []string) []string {
var result []string
originalMap := make(map[string]bool)
for _, v := range original {
originalMap[v] = true
}
for _, v := range search {
if _, ok := originalMap[v]; !ok {
result = append(result, v)
}
}
return result
}