diff --git a/config/config.yaml b/config/config.yaml index 770fc31f6..61cef4251 100644 --- a/config/config.yaml +++ b/config/config.yaml @@ -87,8 +87,8 @@ credential: #腾讯cos,发送图片、视频、文件时需要,请自行申 appID: 1302656840 region: ap-chengdu bucket: echat-1302656840 - secretID: AKIDGNYVChzIQinu7QEgtNp0hnNgqcV8vZTC - secretKey: kz15vW83qM6dBUWIq681eBZA0c0vlIbe + secretID: AKIDGNYVChzIQinu7QEgtNp0hnNgqcV8vZTC1 + secretKey: kz15vW83qM6dBUWIq681eBZA0c0vlIbe1 minio: #MinIO 发送图片、视频、文件时需要,请自行申请后替换,必须修改。 客户端初始化InitSDK,中 object_storage参数为minio bucket: openim location: us-east-1 diff --git a/internal/rpc/cache/cache.go b/internal/rpc/cache/cache.go index ec9fa52bb..7f0c720f6 100644 --- a/internal/rpc/cache/cache.go +++ b/internal/rpc/cache/cache.go @@ -118,7 +118,7 @@ func updateAllFriendToCache(userList []db.User) error { log.NewError("0", utils.GetSelfFuncName(), err.Error()) continue } - if err := db.DB.AddFriendToCache(user.UserID, friendIDList); err != nil { + if err := db.DB.AddFriendToCache(user.UserID, friendIDList...); err != nil { log.NewError("0", utils.GetSelfFuncName(), err.Error()) } } @@ -134,7 +134,7 @@ func updateAllBlackListToCache(userList []db.User) error { log.NewError("", utils.GetSelfFuncName(), err.Error()) continue } - if err := db.DB.AddBlackUserToCache(user.UserID, blackIDList); err != nil { + if err := db.DB.AddBlackUserToCache(user.UserID, blackIDList...); err != nil { log.NewError("0", utils.GetSelfFuncName(), err.Error()) } } @@ -187,6 +187,7 @@ func (s *cacheServer) GetFriendIDListFromCache(_ context.Context, req *pbCache.G resp.CommonResp.ErrMsg = constant.ErrDB.ErrMsg return resp, nil } + log.NewDebug(req.OperationID, utils.GetSelfFuncName(), friendIDList) resp.UserIDList = friendIDList log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp: ", resp.String()) return resp, nil @@ -228,6 +229,7 @@ func (s *cacheServer) GetBlackIDListFromCache(_ context.Context, req *pbCache.Ge resp.CommonResp.ErrMsg = constant.ErrDB.ErrMsg return resp, nil } + log.NewDebug(req.OperationID, utils.GetSelfFuncName(), blackUserIDList) resp.UserIDList = blackUserIDList log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp: ", resp.String()) return resp, nil diff --git a/internal/rpc/friend/firend.go b/internal/rpc/friend/firend.go index 1fcc7d87f..63f1f76d5 100644 --- a/internal/rpc/friend/firend.go +++ b/internal/rpc/friend/firend.go @@ -262,10 +262,10 @@ func (s *friendServer) AddFriendResponse(ctx context.Context, req *pbFriend.AddF etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImCacheName) client := pbCache.NewCacheClient(etcdConn) addFriendToCacheReq.UserID = req.CommID.ToUserID - addFriendToCacheReq.UserID = req.CommID.FromUserID + addFriendToCacheReq.FriendID = req.CommID.FromUserID respPb, err := client.AddFriendToCache(context.Background(), addFriendToCacheReq) addFriendToCacheReq.UserID = req.CommID.FromUserID - addFriendToCacheReq.UserID = req.CommID.ToUserID + addFriendToCacheReq.FriendID = req.CommID.ToUserID respPb, err = client.AddFriendToCache(context.Background(), addFriendToCacheReq) if err != nil { log.NewError(req.CommID.OperationID, utils.GetSelfFuncName(), "AddFriendToCache failed", err.Error()) diff --git a/internal/rpc/office/office.go b/internal/rpc/office/office.go index 17c8dc598..5fdc18435 100644 --- a/internal/rpc/office/office.go +++ b/internal/rpc/office/office.go @@ -450,6 +450,7 @@ func (s *officeServer) CommentOneWorkMoment(_ context.Context, req *pbOffice.Com Content: comment.Content, CreateTime: comment.CreateTime, } + log.NewDebug(req.OperationID, utils.GetSelfFuncName(), "msg: ", *workMomentNotificationMsg) if req.UserID != workMoment.UserID { msg.WorkMomentSendNotification(req.OperationID, workMoment.UserID, workMomentNotificationMsg) } @@ -510,16 +511,7 @@ func (s *officeServer) GetUserFriendWorkMoments(_ context.Context, req *pbOffice log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req.String()) resp = &pbOffice.GetUserFriendWorkMomentsResp{CommonResp: &pbOffice.CommonResp{}, WorkMoments: []*pbOffice.WorkMoment{}} resp.Pagination = &pbCommon.ResponsePagination{CurrentPage: req.Pagination.PageNumber, ShowNumber: req.Pagination.ShowNumber} - friendIDList, err := imdb.GetFriendIDListByUserID(req.UserID) - if err != nil { - log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetFriendIDListByUserID", err.Error()) - resp.CommonResp = &pbOffice.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg} - return resp, nil - } - for _, friendID := range friendIDList { - log.NewDebug(req.OperationID, utils.GetSelfFuncName(), friendID) - } - workMoments, err := db.DB.GetUserFriendWorkMoments(friendIDList, req.Pagination.ShowNumber, req.Pagination.PageNumber, req.UserID) + workMoments, err := db.DB.GetUserFriendWorkMoments(req.Pagination.ShowNumber, req.Pagination.PageNumber, req.UserID) if err != nil { log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetUserFriendWorkMoments", err.Error()) resp.CommonResp = &pbOffice.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg} diff --git a/pkg/common/db/mongoModel.go b/pkg/common/db/mongoModel.go index 408e50802..51ad1c324 100644 --- a/pkg/common/db/mongoModel.go +++ b/pkg/common/db/mongoModel.go @@ -692,7 +692,7 @@ func (d *DataBases) GetUserWorkMoments(opUserID, userID string, showNumber, page return workMomentList, err } -func (d *DataBases) GetUserFriendWorkMoments(friendIDList []string, showNumber, pageNumber int32, userID string) ([]WorkMoment, error) { +func (d *DataBases) GetUserFriendWorkMoments(showNumber, pageNumber int32, userID string) ([]WorkMoment, error) { ctx, _ := context.WithTimeout(context.Background(), time.Duration(config.Config.Mongo.DBTimeout)*time.Second) c := d.mongoClient.Database(config.Config.Mongo.DBDatabase).Collection(cWorkMoment) var workMomentList []WorkMoment @@ -700,7 +700,7 @@ func (d *DataBases) GetUserFriendWorkMoments(friendIDList []string, showNumber, result, err := c.Find(ctx, bson.D{ {"$or", bson.A{ bson.D{{"user_id", userID}}, //self - bson.D{{"user_id", bson.D{{"$in", friendIDList}}}, + bson.D{ {"$or", bson.A{ bson.D{{"permission", constant.WorkMomentPermissionCantSee}, {"permission_user_id_list", bson.D{{"$nin", bson.A{userID}}}}}, bson.D{{"permission", constant.WorkMomentPermissionCanSee}, {"permission_user_id_list", bson.D{{"$in", bson.A{userID}}}}}, diff --git a/pkg/common/db/redisModel.go b/pkg/common/db/redisModel.go index 8b3cdb4c7..0241faa9f 100644 --- a/pkg/common/db/redisModel.go +++ b/pkg/common/db/redisModel.go @@ -6,7 +6,6 @@ import ( pbCommon "Open_IM/pkg/proto/sdk_ws" "encoding/json" "github.com/garyburd/redigo/redis" - "strings" ) const ( @@ -182,32 +181,48 @@ func (d *DataBases) GetUserInfoFromCache(userID string) (*pbCommon.UserInfo, err return userInfo, err } -func (d *DataBases) AddFriendToCache(userID string, friendIDList ...interface{}) error { - _, err := d.Exec("SADD", friendRelationCache+userID, friendIDList...) +func (d *DataBases) AddFriendToCache(userID string, friendIDList ...string) error { + var IDList []interface{} + for _, id := range friendIDList { + IDList = append(IDList, id) + } + _, err := d.Exec("SADD", friendRelationCache+userID, IDList...) return err } -func (d *DataBases) ReduceFriendToCache(userID string, friendIDList ...interface{}) error { - _, err := d.Exec("SREM", friendRelationCache+userID, friendIDList...) +func (d *DataBases) ReduceFriendToCache(userID string, friendIDList ...string) error { + var IDList []interface{} + for _, id := range friendIDList { + IDList = append(IDList, id) + } + _, err := d.Exec("SREM", friendRelationCache+userID, IDList...) return err } func (d *DataBases) GetFriendIDListFromCache(userID string) ([]string, error) { - result, err := redis.String(d.Exec("SMEMBERS", friendRelationCache+userID)) - return strings.Split(result, " "), err + result, err := redis.Strings(d.Exec("SMEMBERS", friendRelationCache+userID)) + return result, err } -func (d *DataBases) AddBlackUserToCache(userID string, blackList ...interface{}) error { - _, err := d.Exec("SADD", blackListCache+userID, blackList...) +func (d *DataBases) AddBlackUserToCache(userID string, blackList ...string) error { + var IDList []interface{} + for _, id := range blackList { + IDList = append(IDList, id) + } + _, err := d.Exec("SADD", blackListCache+userID, IDList...) return err } -func (d *DataBases) ReduceBlackUserFromCache(userID string, blackList ...interface{}) error { - _, err := d.Exec("SREM", blackListCache+userID, blackList...) +func (d *DataBases) ReduceBlackUserFromCache(userID string, blackList ...string) error { + var IDList []interface{} + for _, id := range blackList { + IDList = append(IDList, id) + } + _, err := d.Exec("SREM", blackListCache+userID, IDList...) return err } func (d *DataBases) GetBlackListFromCache(userID string) ([]string, error) { - result, err := redis.String(d.Exec("SMEMBERS", blackListCache+userID)) - return strings.Split(result, " "), err + result, err := redis.Strings(d.Exec("SMEMBERS", blackListCache+userID)) + return result, err }