mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-05-17 09:44:47 +08:00
Merge remote-tracking branch 'origin/errcode' into errcode
This commit is contained in:
commit
7ed60bd8f9
2
go.mod
2
go.mod
@ -4,7 +4,7 @@ go 1.18
|
|||||||
|
|
||||||
require (
|
require (
|
||||||
firebase.google.com/go v3.13.0+incompatible
|
firebase.google.com/go v3.13.0+incompatible
|
||||||
github.com/OpenIMSDK/getcdv3 v1.0.3
|
github.com/OpenIMSDK/getcdv3 v1.0.4
|
||||||
github.com/OpenIMSDK/open_utils v1.0.8
|
github.com/OpenIMSDK/open_utils v1.0.8
|
||||||
github.com/Shopify/sarama v1.32.0
|
github.com/Shopify/sarama v1.32.0
|
||||||
github.com/alibabacloud-go/darabonba-openapi v0.1.11
|
github.com/alibabacloud-go/darabonba-openapi v0.1.11
|
||||||
|
2
go.sum
2
go.sum
@ -393,6 +393,8 @@ github.com/KyleBanks/depth v1.2.1/go.mod h1:jzSb9d0L43HxTQfT+oSA1EEp2q+ne2uh6Xge
|
|||||||
github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU=
|
github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU=
|
||||||
github.com/OpenIMSDK/getcdv3 v1.0.3 h1:3/j92MuDPFhAJYBy/ht0qnybdaaCezefF1pMTClvvq4=
|
github.com/OpenIMSDK/getcdv3 v1.0.3 h1:3/j92MuDPFhAJYBy/ht0qnybdaaCezefF1pMTClvvq4=
|
||||||
github.com/OpenIMSDK/getcdv3 v1.0.3/go.mod h1:ZvsBwAjOZZr7HBF3SytJaHCltuOfBKbM1vLSCjut7kw=
|
github.com/OpenIMSDK/getcdv3 v1.0.3/go.mod h1:ZvsBwAjOZZr7HBF3SytJaHCltuOfBKbM1vLSCjut7kw=
|
||||||
|
github.com/OpenIMSDK/getcdv3 v1.0.4 h1:wKpLcp1gbLbh+fa7b5iCL4fTBLm87hB0+p0ZQMg9tK8=
|
||||||
|
github.com/OpenIMSDK/getcdv3 v1.0.4/go.mod h1:ZvsBwAjOZZr7HBF3SytJaHCltuOfBKbM1vLSCjut7kw=
|
||||||
github.com/OpenIMSDK/open_log v1.0.0 h1:ZQ908aWgPqfHOfkQ/oFSV20AZdRwPw+sZjC/sAPd5cA=
|
github.com/OpenIMSDK/open_log v1.0.0 h1:ZQ908aWgPqfHOfkQ/oFSV20AZdRwPw+sZjC/sAPd5cA=
|
||||||
github.com/OpenIMSDK/open_log v1.0.0/go.mod h1:qWvqF4iT2qBAP1eGGbinc0aAng1Y25X8A9Si1WS3oB4=
|
github.com/OpenIMSDK/open_log v1.0.0/go.mod h1:qWvqF4iT2qBAP1eGGbinc0aAng1Y25X8A9Si1WS3oB4=
|
||||||
github.com/OpenIMSDK/open_utils v1.0.1/go.mod h1:PPRayByXnfu8PR5Xv9wzUMBrm1BV3y7s29GGg8ae47s=
|
github.com/OpenIMSDK/open_utils v1.0.1/go.mod h1:PPRayByXnfu8PR5Xv9wzUMBrm1BV3y7s29GGg8ae47s=
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package convert
|
package convert
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"Open_IM/pkg/common/db/relation"
|
|
||||||
"Open_IM/pkg/common/db/table"
|
"Open_IM/pkg/common/db/table"
|
||||||
sdk "Open_IM/pkg/proto/sdk_ws"
|
sdk "Open_IM/pkg/proto/sdk_ws"
|
||||||
utils "github.com/OpenIMSDK/open_utils"
|
utils "github.com/OpenIMSDK/open_utils"
|
||||||
@ -23,8 +22,8 @@ type DBFriend struct {
|
|||||||
*table.FriendModel
|
*table.FriendModel
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewDBFriend(friend *controller.Friend) *DBFriend {
|
func NewDBFriend(friend *table.FriendModel) *DBFriend {
|
||||||
return &DBFriend{Friend: friend}
|
return &DBFriend{FriendModel: friend}
|
||||||
}
|
}
|
||||||
|
|
||||||
type PBFriend struct {
|
type PBFriend struct {
|
||||||
@ -35,6 +34,14 @@ func NewPBFriend(friendInfo *sdk.FriendInfo) *PBFriend {
|
|||||||
return &PBFriend{FriendInfo: friendInfo}
|
return &PBFriend{FriendInfo: friendInfo}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (*PBFriend) PB2DB(friends []*sdk.FriendInfo) (DBFriends []*table.FriendModel, err error) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func (*DBFriend) DB2PB(friends []*table.FriendModel) (PBFriends []*sdk.FriendInfo, err error) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
func (db *DBFriend) Convert() (*sdk.FriendInfo, error) {
|
func (db *DBFriend) Convert() (*sdk.FriendInfo, error) {
|
||||||
pbFriend := &sdk.FriendInfo{FriendUser: &sdk.UserInfo{}}
|
pbFriend := &sdk.FriendInfo{FriendUser: &sdk.UserInfo{}}
|
||||||
utils.CopyStructFields(pbFriend, db)
|
utils.CopyStructFields(pbFriend, db)
|
||||||
@ -49,8 +56,8 @@ func (db *DBFriend) Convert() (*sdk.FriendInfo, error) {
|
|||||||
return pbFriend, nil
|
return pbFriend, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (pb *PBFriend) Convert() (*relation.Friend, error) {
|
func (pb *PBFriend) Convert() (*table.FriendModel, error) {
|
||||||
dbFriend := &relation.Friend{}
|
dbFriend := &table.FriendModel{}
|
||||||
utils.CopyStructFields(dbFriend, pb)
|
utils.CopyStructFields(dbFriend, pb)
|
||||||
dbFriend.FriendUserID = pb.FriendUser.UserID
|
dbFriend.FriendUserID = pb.FriendUser.UserID
|
||||||
dbFriend.CreateTime = utils.UnixSecondToTime(pb.CreateTime)
|
dbFriend.CreateTime = utils.UnixSecondToTime(pb.CreateTime)
|
||||||
@ -58,11 +65,11 @@ func (pb *PBFriend) Convert() (*relation.Friend, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type DBFriendRequest struct {
|
type DBFriendRequest struct {
|
||||||
*relation.FriendRequest
|
*table.FriendRequestModel
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewDBFriendRequest(friendRequest *relation.FriendRequest) *DBFriendRequest {
|
func NewDBFriendRequest(friendRequest *table.FriendRequestModel) *DBFriendRequest {
|
||||||
return &DBFriendRequest{FriendRequest: friendRequest}
|
return &DBFriendRequest{FriendRequestModel: friendRequest}
|
||||||
}
|
}
|
||||||
|
|
||||||
type PBFriendRequest struct {
|
type PBFriendRequest struct {
|
||||||
@ -73,8 +80,16 @@ func NewPBFriendRequest(friendRequest *sdk.FriendRequest) *PBFriendRequest {
|
|||||||
return &PBFriendRequest{FriendRequest: friendRequest}
|
return &PBFriendRequest{FriendRequest: friendRequest}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (pb *PBFriendRequest) Convert() (*relation.FriendRequest, error) {
|
func (*PBFriendRequest) PB2DB(friendRequests []*sdk.FriendRequest) (DBFriendRequests []*table.FriendRequestModel, err error) {
|
||||||
dbFriendRequest := &relation.FriendRequest{}
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func (*DBFriendRequest) DB2PB(friendRequests []*table.FriendRequestModel) (PBFriendRequests []*sdk.FriendRequest, err error) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func (pb *PBFriendRequest) Convert() (*table.FriendRequestModel, error) {
|
||||||
|
dbFriendRequest := &table.FriendRequestModel{}
|
||||||
utils.CopyStructFields(dbFriendRequest, pb)
|
utils.CopyStructFields(dbFriendRequest, pb)
|
||||||
dbFriendRequest.CreateTime = utils.UnixSecondToTime(int64(pb.CreateTime))
|
dbFriendRequest.CreateTime = utils.UnixSecondToTime(int64(pb.CreateTime))
|
||||||
dbFriendRequest.HandleTime = utils.UnixSecondToTime(int64(pb.HandleTime))
|
dbFriendRequest.HandleTime = utils.UnixSecondToTime(int64(pb.HandleTime))
|
||||||
@ -103,11 +118,19 @@ func (db *DBFriendRequest) Convert() (*sdk.FriendRequest, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type DBBlack struct {
|
type DBBlack struct {
|
||||||
*relation.Black
|
*table.BlackModel
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewDBBlack(black *relation.Black) *DBBlack {
|
func (*PBBlack) PB2DB(blacks []*sdk.BlackInfo) (DBBlacks []*table.BlackModel, err error) {
|
||||||
return &DBBlack{Black: black}
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func (*DBBlack) DB2PB(blacks []*table.BlackModel) (PBBlacks []*sdk.BlackInfo, err error) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewDBBlack(black *table.BlackModel) *DBBlack {
|
||||||
|
return &DBBlack{BlackModel: black}
|
||||||
}
|
}
|
||||||
|
|
||||||
type PBBlack struct {
|
type PBBlack struct {
|
||||||
@ -118,8 +141,8 @@ func NewPBBlack(blackInfo *sdk.BlackInfo) *PBBlack {
|
|||||||
return &PBBlack{BlackInfo: blackInfo}
|
return &PBBlack{BlackInfo: blackInfo}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (pb *PBBlack) Convert() (*relation.Black, error) {
|
func (pb *PBBlack) Convert() (*table.BlackModel, error) {
|
||||||
dbBlack := &relation.Black{}
|
dbBlack := &table.BlackModel{}
|
||||||
dbBlack.BlockUserID = pb.BlackUserInfo.UserID
|
dbBlack.BlockUserID = pb.BlackUserInfo.UserID
|
||||||
dbBlack.CreateTime = utils.UnixSecondToTime(int64(pb.CreateTime))
|
dbBlack.CreateTime = utils.UnixSecondToTime(int64(pb.CreateTime))
|
||||||
return dbBlack, nil
|
return dbBlack, nil
|
||||||
@ -137,11 +160,19 @@ func (db *DBBlack) Convert() (*sdk.BlackInfo, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type DBGroup struct {
|
type DBGroup struct {
|
||||||
*relation.Group
|
*table.GroupModel
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewDBGroup(group *relation.Group) *DBGroup {
|
func (*PBGroup) PB2DB(groups []*sdk.GroupInfo) (DBGroups []*table.GroupModel, err error) {
|
||||||
return &DBGroup{Group: group}
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func (*DBGroup) DB2PB(groups []*table.GroupModel) (PBGroups []*sdk.GroupInfo, err error) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewDBGroup(group *table.GroupModel) *DBGroup {
|
||||||
|
return &DBGroup{GroupModel: group}
|
||||||
}
|
}
|
||||||
|
|
||||||
type PBGroup struct {
|
type PBGroup struct {
|
||||||
@ -152,8 +183,8 @@ func NewPBGroup(groupInfo *sdk.GroupInfo) *PBGroup {
|
|||||||
return &PBGroup{GroupInfo: groupInfo}
|
return &PBGroup{GroupInfo: groupInfo}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (pb *PBGroup) Convert() *relation.Group {
|
func (pb *PBGroup) Convert() *table.GroupModel {
|
||||||
dst := &relation.Group{}
|
dst := &table.GroupModel{}
|
||||||
_ = utils.CopyStructFields(dst, pb)
|
_ = utils.CopyStructFields(dst, pb)
|
||||||
return dst
|
return dst
|
||||||
}
|
}
|
||||||
@ -180,11 +211,19 @@ func (db *DBGroup) Convert() (*sdk.GroupInfo, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type DBGroupMember struct {
|
type DBGroupMember struct {
|
||||||
*relation.GroupMember
|
*table.GroupMemberModel
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewDBGroupMember(groupMember *relation.GroupMember) *DBGroupMember {
|
func (*PBGroupMember) PB2DB(groupMembers []*sdk.GroupMemberFullInfo) (DBGroupMembers []*table.GroupMemberModel, err error) {
|
||||||
return &DBGroupMember{GroupMember: groupMember}
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func (*DBGroupMember) DB2PB(groupMembers []*table.GroupMemberModel) (PBGroupMembers []*sdk.GroupMemberFullInfo, err error) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewDBGroupMember(groupMember *table.GroupMemberModel) *DBGroupMember {
|
||||||
|
return &DBGroupMember{GroupMemberModel: groupMember}
|
||||||
}
|
}
|
||||||
|
|
||||||
type PBGroupMember struct {
|
type PBGroupMember struct {
|
||||||
@ -195,8 +234,8 @@ func NewPBGroupMember(groupMemberFullInfo *sdk.GroupMemberFullInfo) *PBGroupMemb
|
|||||||
return &PBGroupMember{GroupMemberFullInfo: groupMemberFullInfo}
|
return &PBGroupMember{GroupMemberFullInfo: groupMemberFullInfo}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (pb *PBGroupMember) Convert() (*relation.GroupMember, error) {
|
func (pb *PBGroupMember) Convert() (*table.GroupMemberModel, error) {
|
||||||
dst := &relation.GroupMember{}
|
dst := &table.GroupMemberModel{}
|
||||||
utils.CopyStructFields(dst, pb)
|
utils.CopyStructFields(dst, pb)
|
||||||
dst.JoinTime = utils.UnixSecondToTime(int64(pb.JoinTime))
|
dst.JoinTime = utils.UnixSecondToTime(int64(pb.JoinTime))
|
||||||
dst.MuteEndTime = utils.UnixSecondToTime(int64(pb.MuteEndTime))
|
dst.MuteEndTime = utils.UnixSecondToTime(int64(pb.MuteEndTime))
|
||||||
@ -224,11 +263,19 @@ func (db *DBGroupMember) Convert() (*sdk.GroupMemberFullInfo, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type DBGroupRequest struct {
|
type DBGroupRequest struct {
|
||||||
*relation.GroupRequest
|
*table.GroupRequestModel
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewDBGroupRequest(groupRequest *relation.GroupRequest) *DBGroupRequest {
|
func (*PBGroupRequest) PB2DB(groupRequests []*sdk.GroupRequest) (DBGroupRequests []*table.GroupRequestModel, err error) {
|
||||||
return &DBGroupRequest{GroupRequest: groupRequest}
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func (*DBGroupRequest) DB2PB(groupRequests []*table.GroupRequestModel) (PBGroupRequests []*sdk.GroupRequest, err error) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewDBGroupRequest(groupRequest *table.GroupRequestModel) *DBGroupRequest {
|
||||||
|
return &DBGroupRequest{GroupRequestModel: groupRequest}
|
||||||
}
|
}
|
||||||
|
|
||||||
type PBGroupRequest struct {
|
type PBGroupRequest struct {
|
||||||
@ -239,8 +286,8 @@ func NewPBGroupRequest(groupRequest *sdk.GroupRequest) *PBGroupRequest {
|
|||||||
return &PBGroupRequest{GroupRequest: groupRequest}
|
return &PBGroupRequest{GroupRequest: groupRequest}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (pb *PBGroupRequest) Convert() (*relation.GroupRequest, error) {
|
func (pb *PBGroupRequest) Convert() (*table.GroupRequestModel, error) {
|
||||||
dst := &relation.GroupRequest{}
|
dst := &table.GroupRequestModel{}
|
||||||
utils.CopyStructFields(dst, pb)
|
utils.CopyStructFields(dst, pb)
|
||||||
dst.ReqTime = utils.UnixSecondToTime(int64(pb.ReqTime))
|
dst.ReqTime = utils.UnixSecondToTime(int64(pb.ReqTime))
|
||||||
dst.HandledTime = utils.UnixSecondToTime(int64(pb.HandleTime))
|
dst.HandledTime = utils.UnixSecondToTime(int64(pb.HandleTime))
|
||||||
@ -255,11 +302,11 @@ func (db *DBGroupRequest) Convert() (*sdk.GroupRequest, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type DBUser struct {
|
type DBUser struct {
|
||||||
*relation.User
|
*table.UserModel
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewDBUser(user *relation.User) *DBUser {
|
func NewDBUser(user *table.UserModel) *DBUser {
|
||||||
return &DBUser{User: user}
|
return &DBUser{UserModel: user}
|
||||||
}
|
}
|
||||||
|
|
||||||
type PBUser struct {
|
type PBUser struct {
|
||||||
@ -270,7 +317,7 @@ func NewPBUser(userInfo *sdk.UserInfo) *PBUser {
|
|||||||
return &PBUser{UserInfo: userInfo}
|
return &PBUser{UserInfo: userInfo}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (*PBUser) PB2DB(users []*sdk.UserInfo) (DBUsers []*relation.User, err error) {
|
func (*PBUser) PB2DB(users []*sdk.UserInfo) (DBUsers []*table.UserModel, err error) {
|
||||||
for _, v := range users {
|
for _, v := range users {
|
||||||
u, err := NewPBUser(v).Convert()
|
u, err := NewPBUser(v).Convert()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -281,7 +328,7 @@ func (*PBUser) PB2DB(users []*sdk.UserInfo) (DBUsers []*relation.User, err error
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (*DBUser) DB2PB(users []*relation.User) (PBUsers []*sdk.UserInfo, err error) {
|
func (*DBUser) DB2PB(users []*table.UserModel) (PBUsers []*sdk.UserInfo, err error) {
|
||||||
for _, v := range users {
|
for _, v := range users {
|
||||||
u, err := NewDBUser(v).Convert()
|
u, err := NewDBUser(v).Convert()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -292,8 +339,8 @@ func (*DBUser) DB2PB(users []*relation.User) (PBUsers []*sdk.UserInfo, err error
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (pb *PBUser) Convert() (*relation.User, error) {
|
func (pb *PBUser) Convert() (*table.UserModel, error) {
|
||||||
dst := &relation.User{}
|
dst := &table.UserModel{}
|
||||||
utils.CopyStructFields(dst, pb)
|
utils.CopyStructFields(dst, pb)
|
||||||
dst.Birth = utils.UnixSecondToTime(pb.Birthday)
|
dst.Birth = utils.UnixSecondToTime(pb.Birthday)
|
||||||
dst.CreateTime = utils.UnixSecondToTime(int64(pb.CreateTime))
|
dst.CreateTime = utils.UnixSecondToTime(int64(pb.CreateTime))
|
||||||
|
@ -4,7 +4,7 @@ import (
|
|||||||
"Open_IM/internal/common/check"
|
"Open_IM/internal/common/check"
|
||||||
"Open_IM/internal/common/convert"
|
"Open_IM/internal/common/convert"
|
||||||
chat "Open_IM/internal/rpc/msg"
|
chat "Open_IM/internal/rpc/msg"
|
||||||
"Open_IM/pkg/common/db/relation"
|
"Open_IM/pkg/common/db/table"
|
||||||
"Open_IM/pkg/common/token_verify"
|
"Open_IM/pkg/common/token_verify"
|
||||||
"Open_IM/pkg/common/tracelog"
|
"Open_IM/pkg/common/tracelog"
|
||||||
pbFriend "Open_IM/pkg/proto/friend"
|
pbFriend "Open_IM/pkg/proto/friend"
|
||||||
@ -20,15 +20,11 @@ func (s *friendServer) GetBlacks(ctx context.Context, req *pbFriend.GetBlacksReq
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
blackIDList := make([]string, 0, len(blacks))
|
resp.Blacks, err = (*convert.DBBlack)(nil).DB2PB(blacks)
|
||||||
for _, black := range blacks {
|
|
||||||
b, err := convert.NewDBBlack(black).Convert()
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
resp.Blacks = append(resp.Blacks, b)
|
|
||||||
blackIDList = append(blackIDList, black.BlockUserID)
|
|
||||||
}
|
|
||||||
resp.Total = int32(total)
|
resp.Total = int32(total)
|
||||||
return resp, nil
|
return resp, nil
|
||||||
}
|
}
|
||||||
@ -49,10 +45,10 @@ func (s *friendServer) RemoveBlack(ctx context.Context, req *pbFriend.RemoveBlac
|
|||||||
if err := check.Access(ctx, req.OwnerUserID); err != nil {
|
if err := check.Access(ctx, req.OwnerUserID); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if err := s.BlackInterface.Delete(ctx, []*relation.Black{{OwnerUserID: req.OwnerUserID, BlockUserID: req.BlackUserID}}); err != nil {
|
if err := s.BlackInterface.Delete(ctx, []*table.BlackModel{{OwnerUserID: req.OwnerUserID, BlockUserID: req.BlackUserID}}); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
chat.BlackDeletedNotification(req)
|
chat.BlackDeletedNotification(ctx, req)
|
||||||
return resp, nil
|
return resp, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -61,10 +57,10 @@ func (s *friendServer) AddBlack(ctx context.Context, req *pbFriend.AddBlackReq)
|
|||||||
if err := token_verify.CheckAccessV3(ctx, req.OwnerUserID); err != nil {
|
if err := token_verify.CheckAccessV3(ctx, req.OwnerUserID); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
black := relation.Black{OwnerUserID: req.OwnerUserID, BlockUserID: req.BlackUserID, OperatorUserID: tracelog.GetOpUserID(ctx)}
|
black := table.BlackModel{OwnerUserID: req.OwnerUserID, BlockUserID: req.BlackUserID, OperatorUserID: tracelog.GetOpUserID(ctx)}
|
||||||
if err := s.BlackInterface.Create(ctx, []*relation.Black{&black}); err != nil {
|
if err := s.BlackInterface.Create(ctx, []*table.BlackModel{&black}); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
chat.BlackAddedNotification(tracelog.GetOperationID(ctx), req)
|
chat.BlackAddedNotification(ctx, req)
|
||||||
return resp, nil
|
return resp, nil
|
||||||
}
|
}
|
||||||
|
@ -16,8 +16,8 @@ import (
|
|||||||
"Open_IM/pkg/common/token_verify"
|
"Open_IM/pkg/common/token_verify"
|
||||||
"Open_IM/pkg/common/tracelog"
|
"Open_IM/pkg/common/tracelog"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/OpenIMSDK/getcdv3"
|
||||||
|
|
||||||
"Open_IM/pkg/getcdv3"
|
|
||||||
pbConversation "Open_IM/pkg/proto/conversation"
|
pbConversation "Open_IM/pkg/proto/conversation"
|
||||||
pbGroup "Open_IM/pkg/proto/group"
|
pbGroup "Open_IM/pkg/proto/group"
|
||||||
open_im_sdk "Open_IM/pkg/proto/sdk_ws"
|
open_im_sdk "Open_IM/pkg/proto/sdk_ws"
|
||||||
@ -42,6 +42,10 @@ type groupServer struct {
|
|||||||
etcdSchema string
|
etcdSchema string
|
||||||
etcdAddr []string
|
etcdAddr []string
|
||||||
controller.GroupInterface
|
controller.GroupInterface
|
||||||
|
|
||||||
|
etcdConn *getcdv3.EtcdConn
|
||||||
|
//userRpc pbUser.UserClient
|
||||||
|
//conversationRpc pbConversation.ConversationClient
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewGroupServer(port int) *groupServer {
|
func NewGroupServer(port int) *groupServer {
|
||||||
@ -52,12 +56,29 @@ func NewGroupServer(port int) *groupServer {
|
|||||||
etcdSchema: config.Config.Etcd.EtcdSchema,
|
etcdSchema: config.Config.Etcd.EtcdSchema,
|
||||||
etcdAddr: config.Config.Etcd.EtcdAddr,
|
etcdAddr: config.Config.Etcd.EtcdAddr,
|
||||||
}
|
}
|
||||||
|
ttl := 10
|
||||||
|
etcdClient, err := getcdv3.NewEtcdConn(config.Config.Etcd.EtcdSchema, strings.Join(g.etcdAddr, ","), config.Config.RpcRegisterIP, config.Config.Etcd.UserName, config.Config.Etcd.Password, port, ttl)
|
||||||
|
if err != nil {
|
||||||
|
panic("NewEtcdConn failed" + err.Error())
|
||||||
|
}
|
||||||
|
err = etcdClient.RegisterEtcd("", g.rpcRegisterName)
|
||||||
|
if err != nil {
|
||||||
|
panic("NewEtcdConn failed" + err.Error())
|
||||||
|
}
|
||||||
|
etcdClient.SetDefaultEtcdConfig(config.Config.RpcRegisterName.OpenImUserName, config.Config.RpcPort.OpenImUserPort)
|
||||||
|
//conn := etcdClient.GetConn("", config.Config.RpcRegisterName.OpenImUserName)
|
||||||
|
//g.userRpc = pbUser.NewUserClient(conn)
|
||||||
|
|
||||||
|
etcdClient.SetDefaultEtcdConfig(config.Config.RpcRegisterName.OpenImConversationName, config.Config.RpcPort.OpenImConversationPort)
|
||||||
|
//conn = etcdClient.GetConn("", config.Config.RpcRegisterName.OpenImConversationName)
|
||||||
|
//g.conversationRpc = pbConversation.NewConversationClient(conn)
|
||||||
|
|
||||||
//mysql init
|
//mysql init
|
||||||
var mysql relation.Mysql
|
var mysql relation.Mysql
|
||||||
var mongo unrelation.Mongo
|
var mongo unrelation.Mongo
|
||||||
var groupModel table.GroupModel
|
var groupModel table.GroupModel
|
||||||
var redis cache.RedisClient
|
var redis cache.RedisClient
|
||||||
err := mysql.InitConn().AutoMigrateModel(&groupModel)
|
err = mysql.InitConn().AutoMigrateModel(&groupModel)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic("db init err:" + err.Error())
|
panic("db init err:" + err.Error())
|
||||||
}
|
}
|
||||||
@ -870,19 +891,6 @@ func (s *groupServer) SetGroupInfo(ctx context.Context, req *pbGroup.SetGroupInf
|
|||||||
}
|
}
|
||||||
if req.GroupInfoForSet.Notification != "" {
|
if req.GroupInfoForSet.Notification != "" {
|
||||||
//get group member user id
|
//get group member user id
|
||||||
getGroupMemberIDListFromCacheReq := &pbCache.GetGroupMemberIDListFromCacheReq{OperationID: tracelog.GetOperationID(ctx), GroupID: req.GroupInfoForSet.GroupID}
|
|
||||||
etcdConn, err := getcdv3.GetConn(ctx, config.Config.RpcRegisterName.OpenImCacheName)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
client := pbCache.NewCacheClient(etcdConn)
|
|
||||||
cacheResp, err := client.GetGroupMemberIDListFromCache(ctx, getGroupMemberIDListFromCacheReq)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
if err = constant.CommonResp2Err(cacheResp.CommonResp); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
var conversationReq pbConversation.ModifyConversationFieldReq
|
var conversationReq pbConversation.ModifyConversationFieldReq
|
||||||
conversation := pbConversation.Conversation{
|
conversation := pbConversation.Conversation{
|
||||||
OwnerUserID: tracelog.GetOpUserID(ctx),
|
OwnerUserID: tracelog.GetOpUserID(ctx),
|
||||||
@ -895,12 +903,8 @@ func (s *groupServer) SetGroupInfo(ctx context.Context, req *pbGroup.SetGroupInf
|
|||||||
conversationReq.FieldType = constant.FieldGroupAtType
|
conversationReq.FieldType = constant.FieldGroupAtType
|
||||||
conversation.GroupAtType = constant.GroupNotification
|
conversation.GroupAtType = constant.GroupNotification
|
||||||
conversationReq.UserIDList = cacheResp.UserIDList
|
conversationReq.UserIDList = cacheResp.UserIDList
|
||||||
nEtcdConn, err := getcdv3.GetConn(ctx, config.Config.RpcRegisterName.OpenImConversationName)
|
|
||||||
if err != nil {
|
_, err = pbConversation.NewConversationClient(s.etcdConn.GetConn("", config.Config.RpcRegisterName.OpenImConversationName)).ModifyConversationField(ctx, &conversationReq)
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
nClient := pbConversation.NewConversationClient(nEtcdConn)
|
|
||||||
conversationReply, err := nClient.ModifyConversationField(context.Background(), &conversationReq)
|
|
||||||
tracelog.SetCtxInfo(ctx, "ModifyConversationField", err, "req", &conversationReq, "resp", conversationReply)
|
tracelog.SetCtxInfo(ctx, "ModifyConversationField", err, "req", &conversationReq, "resp", conversationReply)
|
||||||
}
|
}
|
||||||
return resp, nil
|
return resp, nil
|
||||||
|
@ -7,6 +7,7 @@ import (
|
|||||||
"Open_IM/pkg/common/constant"
|
"Open_IM/pkg/common/constant"
|
||||||
"Open_IM/pkg/common/db/controller"
|
"Open_IM/pkg/common/db/controller"
|
||||||
"Open_IM/pkg/common/db/relation"
|
"Open_IM/pkg/common/db/relation"
|
||||||
|
"Open_IM/pkg/common/db/table"
|
||||||
"Open_IM/pkg/common/log"
|
"Open_IM/pkg/common/log"
|
||||||
promePkg "Open_IM/pkg/common/prometheus"
|
promePkg "Open_IM/pkg/common/prometheus"
|
||||||
"Open_IM/pkg/common/token_verify"
|
"Open_IM/pkg/common/token_verify"
|
||||||
@ -197,7 +198,7 @@ func (s *userServer) UpdateUserInfo(ctx context.Context, req *pbUser.UpdateUserI
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
err = s.Update(ctx, []*relation.User{user})
|
err = s.Update(ctx, []*table.UserModel{user})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -213,11 +214,11 @@ func (s *userServer) UpdateUserInfo(ctx context.Context, req *pbUser.UpdateUserI
|
|||||||
}
|
}
|
||||||
go func() {
|
go func() {
|
||||||
for _, v := range rpcResp.FriendsInfo {
|
for _, v := range rpcResp.FriendsInfo {
|
||||||
chat.FriendInfoUpdatedNotification(tracelog.GetOperationID(ctx), req.UserInfo.UserID, v.FriendUser.UserID, tracelog.GetOpUserID(ctx))
|
chat.FriendInfoUpdatedNotification(ctx, req.UserInfo.UserID, v.FriendUser.UserID, tracelog.GetOpUserID(ctx))
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
chat.UserInfoUpdatedNotification(tracelog.GetOperationID(ctx), tracelog.GetOpUserID(ctx), req.UserInfo.UserID)
|
chat.UserInfoUpdatedNotification(ctx, tracelog.GetOpUserID(ctx), req.UserInfo.UserID)
|
||||||
if req.UserInfo.FaceURL != "" {
|
if req.UserInfo.FaceURL != "" {
|
||||||
s.SyncJoinedGroupMemberFaceURL(ctx, req.UserInfo.UserID, req.UserInfo.FaceURL, tracelog.GetOperationID(ctx), tracelog.GetOpUserID(ctx))
|
s.SyncJoinedGroupMemberFaceURL(ctx, req.UserInfo.UserID, req.UserInfo.FaceURL, tracelog.GetOperationID(ctx), tracelog.GetOpUserID(ctx))
|
||||||
}
|
}
|
||||||
@ -235,13 +236,13 @@ func (s *userServer) SetGlobalRecvMessageOpt(ctx context.Context, req *pbUser.Se
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
chat.UserInfoUpdatedNotification(tracelog.GetOperationID(ctx), req.UserID, req.UserID)
|
chat.UserInfoUpdatedNotification(ctx, req.UserID, req.UserID)
|
||||||
return &resp, nil
|
return &resp, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *userServer) AccountCheck(ctx context.Context, req *pbUser.AccountCheckReq) (*pbUser.AccountCheckResp, error) {
|
func (s *userServer) AccountCheck(ctx context.Context, req *pbUser.AccountCheckReq) (*pbUser.AccountCheckResp, error) {
|
||||||
resp := pbUser.AccountCheckResp{}
|
resp := pbUser.AccountCheckResp{}
|
||||||
err := token_verify.CheckManagerUserID(ctx, tracelog.GetOpUserID(ctx))
|
err := token_verify.CheckAdmin(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
64
pkg/common/db/cache/black.go
vendored
Normal file
64
pkg/common/db/cache/black.go
vendored
Normal file
@ -0,0 +1,64 @@
|
|||||||
|
package cache
|
||||||
|
|
||||||
|
import (
|
||||||
|
"Open_IM/pkg/common/db/relation"
|
||||||
|
"Open_IM/pkg/common/tracelog"
|
||||||
|
"Open_IM/pkg/utils"
|
||||||
|
"context"
|
||||||
|
"encoding/json"
|
||||||
|
"github.com/dtm-labs/rockscache"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
blackIDsKey = "BLACK_IDS:"
|
||||||
|
blackExpireTime = time.Second * 60 * 60 * 12
|
||||||
|
)
|
||||||
|
|
||||||
|
type BlackCache struct {
|
||||||
|
blackDB *relation.Black
|
||||||
|
expireTime time.Duration
|
||||||
|
rcClient *rockscache.Client
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewBlackCache(blackDB *relation.Black) *BlackCache {
|
||||||
|
return &BlackCache{
|
||||||
|
blackDB: nil,
|
||||||
|
expireTime: 0,
|
||||||
|
rcClient: nil,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b *BlackCache) getBlackIDsKey(ownerUserID string) string {
|
||||||
|
return blackIDsKey + ownerUserID
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b *BlackCache) GetBlackIDs(ctx context.Context, userID string) (blackIDs []string, err error) {
|
||||||
|
getBlackIDList := func() (string, error) {
|
||||||
|
blackIDs, err := b.blackDB.GetBlackIDs(ctx, userID)
|
||||||
|
if err != nil {
|
||||||
|
return "", utils.Wrap(err, "")
|
||||||
|
}
|
||||||
|
bytes, err := json.Marshal(blackIDs)
|
||||||
|
if err != nil {
|
||||||
|
return "", utils.Wrap(err, "")
|
||||||
|
}
|
||||||
|
return string(bytes), nil
|
||||||
|
}
|
||||||
|
defer func() {
|
||||||
|
tracelog.SetCtxDebug(ctx, utils.GetFuncName(1), err, "userID", userID, "blackIDList", blackIDs)
|
||||||
|
}()
|
||||||
|
blackIDListStr, err := b.rcClient.Fetch(blackListCache+userID, time.Second*30*60, getBlackIDList)
|
||||||
|
if err != nil {
|
||||||
|
return nil, utils.Wrap(err, "")
|
||||||
|
}
|
||||||
|
err = json.Unmarshal([]byte(blackIDListStr), &blackIDs)
|
||||||
|
return blackIDs, utils.Wrap(err, "")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b *BlackCache) DelBlackIDListFromCache(ctx context.Context, userID string) (err error) {
|
||||||
|
defer func() {
|
||||||
|
tracelog.SetCtxDebug(ctx, utils.GetFuncName(1), err, "ctx", ctx)
|
||||||
|
}()
|
||||||
|
return b.rcClient.TagAsDeleted(blackListCache + userID)
|
||||||
|
}
|
65
pkg/common/db/cache/friend.go
vendored
Normal file
65
pkg/common/db/cache/friend.go
vendored
Normal file
@ -0,0 +1,65 @@
|
|||||||
|
package cache
|
||||||
|
|
||||||
|
import (
|
||||||
|
"Open_IM/pkg/common/db/relation"
|
||||||
|
"Open_IM/pkg/common/tracelog"
|
||||||
|
"Open_IM/pkg/utils"
|
||||||
|
"context"
|
||||||
|
"encoding/json"
|
||||||
|
"github.com/dtm-labs/rockscache"
|
||||||
|
"github.com/go-redis/redis/v8"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
friendExpireTime = time.Second * 60 * 60 * 12
|
||||||
|
friendIDsKey = "FRIEND_IDS:"
|
||||||
|
)
|
||||||
|
|
||||||
|
type FriendCache struct {
|
||||||
|
friendDB *relation.Friend
|
||||||
|
expireTime time.Duration
|
||||||
|
rcClient *rockscache.Client
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewFriendCache(rdb redis.UniversalClient, friendDB *relation.Friend, options rockscache.Options) *FriendCache {
|
||||||
|
return &FriendCache{
|
||||||
|
friendDB: friendDB,
|
||||||
|
expireTime: friendExpireTime,
|
||||||
|
rcClient: rockscache.NewClient(rdb, options),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (f *FriendCache) getFriendRelationKey(ownerUserID string) string {
|
||||||
|
return friendIDsKey + ownerUserID
|
||||||
|
}
|
||||||
|
|
||||||
|
func (f *FriendCache) GetFriendIDs(ctx context.Context, ownerUserID string) (friendIDs []string, err error) {
|
||||||
|
getFriendIDList := func() (string, error) {
|
||||||
|
friendIDList, err := f.friendDB.GetFriendIDs(ctx, ownerUserID)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
bytes, err := json.Marshal(friendIDList)
|
||||||
|
if err != nil {
|
||||||
|
return "", utils.Wrap(err, "")
|
||||||
|
}
|
||||||
|
return string(bytes), nil
|
||||||
|
}
|
||||||
|
defer func() {
|
||||||
|
tracelog.SetCtxDebug(ctx, utils.GetFuncName(1), err, "ownerUserID", ownerUserID, "friendIDs", friendIDs)
|
||||||
|
}()
|
||||||
|
friendIDListStr, err := f.rcClient.Fetch(f.getFriendRelationKey(ownerUserID), f.expireTime, getFriendIDList)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
err = json.Unmarshal([]byte(friendIDListStr), &friendIDs)
|
||||||
|
return friendIDs, utils.Wrap(err, "")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (f *FriendCache) DelFriendIDs(ctx context.Context, ownerUserID string) (err error) {
|
||||||
|
defer func() {
|
||||||
|
tracelog.SetCtxDebug(ctx, utils.GetFuncName(1), err, "ownerUserID", ownerUserID)
|
||||||
|
}()
|
||||||
|
return f.rcClient.TagAsDeleted(f.getFriendRelationKey(ownerUserID))
|
||||||
|
}
|
57
pkg/common/db/cache/group.go
vendored
57
pkg/common/db/cache/group.go
vendored
@ -2,6 +2,7 @@ package cache
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"Open_IM/pkg/common/constant"
|
"Open_IM/pkg/common/constant"
|
||||||
|
"Open_IM/pkg/common/db/localcache"
|
||||||
"Open_IM/pkg/common/db/relation"
|
"Open_IM/pkg/common/db/relation"
|
||||||
"Open_IM/pkg/common/db/unrelation"
|
"Open_IM/pkg/common/db/unrelation"
|
||||||
"Open_IM/pkg/common/tracelog"
|
"Open_IM/pkg/common/tracelog"
|
||||||
@ -39,18 +40,13 @@ type GroupCache struct {
|
|||||||
|
|
||||||
//local cache
|
//local cache
|
||||||
cacheGroupMtx sync.RWMutex
|
cacheGroupMtx sync.RWMutex
|
||||||
cacheGroupMemberUserIDs map[string]*GroupMemberIDsHash
|
cacheGroupMemberUserIDs map[string]*localcache.GroupMemberIDsHash
|
||||||
}
|
|
||||||
|
|
||||||
type GroupMemberIDsHash struct {
|
|
||||||
MemberListHash uint64
|
|
||||||
UserIDs []string
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewGroupCache(rdb redis.UniversalClient, groupDB *relation.GroupGorm, groupMemberDB *relation.GroupMemberGorm, groupRequestDB *relation.GroupRequestGorm, mongoClient *unrelation.SuperGroupMgoDB, opts rockscache.Options) *GroupCache {
|
func NewGroupCache(rdb redis.UniversalClient, groupDB *relation.GroupGorm, groupMemberDB *relation.GroupMemberGorm, groupRequestDB *relation.GroupRequestGorm, mongoClient *unrelation.SuperGroupMgoDB, opts rockscache.Options) *GroupCache {
|
||||||
return &GroupCache{rcClient: rockscache.NewClient(rdb, opts), expireTime: groupExpireTime,
|
return &GroupCache{rcClient: rockscache.NewClient(rdb, opts), expireTime: groupExpireTime,
|
||||||
group: groupDB, groupMember: groupMemberDB, groupRequest: groupRequestDB, redisClient: NewRedisClient(rdb),
|
group: groupDB, groupMember: groupMemberDB, groupRequest: groupRequestDB, redisClient: NewRedisClient(rdb),
|
||||||
mongoDB: mongoClient, cacheGroupMemberUserIDs: make(map[string]*GroupMemberIDsHash, 0),
|
mongoDB: mongoClient, cacheGroupMemberUserIDs: make(map[string]*localcache.GroupMemberIDsHash, 0),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -287,7 +283,7 @@ func (g *GroupCache) LocalGetGroupMemberIDs(ctx context.Context, groupID string)
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
g.cacheGroupMemberUserIDs[groupID] = &GroupMemberIDsHash{
|
g.cacheGroupMemberUserIDs[groupID] = &localcache.GroupMemberIDsHash{
|
||||||
MemberListHash: remoteHash,
|
MemberListHash: remoteHash,
|
||||||
UserIDs: groupMemberIDsRemote,
|
UserIDs: groupMemberIDsRemote,
|
||||||
}
|
}
|
||||||
@ -350,6 +346,51 @@ func (g *GroupCache) GetGroupMemberInfo(ctx context.Context, groupID, userID str
|
|||||||
return groupMember, utils.Wrap(err, "")
|
return groupMember, utils.Wrap(err, "")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (g *GroupCache) GetGroupMembersInfo(ctx context.Context, count, offset int32, groupID string) (groupMembers []*relation.GroupMember, err error) {
|
||||||
|
defer func() {
|
||||||
|
tracelog.SetCtxDebug(ctx, utils.GetFuncName(1), err, "count", count, "offset", offset, "groupID", groupID, "groupMember", groupMembers)
|
||||||
|
}()
|
||||||
|
groupMemberIDList, err := g.GetGroupMemberIDs(ctx, groupID)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if count < 0 || offset < 0 {
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
var groupMemberList []*relation.GroupMember
|
||||||
|
var start, stop int32
|
||||||
|
start = offset
|
||||||
|
stop = offset + count
|
||||||
|
l := int32(len(groupMemberIDList))
|
||||||
|
if start > stop {
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
if start >= l {
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
if count != 0 {
|
||||||
|
if stop >= l {
|
||||||
|
stop = l
|
||||||
|
}
|
||||||
|
groupMemberIDList = groupMemberIDList[start:stop]
|
||||||
|
} else {
|
||||||
|
if l < 1000 {
|
||||||
|
stop = l
|
||||||
|
} else {
|
||||||
|
stop = 1000
|
||||||
|
}
|
||||||
|
groupMemberIDList = groupMemberIDList[start:stop]
|
||||||
|
}
|
||||||
|
for _, userID := range groupMemberIDList {
|
||||||
|
groupMember, err := g.GetGroupMemberInfo(ctx, groupID, userID)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
groupMembers = append(groupMembers, groupMember)
|
||||||
|
}
|
||||||
|
return groupMemberList, nil
|
||||||
|
}
|
||||||
|
|
||||||
func (g *GroupCache) DelGroupMemberInfo(ctx context.Context, groupID, userID string) (err error) {
|
func (g *GroupCache) DelGroupMemberInfo(ctx context.Context, groupID, userID string) (err error) {
|
||||||
defer func() {
|
defer func() {
|
||||||
tracelog.SetCtxDebug(ctx, utils.GetFuncName(1), err, "groupID", groupID, "userID", userID)
|
tracelog.SetCtxDebug(ctx, utils.GetFuncName(1), err, "groupID", groupID, "userID", userID)
|
||||||
|
4
pkg/common/db/cache/rockscache.go
vendored
4
pkg/common/db/cache/rockscache.go
vendored
@ -16,7 +16,7 @@ import (
|
|||||||
|
|
||||||
const (
|
const (
|
||||||
//userInfoCache = "USER_INFO_CACHE:"
|
//userInfoCache = "USER_INFO_CACHE:"
|
||||||
friendRelationCache = "FRIEND_RELATION_CACHE:"
|
//friendRelationCache = "FRIEND_RELATION_CACHE:"
|
||||||
blackListCache = "BLACK_LIST_CACHE:"
|
blackListCache = "BLACK_LIST_CACHE:"
|
||||||
//groupCache = "GROUP_CACHE:"
|
//groupCache = "GROUP_CACHE:"
|
||||||
//groupInfoCache = "GROUP_INFO_CACHE:"
|
//groupInfoCache = "GROUP_INFO_CACHE:"
|
||||||
@ -24,7 +24,7 @@ const (
|
|||||||
//joinedGroupListCache = "JOINED_GROUP_LIST_CACHE:"
|
//joinedGroupListCache = "JOINED_GROUP_LIST_CACHE:"
|
||||||
//groupMemberInfoCache = "GROUP_MEMBER_INFO_CACHE:"
|
//groupMemberInfoCache = "GROUP_MEMBER_INFO_CACHE:"
|
||||||
//groupAllMemberInfoCache = "GROUP_ALL_MEMBER_INFO_CACHE:"
|
//groupAllMemberInfoCache = "GROUP_ALL_MEMBER_INFO_CACHE:"
|
||||||
allFriendInfoCache = "ALL_FRIEND_INFO_CACHE:"
|
//allFriendInfoCache = "ALL_FRIEND_INFO_CACHE:"
|
||||||
//joinedSuperGroupListCache = "JOINED_SUPER_GROUP_LIST_CACHE:"
|
//joinedSuperGroupListCache = "JOINED_SUPER_GROUP_LIST_CACHE:"
|
||||||
//groupMemberListHashCache = "GROUP_MEMBER_LIST_HASH_CACHE:"
|
//groupMemberListHashCache = "GROUP_MEMBER_LIST_HASH_CACHE:"
|
||||||
//groupMemberNumCache = "GROUP_MEMBER_NUM_CACHE:"
|
//groupMemberNumCache = "GROUP_MEMBER_NUM_CACHE:"
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
package controller
|
package controller
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"Open_IM/pkg/common/db/relation"
|
"Open_IM/pkg/common/db/table"
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
@ -9,11 +9,11 @@ import (
|
|||||||
|
|
||||||
type BlackInterface interface {
|
type BlackInterface interface {
|
||||||
// Create 增加黑名单
|
// Create 增加黑名单
|
||||||
Create(ctx context.Context, blacks []*relation.Black) (err error)
|
Create(ctx context.Context, blacks []*table.BlackModel) (err error)
|
||||||
// Delete 删除黑名单
|
// Delete 删除黑名单
|
||||||
Delete(ctx context.Context, blacks []*relation.Black) (err error)
|
Delete(ctx context.Context, blacks []*table.BlackModel) (err error)
|
||||||
// FindOwnerBlacks 获取黑名单列表
|
// FindOwnerBlacks 获取黑名单列表
|
||||||
FindOwnerBlacks(ctx context.Context, ownerUserID string, pageNumber, showNumber int32) (blacks []*relation.Black, total int64, err error)
|
FindOwnerBlacks(ctx context.Context, ownerUserID string, pageNumber, showNumber int32) (blacks []*table.BlackModel, total int64, err error)
|
||||||
// CheckIn 检查user2是否在user1的黑名单列表中(inUser1Blacks==true) 检查user1是否在user2的黑名单列表中(inUser2Blacks==true)
|
// CheckIn 检查user2是否在user1的黑名单列表中(inUser1Blacks==true) 检查user1是否在user2的黑名单列表中(inUser2Blacks==true)
|
||||||
CheckIn(ctx context.Context, userID1, userID2 string) (inUser1Blacks bool, inUser2Blacks bool, err error)
|
CheckIn(ctx context.Context, userID1, userID2 string) (inUser1Blacks bool, inUser2Blacks bool, err error)
|
||||||
}
|
}
|
||||||
|
@ -187,13 +187,13 @@ func newGroupDatabase(db *gorm.DB, rdb redis.UniversalClient, mgoClient *mongo.C
|
|||||||
groupDB := relation.NewGroupDB(db)
|
groupDB := relation.NewGroupDB(db)
|
||||||
groupMemberDB := relation.NewGroupMemberDB(db)
|
groupMemberDB := relation.NewGroupMemberDB(db)
|
||||||
groupRequestDB := relation.NewGroupRequest(db)
|
groupRequestDB := relation.NewGroupRequest(db)
|
||||||
newDB := db
|
newDB := *db
|
||||||
superGroupMgoDB := unrelation.NewSuperGroupMgoDB(mgoClient)
|
superGroupMgoDB := unrelation.NewSuperGroupMgoDB(mgoClient)
|
||||||
database := &GroupDataBase{
|
database := &GroupDataBase{
|
||||||
groupDB: groupDB,
|
groupDB: groupDB,
|
||||||
groupMemberDB: groupMemberDB,
|
groupMemberDB: groupMemberDB,
|
||||||
groupRequestDB: groupRequestDB,
|
groupRequestDB: groupRequestDB,
|
||||||
db: newDB,
|
db: &newDB,
|
||||||
cache: cache.NewGroupCache(rdb, groupDB, groupMemberDB, groupRequestDB, superGroupMgoDB, rockscache.Options{
|
cache: cache.NewGroupCache(rdb, groupDB, groupMemberDB, groupRequestDB, superGroupMgoDB, rockscache.Options{
|
||||||
RandomExpireAdjustment: 0.2,
|
RandomExpireAdjustment: 0.2,
|
||||||
DisableCacheRead: false,
|
DisableCacheRead: false,
|
||||||
|
38
pkg/common/db/localcache/group.go
Normal file
38
pkg/common/db/localcache/group.go
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
package localcache
|
||||||
|
|
||||||
|
import (
|
||||||
|
"Open_IM/pkg/proto/group"
|
||||||
|
"context"
|
||||||
|
"google.golang.org/grpc"
|
||||||
|
"sync"
|
||||||
|
)
|
||||||
|
|
||||||
|
type GroupLocalCache struct {
|
||||||
|
lock sync.Mutex
|
||||||
|
cache map[string]GroupMemberIDsHash
|
||||||
|
rpc *grpc.ClientConn
|
||||||
|
group group.GroupClient
|
||||||
|
}
|
||||||
|
|
||||||
|
type GroupMemberIDsHash struct {
|
||||||
|
memberListHash uint64
|
||||||
|
userIDs []string
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewGroupMemberIDsLocalCache(rpc *grpc.ClientConn) GroupLocalCache {
|
||||||
|
return GroupLocalCache{
|
||||||
|
cache: make(map[string]GroupMemberIDsHash, 0),
|
||||||
|
rpc: rpc,
|
||||||
|
group: group.NewGroupClient(rpc),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (g *GroupLocalCache) GetGroupMemberIDs(ctx context.Context, groupID string) []string {
|
||||||
|
resp, err := g.group.GetGroupAbstractInfo(ctx, &group.GetGroupAbstractInfoReq{
|
||||||
|
GroupIDs: nil,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return []string{}
|
||||||
|
}
|
@ -1,58 +1,52 @@
|
|||||||
package relation
|
package relation
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"Open_IM/pkg/common/db/table"
|
||||||
"Open_IM/pkg/common/tracelog"
|
"Open_IM/pkg/common/tracelog"
|
||||||
"Open_IM/pkg/utils"
|
"Open_IM/pkg/utils"
|
||||||
"context"
|
"context"
|
||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
"time"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type Black struct {
|
type BlackGorm struct {
|
||||||
OwnerUserID string `gorm:"column:owner_user_id;primary_key;size:64"`
|
DB *gorm.DB
|
||||||
BlockUserID string `gorm:"column:block_user_id;primary_key;size:64"`
|
|
||||||
CreateTime time.Time `gorm:"column:create_time"`
|
|
||||||
AddSource int32 `gorm:"column:add_source"`
|
|
||||||
OperatorUserID string `gorm:"column:operator_user_id;size:64"`
|
|
||||||
Ex string `gorm:"column:ex;size:1024"`
|
|
||||||
DB *gorm.DB `gorm:"-"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewBlack(db *gorm.DB) *Black {
|
func NewBlackGorm(db *gorm.DB) *BlackGorm {
|
||||||
var black Black
|
var black BlackGorm
|
||||||
black.DB = db
|
black.DB = db
|
||||||
return &black
|
return &black
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *Black) Create(ctx context.Context, blacks []*Black) (err error) {
|
func (b *BlackGorm) Create(ctx context.Context, blacks []*table.BlackModel) (err error) {
|
||||||
defer func() {
|
defer func() {
|
||||||
tracelog.SetCtxDebug(ctx, utils.GetFuncName(1), err, "blacks", blacks)
|
tracelog.SetCtxDebug(ctx, utils.GetFuncName(1), err, "blacks", blacks)
|
||||||
}()
|
}()
|
||||||
return utils.Wrap(b.DB.Create(&blacks).Error, "")
|
return utils.Wrap(b.DB.Model(&table.BlackModel{}).Create(&blacks).Error, "")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *Black) Delete(ctx context.Context, blacks []*Black) (err error) {
|
func (b *BlackGorm) Delete(ctx context.Context, blacks []*table.BlackModel) (err error) {
|
||||||
defer func() {
|
defer func() {
|
||||||
tracelog.SetCtxDebug(ctx, utils.GetFuncName(1), err, "blacks", blacks)
|
tracelog.SetCtxDebug(ctx, utils.GetFuncName(1), err, "blacks", blacks)
|
||||||
}()
|
}()
|
||||||
return utils.Wrap(GroupMemberDB.Delete(blacks).Error, "")
|
return utils.Wrap(b.DB.Model(&table.BlackModel{}).Delete(blacks).Error, "")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *Black) UpdateByMap(ctx context.Context, ownerUserID, blockUserID string, args map[string]interface{}) (err error) {
|
func (b *BlackGorm) UpdateByMap(ctx context.Context, ownerUserID, blockUserID string, args map[string]interface{}) (err error) {
|
||||||
defer func() {
|
defer func() {
|
||||||
tracelog.SetCtxDebug(ctx, utils.GetFuncName(1), err, "ownerUserID", ownerUserID, "blockUserID", blockUserID, "args", args)
|
tracelog.SetCtxDebug(ctx, utils.GetFuncName(1), err, "ownerUserID", ownerUserID, "blockUserID", blockUserID, "args", args)
|
||||||
}()
|
}()
|
||||||
return utils.Wrap(b.DB.Where("block_user_id = ? and block_user_id = ?", ownerUserID, blockUserID).Updates(args).Error, "")
|
return utils.Wrap(b.DB.Model(&table.BlackModel{}).Where("block_user_id = ? and block_user_id = ?", ownerUserID, blockUserID).Updates(args).Error, "")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *Black) Update(ctx context.Context, blacks []*Black) (err error) {
|
func (b *BlackGorm) Update(ctx context.Context, blacks []*table.BlackModel) (err error) {
|
||||||
defer func() {
|
defer func() {
|
||||||
tracelog.SetCtxDebug(ctx, utils.GetFuncName(1), err, "blacks", blacks)
|
tracelog.SetCtxDebug(ctx, utils.GetFuncName(1), err, "blacks", blacks)
|
||||||
}()
|
}()
|
||||||
return utils.Wrap(b.DB.Updates(&blacks).Error, "")
|
return utils.Wrap(b.DB.Model(&table.BlackModel{}).Updates(&blacks).Error, "")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *Black) Find(ctx context.Context, blacks []*Black) (blackList []*Black, err error) {
|
func (b *BlackGorm) Find(ctx context.Context, blacks []*table.BlackModel) (blackList []*table.BlackModel, err error) {
|
||||||
defer func() {
|
defer func() {
|
||||||
tracelog.SetCtxDebug(ctx, utils.GetFuncName(1), err, "blacks", blacks, "blackList", blackList)
|
tracelog.SetCtxDebug(ctx, utils.GetFuncName(1), err, "blacks", blacks, "blackList", blackList)
|
||||||
}()
|
}()
|
||||||
@ -60,25 +54,25 @@ func (b *Black) Find(ctx context.Context, blacks []*Black) (blackList []*Black,
|
|||||||
for _, black := range blacks {
|
for _, black := range blacks {
|
||||||
where = append(where, []interface{}{black.OwnerUserID, black.BlockUserID})
|
where = append(where, []interface{}{black.OwnerUserID, black.BlockUserID})
|
||||||
}
|
}
|
||||||
return blackList, utils.Wrap(GroupMemberDB.Where("(owner_user_id, block_user_id) in ?", where).Find(&blackList).Error, "")
|
return blackList, utils.Wrap(b.DB.Model(&table.BlackModel{}).Where("(owner_user_id, block_user_id) in ?", where).Find(&blackList).Error, "")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *Black) Take(ctx context.Context, ownerUserID, blockUserID string) (black *Black, err error) {
|
func (b *BlackGorm) Take(ctx context.Context, ownerUserID, blockUserID string) (black *table.BlackModel, err error) {
|
||||||
black = &Black{}
|
black = &table.BlackModel{}
|
||||||
defer func() {
|
defer func() {
|
||||||
tracelog.SetCtxDebug(ctx, utils.GetFuncName(1), err, "ownerUserID", ownerUserID, "blockUserID", blockUserID, "black", *black)
|
tracelog.SetCtxDebug(ctx, utils.GetFuncName(1), err, "ownerUserID", ownerUserID, "blockUserID", blockUserID, "black", *black)
|
||||||
}()
|
}()
|
||||||
return black, utils.Wrap(b.DB.Where("owner_user_id = ? and block_user_id = ?", ownerUserID, blockUserID).Take(black).Error, "")
|
return black, utils.Wrap(b.DB.Model(&table.BlackModel{}).Where("owner_user_id = ? and block_user_id = ?", ownerUserID, blockUserID).Take(black).Error, "")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *Black) FindOwnerBlacks(ctx context.Context, ownerUserID string, pageNumber, showNumber int32) (blacks []*Black, total int64, err error) {
|
func (b *BlackGorm) FindOwnerBlacks(ctx context.Context, ownerUserID string, pageNumber, showNumber int32) (blacks []*table.BlackModel, total int64, err error) {
|
||||||
defer func() {
|
defer func() {
|
||||||
tracelog.SetCtxDebug(ctx, utils.GetFuncName(1), err, "ownerUserID", ownerUserID, "blacks", blacks)
|
tracelog.SetCtxDebug(ctx, utils.GetFuncName(1), err, "ownerUserID", ownerUserID, "blacks", blacks)
|
||||||
}()
|
}()
|
||||||
err = b.DB.Model(b).Count(&total).Error
|
err = b.DB.Model(&table.BlackModel{}).Model(b).Count(&total).Error
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, 0, utils.Wrap(err, "")
|
return nil, 0, utils.Wrap(err, "")
|
||||||
}
|
}
|
||||||
err = utils.Wrap(b.DB.Limit(int(showNumber)).Offset(int(pageNumber*showNumber)).Find(&blacks).Error, "")
|
err = utils.Wrap(b.DB.Model(&table.BlackModel{}).Limit(int(showNumber)).Offset(int(pageNumber*showNumber)).Find(&blacks).Error, "")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -58,7 +58,6 @@ func (c *ChatLog) Create(msg pbMsg.MsgDataToMQ) error {
|
|||||||
EmitDefaults: false,
|
EmitDefaults: false,
|
||||||
}
|
}
|
||||||
chatLog.Content, _ = marshaler.MarshalToString(&tips)
|
chatLog.Content, _ = marshaler.MarshalToString(&tips)
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
chatLog.Content = string(msg.MsgData.Content)
|
chatLog.Content = string(msg.MsgData.Content)
|
||||||
}
|
}
|
||||||
|
@ -104,3 +104,12 @@ type UserModel struct {
|
|||||||
GlobalRecvMsgOpt int32 `gorm:"column:global_recv_msg_opt"`
|
GlobalRecvMsgOpt int32 `gorm:"column:global_recv_msg_opt"`
|
||||||
status int32 `gorm:"column:status"`
|
status int32 `gorm:"column:status"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type BlackModel struct {
|
||||||
|
OwnerUserID string `gorm:"column:owner_user_id;primary_key;size:64"`
|
||||||
|
BlockUserID string `gorm:"column:block_user_id;primary_key;size:64"`
|
||||||
|
CreateTime time.Time `gorm:"column:create_time"`
|
||||||
|
AddSource int32 `gorm:"column:add_source"`
|
||||||
|
OperatorUserID string `gorm:"column:operator_user_id;size:64"`
|
||||||
|
Ex string `gorm:"column:ex;size:1024"`
|
||||||
|
}
|
56
pkg/common/db/table/unrelation.go
Normal file
56
pkg/common/db/table/unrelation.go
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
package table
|
||||||
|
|
||||||
|
type SuperGroup struct {
|
||||||
|
GroupID string `bson:"group_id" json:"groupID"`
|
||||||
|
MemberIDList []string `bson:"member_id_list" json:"memberIDList"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type UserToSuperGroup struct {
|
||||||
|
UserID string `bson:"user_id" json:"userID"`
|
||||||
|
GroupIDList []string `bson:"group_id_list" json:"groupIDList"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type Tag struct {
|
||||||
|
UserID string `bson:"user_id"`
|
||||||
|
TagID string `bson:"tag_id"`
|
||||||
|
TagName string `bson:"tag_name"`
|
||||||
|
UserList []string `bson:"user_list"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type CommonUser struct {
|
||||||
|
UserID string `bson:"user_id"`
|
||||||
|
UserName string `bson:"user_name"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type TagSendLog struct {
|
||||||
|
UserList []CommonUser `bson:"tag_list"`
|
||||||
|
SendID string `bson:"send_id"`
|
||||||
|
SenderPlatformID int32 `bson:"sender_platform_id"`
|
||||||
|
Content string `bson:"content"`
|
||||||
|
SendTime int64 `bson:"send_time"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type WorkMoment struct {
|
||||||
|
WorkMomentID string `bson:"work_moment_id"`
|
||||||
|
UserID string `bson:"user_id"`
|
||||||
|
UserName string `bson:"user_name"`
|
||||||
|
FaceURL string `bson:"face_url"`
|
||||||
|
Content string `bson:"content"`
|
||||||
|
LikeUserList []*CommonUser `bson:"like_user_list"`
|
||||||
|
AtUserList []*CommonUser `bson:"at_user_list"`
|
||||||
|
PermissionUserList []*CommonUser `bson:"permission_user_list"`
|
||||||
|
Comments []*CommonUser `bson:"comments"`
|
||||||
|
PermissionUserIDList []string `bson:"permission_user_id_list"`
|
||||||
|
Permission int32 `bson:"permission"`
|
||||||
|
CreateTime int32 `bson:"create_time"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type Comment struct {
|
||||||
|
UserID string `bson:"user_id" json:"user_id"`
|
||||||
|
UserName string `bson:"user_name" json:"user_name"`
|
||||||
|
ReplyUserID string `bson:"reply_user_id" json:"reply_user_id"`
|
||||||
|
ReplyUserName string `bson:"reply_user_name" json:"reply_user_name"`
|
||||||
|
ContentID string `bson:"content_id" json:"content_id"`
|
||||||
|
Content string `bson:"content" json:"content"`
|
||||||
|
CreateTime int32 `bson:"create_time" json:"create_time"`
|
||||||
|
}
|
@ -3,6 +3,7 @@ package unrelation
|
|||||||
import (
|
import (
|
||||||
"Open_IM/pkg/common/config"
|
"Open_IM/pkg/common/config"
|
||||||
"Open_IM/pkg/common/constant"
|
"Open_IM/pkg/common/constant"
|
||||||
|
"Open_IM/pkg/common/db/table"
|
||||||
"Open_IM/pkg/utils"
|
"Open_IM/pkg/utils"
|
||||||
"context"
|
"context"
|
||||||
"go.mongodb.org/mongo-driver/bson"
|
"go.mongodb.org/mongo-driver/bson"
|
||||||
@ -22,57 +23,12 @@ type OfficeMgoDB struct {
|
|||||||
WorkMomentCollection *mongo.Collection
|
WorkMomentCollection *mongo.Collection
|
||||||
}
|
}
|
||||||
|
|
||||||
type Tag struct {
|
|
||||||
UserID string `bson:"user_id"`
|
|
||||||
TagID string `bson:"tag_id"`
|
|
||||||
TagName string `bson:"tag_name"`
|
|
||||||
UserList []string `bson:"user_list"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type commonUser struct {
|
|
||||||
UserID string `bson:"user_id"`
|
|
||||||
UserName string `bson:"user_name"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type TagSendLog struct {
|
|
||||||
UserList []commonUser `bson:"tag_list"`
|
|
||||||
SendID string `bson:"send_id"`
|
|
||||||
SenderPlatformID int32 `bson:"sender_platform_id"`
|
|
||||||
Content string `bson:"content"`
|
|
||||||
SendTime int64 `bson:"send_time"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type WorkMoment struct {
|
|
||||||
WorkMomentID string `bson:"work_moment_id"`
|
|
||||||
UserID string `bson:"user_id"`
|
|
||||||
UserName string `bson:"user_name"`
|
|
||||||
FaceURL string `bson:"face_url"`
|
|
||||||
Content string `bson:"content"`
|
|
||||||
LikeUserList []*commonUser `bson:"like_user_list"`
|
|
||||||
AtUserList []*commonUser `bson:"at_user_list"`
|
|
||||||
PermissionUserList []*commonUser `bson:"permission_user_list"`
|
|
||||||
Comments []*commonUser `bson:"comments"`
|
|
||||||
PermissionUserIDList []string `bson:"permission_user_id_list"`
|
|
||||||
Permission int32 `bson:"permission"`
|
|
||||||
CreateTime int32 `bson:"create_time"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type Comment struct {
|
|
||||||
UserID string `bson:"user_id" json:"user_id"`
|
|
||||||
UserName string `bson:"user_name" json:"user_name"`
|
|
||||||
ReplyUserID string `bson:"reply_user_id" json:"reply_user_id"`
|
|
||||||
ReplyUserName string `bson:"reply_user_name" json:"reply_user_name"`
|
|
||||||
ContentID string `bson:"content_id" json:"content_id"`
|
|
||||||
Content string `bson:"content" json:"content"`
|
|
||||||
CreateTime int32 `bson:"create_time" json:"create_time"`
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewOfficeMgoDB(mgoDB *mongo.Database) *OfficeMgoDB {
|
func NewOfficeMgoDB(mgoDB *mongo.Database) *OfficeMgoDB {
|
||||||
return &OfficeMgoDB{mgoDB: mgoDB, TagCollection: mgoDB.Collection(cTag), TagSendLogCollection: mgoDB.Collection(cSendLog), WorkMomentCollection: mgoDB.Collection(cSendLog)}
|
return &OfficeMgoDB{mgoDB: mgoDB, TagCollection: mgoDB.Collection(cTag), TagSendLogCollection: mgoDB.Collection(cSendLog), WorkMomentCollection: mgoDB.Collection(cSendLog)}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (db *OfficeMgoDB) GetUserTags(ctx context.Context, userID string) ([]Tag, error) {
|
func (db *OfficeMgoDB) GetUserTags(ctx context.Context, userID string) ([]table.Tag, error) {
|
||||||
var tags []Tag
|
var tags []table.Tag
|
||||||
cursor, err := db.TagCollection.Find(ctx, bson.M{"user_id": userID})
|
cursor, err := db.TagCollection.Find(ctx, bson.M{"user_id": userID})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return tags, err
|
return tags, err
|
||||||
@ -85,7 +41,7 @@ func (db *OfficeMgoDB) GetUserTags(ctx context.Context, userID string) ([]Tag, e
|
|||||||
|
|
||||||
func (db *OfficeMgoDB) CreateTag(ctx context.Context, userID, tagName string, userList []string) error {
|
func (db *OfficeMgoDB) CreateTag(ctx context.Context, userID, tagName string, userList []string) error {
|
||||||
tagID := generateTagID(tagName, userID)
|
tagID := generateTagID(tagName, userID)
|
||||||
tag := Tag{
|
tag := table.Tag{
|
||||||
UserID: userID,
|
UserID: userID,
|
||||||
TagID: tagID,
|
TagID: tagID,
|
||||||
TagName: tagName,
|
TagName: tagName,
|
||||||
@ -95,8 +51,8 @@ func (db *OfficeMgoDB) CreateTag(ctx context.Context, userID, tagName string, us
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (db *OfficeMgoDB) GetTagByID(ctx context.Context, userID, tagID string) (Tag, error) {
|
func (db *OfficeMgoDB) GetTagByID(ctx context.Context, userID, tagID string) (table.Tag, error) {
|
||||||
var tag Tag
|
var tag table.Tag
|
||||||
err := db.TagCollection.FindOne(ctx, bson.M{"user_id": userID, "tag_id": tagID}).Decode(&tag)
|
err := db.TagCollection.FindOne(ctx, bson.M{"user_id": userID, "tag_id": tagID}).Decode(&tag)
|
||||||
return tag, err
|
return tag, err
|
||||||
}
|
}
|
||||||
@ -107,7 +63,7 @@ func (db *OfficeMgoDB) DeleteTag(ctx context.Context, userID, tagID string) erro
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (db *OfficeMgoDB) SetTag(ctx context.Context, userID, tagID, newName string, increaseUserIDList []string, reduceUserIDList []string) error {
|
func (db *OfficeMgoDB) SetTag(ctx context.Context, userID, tagID, newName string, increaseUserIDList []string, reduceUserIDList []string) error {
|
||||||
var tag Tag
|
var tag table.Tag
|
||||||
if err := db.TagCollection.FindOne(ctx, bson.M{"tag_id": tagID, "user_id": userID}).Decode(&tag); err != nil {
|
if err := db.TagCollection.FindOne(ctx, bson.M{"tag_id": tagID, "user_id": userID}).Decode(&tag); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -140,18 +96,18 @@ func (db *OfficeMgoDB) SetTag(ctx context.Context, userID, tagID, newName string
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (db *OfficeMgoDB) GetUserIDListByTagID(ctx context.Context, userID, tagID string) ([]string, error) {
|
func (db *OfficeMgoDB) GetUserIDListByTagID(ctx context.Context, userID, tagID string) ([]string, error) {
|
||||||
var tag Tag
|
var tag table.Tag
|
||||||
err := db.TagCollection.FindOne(ctx, bson.M{"user_id": userID, "tag_id": tagID}).Decode(&tag)
|
err := db.TagCollection.FindOne(ctx, bson.M{"user_id": userID, "tag_id": tagID}).Decode(&tag)
|
||||||
return tag.UserList, err
|
return tag.UserList, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (db *OfficeMgoDB) SaveTagSendLog(ctx context.Context, tagSendLog *TagSendLog) error {
|
func (db *OfficeMgoDB) SaveTagSendLog(ctx context.Context, tagSendLog *table.TagSendLog) error {
|
||||||
_, err := db.TagSendLogCollection.InsertOne(ctx, tagSendLog)
|
_, err := db.TagSendLogCollection.InsertOne(ctx, tagSendLog)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (db *OfficeMgoDB) GetTagSendLogs(ctx context.Context, userID string, showNumber, pageNumber int32) ([]TagSendLog, error) {
|
func (db *OfficeMgoDB) GetTagSendLogs(ctx context.Context, userID string, showNumber, pageNumber int32) ([]table.TagSendLog, error) {
|
||||||
var tagSendLogs []TagSendLog
|
var tagSendLogs []table.TagSendLog
|
||||||
findOpts := options.Find().SetLimit(int64(showNumber)).SetSkip(int64(showNumber) * (int64(pageNumber) - 1)).SetSort(bson.M{"send_time": -1})
|
findOpts := options.Find().SetLimit(int64(showNumber)).SetSkip(int64(showNumber) * (int64(pageNumber) - 1)).SetSort(bson.M{"send_time": -1})
|
||||||
cursor, err := db.TagSendLogCollection.Find(ctx, bson.M{"send_id": userID}, findOpts)
|
cursor, err := db.TagSendLogCollection.Find(ctx, bson.M{"send_id": userID}, findOpts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -161,7 +117,7 @@ func (db *OfficeMgoDB) GetTagSendLogs(ctx context.Context, userID string, showNu
|
|||||||
return tagSendLogs, err
|
return tagSendLogs, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (db *OfficeMgoDB) CreateOneWorkMoment(ctx context.Context, workMoment *WorkMoment) error {
|
func (db *OfficeMgoDB) CreateOneWorkMoment(ctx context.Context, workMoment *table.WorkMoment) error {
|
||||||
workMomentID := generateWorkMomentID(workMoment.UserID)
|
workMomentID := generateWorkMomentID(workMoment.UserID)
|
||||||
workMoment.WorkMomentID = workMomentID
|
workMoment.WorkMomentID = workMomentID
|
||||||
workMoment.CreateTime = int32(time.Now().Unix())
|
workMoment.CreateTime = int32(time.Now().Unix())
|
||||||
@ -184,13 +140,13 @@ func (db *OfficeMgoDB) DeleteComment(ctx context.Context, workMomentID, contentI
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (db *OfficeMgoDB) GetWorkMomentByID(ctx context.Context, workMomentID string) (*WorkMoment, error) {
|
func (db *OfficeMgoDB) GetWorkMomentByID(ctx context.Context, workMomentID string) (*table.WorkMoment, error) {
|
||||||
workMoment := &WorkMoment{}
|
workMoment := &table.WorkMoment{}
|
||||||
err := db.WorkMomentCollection.FindOne(ctx, bson.M{"work_moment_id": workMomentID}).Decode(workMoment)
|
err := db.WorkMomentCollection.FindOne(ctx, bson.M{"work_moment_id": workMomentID}).Decode(workMoment)
|
||||||
return workMoment, err
|
return workMoment, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (db *OfficeMgoDB) LikeOneWorkMoment(ctx context.Context, likeUserID, userName, workMomentID string) (*WorkMoment, bool, error) {
|
func (db *OfficeMgoDB) LikeOneWorkMoment(ctx context.Context, likeUserID, userName, workMomentID string) (*table.WorkMoment, bool, error) {
|
||||||
workMoment, err := db.GetWorkMomentByID(ctx, workMomentID)
|
workMoment, err := db.GetWorkMomentByID(ctx, workMomentID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, false, err
|
return nil, false, err
|
||||||
@ -203,7 +159,7 @@ func (db *OfficeMgoDB) LikeOneWorkMoment(ctx context.Context, likeUserID, userNa
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if !isAlreadyLike {
|
if !isAlreadyLike {
|
||||||
workMoment.LikeUserList = append(workMoment.LikeUserList, &commonUser{UserID: likeUserID, UserName: userName})
|
workMoment.LikeUserList = append(workMoment.LikeUserList, &table.CommonUser{UserID: likeUserID, UserName: userName})
|
||||||
}
|
}
|
||||||
_, err = db.WorkMomentCollection.UpdateOne(ctx, bson.M{"work_moment_id": workMomentID}, bson.M{"$set": bson.M{"like_user_list": workMoment.LikeUserList}})
|
_, err = db.WorkMomentCollection.UpdateOne(ctx, bson.M{"work_moment_id": workMomentID}, bson.M{"$set": bson.M{"like_user_list": workMoment.LikeUserList}})
|
||||||
return workMoment, !isAlreadyLike, err
|
return workMoment, !isAlreadyLike, err
|
||||||
@ -213,15 +169,15 @@ func (db *OfficeMgoDB) SetUserWorkMomentsLevel(ctx context.Context, userID strin
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (db *OfficeMgoDB) CommentOneWorkMoment(ctx context.Context, comment *Comment, workMomentID string) (WorkMoment, error) {
|
func (db *OfficeMgoDB) CommentOneWorkMoment(ctx context.Context, comment *table.Comment, workMomentID string) (table.WorkMoment, error) {
|
||||||
comment.ContentID = generateWorkMomentCommentID(workMomentID)
|
comment.ContentID = generateWorkMomentCommentID(workMomentID)
|
||||||
var workMoment WorkMoment
|
var workMoment table.WorkMoment
|
||||||
err := db.WorkMomentCollection.FindOneAndUpdate(ctx, bson.M{"work_moment_id": workMomentID}, bson.M{"$push": bson.M{"comments": comment}}).Decode(&workMoment)
|
err := db.WorkMomentCollection.FindOneAndUpdate(ctx, bson.M{"work_moment_id": workMomentID}, bson.M{"$push": bson.M{"comments": comment}}).Decode(&workMoment)
|
||||||
return workMoment, err
|
return workMoment, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (db *OfficeMgoDB) GetUserSelfWorkMoments(ctx context.Context, userID string, showNumber, pageNumber int32) ([]WorkMoment, error) {
|
func (db *OfficeMgoDB) GetUserSelfWorkMoments(ctx context.Context, userID string, showNumber, pageNumber int32) ([]table.WorkMoment, error) {
|
||||||
var workMomentList []WorkMoment
|
var workMomentList []table.WorkMoment
|
||||||
findOpts := options.Find().SetLimit(int64(showNumber)).SetSkip(int64(showNumber) * (int64(pageNumber) - 1)).SetSort(bson.M{"create_time": -1})
|
findOpts := options.Find().SetLimit(int64(showNumber)).SetSkip(int64(showNumber) * (int64(pageNumber) - 1)).SetSort(bson.M{"create_time": -1})
|
||||||
result, err := db.WorkMomentCollection.Find(ctx, bson.M{"user_id": userID}, findOpts)
|
result, err := db.WorkMomentCollection.Find(ctx, bson.M{"user_id": userID}, findOpts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -231,8 +187,8 @@ func (db *OfficeMgoDB) GetUserSelfWorkMoments(ctx context.Context, userID string
|
|||||||
return workMomentList, err
|
return workMomentList, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (db *OfficeMgoDB) GetUserWorkMoments(ctx context.Context, opUserID, userID string, showNumber, pageNumber int32, friendIDList []string) ([]WorkMoment, error) {
|
func (db *OfficeMgoDB) GetUserWorkMoments(ctx context.Context, opUserID, userID string, showNumber, pageNumber int32, friendIDList []string) ([]table.WorkMoment, error) {
|
||||||
var workMomentList []WorkMoment
|
var workMomentList []table.WorkMoment
|
||||||
findOpts := options.Find().SetLimit(int64(showNumber)).SetSkip(int64(showNumber) * (int64(pageNumber) - 1)).SetSort(bson.M{"create_time": -1})
|
findOpts := options.Find().SetLimit(int64(showNumber)).SetSkip(int64(showNumber) * (int64(pageNumber) - 1)).SetSort(bson.M{"create_time": -1})
|
||||||
result, err := db.WorkMomentCollection.Find(ctx, bson.D{ // 等价条件: select * from
|
result, err := db.WorkMomentCollection.Find(ctx, bson.D{ // 等价条件: select * from
|
||||||
{"user_id", userID},
|
{"user_id", userID},
|
||||||
|
@ -2,6 +2,7 @@ package unrelation
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"Open_IM/pkg/common/config"
|
"Open_IM/pkg/common/config"
|
||||||
|
"Open_IM/pkg/common/db/table"
|
||||||
"Open_IM/pkg/utils"
|
"Open_IM/pkg/utils"
|
||||||
"context"
|
"context"
|
||||||
"go.mongodb.org/mongo-driver/bson"
|
"go.mongodb.org/mongo-driver/bson"
|
||||||
@ -22,23 +23,13 @@ type SuperGroupMgoDB struct {
|
|||||||
userToSuperGroupCollection *mongo.Collection
|
userToSuperGroupCollection *mongo.Collection
|
||||||
}
|
}
|
||||||
|
|
||||||
type SuperGroup struct {
|
|
||||||
GroupID string `bson:"group_id" json:"groupID"`
|
|
||||||
MemberIDList []string `bson:"member_id_list" json:"memberIDList"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type UserToSuperGroup struct {
|
|
||||||
UserID string `bson:"user_id" json:"userID"`
|
|
||||||
GroupIDList []string `bson:"group_id_list" json:"groupIDList"`
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewSuperGroupMgoDB(mgoClient *mongo.Client) *SuperGroupMgoDB {
|
func NewSuperGroupMgoDB(mgoClient *mongo.Client) *SuperGroupMgoDB {
|
||||||
mgoDB := mgoClient.Database(config.Config.Mongo.DBDatabase)
|
mgoDB := mgoClient.Database(config.Config.Mongo.DBDatabase)
|
||||||
return &SuperGroupMgoDB{MgoDB: mgoDB, MgoClient: mgoClient, superGroupCollection: mgoDB.Collection(cSuperGroup), userToSuperGroupCollection: mgoDB.Collection(cUserToSuperGroup)}
|
return &SuperGroupMgoDB{MgoDB: mgoDB, MgoClient: mgoClient, superGroupCollection: mgoDB.Collection(cSuperGroup), userToSuperGroupCollection: mgoDB.Collection(cUserToSuperGroup)}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (db *SuperGroupMgoDB) CreateSuperGroup(sCtx mongo.SessionContext, groupID string, initMemberIDList []string) error {
|
func (db *SuperGroupMgoDB) CreateSuperGroup(sCtx mongo.SessionContext, groupID string, initMemberIDList []string) error {
|
||||||
superGroup := SuperGroup{
|
superGroup := table.SuperGroup{
|
||||||
GroupID: groupID,
|
GroupID: groupID,
|
||||||
MemberIDList: initMemberIDList,
|
MemberIDList: initMemberIDList,
|
||||||
}
|
}
|
||||||
@ -60,8 +51,8 @@ func (db *SuperGroupMgoDB) CreateSuperGroup(sCtx mongo.SessionContext, groupID s
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (db *SuperGroupMgoDB) GetSuperGroup(ctx context.Context, groupID string) (*SuperGroup, error) {
|
func (db *SuperGroupMgoDB) GetSuperGroup(ctx context.Context, groupID string) (*table.SuperGroup, error) {
|
||||||
superGroup := SuperGroup{}
|
superGroup := table.SuperGroup{}
|
||||||
err := db.superGroupCollection.FindOne(ctx, bson.M{"group_id": groupID}).Decode(&superGroup)
|
err := db.superGroupCollection.FindOne(ctx, bson.M{"group_id": groupID}).Decode(&superGroup)
|
||||||
return &superGroup, err
|
return &superGroup, err
|
||||||
}
|
}
|
||||||
@ -106,8 +97,8 @@ func (db *SuperGroupMgoDB) RemoverUserFromSuperGroup(ctx context.Context, groupI
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (db *SuperGroupMgoDB) GetSuperGroupByUserID(ctx context.Context, userID string) (*UserToSuperGroup, error) {
|
func (db *SuperGroupMgoDB) GetSuperGroupByUserID(ctx context.Context, userID string) (*table.UserToSuperGroup, error) {
|
||||||
var user UserToSuperGroup
|
var user table.UserToSuperGroup
|
||||||
err := db.userToSuperGroupCollection.FindOne(ctx, bson.M{"user_id": userID}).Decode(&user)
|
err := db.userToSuperGroupCollection.FindOne(ctx, bson.M{"user_id": userID}).Decode(&user)
|
||||||
return &user, utils.Wrap(err, "")
|
return &user, utils.Wrap(err, "")
|
||||||
}
|
}
|
||||||
@ -115,7 +106,7 @@ func (db *SuperGroupMgoDB) GetSuperGroupByUserID(ctx context.Context, userID str
|
|||||||
func (db *SuperGroupMgoDB) DeleteSuperGroup(ctx context.Context, groupID string) error {
|
func (db *SuperGroupMgoDB) DeleteSuperGroup(ctx context.Context, groupID string) error {
|
||||||
opts := options.Session().SetDefaultReadConcern(readconcern.Majority())
|
opts := options.Session().SetDefaultReadConcern(readconcern.Majority())
|
||||||
return db.MgoDB.Client().UseSessionWithOptions(ctx, opts, func(sCtx mongo.SessionContext) error {
|
return db.MgoDB.Client().UseSessionWithOptions(ctx, opts, func(sCtx mongo.SessionContext) error {
|
||||||
superGroup := &SuperGroup{}
|
superGroup := &table.SuperGroup{}
|
||||||
_, err := db.superGroupCollection.DeleteOne(sCtx, bson.M{"group_id": groupID})
|
_, err := db.superGroupCollection.DeleteOne(sCtx, bson.M{"group_id": groupID})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
_ = sCtx.AbortTransaction(ctx)
|
_ = sCtx.AbortTransaction(ctx)
|
||||||
|
@ -1,35 +0,0 @@
|
|||||||
package getcdv3
|
|
||||||
|
|
||||||
import (
|
|
||||||
"Open_IM/pkg/common/config"
|
|
||||||
"Open_IM/pkg/common/constant"
|
|
||||||
"Open_IM/pkg/common/tracelog"
|
|
||||||
"context"
|
|
||||||
"github.com/OpenIMSDK/getcdv3"
|
|
||||||
"google.golang.org/grpc"
|
|
||||||
"strings"
|
|
||||||
)
|
|
||||||
|
|
||||||
func GetDefaultConn(arg1, arg2, arg3, arg4 string) *grpc.ClientConn {
|
|
||||||
return getcdv3.GetConn(arg1, arg2, arg3, arg4, config.Config.Etcd.UserName, config.Config.Etcd.Password)
|
|
||||||
}
|
|
||||||
|
|
||||||
func GetConn(ctx context.Context, serviceName string) (conn *grpc.ClientConn, err error) {
|
|
||||||
defer func() {
|
|
||||||
tracelog.SetCtxInfo(ctx, "GetConn", err, "serviceName", serviceName)
|
|
||||||
}()
|
|
||||||
conn = getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","),
|
|
||||||
serviceName, tracelog.GetOperationID(ctx), config.Config.Etcd.UserName, config.Config.Etcd.Password)
|
|
||||||
if conn == nil {
|
|
||||||
return nil, constant.ErrInternalServer
|
|
||||||
}
|
|
||||||
return conn, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func GetDefaultGatewayConn4Unique(schema, addr, operationID string) []*grpc.ClientConn {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func RegisterEtcd(schema, etcdAddr, myHost string, myPort int, serviceName string, ttl int, operationID string) error {
|
|
||||||
return getcdv3.RegisterEtcd(schema, etcdAddr, myHost, myPort, serviceName, ttl, operationID)
|
|
||||||
}
|
|
Loading…
x
Reference in New Issue
Block a user