Skip to content

Commit

Permalink
Merge branch 'feat/1.4.0/badge' into test
Browse files Browse the repository at this point in the history
  • Loading branch information
LinkinStars committed Sep 3, 2024
2 parents 2aa16ff + 2eaa7db commit 0606d87
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 8 deletions.
8 changes: 8 additions & 0 deletions internal/repo/notification/notification_repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,3 +129,11 @@ func (nr *notificationRepo) GetNotificationPage(ctx context.Context, searchCond
}
return
}

func (nr *notificationRepo) CountNotificationByUser(ctx context.Context, cond *entity.Notification) (int64, error) {
count, err := nr.data.DB.Context(ctx).Count(cond)
if err != nil {
err = errors.InternalServer(reason.DatabaseError).WithError(err).WithStack()
}
return count, err
}
2 changes: 2 additions & 0 deletions internal/service/content/user_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -535,6 +535,7 @@ func (us *UserService) UserVerifyEmail(ctx context.Context, req *schema.UserVeri
}
if err = us.userActivity.UserActive(ctx, userInfo.ID); err != nil {
log.Error(err)
return nil, err
}

// In the case of three-party login, the associated users are bound
Expand Down Expand Up @@ -668,6 +669,7 @@ func (us *UserService) UserChangeEmailVerify(ctx context.Context, content string
if userInfo.MailStatus == entity.EmailStatusToBeVerified {
if err = us.userActivity.UserActive(ctx, userInfo.ID); err != nil {
log.Error(err)
return nil, err
}
}

Expand Down
25 changes: 19 additions & 6 deletions internal/service/notification/notification_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,20 @@ import (
"context"
"encoding/json"
"fmt"
"github.com/apache/incubator-answer/internal/service/badge"
"github.com/apache/incubator-answer/internal/service/report_common"
"github.com/apache/incubator-answer/internal/service/review"
usercommon "github.com/apache/incubator-answer/internal/service/user_common"
"github.com/apache/incubator-answer/pkg/converter"

"github.com/apache/incubator-answer/internal/base/constant"
"github.com/apache/incubator-answer/internal/base/data"
"github.com/apache/incubator-answer/internal/base/handler"
"github.com/apache/incubator-answer/internal/base/pager"
"github.com/apache/incubator-answer/internal/base/translator"
"github.com/apache/incubator-answer/internal/entity"
"github.com/apache/incubator-answer/internal/schema"
"github.com/apache/incubator-answer/internal/service/badge"
notficationcommon "github.com/apache/incubator-answer/internal/service/notification_common"
"github.com/apache/incubator-answer/internal/service/report_common"
"github.com/apache/incubator-answer/internal/service/review"
"github.com/apache/incubator-answer/internal/service/revision_common"
usercommon "github.com/apache/incubator-answer/internal/service/user_common"
"github.com/apache/incubator-answer/pkg/converter"
"github.com/apache/incubator-answer/pkg/uid"
"github.com/jinzhu/copier"
"github.com/segmentfault/pacman/log"
Expand Down Expand Up @@ -203,6 +202,20 @@ func (ns *NotificationService) ClearIDUnRead(ctx context.Context, userID string,
if err != nil {
log.Errorf("remove badge award alert cache failed: %v", err)
}

amount, err := ns.notificationRepo.CountNotificationByUser(ctx, &entity.Notification{
UserID: userID,
Type: notificationInfo.Type,
IsRead: schema.NotificationNotRead,
Status: schema.NotificationStatusNormal,
})
if err != nil {
log.Errorf("count notification failed: %v", err)
return nil
}
if amount == 0 {
_ = ns.notificationCommon.DeleteRedDot(ctx, userID, notificationInfo.Type)
}
return nil
}

Expand Down
15 changes: 15 additions & 0 deletions internal/service/notification_common/notification.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ type NotificationRepo interface {
GetByUserIdObjectIdTypeId(ctx context.Context, userID, objectID string, notificationType int) (*entity.Notification, bool, error)
UpdateNotificationContent(ctx context.Context, notification *entity.Notification) (err error)
GetById(ctx context.Context, id string) (*entity.Notification, bool, error)
CountNotificationByUser(ctx context.Context, cond *entity.Notification) (int64, error)
}

type NotificationCommon struct {
Expand Down Expand Up @@ -226,6 +227,20 @@ func (ns *NotificationCommon) addRedDot(ctx context.Context, userID string, noti
return nil
}

func (ns *NotificationCommon) DeleteRedDot(ctx context.Context, userID string, notificationType int) error {
var key string
if notificationType == schema.NotificationTypeInbox {
key = fmt.Sprintf(constant.RedDotCacheKey, constant.NotificationTypeInbox, userID)
} else {
key = fmt.Sprintf(constant.RedDotCacheKey, constant.NotificationTypeAchievement, userID)
}
err := ns.data.Cache.Del(ctx, key)
if err != nil {
return errors.InternalServer(reason.UnknownError).WithError(err).WithStack()
}
return nil
}

// AddBadgeAwardAlertCache add badge award alert cache
func (ns *NotificationCommon) AddBadgeAwardAlertCache(ctx context.Context, userID, notificationID, badgeID string) (err error) {
key := fmt.Sprintf(constant.RedDotCacheKey, constant.NotificationTypeBadgeAchievement, userID)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,9 @@ func (us *UserCenterLoginService) ExternalLogin(
return nil, err
}

us.activeUser(ctx, oldUserInfo)
if err := us.activeUser(ctx, oldUserInfo); err != nil {
return nil, err
}

accessToken, _, err := us.userCommonService.CacheLoginUserInfo(
ctx, oldUserInfo.ID, oldUserInfo.MailStatus, oldUserInfo.Status, oldExternalLoginUserInfo.ExternalID)
Expand Down Expand Up @@ -181,10 +183,12 @@ func (us *UserCenterLoginService) registerNewUser(ctx context.Context, provider
return userInfo, nil
}

func (us *UserCenterLoginService) activeUser(ctx context.Context, oldUserInfo *entity.User) {
func (us *UserCenterLoginService) activeUser(ctx context.Context, oldUserInfo *entity.User) error {
if err := us.userActivity.UserActive(ctx, oldUserInfo.ID); err != nil {
log.Error(err)
return err
}
return nil
}

func (us *UserCenterLoginService) UserCenterUserSettings(ctx context.Context, userID string) (
Expand Down

0 comments on commit 0606d87

Please sign in to comment.