mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-12-09 22:17:27 +08:00
fix: remove repeat platform on online status.
This commit is contained in:
parent
2f1595ea23
commit
8620e0e296
21
pkg/common/db/cache/user.go
vendored
21
pkg/common/db/cache/user.go
vendored
@ -287,10 +287,12 @@ func (u *UserCacheRedis) SetUserStatus(ctx context.Context, userID string, statu
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return errs.Wrap(err)
|
return errs.Wrap(err)
|
||||||
}
|
}
|
||||||
|
onlineStatus.PlatformIDs = RemoveRepeatedElementsInList(append(onlineStatus.PlatformIDs, platformID))
|
||||||
|
} else {
|
||||||
|
onlineStatus.PlatformIDs = append(onlineStatus.PlatformIDs, platformID)
|
||||||
}
|
}
|
||||||
onlineStatus.Status = constant.Online
|
onlineStatus.Status = constant.Online
|
||||||
onlineStatus.UserID = userID
|
onlineStatus.UserID = userID
|
||||||
onlineStatus.PlatformIDs = append(onlineStatus.PlatformIDs, platformID)
|
|
||||||
newjsonData, err := json.Marshal(&onlineStatus)
|
newjsonData, err := json.Marshal(&onlineStatus)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errs.Wrap(err)
|
return errs.Wrap(err)
|
||||||
@ -304,3 +306,20 @@ func (u *UserCacheRedis) SetUserStatus(ctx context.Context, userID string, statu
|
|||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type Comparable interface {
|
||||||
|
~int | ~string | ~float64 | ~int32
|
||||||
|
}
|
||||||
|
|
||||||
|
func RemoveRepeatedElementsInList[T Comparable](slc []T) []T {
|
||||||
|
var result []T
|
||||||
|
tempMap := map[T]struct{}{}
|
||||||
|
for _, e := range slc {
|
||||||
|
if _, found := tempMap[e]; !found {
|
||||||
|
tempMap[e] = struct{}{}
|
||||||
|
result = append(result, e)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user