mirror of https://gitee.com/answerdev/answer.git
feat(user): group by user info in timeline
This commit is contained in:
parent
99a61fcf7c
commit
6fa3bf0be0
|
@ -33,14 +33,12 @@ type ActObjectTimeline struct {
|
||||||
RevisionID string `json:"revision_id"`
|
RevisionID string `json:"revision_id"`
|
||||||
CreatedAt int64 `json:"created_at"`
|
CreatedAt int64 `json:"created_at"`
|
||||||
ActivityType string `json:"activity_type"`
|
ActivityType string `json:"activity_type"`
|
||||||
Username string `json:"username"`
|
|
||||||
UserDisplayName string `json:"user_display_name"`
|
|
||||||
Comment string `json:"comment"`
|
Comment string `json:"comment"`
|
||||||
ObjectID string `json:"object_id"`
|
ObjectID string `json:"object_id"`
|
||||||
ObjectType string `json:"object_type"`
|
ObjectType string `json:"object_type"`
|
||||||
Cancelled bool `json:"cancelled"`
|
Cancelled bool `json:"cancelled"`
|
||||||
CancelledAt int64 `json:"cancelled_at"`
|
CancelledAt int64 `json:"cancelled_at"`
|
||||||
UserID string `json:"id"`
|
UserInfo *UserBasicInfo `json:"user_info,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// ActObjectInfo act object info
|
// ActObjectInfo act object info
|
||||||
|
|
|
@ -369,6 +369,7 @@ type QuestionPageRespOperator struct {
|
||||||
Username string `json:"username"`
|
Username string `json:"username"`
|
||||||
Rank int `json:"rank"`
|
Rank int `json:"rank"`
|
||||||
DisplayName string `json:"display_name"`
|
DisplayName string `json:"display_name"`
|
||||||
|
Status string `json:"status"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type AdminQuestionPageReq struct {
|
type AdminQuestionPageReq struct {
|
||||||
|
|
|
@ -91,6 +91,7 @@ func (as *ActivityService) GetObjectTimeline(ctx context.Context, req *schema.Ge
|
||||||
CreatedAt: act.CreatedAt.Unix(),
|
CreatedAt: act.CreatedAt.Unix(),
|
||||||
Cancelled: act.Cancelled == entity.ActivityCancelled,
|
Cancelled: act.Cancelled == entity.ActivityCancelled,
|
||||||
ObjectID: act.ObjectID,
|
ObjectID: act.ObjectID,
|
||||||
|
UserInfo: &schema.UserBasicInfo{},
|
||||||
}
|
}
|
||||||
item.ObjectType, _ = obj.GetObjectTypeStrByObjectID(act.ObjectID)
|
item.ObjectType, _ = obj.GetObjectTypeStrByObjectID(act.ObjectID)
|
||||||
if item.Cancelled {
|
if item.Cancelled {
|
||||||
|
@ -120,13 +121,13 @@ func (as *ActivityService) GetObjectTimeline(ctx context.Context, req *schema.Ge
|
||||||
|
|
||||||
// if activity is down vote, only admin can see who does it.
|
// if activity is down vote, only admin can see who does it.
|
||||||
if item.ActivityType == constant.ActDownVote && !req.IsAdmin {
|
if item.ActivityType == constant.ActDownVote && !req.IsAdmin {
|
||||||
item.Username = "N/A"
|
item.UserInfo.Username = "N/A"
|
||||||
item.UserDisplayName = "N/A"
|
item.UserInfo.DisplayName = "N/A"
|
||||||
} else {
|
} else {
|
||||||
if act.TriggerUserID > 0 {
|
if act.TriggerUserID > 0 {
|
||||||
item.UserID = fmt.Sprintf("%d", act.TriggerUserID)
|
item.UserInfo.ID = fmt.Sprintf("%d", act.TriggerUserID)
|
||||||
} else {
|
} else {
|
||||||
item.UserID = act.UserID
|
item.UserInfo.ID = act.UserID
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -209,10 +210,10 @@ func (as *ActivityService) formatTimelineUserInfo(ctx context.Context, timeline
|
||||||
userExist := make(map[string]bool)
|
userExist := make(map[string]bool)
|
||||||
userIDs := make([]string, 0)
|
userIDs := make([]string, 0)
|
||||||
for _, info := range timeline {
|
for _, info := range timeline {
|
||||||
if len(info.UserID) == 0 || userExist[info.UserID] {
|
if len(info.UserInfo.ID) == 0 || userExist[info.UserInfo.ID] {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
userIDs = append(userIDs, info.UserID)
|
userIDs = append(userIDs, info.UserInfo.ID)
|
||||||
}
|
}
|
||||||
if len(userIDs) == 0 {
|
if len(userIDs) == 0 {
|
||||||
return
|
return
|
||||||
|
@ -223,13 +224,10 @@ func (as *ActivityService) formatTimelineUserInfo(ctx context.Context, timeline
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
for _, info := range timeline {
|
for _, info := range timeline {
|
||||||
if len(info.UserID) == 0 {
|
if len(info.UserInfo.ID) == 0 {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if userInfo, ok := userInfoMapping[info.UserID]; ok {
|
info.UserInfo = userInfoMapping[info.UserInfo.ID]
|
||||||
info.Username = userInfo.Username
|
|
||||||
info.UserDisplayName = userInfo.DisplayName
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -387,6 +387,7 @@ func (qs *QuestionCommon) FormatQuestionsPage(
|
||||||
item.Operator.DisplayName = userInfo.DisplayName
|
item.Operator.DisplayName = userInfo.DisplayName
|
||||||
item.Operator.Username = userInfo.Username
|
item.Operator.Username = userInfo.Username
|
||||||
item.Operator.Rank = userInfo.Rank
|
item.Operator.Rank = userInfo.Rank
|
||||||
|
item.Operator.Status = userInfo.Status
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue