Merge remote-tracking branch 'origin/errcode' into errcode

test-errcode
Gordon 2 years ago
commit 7e7d5fc41b

@ -2,6 +2,7 @@ package user
import (
"context"
"time"
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/config"
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/constant"
@ -153,18 +154,24 @@ func (s *userServer) GetPaginationUsers(ctx context.Context, req *pbuser.GetPagi
}
resp.Total = int32(total)
resp.Users, err = (*convert.DBUser)(nil).DB2PB(usersDB)
return resp, nil
return resp, err
}
// ok
func (s *userServer) UserRegister(ctx context.Context, req *pbuser.UserRegisterReq) (resp *pbuser.UserRegisterResp, err error) {
resp = &pbuser.UserRegisterResp{}
if len(req.Users) == 0 {
return nil, errs.ErrArgs.Wrap("users is empty")
}
if utils.DuplicateAny(req.Users, func(e *sdkws.UserInfo) string { return e.UserID }) {
return nil, errs.ErrArgs.Wrap("userID repeated")
}
userIDs := make([]string, 0)
for _, v := range req.Users {
userIDs = append(userIDs, v.UserID)
for _, user := range req.Users {
if user.UserID == "" {
return nil, errs.ErrArgs.Wrap("userID is empty")
}
userIDs = append(userIDs, user.UserID)
}
exist, err := s.IsExist(ctx, userIDs)
if err != nil {
@ -173,12 +180,20 @@ func (s *userServer) UserRegister(ctx context.Context, req *pbuser.UserRegisterR
if exist {
return nil, errs.ErrRegisteredAlready.Wrap("userID registered already")
}
users, err := (*convert.PBUser)(nil).PB2DB(req.Users)
if err != nil {
return nil, err
}
err = s.Create(ctx, users)
if err != nil {
now := time.Now()
users := make([]*tablerelation.UserModel, 0, len(req.Users))
for _, user := range req.Users {
users = append(users, &tablerelation.UserModel{
UserID: user.UserID,
Nickname: user.Nickname,
FaceURL: user.FaceURL,
Ex: user.Ex,
CreateTime: now,
AppMangerLevel: user.AppMangerLevel,
GlobalRecvMsgOpt: user.GlobalRecvMsgOpt,
})
}
if err := s.Create(ctx, users); err != nil {
return nil, err
}
return resp, nil

@ -168,11 +168,6 @@ const (
MinioDurationTimes = 3600
//Aws
AwsDurationTimes = 3600
// verificationCode used for
VerificationCodeForRegister = 1
VerificationCodeForReset = 2
VerificationCodeForRegisterSuffix = "_forRegister"
VerificationCodeForResetSuffix = "_forReset"
//callbackCommand
CallbackBeforeSendSingleMsgCommand = "callbackBeforeSendSingleMsgCommand"

@ -13,8 +13,9 @@ import (
pbMsg "github.com/OpenIMSDK/Open-IM-Server/pkg/proto/msg"
"github.com/OpenIMSDK/Open-IM-Server/pkg/proto/sdkws"
"github.com/OpenIMSDK/Open-IM-Server/pkg/utils"
"github.com/golang/protobuf/jsonpb"
"github.com/golang/protobuf/proto"
"github.com/gogo/protobuf/jsonpb"
"google.golang.org/protobuf/proto"
"github.com/go-redis/redis/v8"
)
@ -212,28 +213,30 @@ func (c *cache) DeleteTokenByUidPid(ctx context.Context, userID string, platform
return utils.Wrap1(c.rdb.HDel(ctx, key, fields...).Err())
}
func (c *cache) GetMessagesBySeq(ctx context.Context, userID string, seqList []int64) (seqMsg []*sdkws.MsgData, failedSeqList []int64, err error) {
var errResult error
for _, v := range seqList {
func (c *cache) GetMessagesBySeq(ctx context.Context, userID string, seqs []int64) (seqMsgs []*sdkws.MsgData, failedSeqs []int64, err error) {
pipe := c.rdb.Pipeline()
for _, v := range seqs {
//MESSAGE_CACHE:169.254.225.224_reliability1653387820_0_1
key := messageCache + userID + "_" + strconv.Itoa(int(v))
result, err := c.rdb.Get(ctx, key).Result()
if err != nil {
errResult = err
failedSeqList = append(failedSeqList, v)
if err := pipe.Get(ctx, key).Err(); err != nil && err != redis.Nil {
return nil, nil, err
}
}
result, err := pipe.Exec(ctx)
for i, v := range result {
if v.Err() != nil {
failedSeqs = append(failedSeqs, seqs[i])
} else {
msg := sdkws.MsgData{}
err = jsonpb.UnmarshalString(result, &msg)
err = jsonpb.UnmarshalString(v.String(), &msg)
if err != nil {
errResult = err
failedSeqList = append(failedSeqList, v)
failedSeqs = append(failedSeqs, seqs[i])
} else {
seqMsg = append(seqMsg, &msg)
seqMsgs = append(seqMsgs, &msg)
}
}
}
return seqMsg, failedSeqList, errResult
return seqMsgs, failedSeqs, err
}
func (c *cache) SetMessageToCache(ctx context.Context, userID string, msgList []*pbMsg.MsgDataToMQ) (int, error) {
@ -258,12 +261,14 @@ func (c *cache) SetMessageToCache(ctx context.Context, userID string, msgList []
}
func (c *cache) DeleteMessageFromCache(ctx context.Context, userID string, msgList []*pbMsg.MsgDataToMQ) error {
pipe := c.rdb.Pipeline()
for _, v := range msgList {
if err := c.rdb.Del(ctx, messageCache+userID+"_"+strconv.Itoa(int(v.MsgData.Seq))).Err(); err != nil {
if err := pipe.Del(ctx, messageCache+userID+"_"+strconv.Itoa(int(v.MsgData.Seq))).Err(); err != nil {
return utils.Wrap1(err)
}
}
return nil
_, err := pipe.Exec(ctx)
return utils.Wrap1(err)
}
func (c *cache) CleanUpOneUserAllMsg(ctx context.Context, userID string) error {
@ -275,12 +280,14 @@ func (c *cache) CleanUpOneUserAllMsg(ctx context.Context, userID string) error {
if err != nil {
return utils.Wrap1(err)
}
pipe := c.rdb.Pipeline()
for _, v := range vals {
if err := c.rdb.Del(ctx, v).Err(); err != nil {
if err := pipe.Del(ctx, v).Err(); err != nil {
return utils.Wrap1(err)
}
}
return nil
_, err = pipe.Exec(ctx)
return utils.Wrap1(err)
}
func (c *cache) HandleSignalInvite(ctx context.Context, msg *sdkws.MsgData, pushToUserID string) (isSend bool, err error) {
@ -306,26 +313,31 @@ func (c *cache) HandleSignalInvite(ctx context.Context, msg *sdkws.MsgData, push
return false, nil
}
if isInviteSignal {
pipe := c.rdb.Pipeline()
for _, userID := range inviteeUserIDs {
timeout, err := strconv.Atoi(config.Config.Rtc.SignalTimeout)
if err != nil {
return false, utils.Wrap1(err)
}
keyList := signalListCache + userID
err = c.rdb.LPush(ctx, keyList, msg.ClientMsgID).Err()
keys := signalListCache + userID
err = pipe.LPush(ctx, keys, msg.ClientMsgID).Err()
if err != nil {
return false, utils.Wrap1(err)
}
err = c.rdb.Expire(ctx, keyList, time.Duration(timeout)*time.Second).Err()
err = pipe.Expire(ctx, keys, time.Duration(timeout)*time.Second).Err()
if err != nil {
return false, utils.Wrap1(err)
}
key := signalCache + msg.ClientMsgID
err = c.rdb.Set(ctx, key, msg.Content, time.Duration(timeout)*time.Second).Err()
err = pipe.Set(ctx, key, msg.Content, time.Duration(timeout)*time.Second).Err()
if err != nil {
return false, utils.Wrap1(err)
}
}
_, err := pipe.Exec(ctx)
if err != nil {
return false, utils.Wrap1(err)
}
}
return true, nil
}
@ -367,8 +379,8 @@ func (c *cache) DelUserSignalList(ctx context.Context, userID string) error {
return utils.Wrap1(c.rdb.Del(ctx, signalListCache+userID).Err())
}
func (c *cache) DelMsgFromCache(ctx context.Context, userID string, seqList []int64) error {
for _, seq := range seqList {
func (c *cache) DelMsgFromCache(ctx context.Context, userID string, seqs []int64) error {
for _, seq := range seqs {
key := messageCache + userID + "_" + strconv.Itoa(int(seq))
result, err := c.rdb.Get(ctx, key).Result()
if err != nil {

@ -17,7 +17,7 @@ var errIndex = errors.New("err index")
type metaCache interface {
ExecDel(ctx context.Context) error
// delete key rapid
DeleteKey(ctx context.Context, key string) error
DelKey(ctx context.Context, key string) error
AddKeys(keys ...string)
GetPreDeleteKeys() []string
}
@ -38,7 +38,7 @@ func (m *metaCacheRedis) ExecDel(ctx context.Context) error {
return nil
}
func (m *metaCacheRedis) DeleteKey(ctx context.Context, key string) error {
func (m *metaCacheRedis) DelKey(ctx context.Context, key string) error {
return m.rcClient.TagAsDeleted2(ctx, key)
}
@ -110,12 +110,14 @@ func batchGetCache[T any](ctx context.Context, rcClient *rockscache.Client, keys
return nil, err
}
for _, v := range batchMap {
var t T
err = json.Unmarshal([]byte(v), &t)
if err != nil {
return nil, utils.Wrap(err, "unmarshal failed")
if v != "" {
var t T
err = json.Unmarshal([]byte(v), &t)
if err != nil {
return nil, utils.Wrap(err, "unmarshal failed")
}
tArrays = append(tArrays, t)
}
tArrays = append(tArrays, t)
}
return tArrays, nil
}

@ -3,11 +3,12 @@ package log
import (
"context"
"fmt"
"time"
"github.com/pkg/errors"
"gorm.io/gorm"
gormLogger "gorm.io/gorm/logger"
gormUtils "gorm.io/gorm/utils"
"time"
)
type SqlLogger struct {
@ -42,7 +43,7 @@ func (SqlLogger) Error(ctx context.Context, msg string, args ...interface{}) {
ZError(ctx, msg, nil, args)
}
func (l SqlLogger) Trace(ctx context.Context, begin time.Time, fc func() (sql string, rowsAffected int64), err error) {
func (l *SqlLogger) Trace(ctx context.Context, begin time.Time, fc func() (sql string, rowsAffected int64), err error) {
if l.LogLevel <= gormLogger.Silent {
return
}

File diff suppressed because it is too large Load Diff

@ -65,15 +65,10 @@ message UserInfo{
string userID = 1;
string nickname = 2;
string faceURL = 3;
int32 gender = 4;
string phoneNumber = 5;
uint32 birth = 6;
string email = 7;
string ex = 8;
int64 createTime = 9;
int32 appMangerLevel = 10;
int32 globalRecvMsgOpt = 11;
int64 birthday = 13;
string ex = 4;
int64 createTime = 5;
int32 appMangerLevel = 6;
int32 globalRecvMsgOpt = 7;
}
message FriendInfo{

@ -2,6 +2,8 @@ package check
import (
"context"
"strings"
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/config"
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/log"
"github.com/OpenIMSDK/Open-IM-Server/pkg/discoveryregistry"
@ -10,7 +12,6 @@ import (
"github.com/OpenIMSDK/Open-IM-Server/pkg/proto/user"
"github.com/OpenIMSDK/Open-IM-Server/pkg/utils"
"google.golang.org/grpc"
"strings"
)
func NewUserCheck(client discoveryregistry.SvcDiscoveryRegistry) *UserCheck {
@ -78,7 +79,6 @@ func (u *UserCheck) GetPublicUserInfos(ctx context.Context, userIDs []string, co
UserID: e.UserID,
Nickname: e.Nickname,
FaceURL: e.FaceURL,
Gender: e.Gender,
Ex: e.Ex,
}
}), nil

@ -129,11 +129,9 @@ func (db *DBFriendRequest) DB2PB(ctx context.Context, friendRequests []*relation
pbFriendRequest.FromUserID = users[v.FromUserID].UserID
pbFriendRequest.FromNickname = users[v.FromUserID].Nickname
pbFriendRequest.FromFaceURL = users[v.FromUserID].FaceURL
pbFriendRequest.FromGender = users[v.FromUserID].Gender
pbFriendRequest.ToUserID = users[v.ToUserID].UserID
pbFriendRequest.ToNickname = users[v.ToUserID].Nickname
pbFriendRequest.ToFaceURL = users[v.ToUserID].FaceURL
pbFriendRequest.ToGender = users[v.ToUserID].Gender
pbFriendRequest.CreateTime = v.CreateTime.Unix()
pbFriendRequest.HandleTime = v.HandleTime.Unix()
pbFriendRequest.HandlerUserID = v.HandlerUserID
@ -162,14 +160,12 @@ func (db *DBFriendRequest) Convert(ctx context.Context) (*sdk.FriendRequest, err
}
pbFriendRequest.FromNickname = user.Nickname
pbFriendRequest.FromFaceURL = user.FaceURL
pbFriendRequest.FromGender = user.Gender
user, err = db.userCheck.GetUserInfo(ctx, db.ToUserID)
if err != nil {
return nil, err
}
pbFriendRequest.ToNickname = user.Nickname
pbFriendRequest.ToFaceURL = user.FaceURL
pbFriendRequest.ToGender = user.Gender
pbFriendRequest.CreateTime = db.CreateTime.Unix()
pbFriendRequest.HandleTime = db.HandleTime.Unix()
return pbFriendRequest, nil
@ -474,7 +470,6 @@ func (*DBUser) DB2PB(users []*relation.UserModel) (PBUsers []*sdk.UserInfo, err
func (pb *PBUser) Convert() (*relation.UserModel, error) {
dst := &relation.UserModel{}
utils.CopyStructFields(dst, pb)
dst.Birth = utils.UnixSecondToTime(pb.Birthday)
dst.CreateTime = utils.UnixSecondToTime(pb.CreateTime)
return dst, nil
}
@ -483,7 +478,6 @@ func (db *DBUser) Convert() (*sdk.UserInfo, error) {
dst := &sdk.UserInfo{}
utils.CopyStructFields(dst, db)
dst.CreateTime = db.CreateTime.Unix()
dst.Birthday = db.Birth.Unix()
return dst, nil
}

@ -2,6 +2,7 @@ package notification
import (
"context"
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/config"
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/constant"
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/log"
@ -196,7 +197,7 @@ func (c *Check) groupNotification(ctx context.Context, contentType int32, m prot
}
// 创建群后调用
func (c *Check) GroupCreatedNotification(ctx context.Context, groupID string, initMemberList []string) {
func (c *Check) GroupCreatedNotification(ctx context.Context, groupID string, initMembers []string) {
GroupCreatedTips := sdkws.GroupCreatedTips{Group: &sdkws.GroupInfo{},
OpUser: &sdkws.GroupMemberFullInfo{}, GroupOwnerUser: &sdkws.GroupMemberFullInfo{}}
if err := c.setOpUserInfo(ctx, groupID, GroupCreatedTips.OpUser); err != nil {
@ -210,7 +211,7 @@ func (c *Check) GroupCreatedNotification(ctx context.Context, groupID string, in
if err := c.setGroupOwnerInfo(ctx, groupID, GroupCreatedTips.GroupOwnerUser); err != nil {
return
}
for _, v := range initMemberList {
for _, v := range initMembers {
var groupMemberInfo sdkws.GroupMemberFullInfo
if err := c.setGroupMemberInfo(ctx, groupID, v, &groupMemberInfo); err != nil {
continue

Loading…
Cancel
Save