Skip to content

A Q&A platform software for teams at any scales. Whether it's a community forum, help center, or knowledge management platform, you can always count on Apache Answer.

Merge branch 'feat/0.5.0/timeline' into feat/0.6.0/user-role

LinkinStar74015c13eba8
diff --cc cmd/answer/wire_gen.go
index 8d68e3f1,3bab5d81..49a43986
--- a/cmd/answer/wire_gen.go
+++ b/cmd/answer/wire_gen.go
@@@ -197,10 -189,9 +197,10 @@@ func initApplication(debug bool, server
activityCommon := activity_common2.NewActivityCommon(activityRepo)
activityActivityRepo := activity.NewActivityRepo(dataData)
commentCommonService := comment_common.NewCommentCommonService(commentCommonRepo)
- activityService := activity2.NewActivityService(activityActivityRepo, userCommon, activityCommon, tagCommonService, objService, commentCommonService, revisionService)
+ activityService := activity2.NewActivityService(activityActivityRepo, userCommon, activityCommon, tagCommonService, objService, commentCommonService, revisionService, metaService)
activityController := controller.NewActivityController(activityCommon, activityService)
- answerAPIRouter := router.NewAnswerAPIRouter(langController, userController, commentController, reportController, voteController, tagController, followController, collectionController, questionController, answerController, searchController, revisionController, rankController, controller_backyardReportController, userBackyardController, reasonController, themeController, siteInfoController, siteinfoController, notificationController, dashboardController, uploadController, activityController)
+ roleController := controller_backyard.NewRoleController(roleService)
+ answerAPIRouter := router.NewAnswerAPIRouter(langController, userController, commentController, reportController, voteController, tagController, followController, collectionController, questionController, answerController, searchController, revisionController, rankController, controller_backyardReportController, userBackyardController, reasonController, themeController, siteInfoController, siteinfoController, notificationController, dashboardController, uploadController, activityController, roleController)
swaggerRouter := router.NewSwaggerRouter(swaggerConf)
uiRouter := router.NewUIRouter()
authUserMiddleware := middleware.NewAuthUserMiddleware(authService)
diff --cc internal/controller/tag_controller.go
index 1164f1d4,8e88845c..62af3888
--- a/internal/controller/tag_controller.go
+++ b/internal/controller/tag_controller.go
@@@ -73,7 -69,7 +73,7 @@@ func (tc *TagController) RemoveTag(ctx
return
}
- err = tc.tagService.RemoveTag(ctx, req.TagID)
- err := tc.tagService.RemoveTag(ctx, req)
++ err = tc.tagService.RemoveTag(ctx, req)
handler.HandleResponse(ctx, err, nil)
}
diff --cc internal/schema/activity.go
index be90a845,5765110f..57c45ea1
--- a/internal/schema/activity.go
+++ b/internal/schema/activity.go
@@@ -42,12 -44,11 +44,13 @@@ type ActObjectTimeline struct
// ActObjectInfo act object info
type ActObjectInfo struct {
- ObjectType string `json:"object_type"`
- Title string `json:"title"`
- QuestionID string `json:"question_id"`
- AnswerID string `json:"answer_id"`
+ Title string `json:"title"`
+ ObjectType string `json:"object_type"`
+ QuestionID string `json:"question_id"`
+ AnswerID string `json:"answer_id"`
+ Username string `json:"username"`
+ DisplayName string `json:"display_name"`
+ MainTagSlugName string `json:"main_tag_slug_name"`
}
// GetObjectTimelineDetailReq get object timeline detail request
diff --cc internal/service/activity/activity.go
index 2ef56a9c,6169a2b6..4fe151b9
--- a/internal/service/activity/activity.go
+++ b/internal/service/activity/activity.go
@@@ -102,36 -93,112 +93,123 @@@ func (as *ActivityService) GetObjectTim
// database save activity type is number, change to activity type string is like "question.asked".
// so we need to cut the front part of '.'
- item.ObjectType, item.ActivityType, _ = strings.Cut(config.ID2KeyMapping[act.ActivityType], ".")
-
- isHidden, formattedActivityType := formatActivity(item.ActivityType)
- if isHidden {
+ _, item.ActivityType, _ = strings.Cut(config.ID2KeyMapping[act.ActivityType], ".")
+ // format activity type string to show
+ if isHidden, formattedActivityType := formatActivity(item.ActivityType); isHidden {
continue
+ } else {
+ item.ActivityType = formattedActivityType
+ }
+
+ // if activity is down vote, only admin can see who does it.
+ if item.ActivityType == constant.ActDownVote && !req.IsAdmin {
+ item.Username = "N/A"
+ item.UserDisplayName = "N/A"
+ } else {
+ item.UserID = act.UserID
}
- item.ActivityType = formattedActivityType
- // get user info
- userBasicInfo, exist, err := as.userCommon.GetUserBasicInfoByID(ctx, act.UserID)
+ item.Comment = as.getTimelineActivityComment(ctx, item.ObjectID, item.ObjectType, item.ActivityType, item.RevisionID)
+ resp.Timeline = append(resp.Timeline, item)
+ }
+ as.formatTimelineUserInfo(ctx, resp.Timeline)
+ return
+ }
+
+ func (as *ActivityService) getTimelineMainObjInfo(ctx context.Context, objectID string) (
+ resp *schema.ActObjectInfo, err error) {
+ resp = &schema.ActObjectInfo{}
+ objInfo, err := as.objectInfoService.GetInfo(ctx, objectID)
+ if err != nil {
+ return nil, err
+ }
+ resp.Title = objInfo.Title
+ if objInfo.ObjectType == constant.TagObjectType {
+ tag, exist, _ := as.tagCommonService.GetTagByID(ctx, objInfo.TagID)
+ if exist {
+ resp.Title = tag.SlugName
+ resp.MainTagSlugName = tag.MainTagSlugName
+ }
+ }
+ resp.ObjectType = objInfo.ObjectType
+ resp.QuestionID = objInfo.QuestionID
+ resp.AnswerID = objInfo.AnswerID
++ if len(objInfo.ObjectCreatorUserID) > 0 {
++ // get object creator user info
++ userBasicInfo, exist, err := as.userCommon.GetUserBasicInfoByID(ctx, objInfo.ObjectCreatorUserID)
+ if err != nil {
+ return nil, err
+ }
+ if exist {
- item.Username = userBasicInfo.Username
- item.UserDisplayName = userBasicInfo.DisplayName
++ resp.Username = userBasicInfo.Username
++ resp.DisplayName = userBasicInfo.DisplayName
++ }
++ }
+ return resp, nil
+ }
+
+ func (as *ActivityService) getTimelineActivityComment(ctx context.Context, objectID, objectType,
+ activityType, revisionID string) (comment string) {
+ if objectType == constant.CommentObjectType {
+ commentInfo, err := as.commentCommonService.GetComment(ctx, objectID)
+ if err != nil {
+ log.Error(err)
+ } else {
+ return commentInfo.ParsedText
}
+ return
+ }
- if item.ObjectType == constant.CommentObjectType {
- comment, err := as.commentCommonService.GetComment(ctx, item.ObjectID)
- if err != nil {
- log.Error(err)
- } else {
- item.Comment = comment.ParsedText
+ if activityType == constant.ActEdited {
+ revision, err := as.revisionService.GetRevision(ctx, revisionID)
+ if err != nil {
+ log.Error(err)
+ } else {
+ return revision.Log
+ }
+ return
+ }
+ if activityType == constant.ActClosed {
+ // only question can be closed
+ metaInfo, err := as.metaService.GetMetaByObjectIdAndKey(ctx, objectID, entity.QuestionCloseReasonKey)
+ if err != nil {
+ log.Error(err)
+ } else {
+ closeMsg := &schema.CloseQuestionMeta{}
+ if err := json.Unmarshal([]byte(metaInfo.Value), closeMsg); err == nil {
+ return closeMsg.CloseMsg
}
}
+ }
+ return ""
+ }
- resp.Timeline = append(resp.Timeline, item)
+ func (as *ActivityService) formatTimelineUserInfo(ctx context.Context, timeline []*schema.ActObjectTimeline) {
+ userExist := make(map[string]bool)
+ userIDs := make([]string, 0)
+ for _, info := range timeline {
+ if len(info.UserID) == 0 || userExist[info.UserID] {
+ continue
+ }
+ userIDs = append(userIDs, info.UserID)
+ }
+ if len(userIDs) == 0 {
+ return
+ }
+ userInfoMapping, err := as.userCommon.BatchUserBasicInfoByID(ctx, userIDs)
+ if err != nil {
+ log.Error(err)
+ return
+ }
+ for _, info := range timeline {
+ if len(info.UserID) == 0 {
+ continue
+ }
+ if userInfo, ok := userInfoMapping[info.UserID]; ok {
+ info.Username = userInfo.Username
+ info.UserDisplayName = userInfo.DisplayName
+ }
}
- return
}
// GetObjectTimelineDetail get object timeline
diff --cc internal/service/object_info/object_info.go
index 52bc4658,2aa2f8ae..9ab18e70
--- a/internal/service/object_info/object_info.go
+++ b/internal/service/object_info/object_info.go
@@@ -36,84 -33,8 +36,84 @@@ func NewObjService
questionRepo: questionRepo,
commentRepo: commentRepo,
tagRepo: tagRepo,
+ tagCommon: tagCommon,
}
}
+func (os *ObjService) GetUnreviewedRevisionInfo(ctx context.Context, objectID string) (objInfo *schema.UnreviewedRevisionInfoInfo, err error) {
+ objInfo = &schema.UnreviewedRevisionInfoInfo{}
+
+ objectType, err := obj.GetObjectTypeStrByObjectID(objectID)
+ if err != nil {
+ return nil, err
+ }
+ switch objectType {
+ case constant.QuestionObjectType:
+ questionInfo, exist, err := os.questionRepo.GetQuestion(ctx, objectID)
+ if err != nil {
+ return nil, err
+ }
+ if !exist {
+ break
+ }
+ taglist, err := os.tagCommon.GetObjectEntityTag(ctx, objectID)
+ if err != nil {
+ return nil, err
+ }
+ os.tagCommon.TagsFormatRecommendAndReserved(ctx, taglist)
+ tags, err := os.tagCommon.TagFormat(ctx, taglist)
+ if err != nil {
+ return nil, err
+ }
+ objInfo = &schema.UnreviewedRevisionInfoInfo{
+ ObjectID: questionInfo.ID,
+ Title: questionInfo.Title,
+ Content: questionInfo.OriginalText,
+ Html: questionInfo.ParsedText,
+ Tags: tags,
+ }
+ case constant.AnswerObjectType:
+ answerInfo, exist, err := os.answerRepo.GetAnswer(ctx, objectID)
+ if err != nil {
+ return nil, err
+ }
+ if !exist {
+ break
+ }
+
+ questionInfo, exist, err := os.questionRepo.GetQuestion(ctx, answerInfo.QuestionID)
+ if err != nil {
+ return nil, err
+ }
+ if !exist {
+ break
+ }
+ objInfo = &schema.UnreviewedRevisionInfoInfo{
+ ObjectID: answerInfo.ID,
+ Title: questionInfo.Title,
+ Content: answerInfo.OriginalText,
+ Html: answerInfo.ParsedText,
+ }
+
+ case constant.TagObjectType:
- tagInfo, exist, err := os.tagRepo.GetTagByID(ctx, objectID)
++ tagInfo, exist, err := os.tagRepo.GetTagByID(ctx, objectID, true)
+ if err != nil {
+ return nil, err
+ }
+ if !exist {
+ break
+ }
+ objInfo = &schema.UnreviewedRevisionInfoInfo{
+ ObjectID: tagInfo.ID,
+ Title: tagInfo.SlugName,
+ Content: tagInfo.OriginalText,
+ Html: tagInfo.ParsedText,
+ }
+ }
+ if objInfo == nil {
+ err = errors.BadRequest(reason.ObjectNotFound)
+ }
+ return objInfo, err
+}
// GetInfo get object simple information
func (os *ObjService) GetInfo(ctx context.Context, objectID string) (objInfo *schema.SimpleObjectInfo, err error) {