mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-04-06 04:15:46 +08:00
Merge remote-tracking branch 'origin/errcode' into errcode
This commit is contained in:
commit
ec43f2847e
@ -2,14 +2,13 @@
|
||||
# The class cannot be named by Pascal or camel case.
|
||||
# If it is not used, the corresponding structure will not be set,
|
||||
# and it will not be read naturally.
|
||||
serverversion: 2.3.1
|
||||
serverversion: 2.3.7
|
||||
#---------------Infrastructure configuration---------------------#
|
||||
etcd:
|
||||
etcdSchema: openim #默认即可
|
||||
etcdAddr: [ 127.0.0.1:2379 ] #单机部署时,默认即可
|
||||
zookeeper:
|
||||
schema: openim #默认即可
|
||||
zkAddr: [ 127.0.0.1:2181 ] #单机部署时,默认即可
|
||||
userName:
|
||||
password:
|
||||
secret:
|
||||
|
||||
mysql:
|
||||
dbMysqlAddress: [ 127.0.0.1:13306 ] #mysql地址 目前仅支持单机,默认即可
|
||||
|
@ -91,6 +91,11 @@ func NewGroupServer(port int) *groupServer {
|
||||
if err != nil {
|
||||
panic(err.Error())
|
||||
}
|
||||
registerIP, err := utils.GetRpcIP()
|
||||
err = zkClient.Register(config.Config.RpcRegisterName.OpenImGroupName, registerIP, port)
|
||||
if err != nil {
|
||||
panic(err.Error())
|
||||
}
|
||||
var registerCenter discoveryRegistry.SvcDiscoveryRegistry = zkClient
|
||||
conns, err := registerCenter.GetConns(config.Config.RpcRegisterName.OpenImConversationName)
|
||||
g.GroupInterface = controller.NewGroupController(groupModel.DB, redis.GetClient(), mongo.GetClient())
|
||||
|
@ -154,12 +154,11 @@ type config struct {
|
||||
OpenImCacheName string `yaml:"openImCacheName"`
|
||||
OpenImRealTimeCommName string `yaml:"openImRealTimeCommName"`
|
||||
}
|
||||
Etcd struct {
|
||||
EtcdSchema string `yaml:"etcdSchema"`
|
||||
EtcdAddr []string `yaml:"etcdAddr"`
|
||||
UserName string `yaml:"userName"`
|
||||
Password string `yaml:"password"`
|
||||
Secret string `yaml:"secret"`
|
||||
Zookeeper struct {
|
||||
Schema string `yaml:"schema"`
|
||||
ZkAddr []string `yaml:"zkAddr"`
|
||||
UserName string `yaml:"userName"`
|
||||
Password string `yaml:"password"`
|
||||
}
|
||||
Log struct {
|
||||
StorageLocation string `yaml:"storageLocation"`
|
||||
|
@ -1,24 +1,25 @@
|
||||
package localcache
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/proto/conversation"
|
||||
"context"
|
||||
"google.golang.org/grpc"
|
||||
"github.com/OpenIMSDK/openKeeper"
|
||||
"sync"
|
||||
)
|
||||
|
||||
type ConversationLocalCacheInterface interface {
|
||||
GetRecvMsgNotNotifyUserIDs(ctx context.Context, groupID string) []string
|
||||
}
|
||||
|
||||
type ConversationLocalCache struct {
|
||||
lock sync.Mutex
|
||||
SuperGroupRecvMsgNotNotifyUserIDs map[string][]string
|
||||
rpc *grpc.ClientConn
|
||||
conversation conversation.ConversationClient
|
||||
zkClient *openKeeper.ZkClient
|
||||
}
|
||||
|
||||
func NewConversationLocalCache(rpc *grpc.ClientConn) ConversationLocalCache {
|
||||
func NewConversationLocalCache(zkClient *openKeeper.ZkClient) ConversationLocalCache {
|
||||
return ConversationLocalCache{
|
||||
SuperGroupRecvMsgNotNotifyUserIDs: make(map[string][]string, 0),
|
||||
rpc: rpc,
|
||||
conversation: conversation.NewConversationClient(rpc),
|
||||
zkClient: zkClient,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,18 +1,23 @@
|
||||
package localcache
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/config"
|
||||
"Open_IM/pkg/common/constant"
|
||||
"Open_IM/pkg/proto/group"
|
||||
"context"
|
||||
"github.com/OpenIMSDK/openKeeper"
|
||||
"google.golang.org/grpc"
|
||||
"sync"
|
||||
)
|
||||
|
||||
type GroupLocalCacheInterface interface {
|
||||
GetGroupMemberIDs(ctx context.Context, groupID string) ([]string, error)
|
||||
}
|
||||
|
||||
type GroupLocalCache struct {
|
||||
lock sync.Mutex
|
||||
cache map[string]GroupMemberIDsHash
|
||||
rpc *grpc.ClientConn
|
||||
group group.GroupClient
|
||||
lock sync.Mutex
|
||||
cache map[string]GroupMemberIDsHash
|
||||
zkClient *openKeeper.ZkClient
|
||||
}
|
||||
|
||||
type GroupMemberIDsHash struct {
|
||||
@ -20,18 +25,22 @@ type GroupMemberIDsHash struct {
|
||||
userIDs []string
|
||||
}
|
||||
|
||||
func NewGroupMemberIDsLocalCache(rpc *grpc.ClientConn) GroupLocalCache {
|
||||
func NewGroupMemberIDsLocalCache(zkClient *openKeeper.ZkClient) GroupLocalCache {
|
||||
return GroupLocalCache{
|
||||
cache: make(map[string]GroupMemberIDsHash, 0),
|
||||
rpc: rpc,
|
||||
group: group.NewGroupClient(rpc),
|
||||
cache: make(map[string]GroupMemberIDsHash, 0),
|
||||
zkClient: zkClient,
|
||||
}
|
||||
}
|
||||
|
||||
func (g *GroupLocalCache) GetGroupMemberIDs(ctx context.Context, groupID string) ([]string, error) {
|
||||
g.lock.Lock()
|
||||
defer g.lock.Unlock()
|
||||
resp, err := g.group.GetGroupAbstractInfo(ctx, &group.GetGroupAbstractInfoReq{
|
||||
conn, err := g.zkClient.GetConn(config.Config.RpcRegisterName.OpenImGroupName, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
client := group.NewGroupClient(conn)
|
||||
resp, err := client.GetGroupAbstractInfo(ctx, &group.GetGroupAbstractInfoReq{
|
||||
GroupIDs: []string{groupID},
|
||||
})
|
||||
if err != nil {
|
||||
@ -44,7 +53,7 @@ func (g *GroupLocalCache) GetGroupMemberIDs(ctx context.Context, groupID string)
|
||||
if ok && localHashInfo.memberListHash == resp.GroupAbstractInfos[0].GroupMemberListHash {
|
||||
return localHashInfo.userIDs, nil
|
||||
}
|
||||
groupMembersResp, err := g.group.GetGroupMemberList(ctx, &group.GetGroupMemberListReq{
|
||||
groupMembersResp, err := client.GetGroupMemberList(ctx, &group.GetGroupMemberListReq{
|
||||
GroupID: groupID,
|
||||
})
|
||||
if err != nil {
|
||||
|
@ -1,275 +0,0 @@
|
||||
package relation
|
||||
|
||||
//type Register struct {
|
||||
// Account string `gorm:"column:account;primary_key;type:char(255)" json:"account"`
|
||||
// Password string `gorm:"column:password;type:varchar(255)" json:"password"`
|
||||
// Ex string `gorm:"column:ex;size:1024" json:"ex"`
|
||||
// UserID string `gorm:"column:user_id;type:varchar(255)" json:"userID"`
|
||||
// AreaCode string `gorm:"column:area_code;type:varchar(255)"`
|
||||
// InvitationCode string `gorm:"column:invitation_code;type:varchar(255)"`
|
||||
// RegisterIP string `gorm:"column:register_ip;type:varchar(255)"`
|
||||
//}
|
||||
|
||||
//type Invitation struct {
|
||||
// InvitationCode string `gorm:"column:invitation_code;primary_key;type:varchar(32)"`
|
||||
// CreateTime time.Time `gorm:"column:create_time"`
|
||||
// UserID string `gorm:"column:user_id;index:userID"`
|
||||
// LastTime time.Time `gorm:"column:last_time"`
|
||||
// Status int32 `gorm:"column:status"`
|
||||
//}
|
||||
|
||||
// message FriendInfo{
|
||||
// string OwnerUserID = 1;
|
||||
// string Remark = 2;
|
||||
// int64 CreateTime = 3;
|
||||
// UserInfo FriendUser = 4;
|
||||
// int32 AddSource = 5;
|
||||
// string OperatorUserID = 6;
|
||||
// string Ex = 7;
|
||||
// }
|
||||
// open_im_sdk.FriendInfo(FriendUser) != imdb.Friend(FriendUserID)
|
||||
//type Friend struct {
|
||||
// OwnerUserID string `gorm:"column:owner_user_id;primary_key;size:64"`
|
||||
// FriendUserID string `gorm:"column:friend_user_id;primary_key;size:64"`
|
||||
// Remark string `gorm:"column:remark;size:255"`
|
||||
// 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"`
|
||||
//}
|
||||
|
||||
// message FriendRequest{
|
||||
// string FromUserID = 1;
|
||||
// string ToUserID = 2;
|
||||
// int32 HandleResult = 3;
|
||||
// string ReqMsg = 4;
|
||||
// int64 CreateTime = 5;
|
||||
// string HandlerUserID = 6;
|
||||
// string HandleMsg = 7;
|
||||
// int64 HandleTime = 8;
|
||||
// string Ex = 9;
|
||||
// }
|
||||
// open_im_sdk.FriendRequest(nickname, farce url ...) != imdb.FriendRequest
|
||||
//type FriendRequest struct {
|
||||
// FromUserID string `gorm:"column:from_user_id;primary_key;size:64"`
|
||||
// ToUserID string `gorm:"column:to_user_id;primary_key;size:64"`
|
||||
// HandleResult int32 `gorm:"column:handle_result"`
|
||||
// ReqMsg string `gorm:"column:req_msg;size:255"`
|
||||
// CreateTime time.Time `gorm:"column:create_time"`
|
||||
// HandlerUserID string `gorm:"column:handler_user_id;size:64"`
|
||||
// HandleMsg string `gorm:"column:handle_msg;size:255"`
|
||||
// HandleTime time.Time `gorm:"column:handle_time"`
|
||||
// Ex string `gorm:"column:ex;size:1024"`
|
||||
//}
|
||||
//
|
||||
//func (FriendRequest) TableName() string {
|
||||
// return "friend_requests"
|
||||
//}
|
||||
|
||||
// message GroupInfo{
|
||||
// string GroupID = 1;
|
||||
// string GroupName = 2;
|
||||
// string Notification = 3;
|
||||
// string Introduction = 4;
|
||||
// string FaceUrl = 5;
|
||||
// string OwnerUserID = 6;
|
||||
// uint32 MemberCount = 8;
|
||||
// int64 CreateTime = 7;
|
||||
// string Ex = 9;
|
||||
// int32 Status = 10;
|
||||
// string CreatorUserID = 11;
|
||||
// int32 GroupType = 12;
|
||||
// }
|
||||
//
|
||||
// open_im_sdk.GroupInfo (OwnerUserID , MemberCount )> imdb.Group
|
||||
//type Group struct {
|
||||
// //`json:"operationID" binding:"required"`
|
||||
// //`protobuf:"bytes,1,opt,name=GroupID" json:"GroupID,omitempty"` `json:"operationID" binding:"required"`
|
||||
// GroupID string `gorm:"column:group_id;primary_key;size:64" json:"groupID" binding:"required"`
|
||||
// GroupName string `gorm:"column:name;size:255" json:"groupName"`
|
||||
// Notification string `gorm:"column:notification;size:255" json:"notification"`
|
||||
// Introduction string `gorm:"column:introduction;size:255" json:"introduction"`
|
||||
// FaceURL string `gorm:"column:face_url;size:255" json:"faceURL"`
|
||||
// CreateTime time.Time `gorm:"column:create_time;index:create_time"`
|
||||
// Ex string `gorm:"column:ex" json:"ex;size:1024" json:"ex"`
|
||||
// Status int32 `gorm:"column:status"`
|
||||
// CreatorUserID string `gorm:"column:creator_user_id;size:64"`
|
||||
// GroupType int32 `gorm:"column:group_type"`
|
||||
// NeedVerification int32 `gorm:"column:need_verification"`
|
||||
// LookMemberInfo int32 `gorm:"column:look_member_info" json:"lookMemberInfo"`
|
||||
// ApplyMemberFriend int32 `gorm:"column:apply_member_friend" json:"applyMemberFriend"`
|
||||
// NotificationUpdateTime time.Time `gorm:"column:notification_update_time"`
|
||||
// NotificationUserID string `gorm:"column:notification_user_id;size:64"`
|
||||
// DB *gorm.DB `gorm:"-" json:"-"`
|
||||
//}
|
||||
|
||||
// message GroupMemberFullInfo {
|
||||
// string GroupID = 1 ;
|
||||
// string UserID = 2 ;
|
||||
// int32 roleLevel = 3;
|
||||
// int64 JoinTime = 4;
|
||||
// string NickName = 5;
|
||||
// string FaceUrl = 6;
|
||||
// int32 JoinSource = 8;
|
||||
// string OperatorUserID = 9;
|
||||
// string Ex = 10;
|
||||
// int32 AppMangerLevel = 7; //if >0
|
||||
// } open_im_sdk.GroupMemberFullInfo(AppMangerLevel) > imdb.GroupMember
|
||||
//type GroupMember struct {
|
||||
// GroupID string `gorm:"column:group_id;primary_key;size:64"`
|
||||
// UserID string `gorm:"column:user_id;primary_key;size:64"`
|
||||
// Nickname string `gorm:"column:nickname;size:255"`
|
||||
// FaceURL string `gorm:"column:user_group_face_url;size:255"`
|
||||
// RoleLevel int32 `gorm:"column:role_level"`
|
||||
// JoinTime time.Time `gorm:"column:join_time"`
|
||||
// JoinSource int32 `gorm:"column:join_source"`
|
||||
// InviterUserID string `gorm:"column:inviter_user_id;size:64"`
|
||||
// OperatorUserID string `gorm:"column:operator_user_id;size:64"`
|
||||
// MuteEndTime time.Time `gorm:"column:mute_end_time"`
|
||||
// Ex string `gorm:"column:ex;size:1024"`
|
||||
//}
|
||||
|
||||
// message GroupRequest{
|
||||
// string UserID = 1;
|
||||
// string GroupID = 2;
|
||||
// string HandleResult = 3;
|
||||
// string ReqMsg = 4;
|
||||
// string HandleMsg = 5;
|
||||
// int64 ReqTime = 6;
|
||||
// string HandleUserID = 7;
|
||||
// int64 HandleTime = 8;
|
||||
// string Ex = 9;
|
||||
// }open_im_sdk.GroupRequest == imdb.GroupRequest
|
||||
//type GroupRequest struct {
|
||||
// UserID string `gorm:"column:user_id;primary_key;size:64"`
|
||||
// GroupID string `gorm:"column:group_id;primary_key;size:64"`
|
||||
// HandleResult int32 `gorm:"column:handle_result"`
|
||||
// ReqMsg string `gorm:"column:req_msg;size:1024"`
|
||||
// HandledMsg string `gorm:"column:handle_msg;size:1024"`
|
||||
// ReqTime time.Time `gorm:"column:req_time"`
|
||||
// HandleUserID string `gorm:"column:handle_user_id;size:64"`
|
||||
// HandledTime time.Time `gorm:"column:handle_time"`
|
||||
// JoinSource int32 `gorm:"column:join_source"`
|
||||
// InviterUserID string `gorm:"column:inviter_user_id;size:64"`
|
||||
// Ex string `gorm:"column:ex;size:1024"`
|
||||
//}
|
||||
|
||||
// string UserID = 1;
|
||||
// string Nickname = 2;
|
||||
// string FaceUrl = 3;
|
||||
// int32 Gender = 4;
|
||||
// string PhoneNumber = 5;
|
||||
// string Birth = 6;
|
||||
// string Email = 7;
|
||||
// string Ex = 8;
|
||||
// string CreateIp = 9;
|
||||
// int64 CreateTime = 10;
|
||||
// int32 AppMangerLevel = 11;
|
||||
// open_im_sdk.User == imdb.User
|
||||
//type User struct {
|
||||
// UserID string `gorm:"column:user_id;primary_key;size:64"`
|
||||
// Nickname string `gorm:"column:name;size:255"`
|
||||
// FaceURL string `gorm:"column:face_url;size:255"`
|
||||
// Gender int32 `gorm:"column:gender"`
|
||||
// PhoneNumber string `gorm:"column:phone_number;size:32"`
|
||||
// Birth time.Time `gorm:"column:birth"`
|
||||
// Email string `gorm:"column:email;size:64"`
|
||||
// Ex string `gorm:"column:ex;size:1024"`
|
||||
// CreateTime time.Time `gorm:"column:create_time;index:create_time"`
|
||||
// AppMangerLevel int32 `gorm:"column:app_manger_level"`
|
||||
// GlobalRecvMsgOpt int32 `gorm:"column:global_recv_msg_opt"`
|
||||
//
|
||||
// status int32 `gorm:"column:status"`
|
||||
//}
|
||||
|
||||
//type UserIpRecord struct {
|
||||
// UserID string `gorm:"column:user_id;primary_key;size:64"`
|
||||
// CreateIp string `gorm:"column:create_ip;size:15"`
|
||||
// LastLoginTime time.Time `gorm:"column:last_login_time"`
|
||||
// LastLoginIp string `gorm:"column:last_login_ip;size:15"`
|
||||
// LoginTimes int32 `gorm:"column:login_times"`
|
||||
//}
|
||||
//
|
||||
//// ip limit login
|
||||
//type IpLimit struct {
|
||||
// Ip string `gorm:"column:ip;primary_key;size:15"`
|
||||
// LimitRegister int32 `gorm:"column:limit_register;size:1"`
|
||||
// LimitLogin int32 `gorm:"column:limit_login;size:1"`
|
||||
// CreateTime time.Time `gorm:"column:create_time"`
|
||||
// LimitTime time.Time `gorm:"column:limit_time"`
|
||||
//}
|
||||
//
|
||||
//// ip login
|
||||
//type UserIpLimit struct {
|
||||
// UserID string `gorm:"column:user_id;primary_key;size:64"`
|
||||
// Ip string `gorm:"column:ip;primary_key;size:15"`
|
||||
// CreateTime time.Time `gorm:"column:create_time"`
|
||||
//}
|
||||
|
||||
// message BlackInfo{
|
||||
// string OwnerUserID = 1;
|
||||
// int64 CreateTime = 2;
|
||||
// PublicUserInfo BlackUserInfo = 4;
|
||||
// int32 AddSource = 5;
|
||||
// string OperatorUserID = 6;
|
||||
// string Ex = 7;
|
||||
// }
|
||||
// open_im_sdk.BlackInfo(BlackUserInfo) != imdb.Black (BlockUserID)
|
||||
//type Black 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"`
|
||||
//}
|
||||
|
||||
//type ChatLog struct {
|
||||
// ServerMsgID string `gorm:"column:server_msg_id;primary_key;type:char(64)" json:"serverMsgID"`
|
||||
// ClientMsgID string `gorm:"column:client_msg_id;type:char(64)" json:"clientMsgID"`
|
||||
// SendID string `gorm:"column:send_id;type:char(64);index:send_id,priority:2" json:"sendID"`
|
||||
// RecvID string `gorm:"column:recv_id;type:char(64);index:recv_id,priority:2" json:"recvID"`
|
||||
// SenderPlatformID int32 `gorm:"column:sender_platform_id" json:"senderPlatformID"`
|
||||
// SenderNickname string `gorm:"column:sender_nick_name;type:varchar(255)" json:"senderNickname"`
|
||||
// SenderFaceURL string `gorm:"column:sender_face_url;type:varchar(255);" json:"senderFaceURL"`
|
||||
// SessionType int32 `gorm:"column:session_type;index:session_type,priority:2;index:session_type_alone" json:"sessionType"`
|
||||
// MsgFrom int32 `gorm:"column:msg_from" json:"msgFrom"`
|
||||
// ContentType int32 `gorm:"column:content_type;index:content_type,priority:2;index:content_type_alone" json:"contentType"`
|
||||
// Content string `gorm:"column:content;type:varchar(3000)" json:"content"`
|
||||
// Status int32 `gorm:"column:status" json:"status"`
|
||||
// SendTime time.Time `gorm:"column:send_time;index:sendTime;index:content_type,priority:1;index:session_type,priority:1;index:recv_id,priority:1;index:send_id,priority:1" json:"sendTime"`
|
||||
// CreateTime time.Time `gorm:"column:create_time" json:"createTime"`
|
||||
// Ex string `gorm:"column:ex;type:varchar(1024)" json:"ex"`
|
||||
//}
|
||||
//
|
||||
//func (ChatLog) TableName() string {
|
||||
// return "chat_logs"
|
||||
//}
|
||||
|
||||
//type BlackList struct {
|
||||
// UserId string `gorm:"column:uid"`
|
||||
// BeginDisableTime time.Time `gorm:"column:begin_disable_time"`
|
||||
// EndDisableTime time.Time `gorm:"column:end_disable_time"`
|
||||
//}
|
||||
//type Conversation struct {
|
||||
// OwnerUserID string `gorm:"column:owner_user_id;primary_key;type:char(128)" json:"OwnerUserID"`
|
||||
// ConversationID string `gorm:"column:conversation_id;primary_key;type:char(128)" json:"conversationID"`
|
||||
// ConversationType int32 `gorm:"column:conversation_type" json:"conversationType"`
|
||||
// UserID string `gorm:"column:user_id;type:char(64)" json:"userID"`
|
||||
// GroupID string `gorm:"column:group_id;type:char(128)" json:"groupID"`
|
||||
// RecvMsgOpt int32 `gorm:"column:recv_msg_opt" json:"recvMsgOpt"`
|
||||
// UnreadCount int32 `gorm:"column:unread_count" json:"unreadCount"`
|
||||
// DraftTextTime int64 `gorm:"column:draft_text_time" json:"draftTextTime"`
|
||||
// IsPinned bool `gorm:"column:is_pinned" json:"isPinned"`
|
||||
// IsPrivateChat bool `gorm:"column:is_private_chat" json:"isPrivateChat"`
|
||||
// BurnDuration int32 `gorm:"column:burn_duration;default:30" json:"burnDuration"`
|
||||
// GroupAtType int32 `gorm:"column:group_at_type" json:"groupAtType"`
|
||||
// IsNotInGroup bool `gorm:"column:is_not_in_group" json:"isNotInGroup"`
|
||||
// UpdateUnreadCountTime int64 `gorm:"column:update_unread_count_time" json:"updateUnreadCountTime"`
|
||||
// AttachedInfo string `gorm:"column:attached_info;type:varchar(1024)" json:"attachedInfo"`
|
||||
// Ex string `gorm:"column:ex;type:varchar(1024)" json:"ex"`
|
||||
//}
|
||||
|
||||
//func (Conversation) TableName() string {
|
||||
// return "conversations"
|
||||
//}
|
@ -71,12 +71,6 @@ func (s *Statistics) GetGroupNum(to time.Time) (num int64, err error) {
|
||||
return num, err
|
||||
}
|
||||
|
||||
type ActiveGroup struct {
|
||||
Name string
|
||||
ID string `gorm:"column:recv_id"`
|
||||
MessageNum int `gorm:"column:message_num"`
|
||||
}
|
||||
|
||||
func (s *Statistics) GetActiveGroups(from, to time.Time, limit int) ([]*ActiveGroup, error) {
|
||||
var activeGroups []*ActiveGroup
|
||||
err := s.getChatLogModel().Select("recv_id, count(*) as message_num").Where("send_time >= ? and send_time <= ? and session_type in (?)", from, to, []int{constant.GroupChatType, constant.SuperGroupChatType}).Group("recv_id").Limit(limit).Order("message_num DESC").Find(&activeGroups).Error
|
||||
@ -90,12 +84,6 @@ func (s *Statistics) GetActiveGroups(from, to time.Time, limit int) ([]*ActiveGr
|
||||
return activeGroups, err
|
||||
}
|
||||
|
||||
type ActiveUser struct {
|
||||
Name string
|
||||
ID string `gorm:"column:send_id"`
|
||||
MessageNum int `gorm:"column:message_num"`
|
||||
}
|
||||
|
||||
func (s *Statistics) GetActiveUsers(from, to time.Time, limit int) (activeUsers []*ActiveUser, err error) {
|
||||
err = s.getChatLogModel().Select("send_id, count(*) as message_num").Where("send_time >= ? and send_time <= ? and session_type in (?)", from, to, []int{constant.SingleChatType, constant.GroupChatType, constant.SuperGroupChatType}).Group("send_id").Limit(limit).Order("message_num DESC").Find(&activeUsers).Error
|
||||
for _, activeUser := range activeUsers {
|
||||
|
30
pkg/common/db/table/relation/statistics.go
Normal file
30
pkg/common/db/table/relation/statistics.go
Normal file
@ -0,0 +1,30 @@
|
||||
package relation
|
||||
|
||||
import "time"
|
||||
|
||||
// these two is virtual table just for cms
|
||||
type ActiveGroup struct {
|
||||
Name string
|
||||
ID string `gorm:"column:recv_id"`
|
||||
MessageNum int `gorm:"column:message_num"`
|
||||
}
|
||||
|
||||
type ActiveUser struct {
|
||||
Name string
|
||||
ID string `gorm:"column:send_id"`
|
||||
MessageNum int `gorm:"column:message_num"`
|
||||
}
|
||||
|
||||
type StatisticsInterface interface {
|
||||
GetActiveUserNum(from, to time.Time) (num int64, err error)
|
||||
GetIncreaseUserNum(from, to time.Time) (num int64, err error)
|
||||
GetTotalUserNum() (num int64, err error)
|
||||
GetTotalUserNumByDate(to time.Time) (num int64, err error)
|
||||
GetSingleChatMessageNum(from, to time.Time) (num int64, err error)
|
||||
GetGroupMessageNum(from, to time.Time) (num int64, err error)
|
||||
GetIncreaseGroupNum(from, to time.Time) (num int64, err error)
|
||||
GetTotalGroupNum() (num int64, err error)
|
||||
GetGroupNum(to time.Time) (num int64, err error)
|
||||
GetActiveGroups(from, to time.Time, limit int) ([]*ActiveGroup, error)
|
||||
GetActiveUsers(from, to time.Time, limit int) (activeUsers []*ActiveUser, err error)
|
||||
}
|
@ -1,6 +1,8 @@
|
||||
package unrelation
|
||||
|
||||
import "go.mongodb.org/mongo-driver/mongo"
|
||||
import (
|
||||
"context"
|
||||
)
|
||||
|
||||
const (
|
||||
CSuperGroup = "super_group"
|
||||
@ -26,5 +28,11 @@ func (UserToSuperGroupModel) TableName() string {
|
||||
}
|
||||
|
||||
type SuperGroupModelInterface interface {
|
||||
CreateSuperGroup(sCtx mongo.SessionContext, groupID string, initMemberIDs []string) error
|
||||
// tx is your transaction object
|
||||
CreateSuperGroup(ctx context.Context, groupID string, initMemberIDs []string, tx ...interface{}) error
|
||||
GetSuperGroup(ctx context.Context, groupID string) (SuperGroupModel, error)
|
||||
AddUserToSuperGroup(ctx context.Context, groupID string, userIDs []string, tx ...interface{}) error
|
||||
RemoverUserFromSuperGroup(ctx context.Context, groupID string, userIDs []string, tx ...interface{}) error
|
||||
GetSuperGroupByUserID(ctx context.Context, userID string) (*UserToSuperGroupModel, error)
|
||||
DeleteSuperGroup(ctx context.Context, groupID string, tx ...interface{}) error
|
||||
}
|
||||
|
@ -1,5 +1,7 @@
|
||||
package unrelation
|
||||
|
||||
import "context"
|
||||
|
||||
const (
|
||||
CTag = "tag"
|
||||
CSendLog = "send_log"
|
||||
@ -29,4 +31,12 @@ func (TagSendLogModel) TableName() string {
|
||||
}
|
||||
|
||||
type TagModelInterface interface {
|
||||
GetUserTags(ctx context.Context, userID string) ([]TagModel, error)
|
||||
CreateTag(ctx context.Context, userID, tagName string, userList []string) error
|
||||
GetTagByID(ctx context.Context, userID, tagID string) (TagModel, error)
|
||||
DeleteTag(ctx context.Context, userID, tagID string) error
|
||||
SetTag(ctx context.Context, userID, tagID, newName string, increaseUserIDList []string, reduceUserIDList []string) error
|
||||
GetUserIDListByTagID(ctx context.Context, userID, tagID string) ([]string, error)
|
||||
SaveTagSendLog(ctx context.Context, tagSendLog *TagSendLogModel) error
|
||||
GetTagSendLogs(ctx context.Context, userID string, showNumber, pageNumber int32) ([]TagSendLogModel, error)
|
||||
}
|
||||
|
@ -1,5 +1,7 @@
|
||||
package unrelation
|
||||
|
||||
import "context"
|
||||
|
||||
const (
|
||||
CWorkMoment = "work_moment"
|
||||
)
|
||||
@ -32,3 +34,15 @@ type Comment struct {
|
||||
func (WorkMoment) TableName() string {
|
||||
return CWorkMoment
|
||||
}
|
||||
|
||||
type WorkMomentModelInterface interface {
|
||||
CreateOneWorkMoment(ctx context.Context, workMoment *WorkMoment) error
|
||||
DeleteOneWorkMoment(ctx context.Context, workMomentID string) error
|
||||
DeleteComment(ctx context.Context, workMomentID, contentID, opUserID string) error
|
||||
GetWorkMomentByID(ctx context.Context, workMomentID string) (*WorkMoment, error)
|
||||
LikeOneWorkMoment(ctx context.Context, likeUserID, userName, workMomentID string) (*WorkMoment, bool, error)
|
||||
CommentOneWorkMoment(ctx context.Context, comment *Comment, workMomentID string) (*WorkMoment, error)
|
||||
GetUserSelfWorkMoments(ctx context.Context, userID string, showNumber, pageNumber int32) ([]*WorkMoment, error)
|
||||
GetUserWorkMoments(ctx context.Context, opUserID, userID string, showNumber, pageNumber int32, friendIDList []string) ([]*WorkMoment, error)
|
||||
GetUserFriendWorkMoments(ctx context.Context, showNumber, pageNumber int32, userID string, friendIDList []string) ([]*WorkMoment, error)
|
||||
}
|
||||
|
@ -119,7 +119,6 @@ func (m *Mongo) createMongoIndex(collection string, isUnique bool, keys ...strin
|
||||
keysDoc = keysDoc.Append(key, bsonx.Int32(1))
|
||||
}
|
||||
}
|
||||
|
||||
// create index
|
||||
index := mongo.IndexModel{
|
||||
Keys: keysDoc,
|
||||
|
@ -1,237 +0,0 @@
|
||||
package unrelation
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/config"
|
||||
"Open_IM/pkg/common/constant"
|
||||
"Open_IM/pkg/common/db/table/unrelation"
|
||||
"Open_IM/pkg/utils"
|
||||
"context"
|
||||
"go.mongodb.org/mongo-driver/bson"
|
||||
"go.mongodb.org/mongo-driver/mongo"
|
||||
"go.mongodb.org/mongo-driver/mongo/options"
|
||||
"time"
|
||||
)
|
||||
|
||||
type OfficeMongoDriver struct {
|
||||
mgoDB *mongo.Database
|
||||
TagCollection *mongo.Collection
|
||||
TagSendLogCollection *mongo.Collection
|
||||
WorkMomentCollection *mongo.Collection
|
||||
}
|
||||
|
||||
func NewOfficeMongoDriver(mgoDB *mongo.Database) *OfficeMongoDriver {
|
||||
return &OfficeMongoDriver{mgoDB: mgoDB, TagCollection: mgoDB.Collection(unrelation.CTag), TagSendLogCollection: mgoDB.Collection(unrelation.CSendLog), WorkMomentCollection: mgoDB.Collection(unrelation.CSendLog)}
|
||||
}
|
||||
|
||||
func (db *OfficeMongoDriver) GetUserTags(ctx context.Context, userID string) ([]unrelation.TagModel, error) {
|
||||
var tags []unrelation.TagModel
|
||||
cursor, err := db.TagCollection.Find(ctx, bson.M{"user_id": userID})
|
||||
if err != nil {
|
||||
return tags, err
|
||||
}
|
||||
if err = cursor.All(ctx, &tags); err != nil {
|
||||
return tags, err
|
||||
}
|
||||
return tags, nil
|
||||
}
|
||||
|
||||
func (db *OfficeMongoDriver) CreateTag(ctx context.Context, userID, tagName string, userList []string) error {
|
||||
tagID := generateTagID(tagName, userID)
|
||||
tag := unrelation.TagModel{
|
||||
UserID: userID,
|
||||
TagID: tagID,
|
||||
TagName: tagName,
|
||||
UserList: userList,
|
||||
}
|
||||
_, err := db.TagCollection.InsertOne(ctx, tag)
|
||||
return err
|
||||
}
|
||||
|
||||
func (db *OfficeMongoDriver) GetTagByID(ctx context.Context, userID, tagID string) (unrelation.TagModel, error) {
|
||||
var tag unrelation.TagModel
|
||||
err := db.TagCollection.FindOne(ctx, bson.M{"user_id": userID, "tag_id": tagID}).Decode(&tag)
|
||||
return tag, err
|
||||
}
|
||||
|
||||
func (db *OfficeMongoDriver) DeleteTag(ctx context.Context, userID, tagID string) error {
|
||||
_, err := db.TagCollection.DeleteOne(ctx, bson.M{"user_id": userID, "tag_id": tagID})
|
||||
return err
|
||||
}
|
||||
|
||||
func (db *OfficeMongoDriver) SetTag(ctx context.Context, userID, tagID, newName string, increaseUserIDList []string, reduceUserIDList []string) error {
|
||||
var tag unrelation.TagModel
|
||||
if err := db.TagCollection.FindOne(ctx, bson.M{"tag_id": tagID, "user_id": userID}).Decode(&tag); err != nil {
|
||||
return err
|
||||
}
|
||||
if newName != "" {
|
||||
_, err := db.TagCollection.UpdateOne(ctx, bson.M{"user_id": userID, "tag_id": tagID}, bson.M{"$set": bson.M{"tag_name": newName}})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
tag.UserList = append(tag.UserList, increaseUserIDList...)
|
||||
tag.UserList = utils.RemoveRepeatedStringInList(tag.UserList)
|
||||
for _, v := range reduceUserIDList {
|
||||
for i2, v2 := range tag.UserList {
|
||||
if v == v2 {
|
||||
tag.UserList[i2] = ""
|
||||
}
|
||||
}
|
||||
}
|
||||
var newUserList []string
|
||||
for _, v := range tag.UserList {
|
||||
if v != "" {
|
||||
newUserList = append(newUserList, v)
|
||||
}
|
||||
}
|
||||
_, err := db.TagCollection.UpdateOne(ctx, bson.M{"user_id": userID, "tag_id": tagID}, bson.M{"$set": bson.M{"user_list": newUserList}})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (db *OfficeMongoDriver) GetUserIDListByTagID(ctx context.Context, userID, tagID string) ([]string, error) {
|
||||
var tag unrelation.TagModel
|
||||
err := db.TagCollection.FindOne(ctx, bson.M{"user_id": userID, "tag_id": tagID}).Decode(&tag)
|
||||
return tag.UserList, err
|
||||
}
|
||||
|
||||
func (db *OfficeMongoDriver) SaveTagSendLog(ctx context.Context, tagSendLog *unrelation.TagSendLogModel) error {
|
||||
_, err := db.TagSendLogCollection.InsertOne(ctx, tagSendLog)
|
||||
return err
|
||||
}
|
||||
|
||||
func (db *OfficeMongoDriver) GetTagSendLogs(ctx context.Context, userID string, showNumber, pageNumber int32) ([]unrelation.TagSendLogModel, error) {
|
||||
var tagSendLogs []unrelation.TagSendLogModel
|
||||
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)
|
||||
if err != nil {
|
||||
return tagSendLogs, err
|
||||
}
|
||||
err = cursor.All(ctx, &tagSendLogs)
|
||||
return tagSendLogs, err
|
||||
}
|
||||
|
||||
func (db *OfficeMongoDriver) CreateOneWorkMoment(ctx context.Context, workMoment *unrelation.WorkMoment) error {
|
||||
workMomentID := generateWorkMomentID(workMoment.UserID)
|
||||
workMoment.WorkMomentID = workMomentID
|
||||
workMoment.CreateTime = int32(time.Now().Unix())
|
||||
_, err := db.WorkMomentCollection.InsertOne(ctx, workMoment)
|
||||
return err
|
||||
}
|
||||
|
||||
func (db *OfficeMongoDriver) DeleteOneWorkMoment(ctx context.Context, workMomentID string) error {
|
||||
_, err := db.WorkMomentCollection.DeleteOne(ctx, bson.M{"work_moment_id": workMomentID})
|
||||
return err
|
||||
}
|
||||
|
||||
func (db *OfficeMongoDriver) DeleteComment(ctx context.Context, workMomentID, contentID, opUserID string) error {
|
||||
_, err := db.WorkMomentCollection.UpdateOne(ctx, bson.D{{"work_moment_id", workMomentID},
|
||||
{"$or", bson.A{
|
||||
bson.D{{"user_id", opUserID}},
|
||||
bson.D{{"comments", bson.M{"$elemMatch": bson.M{"user_id": opUserID}}}},
|
||||
},
|
||||
}}, bson.M{"$pull": bson.M{"comments": bson.M{"content_id": contentID}}})
|
||||
return err
|
||||
}
|
||||
|
||||
func (db *OfficeMongoDriver) GetWorkMomentByID(ctx context.Context, workMomentID string) (*unrelation.WorkMoment, error) {
|
||||
workMoment := &unrelation.WorkMoment{}
|
||||
err := db.WorkMomentCollection.FindOne(ctx, bson.M{"work_moment_id": workMomentID}).Decode(workMoment)
|
||||
return workMoment, err
|
||||
}
|
||||
|
||||
func (db *OfficeMongoDriver) LikeOneWorkMoment(ctx context.Context, likeUserID, userName, workMomentID string) (*unrelation.WorkMoment, bool, error) {
|
||||
workMoment, err := db.GetWorkMomentByID(ctx, workMomentID)
|
||||
if err != nil {
|
||||
return nil, false, err
|
||||
}
|
||||
var isAlreadyLike bool
|
||||
for i, user := range workMoment.LikeUserList {
|
||||
if likeUserID == user.UserID {
|
||||
isAlreadyLike = true
|
||||
workMoment.LikeUserList = append(workMoment.LikeUserList[0:i], workMoment.LikeUserList[i+1:]...)
|
||||
}
|
||||
}
|
||||
if !isAlreadyLike {
|
||||
workMoment.LikeUserList = append(workMoment.LikeUserList, &unrelation.CommonUserModel{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}})
|
||||
return workMoment, !isAlreadyLike, err
|
||||
}
|
||||
|
||||
func (db *OfficeMongoDriver) SetUserWorkMomentsLevel(ctx context.Context, userID string, level int32) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (db *OfficeMongoDriver) CommentOneWorkMoment(ctx context.Context, comment *unrelation.Comment, workMomentID string) (unrelation.WorkMoment, error) {
|
||||
comment.ContentID = generateWorkMomentCommentID(workMomentID)
|
||||
var workMoment unrelation.WorkMoment
|
||||
err := db.WorkMomentCollection.FindOneAndUpdate(ctx, bson.M{"work_moment_id": workMomentID}, bson.M{"$push": bson.M{"comments": comment}}).Decode(&workMoment)
|
||||
return workMoment, err
|
||||
}
|
||||
|
||||
func (db *OfficeMongoDriver) GetUserSelfWorkMoments(ctx context.Context, userID string, showNumber, pageNumber int32) ([]unrelation.WorkMoment, error) {
|
||||
var workMomentList []unrelation.WorkMoment
|
||||
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)
|
||||
if err != nil {
|
||||
return workMomentList, nil
|
||||
}
|
||||
err = result.All(ctx, &workMomentList)
|
||||
return workMomentList, err
|
||||
}
|
||||
|
||||
func (db *OfficeMongoDriver) GetUserWorkMoments(ctx context.Context, opUserID, userID string, showNumber, pageNumber int32, friendIDList []string) ([]unrelation.WorkMoment, error) {
|
||||
var workMomentList []unrelation.WorkMoment
|
||||
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
|
||||
{"user_id", userID},
|
||||
{"$or", bson.A{
|
||||
bson.D{{"permission", constant.WorkMomentPermissionCantSee}, {"permission_user_id_list", bson.D{{"$nin", bson.A{opUserID}}}}},
|
||||
bson.D{{"permission", constant.WorkMomentPermissionCanSee}, {"permission_user_id_list", bson.D{{"$in", bson.A{opUserID}}}}},
|
||||
bson.D{{"permission", constant.WorkMomentPublic}},
|
||||
}},
|
||||
}, findOpts)
|
||||
if err != nil {
|
||||
return workMomentList, nil
|
||||
}
|
||||
err = result.All(ctx, &workMomentList)
|
||||
return workMomentList, err
|
||||
}
|
||||
|
||||
func (db *OfficeMongoDriver) GetUserFriendWorkMoments(ctx context.Context, showNumber, pageNumber int32, userID string, friendIDList []string) ([]unrelation.WorkMoment, error) {
|
||||
var workMomentList []unrelation.WorkMoment
|
||||
findOpts := options.Find().SetLimit(int64(showNumber)).SetSkip(int64(showNumber) * (int64(pageNumber) - 1)).SetSort(bson.M{"create_time": -1})
|
||||
var filter bson.D
|
||||
permissionFilter := 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}}}}},
|
||||
bson.D{{"permission", constant.WorkMomentPublic}},
|
||||
}}}
|
||||
if config.Config.WorkMoment.OnlyFriendCanSee {
|
||||
filter = bson.D{
|
||||
{"$or", bson.A{
|
||||
bson.D{{"user_id", userID}}, //self
|
||||
bson.D{{"$and", bson.A{permissionFilter, bson.D{{"user_id", bson.D{{"$in", friendIDList}}}}}}},
|
||||
},
|
||||
},
|
||||
}
|
||||
} else {
|
||||
filter = bson.D{
|
||||
{"$or", bson.A{
|
||||
bson.D{{"user_id", userID}}, //self
|
||||
permissionFilter,
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
result, err := db.WorkMomentCollection.Find(ctx, filter, findOpts)
|
||||
if err != nil {
|
||||
return workMomentList, err
|
||||
}
|
||||
err = result.All(ctx, &workMomentList)
|
||||
return workMomentList, err
|
||||
}
|
110
pkg/common/db/unrelation/tag.go
Normal file
110
pkg/common/db/unrelation/tag.go
Normal file
@ -0,0 +1,110 @@
|
||||
package unrelation
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/db/table/unrelation"
|
||||
"Open_IM/pkg/utils"
|
||||
"context"
|
||||
"go.mongodb.org/mongo-driver/bson"
|
||||
"go.mongodb.org/mongo-driver/mongo"
|
||||
"go.mongodb.org/mongo-driver/mongo/options"
|
||||
)
|
||||
|
||||
type TagMongoDriver struct {
|
||||
mgoDB *mongo.Database
|
||||
TagCollection *mongo.Collection
|
||||
TagSendLogCollection *mongo.Collection
|
||||
}
|
||||
|
||||
func NewTagMongoDriver(mgoDB *mongo.Database) *TagMongoDriver {
|
||||
return &TagMongoDriver{mgoDB: mgoDB, TagCollection: mgoDB.Collection(unrelation.CTag), TagSendLogCollection: mgoDB.Collection(unrelation.CSendLog)}
|
||||
}
|
||||
|
||||
func (db *TagMongoDriver) GetUserTags(ctx context.Context, userID string) ([]unrelation.TagModel, error) {
|
||||
var tags []unrelation.TagModel
|
||||
cursor, err := db.TagCollection.Find(ctx, bson.M{"user_id": userID})
|
||||
if err != nil {
|
||||
return tags, err
|
||||
}
|
||||
if err = cursor.All(ctx, &tags); err != nil {
|
||||
return tags, err
|
||||
}
|
||||
return tags, nil
|
||||
}
|
||||
|
||||
func (db *TagMongoDriver) CreateTag(ctx context.Context, userID, tagName string, userList []string) error {
|
||||
tagID := generateTagID(tagName, userID)
|
||||
tag := unrelation.TagModel{
|
||||
UserID: userID,
|
||||
TagID: tagID,
|
||||
TagName: tagName,
|
||||
UserList: userList,
|
||||
}
|
||||
_, err := db.TagCollection.InsertOne(ctx, tag)
|
||||
return err
|
||||
}
|
||||
|
||||
func (db *TagMongoDriver) GetTagByID(ctx context.Context, userID, tagID string) (unrelation.TagModel, error) {
|
||||
var tag unrelation.TagModel
|
||||
err := db.TagCollection.FindOne(ctx, bson.M{"user_id": userID, "tag_id": tagID}).Decode(&tag)
|
||||
return tag, err
|
||||
}
|
||||
|
||||
func (db *TagMongoDriver) DeleteTag(ctx context.Context, userID, tagID string) error {
|
||||
_, err := db.TagCollection.DeleteOne(ctx, bson.M{"user_id": userID, "tag_id": tagID})
|
||||
return err
|
||||
}
|
||||
|
||||
func (db *TagMongoDriver) SetTag(ctx context.Context, userID, tagID, newName string, increaseUserIDList []string, reduceUserIDList []string) error {
|
||||
var tag unrelation.TagModel
|
||||
if err := db.TagCollection.FindOne(ctx, bson.M{"tag_id": tagID, "user_id": userID}).Decode(&tag); err != nil {
|
||||
return err
|
||||
}
|
||||
if newName != "" {
|
||||
_, err := db.TagCollection.UpdateOne(ctx, bson.M{"user_id": userID, "tag_id": tagID}, bson.M{"$set": bson.M{"tag_name": newName}})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
tag.UserList = append(tag.UserList, increaseUserIDList...)
|
||||
tag.UserList = utils.RemoveRepeatedStringInList(tag.UserList)
|
||||
for _, v := range reduceUserIDList {
|
||||
for i2, v2 := range tag.UserList {
|
||||
if v == v2 {
|
||||
tag.UserList[i2] = ""
|
||||
}
|
||||
}
|
||||
}
|
||||
var newUserList []string
|
||||
for _, v := range tag.UserList {
|
||||
if v != "" {
|
||||
newUserList = append(newUserList, v)
|
||||
}
|
||||
}
|
||||
_, err := db.TagCollection.UpdateOne(ctx, bson.M{"user_id": userID, "tag_id": tagID}, bson.M{"$set": bson.M{"user_list": newUserList}})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (db *TagMongoDriver) GetUserIDListByTagID(ctx context.Context, userID, tagID string) ([]string, error) {
|
||||
var tag unrelation.TagModel
|
||||
err := db.TagCollection.FindOne(ctx, bson.M{"user_id": userID, "tag_id": tagID}).Decode(&tag)
|
||||
return tag.UserList, err
|
||||
}
|
||||
|
||||
func (db *TagMongoDriver) SaveTagSendLog(ctx context.Context, tagSendLog *unrelation.TagSendLogModel) error {
|
||||
_, err := db.TagSendLogCollection.InsertOne(ctx, tagSendLog)
|
||||
return err
|
||||
}
|
||||
|
||||
func (db *TagMongoDriver) GetTagSendLogs(ctx context.Context, userID string, showNumber, pageNumber int32) ([]unrelation.TagSendLogModel, error) {
|
||||
var tagSendLogs []unrelation.TagSendLogModel
|
||||
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)
|
||||
if err != nil {
|
||||
return tagSendLogs, err
|
||||
}
|
||||
err = cursor.All(ctx, &tagSendLogs)
|
||||
return tagSendLogs, err
|
||||
}
|
140
pkg/common/db/unrelation/work_moment.go
Normal file
140
pkg/common/db/unrelation/work_moment.go
Normal file
@ -0,0 +1,140 @@
|
||||
package unrelation
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/config"
|
||||
"Open_IM/pkg/common/constant"
|
||||
"Open_IM/pkg/common/db/table/unrelation"
|
||||
"context"
|
||||
"go.mongodb.org/mongo-driver/bson"
|
||||
"go.mongodb.org/mongo-driver/mongo"
|
||||
"go.mongodb.org/mongo-driver/mongo/options"
|
||||
"time"
|
||||
)
|
||||
|
||||
type WorkMomentMongoDriver struct {
|
||||
mgoDB *mongo.Database
|
||||
WorkMomentCollection *mongo.Collection
|
||||
}
|
||||
|
||||
func NewWorkMomentMongoDriver(mgoDB *mongo.Database) *WorkMomentMongoDriver {
|
||||
return &WorkMomentMongoDriver{mgoDB: mgoDB, WorkMomentCollection: mgoDB.Collection(unrelation.CWorkMoment)}
|
||||
}
|
||||
|
||||
func (db *WorkMomentMongoDriver) CreateOneWorkMoment(ctx context.Context, workMoment *unrelation.WorkMoment) error {
|
||||
workMomentID := generateWorkMomentID(workMoment.UserID)
|
||||
workMoment.WorkMomentID = workMomentID
|
||||
workMoment.CreateTime = int32(time.Now().Unix())
|
||||
_, err := db.WorkMomentCollection.InsertOne(ctx, workMoment)
|
||||
return err
|
||||
}
|
||||
|
||||
func (db *WorkMomentMongoDriver) DeleteOneWorkMoment(ctx context.Context, workMomentID string) error {
|
||||
_, err := db.WorkMomentCollection.DeleteOne(ctx, bson.M{"work_moment_id": workMomentID})
|
||||
return err
|
||||
}
|
||||
|
||||
func (db *WorkMomentMongoDriver) DeleteComment(ctx context.Context, workMomentID, contentID, opUserID string) error {
|
||||
_, err := db.WorkMomentCollection.UpdateOne(ctx, bson.D{{"work_moment_id", workMomentID},
|
||||
{"$or", bson.A{
|
||||
bson.D{{"user_id", opUserID}},
|
||||
bson.D{{"comments", bson.M{"$elemMatch": bson.M{"user_id": opUserID}}}},
|
||||
},
|
||||
}}, bson.M{"$pull": bson.M{"comments": bson.M{"content_id": contentID}}})
|
||||
return err
|
||||
}
|
||||
|
||||
func (db *WorkMomentMongoDriver) GetWorkMomentByID(ctx context.Context, workMomentID string) (*unrelation.WorkMoment, error) {
|
||||
workMoment := &unrelation.WorkMoment{}
|
||||
err := db.WorkMomentCollection.FindOne(ctx, bson.M{"work_moment_id": workMomentID}).Decode(workMoment)
|
||||
return workMoment, err
|
||||
}
|
||||
|
||||
func (db *WorkMomentMongoDriver) LikeOneWorkMoment(ctx context.Context, likeUserID, userName, workMomentID string) (*unrelation.WorkMoment, bool, error) {
|
||||
workMoment, err := db.GetWorkMomentByID(ctx, workMomentID)
|
||||
if err != nil {
|
||||
return nil, false, err
|
||||
}
|
||||
var isAlreadyLike bool
|
||||
for i, user := range workMoment.LikeUserList {
|
||||
if likeUserID == user.UserID {
|
||||
isAlreadyLike = true
|
||||
workMoment.LikeUserList = append(workMoment.LikeUserList[0:i], workMoment.LikeUserList[i+1:]...)
|
||||
}
|
||||
}
|
||||
if !isAlreadyLike {
|
||||
workMoment.LikeUserList = append(workMoment.LikeUserList, &unrelation.CommonUserModel{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}})
|
||||
return workMoment, !isAlreadyLike, err
|
||||
}
|
||||
|
||||
func (db *WorkMomentMongoDriver) CommentOneWorkMoment(ctx context.Context, comment *unrelation.Comment, workMomentID string) (unrelation.WorkMoment, error) {
|
||||
comment.ContentID = generateWorkMomentCommentID(workMomentID)
|
||||
var workMoment unrelation.WorkMoment
|
||||
err := db.WorkMomentCollection.FindOneAndUpdate(ctx, bson.M{"work_moment_id": workMomentID}, bson.M{"$push": bson.M{"comments": comment}}).Decode(&workMoment)
|
||||
return workMoment, err
|
||||
}
|
||||
|
||||
func (db *WorkMomentMongoDriver) GetUserSelfWorkMoments(ctx context.Context, userID string, showNumber, pageNumber int32) ([]unrelation.WorkMoment, error) {
|
||||
var workMomentList []unrelation.WorkMoment
|
||||
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)
|
||||
if err != nil {
|
||||
return workMomentList, nil
|
||||
}
|
||||
err = result.All(ctx, &workMomentList)
|
||||
return workMomentList, err
|
||||
}
|
||||
|
||||
func (db *WorkMomentMongoDriver) GetUserWorkMoments(ctx context.Context, opUserID, userID string, showNumber, pageNumber int32, friendIDList []string) ([]unrelation.WorkMoment, error) {
|
||||
var workMomentList []unrelation.WorkMoment
|
||||
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
|
||||
{"user_id", userID},
|
||||
{"$or", bson.A{
|
||||
bson.D{{"permission", constant.WorkMomentPermissionCantSee}, {"permission_user_id_list", bson.D{{"$nin", bson.A{opUserID}}}}},
|
||||
bson.D{{"permission", constant.WorkMomentPermissionCanSee}, {"permission_user_id_list", bson.D{{"$in", bson.A{opUserID}}}}},
|
||||
bson.D{{"permission", constant.WorkMomentPublic}},
|
||||
}},
|
||||
}, findOpts)
|
||||
if err != nil {
|
||||
return workMomentList, nil
|
||||
}
|
||||
err = result.All(ctx, &workMomentList)
|
||||
return workMomentList, err
|
||||
}
|
||||
|
||||
func (db *WorkMomentMongoDriver) GetUserFriendWorkMoments(ctx context.Context, showNumber, pageNumber int32, userID string, friendIDList []string) ([]unrelation.WorkMoment, error) {
|
||||
var workMomentList []unrelation.WorkMoment
|
||||
findOpts := options.Find().SetLimit(int64(showNumber)).SetSkip(int64(showNumber) * (int64(pageNumber) - 1)).SetSort(bson.M{"create_time": -1})
|
||||
var filter bson.D
|
||||
permissionFilter := 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}}}}},
|
||||
bson.D{{"permission", constant.WorkMomentPublic}},
|
||||
}}}
|
||||
if config.Config.WorkMoment.OnlyFriendCanSee {
|
||||
filter = bson.D{
|
||||
{"$or", bson.A{
|
||||
bson.D{{"user_id", userID}}, //self
|
||||
bson.D{{"$and", bson.A{permissionFilter, bson.D{{"user_id", bson.D{{"$in", friendIDList}}}}}}},
|
||||
},
|
||||
},
|
||||
}
|
||||
} else {
|
||||
filter = bson.D{
|
||||
{"$or", bson.A{
|
||||
bson.D{{"user_id", userID}}, //self
|
||||
permissionFilter,
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
result, err := db.WorkMomentCollection.Find(ctx, filter, findOpts)
|
||||
if err != nil {
|
||||
return workMomentList, err
|
||||
}
|
||||
err = result.All(ctx, &workMomentList)
|
||||
return workMomentList, err
|
||||
}
|
@ -15,8 +15,12 @@ import (
|
||||
)
|
||||
|
||||
type SvcDiscoveryRegistry interface {
|
||||
Register(serviceName, host string, port int, opts ...grpc.DialOption) error
|
||||
UnRegister() error
|
||||
GetConns(serviceName string, opts ...grpc.DialOption) ([]*grpc.ClientConn, error)
|
||||
GetConn(serviceName string, strategy func(slice []*grpc.ClientConn) int, opts ...grpc.DialOption) (*grpc.ClientConn, error)
|
||||
//RegisterConf(conf []byte) error
|
||||
//LoadConf() ([]byte, error)
|
||||
}
|
||||
|
||||
func registerConf(key, conf string) {
|
28
pkg/discovery_registry/startegy.go
Normal file
28
pkg/discovery_registry/startegy.go
Normal file
@ -0,0 +1,28 @@
|
||||
package discoveryRegistry
|
||||
|
||||
import "google.golang.org/grpc"
|
||||
|
||||
type Robin struct {
|
||||
next int
|
||||
}
|
||||
|
||||
func (r *Robin) Robin(slice []*grpc.ClientConn) int {
|
||||
index := r.next
|
||||
r.next += 1
|
||||
if r.next > len(slice)-1 {
|
||||
r.next = 0
|
||||
}
|
||||
return index
|
||||
}
|
||||
|
||||
type Hash struct {
|
||||
}
|
||||
|
||||
func (r *Hash) Hash(slice []*grpc.ClientConn) int {
|
||||
index := r.next
|
||||
r.next += 1
|
||||
if r.next > len(slice)-1 {
|
||||
r.next = 0
|
||||
}
|
||||
return index
|
||||
}
|
1
pkg/discovery_registry/zk.go
Normal file
1
pkg/discovery_registry/zk.go
Normal file
@ -0,0 +1 @@
|
||||
package discoveryRegistry
|
@ -1,6 +1,7 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/config"
|
||||
"errors"
|
||||
"net"
|
||||
)
|
||||
@ -23,3 +24,15 @@ func GetLocalIP() (string, error) {
|
||||
|
||||
return "", errors.New("no ip")
|
||||
}
|
||||
|
||||
func GetRpcIP() (string, error) {
|
||||
registerIP := config.Config.RpcRegisterIP
|
||||
if registerIP == "" {
|
||||
ip, err := GetLocalIP()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
registerIP = ip
|
||||
}
|
||||
return registerIP, nil
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user