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

This commit is contained in:
Gordon
2023-02-10 20:58:54 +08:00
109 changed files with 992 additions and 36145 deletions
+5 -5
View File
@@ -57,7 +57,7 @@ package apistruct
//}
//type GetBlackListResp struct {
// CommResp
// BlackUserInfoList []*open_im_sdk.PublicUserInfo `json:"-"`
// BlackUserInfoList []*sdkws.PublicUserInfo `json:"-"`
// Map []map[string]interface{} `json:"data" swaggerignore:"true"`
//}
//
@@ -99,7 +99,7 @@ package apistruct
//}
//type GetFriendsInfoResp struct {
// CommResp
// FriendInfoList []*open_im_sdk.FriendInfo `json:"-"`
// FriendInfoList []*sdkws.FriendInfo `json:"-"`
// Map []map[string]interface{} `json:"data" swaggerignore:"true"`
//}
//
@@ -109,7 +109,7 @@ package apistruct
//}
//type GetFriendListResp struct {
// CommResp
// FriendInfoList []*open_im_sdk.FriendInfo `json:"-"`
// FriendInfoList []*sdkws.FriendInfo `json:"-"`
// Map []map[string]interface{} `json:"data" swaggerignore:"true"`
//}
//
@@ -119,7 +119,7 @@ package apistruct
//}
//type GetFriendApplyListResp struct {
// CommResp
// FriendRequestList []*open_im_sdk.FriendRequest `json:"-"`
// FriendRequestList []*sdkws.FriendRequest `json:"-"`
// Map []map[string]interface{} `json:"data" swaggerignore:"true"`
//}
//
@@ -129,7 +129,7 @@ package apistruct
//}
//type GetSelfApplyListResp struct {
// CommResp
// FriendRequestList []*open_im_sdk.FriendRequest `json:"-"`
// FriendRequestList []*sdkws.FriendRequest `json:"-"`
// Map []map[string]interface{} `json:"data" swaggerignore:"true"`
//}
+16 -16
View File
@@ -1,7 +1,7 @@
package apistruct
import (
open_im_sdk "Open_IM/pkg/proto/sdkws"
sdkws "Open_IM/pkg/proto/sdkws"
)
type CommResp struct {
@@ -32,8 +32,8 @@ type GetGroupMembersInfoReq struct {
}
type GetGroupMembersInfoResp struct {
CommResp
MemberList []*open_im_sdk.GroupMemberFullInfo `json:"-"`
Data []map[string]interface{} `json:"data" swaggerignore:"true"`
MemberList []*sdkws.GroupMemberFullInfo `json:"-"`
Data []map[string]interface{} `json:"data" swaggerignore:"true"`
}
type InviteUserToGroupReq struct {
@@ -53,7 +53,7 @@ type GetJoinedGroupListReq struct {
}
type GetJoinedGroupListResp struct {
CommResp
GroupInfoList []*open_im_sdk.GroupInfo `json:"-"`
GroupInfoList []*sdkws.GroupInfo `json:"-"`
Data []map[string]interface{} `json:"data" swaggerignore:"true"`
}
@@ -65,9 +65,9 @@ type GetGroupMemberListReq struct {
}
type GetGroupMemberListResp struct {
CommResp
NextSeq int32 `json:"nextSeq"`
MemberList []*open_im_sdk.GroupMemberFullInfo `json:"-"`
Data []map[string]interface{} `json:"data" swaggerignore:"true"`
NextSeq int32 `json:"nextSeq"`
MemberList []*sdkws.GroupMemberFullInfo `json:"-"`
Data []map[string]interface{} `json:"data" swaggerignore:"true"`
}
type GetGroupAllMemberReq struct {
@@ -78,8 +78,8 @@ type GetGroupAllMemberReq struct {
}
type GetGroupAllMemberResp struct {
CommResp
MemberList []*open_im_sdk.GroupMemberFullInfo `json:"-"`
Data []map[string]interface{} `json:"data" swaggerignore:"true"`
MemberList []*sdkws.GroupMemberFullInfo `json:"-"`
Data []map[string]interface{} `json:"data" swaggerignore:"true"`
}
//
@@ -91,7 +91,7 @@ type GetGroupAllMemberResp struct {
//}
//type GetGroupAllMemberListBySplitResp struct {
// CommResp
// MemberList []*open_im_sdk.GroupMemberFullInfo `json:"-"`
// MemberList []*sdkws.GroupMemberFullInfo `json:"-"`
// Map []map[string]interface{} `json:"data" swaggerignore:"true"`
//}
@@ -109,7 +109,7 @@ type CreateGroupReq struct {
}
type CreateGroupResp struct {
CommResp
GroupInfo open_im_sdk.GroupInfo `json:"-"`
GroupInfo sdkws.GroupInfo `json:"-"`
Data map[string]interface{} `json:"data" swaggerignore:"true"`
}
@@ -119,8 +119,8 @@ type GetGroupApplicationListReq struct {
}
type GetGroupApplicationListResp struct {
CommResp
GroupRequestList []*open_im_sdk.GroupRequest `json:"-"`
Data []map[string]interface{} `json:"data" swaggerignore:"true"`
GroupRequestList []*sdkws.GroupRequest `json:"-"`
Data []map[string]interface{} `json:"data" swaggerignore:"true"`
}
type GetUserReqGroupApplicationListReq struct {
@@ -129,7 +129,7 @@ type GetUserReqGroupApplicationListReq struct {
}
type GetUserRespGroupApplicationResp struct {
GroupRequestList []*open_im_sdk.GroupRequest `json:"data"`
GroupRequestList []*sdkws.GroupRequest `json:"data"`
}
type GetGroupInfoReq struct {
@@ -138,12 +138,12 @@ type GetGroupInfoReq struct {
}
type GetGroupInfoResp struct {
CommResp
GroupInfoList []*open_im_sdk.GroupInfo `json:"-"`
GroupInfoList []*sdkws.GroupInfo `json:"-"`
Data []map[string]interface{} `json:"data" swaggerignore:"true"`
}
//type GroupInfoAlias struct {
// open_im_sdk.GroupInfo
// sdkws.GroupInfo
// NeedVerification int32 `protobuf:"bytes,13,opt,name=needVerification" json:"needVerification,omitempty"`
//}
-88
View File
@@ -1,88 +0,0 @@
package apistruct
import (
pbOffice "Open_IM/pkg/proto/office"
)
type GetUserTagsReq struct {
OperationID string `json:"operationID" binding:"required"`
}
type GetUserTagsResp struct {
CommResp
Data struct {
Tags []*pbOffice.Tag `json:"tags"`
} `json:"data"`
}
type CreateTagReq struct {
TagName string `json:"tagName" binding:"required"` // tag名称
UserIDList []string `json:"userIDList" binding:"required"` // 用户ID列表
OperationID string `json:"operationID" binding:"required"`
}
type CreateTagResp struct {
CommResp
}
type DeleteTagReq struct {
TagID string `json:"tagID" binding:"required"`
OperationID string `json:"operationID" binding:"required"`
}
type DeleteTagResp struct {
CommResp
}
type SetTagReq struct {
TagID string `json:"tagID" binding:"required"`
NewName string `json:"newName"`
IncreaseUserIDList []string `json:"increaseUserIDList"`
ReduceUserIDList []string `json:"reduceUserIDList"`
OperationID string `json:"operationID" binding:"required"`
}
type SetTagResp struct {
CommResp
}
type SendMsg2TagReq struct {
TagList []string `json:"tagList"`
UserList []string `json:"userList"`
GroupList []string `json:"groupList"`
SenderPlatformID int32 `json:"senderPlatformID" binding:"required"`
Content string `json:"content" binding:"required"`
OperationID string `json:"operationID" binding:"required"`
}
type SendMsg2TagResp struct {
CommResp
}
type GetTagSendLogsReq struct {
PageNumber int32 `json:"pageNumber" binding:"required"`
ShowNumber int32 `json:"showNumber" binding:"required"`
OperationID string `json:"operationID" binding:"required"`
}
type GetTagSendLogsResp struct {
CommResp
Data struct {
Logs []*pbOffice.TagSendLog `json:"logs"`
CurrentPage int32 `json:"currentPage"`
ShowNumber int32 `json:"showNumber"`
} `json:"data"`
}
type GetUserTagByIDReq struct {
TagID string `json:"tagID" binding:"required"`
OperationID string `json:"operationID" binding:"required"`
}
type GetUserTagByIDResp struct {
CommResp
Data struct {
Tag *pbOffice.Tag `json:"tag"`
} `json:"data"`
}
+4 -4
View File
@@ -1,7 +1,7 @@
package apistruct
import (
open_im_sdk "Open_IM/pkg/proto/sdkws"
sdkws "Open_IM/pkg/proto/sdkws"
)
type GetUsersInfoReq struct {
@@ -10,8 +10,8 @@ type GetUsersInfoReq struct {
}
type GetUsersInfoResp struct {
CommResp
UserInfoList []*open_im_sdk.PublicUserInfo `json:"-"`
Data []map[string]interface{} `json:"data" swaggerignore:"true"`
UserInfoList []*sdkws.PublicUserInfo `json:"-"`
Data []map[string]interface{} `json:"data" swaggerignore:"true"`
}
type UpdateSelfUserInfoReq struct {
@@ -35,7 +35,7 @@ type GetSelfUserInfoReq struct {
}
type GetSelfUserInfoResp struct {
CommResp
UserInfo *open_im_sdk.UserInfo `json:"-"`
UserInfo *sdkws.UserInfo `json:"-"`
Data map[string]interface{} `json:"data" swaggerignore:"true"`
}
-138
View File
@@ -1,138 +0,0 @@
package apistruct
import "Open_IM/pkg/proto/office"
type CreateOneWorkMomentReq struct {
office.CreateOneWorkMomentReq
}
type CreateOneWorkMomentResp struct {
CommResp
Data struct{} `json:"data"`
}
type DeleteOneWorkMomentReq struct {
WorkMomentID string `json:"workMomentID" binding:"required"`
OperationID string `json:"operationID" binding:"required"`
}
type DeleteOneWorkMomentResp struct {
CommResp
Data struct{} `json:"data"`
}
type LikeOneWorkMomentReq struct {
WorkMomentID string `json:"workMomentID" binding:"required"`
OperationID string `json:"operationID" binding:"required"`
}
type LikeOneWorkMomentResp struct {
CommResp
Data struct{} `json:"data"`
}
type CommentOneWorkMomentReq struct {
WorkMomentID string `json:"workMomentID" binding:"required"`
ReplyUserID string `json:"replyUserID"`
Content string `json:"content" binding:"required"`
OperationID string `json:"operationID" binding:"required"`
}
type CommentOneWorkMomentResp struct {
CommResp
Data struct{} `json:"data"`
}
type DeleteCommentReq struct {
WorkMomentID string `json:"workMomentID" binding:"required"`
ContentID string `json:"contentID" binding:"required"`
OperationID string `json:"operationID" binding:"required"`
}
type DeleteCommentResp struct {
CommResp
Data struct{} `json:"data"`
}
type WorkMomentsUserCommonReq struct {
PageNumber int32 `json:"pageNumber" binding:"required"`
ShowNumber int32 `json:"showNumber" binding:"required"`
OperationID string `json:"operationID" binding:"required"`
}
type GetWorkMomentByIDReq struct {
WorkMomentID string `json:"workMomentID" binding:"required"`
OperationID string `json:"operationID" binding:"required"`
}
type WorkMoment struct {
WorkMomentID string `json:"workMomentID"`
UserID string `json:"userID"`
Content string `json:"content"`
LikeUserList []*WorkMomentUser `json:"likeUsers"`
Comments []*Comment `json:"comments"`
FaceURL string `json:"faceURL"`
UserName string `json:"userName"`
AtUserList []*WorkMomentUser `json:"atUsers"`
PermissionUserList []*WorkMomentUser `json:"permissionUsers"`
CreateTime int32 `json:"createTime"`
Permission int32 `json:"permission"`
}
type WorkMomentUser struct {
UserID string `json:"userID"`
UserName string `json:"userName"`
}
type Comment struct {
UserID string `json:"userID"`
UserName string `json:"userName"`
ReplyUserID string `json:"replyUserID"`
ReplyUserName string `json:"replyUserName"`
ContentID string `json:"contentID"`
Content string `json:"content"`
CreateTime int32 `json:"createTime"`
}
type GetWorkMomentByIDResp struct {
CommResp
Data struct {
WorkMoment *WorkMoment `json:"workMoment"`
} `json:"data"`
}
type GetUserWorkMomentsReq struct {
WorkMomentsUserCommonReq
UserID string `json:"userID"`
}
type GetUserWorkMomentsResp struct {
CommResp
Data struct {
WorkMoments []*WorkMoment `json:"workMoments"`
CurrentPage int32 `json:"currentPage"`
ShowNumber int32 `json:"showNumber"`
} `json:"data"`
}
type GetUserFriendWorkMomentsReq struct {
WorkMomentsUserCommonReq
}
type GetUserFriendWorkMomentsResp struct {
CommResp
Data struct {
WorkMoments []*WorkMoment `json:"workMoments"`
CurrentPage int32 `json:"currentPage"`
ShowNumber int32 `json:"showNumber"`
} `json:"data"`
}
type SetUserWorkMomentsLevelReq struct {
office.SetUserWorkMomentsLevelReq
}
type SetUserWorkMomentsLevelResp struct {
CommResp
Data struct{} `json:"data"`
}
+2 -2
View File
@@ -1,7 +1,7 @@
package callbackstruct
import (
"Open_IM/pkg/proto/group"
"Open_IM/pkg/apistruct"
common "Open_IM/pkg/proto/sdkws"
)
@@ -9,7 +9,7 @@ type CallbackBeforeCreateGroupReq struct {
CallbackCommand string `json:"callbackCommand"`
OperationID string `json:"operationID"`
common.GroupInfo
InitMemberList []*group.GroupAddMemberInfo `json:"initMemberList"`
InitMemberList []*apistruct.GroupAddMemberInfo `json:"initMemberList"`
}
type CallbackBeforeCreateGroupResp struct {
-56
View File
@@ -1,56 +0,0 @@
package cmsstruct
import (
"Open_IM/pkg/api_struct"
sdkws "Open_IM/pkg/proto/sdkws"
)
type AdminLoginRequest struct {
AdminName string `json:"adminID" binding:"required"`
Secret string `json:"secret" binding:"required"`
OperationID string `json:"operationID" binding:"required"`
}
type AdminLoginResponse struct {
Token string `json:"token"`
UserName string `json:"userName"`
FaceURL string `json:"faceURL"`
}
type GetUserTokenRequest struct {
UserID string `json:"userID" binding:"required"`
OperationID string `json:"operationID" binding:"required"`
PlatFormID int32 `json:"platformID" binding:"required"`
}
type GetUserTokenResponse struct {
Token string `json:"token"`
ExpTime int64 `json:"expTime"`
}
type AddUserRegisterAddFriendIDListRequest struct {
OperationID string `json:"operationID" binding:"required"`
UserIDList []string `json:"userIDList" binding:"required"`
}
type AddUserRegisterAddFriendIDListResponse struct {
}
type ReduceUserRegisterAddFriendIDListRequest struct {
OperationID string `json:"operationID" binding:"required"`
UserIDList []string `json:"userIDList" binding:"required"`
Operation int32 `json:"operation"`
}
type ReduceUserRegisterAddFriendIDListResponse struct {
}
type GetUserRegisterAddFriendIDListRequest struct {
OperationID string `json:"operationID" binding:"required"`
apistruct.RequestPagination
}
type GetUserRegisterAddFriendIDListResponse struct {
Users []*sdkws.UserInfo `json:"users"`
apistruct.ResponsePagination
}
-11
View File
@@ -1,11 +0,0 @@
package cmsstruct
type RequestPagination struct {
PageNumber int `json:"pageNumber" binding:"required"`
ShowNumber int `json:"showNumber" binding:"required"`
}
type ResponsePagination struct {
CurrentPage int `json:"currentPage"`
ShowNumber int `json:"showNumber"`
}
-25
View File
@@ -1,25 +0,0 @@
package cmsstruct
type GetFriendsReq struct {
OperationID string `json:"operationID"`
UserID string `json:"userID"`
FriendUserName string `json:"friendUserName"`
FriendUserID string `json:"friendUserID"`
RequestPagination
}
type FriendInfo struct {
OwnerUserID string `json:"ownerUserID"`
Remark string `json:"remark"`
CreateTime uint32 `json:"createTime"`
UserID string `json:"userID"`
Nickname string `json:"nickName"`
AddSource int32 `json:"addSource"`
OperatorUserID string `json:"operatorUserID"`
}
type GetFriendsResp struct {
ResponsePagination
FriendInfoList []*FriendInfo `json:"friendInfoList"`
FriendNums int32 `json:"friendNums"`
}
-64
View File
@@ -1,64 +0,0 @@
package cmsstruct
type GroupResponse struct {
GroupOwnerName string `json:"GroupOwnerName"`
GroupOwnerID string `json:"GroupOwnerID"`
GroupID string `json:"groupID"`
GroupName string `json:"groupName"`
Notification string `json:"notification"`
Introduction string `json:"introduction"`
FaceURL string `json:"faceURL"`
OwnerUserID string `json:"ownerUserID"`
CreateTime uint32 `json:"createTime"`
MemberCount uint32 `json:"memberCount"`
Ex string `json:"ex"`
Status int32 `json:"status"`
CreatorUserID string `json:"creatorUserID"`
GroupType int32 `json:"groupType"`
NeedVerification int32 `json:"needVerification"`
LookMemberInfo int32 `json:"lookMemberInfo"`
ApplyMemberFriend int32 `json:"applyMemberFriend"`
NotificationUpdateTime uint32 `json:"notificationUpdateTime"`
NotificationUserID string `json:"notificationUserID"`
}
type GetGroupsRequest struct {
RequestPagination
OperationID string `json:"operationID" binding:"required"`
GroupID string `json:"groupID"`
GroupName string `json:"groupName"`
}
type GetGroupsResponse struct {
Groups []GroupResponse `json:"groups"`
GroupNums int `json:"groupNums"`
ResponsePagination
}
type GetGroupMembersRequest struct {
GroupID string `form:"groupID" binding:"required"`
UserName string `form:"userName"`
OperationID string `json:"operationID" binding:"required"`
RequestPagination
}
type GroupMemberResponse struct {
GroupID string `json:"groupID"`
UserID string `json:"userID"`
RoleLevel int32 `json:"roleLevel"`
JoinTime int32 `json:"joinTime"`
Nickname string `json:"nickname"`
FaceURL string `json:"faceURL"`
AppMangerLevel int32 `json:"appMangerLevel"` //if >0
JoinSource int32 `json:"joinSource"`
OperatorUserID string `json:"operatorUserID"`
Ex string `json:"ex"`
MuteEndTime uint32 `json:"muteEndTime"`
InviterUserID string `json:"inviterUserID"`
}
type GetGroupMembersResponse struct {
GroupMembers []GroupMemberResponse `json:"groupMembers"`
ResponsePagination
MemberNums int `json:"memberNums"`
}
-48
View File
@@ -1,48 +0,0 @@
package cmsstruct
import (
pbCommon "Open_IM/pkg/proto/sdkws"
)
type GetChatLogsReq struct {
SessionType int `json:"sessionType"`
ContentType int `json:"contentType"`
Content string `json:"content"`
SendID string `json:"sendID"`
RecvID string `json:"recvID"`
GroupID string `json:"groupID"`
SendTime string `json:"sendTime"`
RequestPagination
OperationID string `json:"operationID"`
}
type ChatLog struct {
SendID string `json:"sendID,omitempty"`
RecvID string `json:"recvID,omitempty"`
GroupID string `json:"groupID,omitempty"`
ClientMsgID string `json:"clientMsgID,omitempty"`
ServerMsgID string `json:"serverMsgID,omitempty"`
SenderPlatformID int32 `json:"senderPlatformID,omitempty"`
SenderNickname string `json:"senderNickname,omitempty"`
SenderFaceURL string `json:"senderFaceURL,omitempty"`
SessionType int32 `json:"sessionType,omitempty"`
MsgFrom int32 `json:"msgFrom,omitempty"`
ContentType int32 `json:"contentType,omitempty"`
Content string `json:"content,omitempty"`
Seq uint32 `json:"seq,omitempty"`
SendTime int64 `json:"sendTime,omitempty"`
CreateTime int64 `json:"createTime,omitempty"`
Status int32 `json:"status,omitempty"`
Options map[string]bool `json:"options,omitempty"`
OfflinePushInfo *pbCommon.OfflinePushInfo `json:"offlinePushInfo,omitempty"`
AtUserIDList []string `json:"atUserIDList,omitempty"`
MsgDataList []byte `json:"msgDataList,omitempty"`
AttachedInfo string `json:"attachedInfo,omitempty"`
Ex string `json:"ex,omitempty"`
}
type GetChatLogsResp struct {
ChatLogs []*ChatLog `json:"chatLogs"`
ChatLogsNum int `json:"logNums"`
ResponsePagination
}
-90
View File
@@ -1,90 +0,0 @@
package cmsstruct
type GetStatisticsRequest struct {
From string `json:"from" binding:"required"`
To string `json:"to" binding:"required"`
OperationID string `json:"operationID" binding:"required"`
}
type GetMessageStatisticsRequest struct {
GetStatisticsRequest
}
type GetMessageStatisticsResponse struct {
PrivateMessageNum int `json:"privateMessageNum"`
GroupMessageNum int `json:"groupMessageNum"`
PrivateMessageNumList []struct {
Date string `json:"date"`
MessageNum int `json:"messageNum"`
} `json:"privateMessageNumList"`
GroupMessageNumList []struct {
Date string `json:"date"`
MessageNum int `json:"messageNum"`
} `json:"groupMessageNumList"`
}
type GetUserStatisticsRequest struct {
GetStatisticsRequest
}
type GetUserStatisticsResponse struct {
IncreaseUserNum int `json:"increaseUserNum"`
ActiveUserNum int `json:"activeUserNum"`
TotalUserNum int `json:"totalUserNum"`
IncreaseUserNumList []struct {
Date string `json:"date"`
IncreaseUserNum int `json:"increaseUserNum"`
} `json:"increaseUserNumList"`
ActiveUserNumList []struct {
Date string `json:"date"`
ActiveUserNum int `json:"activeUserNum"`
} `json:"activeUserNumList"`
TotalUserNumList []struct {
Date string `json:"date"`
TotalUserNum int `json:"totalUserNum"`
} `json:"totalUserNumList"`
}
type GetGroupStatisticsRequest struct {
GetStatisticsRequest
}
// 群聊统计
type GetGroupStatisticsResponse struct {
IncreaseGroupNum int `json:"increaseGroupNum"`
TotalGroupNum int `json:"totalGroupNum"`
IncreaseGroupNumList []struct {
Date string `json:"date"`
IncreaseGroupNum int `json:"increaseGroupNum"`
} `json:"increaseGroupNumList"`
TotalGroupNumList []struct {
Date string `json:"date"`
TotalGroupNum int `json:"totalGroupNum"`
} `json:"totalGroupNumList"`
}
type GetActiveUserRequest struct {
GetStatisticsRequest
// RequestPagination
}
type GetActiveUserResponse struct {
ActiveUserList []struct {
NickName string `json:"nickName"`
UserId string `json:"userID"`
MessageNum int `json:"messageNum"`
} `json:"activeUserList"`
}
type GetActiveGroupRequest struct {
GetStatisticsRequest
// RequestPagination
}
type GetActiveGroupResponse struct {
ActiveGroupList []struct {
GroupName string `json:"groupName"`
GroupId string `json:"groupID"`
MessageNum int `json:"messageNum"`
} `json:"activeGroupList"`
}
-76
View File
@@ -1,76 +0,0 @@
package cmsstruct
type UserResponse struct {
FaceURL string `json:"faceURL"`
Nickname string `json:"nickName"`
UserID string `json:"userID"`
CreateTime string `json:"createTime,omitempty"`
CreateIp string `json:"createIp,omitempty"`
LastLoginTime string `json:"lastLoginTime,omitempty"`
LastLoginIp string `json:"lastLoginIP,omitempty"`
LoginTimes int32 `json:"loginTimes"`
LoginLimit int32 `json:"loginLimit"`
IsBlock bool `json:"isBlock"`
PhoneNumber string `json:"phoneNumber"`
Email string `json:"email"`
Birth string `json:"birth"`
Gender int `json:"gender"`
}
type AddUserRequest struct {
OperationID string `json:"operationID" binding:"required"`
PhoneNumber string `json:"phoneNumber" binding:"required"`
UserId string `json:"userID" binding:"required"`
Name string `json:"name" binding:"required"`
Email string `json:"email"`
Birth string `json:"birth"`
Gender string `json:"gender"`
FaceURL string `json:"faceURL"`
}
type AddUserResponse struct {
}
type BlockUser struct {
UserResponse
BeginDisableTime string `json:"beginDisableTime"`
EndDisableTime string `json:"endDisableTime"`
}
type BlockUserRequest struct {
OperationID string `json:"operationID" binding:"required"`
UserID string `json:"userID" binding:"required"`
EndDisableTime string `json:"endDisableTime" binding:"required"`
}
type BlockUserResponse struct {
}
type UnblockUserRequest struct {
OperationID string `json:"operationID" binding:"required"`
UserID string `json:"userID" binding:"required"`
}
type UnBlockUserResponse struct {
}
type GetBlockUsersRequest struct {
OperationID string `json:"operationID" binding:"required"`
RequestPagination
}
type GetBlockUsersResponse struct {
BlockUsers []BlockUser `json:"blockUsers"`
ResponsePagination
UserNums int32 `json:"userNums"`
}
type GetUserIDByEmailAndPhoneNumberRequest struct {
OperationID string `json:"operationID" binding:"required"`
PhoneNumber string `json:"phoneNumber"`
Email string `json:"email"`
}
type GetUserIDByEmailAndPhoneNumberResponse struct {
UserIDList []string `json:"userIDList"`
}
-25
View File
@@ -37,10 +37,6 @@ type config struct {
GinPort []int `yaml:"openImApiPort"`
ListenIP string `yaml:"listenIP"`
}
CmsApi struct {
GinPort []int `yaml:"openImCmsApiPort"`
ListenIP string `yaml:"listenIP"`
}
Sdk struct {
WsPort []int `yaml:"openImSdkWsPort"`
DataDir []string `yaml:"dataDir"`
@@ -131,8 +127,6 @@ type config struct {
OpenImGroupPort []int `yaml:"openImGroupPort"`
OpenImAuthPort []int `yaml:"openImAuthPort"`
OpenImPushPort []int `yaml:"openImPushPort"`
OpenImAdminCmsPort []int `yaml:"openImAdminCmsPort"`
OpenImOfficePort []int `yaml:"openImOfficePort"`
OpenImConversationPort []int `yaml:"openImConversationPort"`
OpenImCachePort []int `yaml:"openImCachePort"`
OpenImRealTimeCommPort []int `yaml:"openImRealTimeCommPort"`
@@ -146,8 +140,6 @@ type config struct {
OpenImRelayName string `yaml:"openImRelayName"`
OpenImGroupName string `yaml:"openImGroupName"`
OpenImAuthName string `yaml:"openImAuthName"`
OpenImAdminCMSName string `yaml:"openImAdminCMSName"`
OpenImOfficeName string `yaml:"openImOfficeName"`
OpenImConversationName string `yaml:"openImConversationName"`
OpenImCacheName string `yaml:"openImCacheName"`
OpenImRealTimeCommName string `yaml:"openImRealTimeCommName"`
@@ -473,16 +465,6 @@ type config struct {
CloseTips string `yaml:"closeTips"`
} `yaml:"defaultTips"`
} `yaml:"conversationSetPrivate"`
WorkMomentsNotification struct {
Conversation PConversation `yaml:"conversation"`
OfflinePush POfflinePush `yaml:"offlinePush"`
DefaultTips PDefaultTips `yaml:"defaultTips"`
} `yaml:"workMomentsNotification"`
JoinDepartmentNotification struct {
Conversation PConversation `yaml:"conversation"`
OfflinePush POfflinePush `yaml:"offlinePush"`
DefaultTips PDefaultTips `yaml:"defaultTips"`
} `yaml:"joinDepartmentNotification"`
Signal struct {
OfflinePush struct {
Title string `yaml:"title"`
@@ -490,9 +472,6 @@ type config struct {
} `yaml:"signal"`
}
WorkMoment struct {
OnlyFriendCanSee bool `yaml:"onlyFriendCanSee"`
} `yaml:"workMoment"`
Rtc struct {
SignalTimeout string `yaml:"signalTimeout"`
} `yaml:"rtc"`
@@ -506,11 +485,7 @@ type config struct {
GroupPrometheusPort []int `yaml:"groupPrometheusPort"`
AuthPrometheusPort []int `yaml:"authPrometheusPort"`
PushPrometheusPort []int `yaml:"pushPrometheusPort"`
AdminCmsPrometheusPort []int `yaml:"adminCmsPrometheusPort"`
OfficePrometheusPort []int `yaml:"officePrometheusPort"`
OrganizationPrometheusPort []int `yaml:"organizationPrometheusPort"`
ConversationPrometheusPort []int `yaml:"conversationPrometheusPort"`
CachePrometheusPort []int `yaml:"cachePrometheusPort"`
RealTimeCommPrometheusPort []int `yaml:"realTimeCommPrometheusPort"`
MessageTransferPrometheusPort []int `yaml:"messageTransferPrometheusPort"`
} `yaml:"prometheus"`
-14
View File
@@ -94,9 +94,6 @@ const (
ConversationPrivateChatNotification = 1701
ConversationUnreadNotification = 1702
WorkMomentNotificationBegin = 1900
WorkMomentNotification = 1901
BusinessNotificationBegin = 2000
BusinessNotification = 2001
BusinessNotificationEnd = 2099
@@ -218,17 +215,6 @@ const (
VideoType = 2
ImageType = 3
// workMoment permission
WorkMomentPublic = 0
WorkMomentPrivate = 1
WorkMomentPermissionCanSee = 2
WorkMomentPermissionCantSee = 3
// workMoment sdk notification type
WorkMomentCommentNotification = 0
WorkMomentLikeNotification = 1
WorkMomentAtUserNotification = 2
// sendMsgStaus
MsgStatusNotExist = 0
MsgIsSending = 1
+1
View File
@@ -13,6 +13,7 @@ var (
ErrUserIDNotFound = &ErrInfo{UserIDNotFoundError, "UserIDNotFoundError", ""}
ErrGroupIDNotFound = &ErrInfo{GroupIDNotFoundError, "GroupIDNotFoundError", ""}
ErrGroupIDExisted = &ErrInfo{GroupIDNotFoundError, "GroupIDExisted", ""} // todo group id 已存在
ErrRecordNotFound = &ErrInfo{RecordNotFoundError, "RecordNotFoundError", ""}
+126 -115
View File
@@ -1,17 +1,14 @@
package cache
import (
"Open_IM/pkg/common/db/relation"
relationTb "Open_IM/pkg/common/db/table/relation"
"Open_IM/pkg/common/db/unrelation"
"Open_IM/pkg/common/tracelog"
"Open_IM/pkg/utils"
"context"
"encoding/json"
"github.com/dtm-labs/rockscache"
"github.com/go-redis/redis/v8"
"math/big"
"strconv"
"strings"
"time"
)
@@ -157,6 +154,27 @@ func (g *GroupCacheRedis) GetGroupMembersHash(ctx context.Context, groupID strin
})
}
func (g *GroupCacheRedis) GetGroupMemberHash1(ctx context.Context, groupIDs []string) (map[string]*relationTb.GroupSimpleUserID, error) {
// todo
mapGroupUserIDs, err := g.groupMember.FindJoinUserID(ctx, groupIDs)
if err != nil {
return nil, err
}
res := make(map[string]*relationTb.GroupSimpleUserID)
for _, groupID := range groupIDs {
userIDs := mapGroupUserIDs[groupID]
users := &relationTb.GroupSimpleUserID{}
if len(userIDs) > 0 {
utils.Sort(userIDs, true)
bi := big.NewInt(0)
bi.SetString(utils.Md5(strings.Join(userIDs, ";"))[0:8], 16)
users.Hash = bi.Uint64()
}
res[groupID] = users
}
return res, nil
}
func (g *GroupCacheRedis) DelGroupMembersHash(ctx context.Context, groupID string) (err error) {
defer func() {
tracelog.SetCtxDebug(ctx, utils.GetFuncName(1), err, "groupID", groupID)
@@ -178,111 +196,104 @@ func (g *GroupCacheRedis) DelGroupMemberIDs(ctx context.Context, groupID string)
return g.rcClient.TagAsDeleted(g.getGroupMemberIDsKey(groupID))
}
// JoinedGroups
func (g *GroupCacheRedis) GetJoinedGroupIDs(ctx context.Context, userID string) (joinedGroupIDs []string, err error) {
getJoinedGroupIDList := func() (string, error) {
joinedGroupList, err := relation.GetJoinedGroupIDListByUserID(userID)
if err != nil {
return "", err
}
bytes, err := json.Marshal(joinedGroupList)
if err != nil {
return "", utils.Wrap(err, "")
}
return string(bytes), nil
}
defer func() {
tracelog.SetCtxDebug(ctx, utils.GetFuncName(1), err, "userID", userID, "joinedGroupIDs", joinedGroupIDs)
}()
joinedGroupIDListStr, err := g.rcClient.Fetch(g.getJoinedGroupsKey(userID), time.Second*30*60, getJoinedGroupIDList)
if err != nil {
return nil, err
}
err = json.Unmarshal([]byte(joinedGroupIDListStr), &joinedGroupIDs)
return joinedGroupIDs, utils.Wrap(err, "")
}
//// JoinedGroups
//func (g *GroupCacheRedis) GetJoinedGroupIDs(ctx context.Context, userID string) (joinedGroupIDs []string, err error) {
// getJoinedGroupIDList := func() (string, error) {
// joinedGroupList, err := relation.GetJoinedGroupIDListByUserID(userID)
// if err != nil {
// return "", err
// }
// bytes, err := json.Marshal(joinedGroupList)
// if err != nil {
// return "", utils.Wrap(err, "")
// }
// return string(bytes), nil
// }
// defer func() {
// tracelog.SetCtxDebug(ctx, utils.GetFuncName(1), err, "userID", userID, "joinedGroupIDs", joinedGroupIDs)
// }()
// joinedGroupIDListStr, err := g.rcClient.Fetch(g.getJoinedGroupsKey(userID), time.Second*30*60, getJoinedGroupIDList)
// if err != nil {
// return nil, err
// }
// err = json.Unmarshal([]byte(joinedGroupIDListStr), &joinedGroupIDs)
// return joinedGroupIDs, utils.Wrap(err, "")
//}
func (g *GroupCacheRedis) DelJoinedGroupIDs(ctx context.Context, userID string) (err error) {
func (g *GroupCacheRedis) DelJoinedGroupID(ctx context.Context, userID string) (err error) {
defer func() {
tracelog.SetCtxDebug(ctx, utils.GetFuncName(1), err, "userID", userID)
}()
return g.rcClient.TagAsDeleted(g.getJoinedGroupsKey(userID))
}
// GetGroupMemberInfo
func (g *GroupCacheRedis) GetGroupMemberInfo(ctx context.Context, groupID, userID string) (groupMember *relation.GroupMember, err error) {
getGroupMemberInfo := func() (string, error) {
groupMemberInfo, err := relation.GetGroupMemberInfoByGroupIDAndUserID(groupID, userID)
if err != nil {
return "", err
}
bytes, err := json.Marshal(groupMemberInfo)
if err != nil {
return "", utils.Wrap(err, "")
}
return string(bytes), nil
}
defer func() {
tracelog.SetCtxDebug(ctx, utils.GetFuncName(1), err, "groupID", groupID, "userID", userID, "groupMember", *groupMember)
}()
groupMemberInfoStr, err := g.rcClient.Fetch(g.getGroupMemberInfoKey(groupID, userID), time.Second*30*60, getGroupMemberInfo)
if err != nil {
return nil, err
}
groupMember = &relation.GroupMember{}
err = json.Unmarshal([]byte(groupMemberInfoStr), groupMember)
return groupMember, utils.Wrap(err, "")
//func (g *GroupCacheRedis) DelJoinedGroupIDs(ctx context.Context, userIDs []string) (err error) {
// defer func() {
// tracelog.SetCtxDebug(ctx, utils.GetFuncName(1), err, "userID", userID)
// }()
// for _, userID := range userIDs {
// if err := g.DelJoinedGroupID(ctx, userID); err != nil {
// return err
// }
// }
// return nil
//}
func (g *GroupCacheRedis) GetGroupMemberInfo(ctx context.Context, groupID, userID string) (groupMember *relationTb.GroupMemberModel, err error) {
return GetCache(ctx, g.rcClient, g.getGroupMemberInfoKey(groupID, userID), g.expireTime, func(ctx context.Context) (*relationTb.GroupMemberModel, error) {
return g.groupMember.Take(ctx, groupID, userID)
})
}
func (g *GroupCacheRedis) GetGroupMembersInfo(ctx context.Context, groupID, userIDs []string) (groupMember *relationTb.GroupMemberModel, err error) {
//func (g *GroupCacheRedis) GetGroupMembersInfo(ctx context.Context, groupID, userIDs []string) (groupMember *relationTb.GroupMemberModel, err error) {
//
// return nil, err
//}
return nil, err
}
func (g *GroupCacheRedis) 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 *GroupCacheRedis) 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 *GroupCacheRedis) DelGroupMemberInfo(ctx context.Context, groupID, userID string) (err error) {
defer func() {
@@ -292,23 +303,23 @@ func (g *GroupCacheRedis) DelGroupMemberInfo(ctx context.Context, groupID, userI
}
// groupMemberNum
func (g *GroupCacheRedis) GetGroupMemberNum(ctx context.Context, groupID string) (num int, err error) {
getGroupMemberNum := func() (string, error) {
num, err := relation.GetGroupMemberNumByGroupID(groupID)
if err != nil {
return "", err
}
return strconv.Itoa(int(num)), nil
}
defer func() {
tracelog.SetCtxDebug(ctx, utils.GetFuncName(1), err, "groupID", groupID, "num", num)
}()
groupMember, err := g.rcClient.Fetch(g.getGroupMemberNumKey(groupID), time.Second*30*60, getGroupMemberNum)
if err != nil {
return 0, err
}
return strconv.Atoi(groupMember)
}
//func (g *GroupCacheRedis) GetGroupMemberNum(ctx context.Context, groupID string) (num int, err error) {
// getGroupMemberNum := func() (string, error) {
// num, err := relation.GetGroupMemberNumByGroupID(groupID)
// if err != nil {
// return "", err
// }
// return strconv.Itoa(int(num)), nil
// }
// defer func() {
// tracelog.SetCtxDebug(ctx, utils.GetFuncName(1), err, "groupID", groupID, "num", num)
// }()
// groupMember, err := g.rcClient.Fetch(g.getGroupMemberNumKey(groupID), time.Second*30*60, getGroupMemberNum)
// if err != nil {
// return 0, err
// }
// return strconv.Atoi(groupMember)
//}
func (g *GroupCacheRedis) DelGroupMemberNum(ctx context.Context, groupID string) (err error) {
defer func() {
-142
View File
@@ -1,142 +0,0 @@
package controller
import (
"Open_IM/pkg/common/db/relation"
"gorm.io/gorm"
"time"
)
type AdminCMSInterface 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) (activeGroups []*relation.ActiveGroup, err error)
GetActiveUsers(from, to time.Time, limit int) (activeUsers []*relation.ActiveUser, err error)
}
type AdminCMSController struct {
database AdminCMSDatabaseInterface
}
func NewAdminCMSController(db *gorm.DB) AdminCMSInterface {
adminCMSController := &AdminCMSController{
database: newAdminCMSDatabase(db),
}
return adminCMSController
}
func newAdminCMSDatabase(db *gorm.DB) AdminCMSDatabaseInterface {
return &AdminCMSDatabase{Statistics: relation.NewStatistics(db)}
}
func (admin *AdminCMSController) GetActiveUserNum(from, to time.Time) (num int64, err error) {
return admin.database.GetActiveUserNum(from, to)
}
func (admin *AdminCMSController) GetIncreaseUserNum(from, to time.Time) (num int64, err error) {
return admin.database.GetIncreaseUserNum(from, to)
}
func (admin *AdminCMSController) GetTotalUserNum() (num int64, err error) {
return admin.database.GetTotalUserNum()
}
func (admin *AdminCMSController) GetTotalUserNumByDate(to time.Time) (num int64, err error) {
return admin.database.GetTotalUserNumByDate(to)
}
func (admin *AdminCMSController) GetSingleChatMessageNum(from, to time.Time) (num int64, err error) {
return admin.GetSingleChatMessageNum(from, to)
}
func (admin *AdminCMSController) GetGroupMessageNum(from, to time.Time) (num int64, err error) {
return admin.database.GetGroupMessageNum(from, to)
}
func (admin *AdminCMSController) GetIncreaseGroupNum(from, to time.Time) (num int64, err error) {
return admin.database.GetIncreaseGroupNum(from, to)
}
func (admin *AdminCMSController) GetTotalGroupNum() (num int64, err error) {
return admin.database.GetTotalGroupNum()
}
func (admin *AdminCMSController) GetGroupNum(to time.Time) (num int64, err error) {
return admin.database.GetGroupNum(to)
}
func (admin *AdminCMSController) GetActiveGroups(from, to time.Time, limit int) ([]*relation.ActiveGroup, error) {
return admin.database.GetActiveGroups(from, to, limit)
}
func (admin *AdminCMSController) GetActiveUsers(from, to time.Time, limit int) (activeUsers []*relation.ActiveUser, err error) {
return admin.database.GetActiveUsers(from, to, limit)
}
type AdminCMSDatabaseInterface 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) ([]*relation.ActiveGroup, error)
GetActiveUsers(from, to time.Time, limit int) (activeUsers []*relation.ActiveUser, err error)
}
type AdminCMSDatabase struct {
Statistics *relation.Statistics
}
func (admin *AdminCMSDatabase) GetActiveUserNum(from, to time.Time) (num int64, err error) {
return admin.Statistics.GetActiveUserNum(from, to)
}
func (admin *AdminCMSDatabase) GetIncreaseUserNum(from, to time.Time) (num int64, err error) {
return admin.Statistics.GetIncreaseUserNum(from, to)
}
func (admin *AdminCMSDatabase) GetTotalUserNum() (num int64, err error) {
return admin.Statistics.GetTotalUserNum()
}
func (admin *AdminCMSDatabase) GetTotalUserNumByDate(to time.Time) (num int64, err error) {
return admin.Statistics.GetTotalUserNumByDate(to)
}
func (admin *AdminCMSDatabase) GetSingleChatMessageNum(from, to time.Time) (num int64, err error) {
return admin.Statistics.GetSingleChatMessageNum(from, to)
}
func (admin *AdminCMSDatabase) GetGroupMessageNum(from, to time.Time) (num int64, err error) {
return admin.Statistics.GetGroupMessageNum(from, to)
}
func (admin *AdminCMSDatabase) GetIncreaseGroupNum(from, to time.Time) (num int64, err error) {
return admin.Statistics.GetIncreaseGroupNum(from, to)
}
func (admin *AdminCMSDatabase) GetTotalGroupNum() (num int64, err error) {
return admin.Statistics.GetTotalGroupNum()
}
func (admin *AdminCMSDatabase) GetGroupNum(to time.Time) (num int64, err error) {
return admin.Statistics.GetGroupNum(to)
}
func (admin *AdminCMSDatabase) GetActiveGroups(from, to time.Time, limit int) ([]*relation.ActiveGroup, error) {
return admin.Statistics.GetActiveGroups(from, to, limit)
}
func (admin *AdminCMSDatabase) GetActiveUsers(from, to time.Time, limit int) (activeUsers []*relation.ActiveUser, err error) {
return admin.Statistics.GetActiveUsers(from, to, limit)
}
+19 -35
View File
@@ -15,8 +15,6 @@ import (
"github.com/go-redis/redis/v8"
"go.mongodb.org/mongo-driver/mongo"
"gorm.io/gorm"
"math/big"
"strings"
)
//type GroupInterface GroupDataBaseInterface
@@ -248,7 +246,7 @@ type GroupDataBase struct {
func (g *GroupDataBase) delGroupMemberCache(ctx context.Context, groupID string, userIDs []string) error {
for _, userID := range userIDs {
if err := g.cache.DelJoinedGroupIDs(ctx, userID); err != nil {
if err := g.cache.DelJoinedGroupID(ctx, userID); err != nil {
return err
}
if err := g.cache.DelJoinedSuperGroupIDs(ctx, userID); err != nil {
@@ -272,21 +270,24 @@ func (g *GroupDataBase) FindGroupMemberUserID(ctx context.Context, groupID strin
}
func (g *GroupDataBase) CreateGroup(ctx context.Context, groups []*relationTb.GroupModel, groupMembers []*relationTb.GroupMemberModel) error {
if len(groups) > 0 && len(groupMembers) > 0 {
return g.db.Transaction(func(tx *gorm.DB) error {
return g.db.Transaction(func(tx *gorm.DB) error {
if len(groups) > 0 {
if err := g.groupDB.Create(ctx, groups, tx); err != nil {
return err
}
return g.groupMemberDB.Create(ctx, groupMembers, tx)
})
}
if len(groups) > 0 {
return g.groupDB.Create(ctx, groups)
}
if len(groupMembers) > 0 {
return g.groupMemberDB.Create(ctx, groupMembers)
}
return nil
}
if len(groupMembers) > 0 {
if err := g.groupMemberDB.Create(ctx, groupMembers, tx); err != nil {
return err
}
//if err := g.cache.DelJoinedGroupIDs(ctx, utils.Slice(groupMembers, func(e *relationTb.GroupMemberModel) string {
// return e.UserID
//})); err != nil {
// return err
//}
}
return nil
})
}
func (g *GroupDataBase) TakeGroup(ctx context.Context, groupID string) (group *relationTb.GroupModel, err error) {
@@ -337,12 +338,11 @@ func (g *GroupDataBase) TakeGroupMember(ctx context.Context, groupID string, use
}
func (g *GroupDataBase) TakeGroupOwner(ctx context.Context, groupID string) (*relationTb.GroupMemberModel, error) {
return g.groupMemberDB.TakeOwner(ctx, groupID)
return g.groupMemberDB.TakeOwner(ctx, groupID) // todo cache group owner
}
func (g *GroupDataBase) FindGroupMember(ctx context.Context, groupIDs []string, userIDs []string, roleLevels []int32) ([]*relationTb.GroupMemberModel, error) {
//g.cache.GetGroupMembersInfo()
return g.groupMemberDB.Find(ctx, groupIDs, userIDs, roleLevels)
return g.groupMemberDB.Find(ctx, groupIDs, userIDs, roleLevels) // todo cache group find
}
func (g *GroupDataBase) PageGroupMember(ctx context.Context, groupIDs []string, userIDs []string, roleLevels []int32, pageNumber, showNumber int32) (uint32, []*relationTb.GroupMemberModel, error) {
@@ -383,23 +383,7 @@ func (g *GroupDataBase) DeleteGroupMember(ctx context.Context, groupID string, u
}
func (g *GroupDataBase) MapGroupMemberUserID(ctx context.Context, groupIDs []string) (map[string]*relationTb.GroupSimpleUserID, error) {
mapGroupUserIDs, err := g.groupMemberDB.FindJoinUserID(ctx, groupIDs)
if err != nil {
return nil, err
}
res := make(map[string]*relationTb.GroupSimpleUserID)
for _, groupID := range groupIDs {
userIDs := mapGroupUserIDs[groupID]
users := &relationTb.GroupSimpleUserID{}
if len(userIDs) > 0 {
utils.Sort(userIDs, true)
bi := big.NewInt(0)
bi.SetString(utils.Md5(strings.Join(userIDs, ";"))[0:8], 16)
users.Hash = bi.Uint64()
}
res[groupID] = users
}
return res, nil
return g.cache.GetGroupMemberHash1(ctx, groupIDs)
}
func (g *GroupDataBase) MapGroupMemberNum(ctx context.Context, groupIDs []string) (map[string]uint32, error) {
+4 -2
View File
@@ -8,10 +8,12 @@ import (
type MsgInterface interface {
BatchInsertChat2DB(ctx context.Context, userID string, msgList []*pbMsg.MsgDataToMQ, currentMaxSeq uint64) error
BatchInsertChat2Cache(ctx context.Context, insertID string, msgList []*pbMsg.MsgDataToMQ) (error, uint64)
DelMsgBySeqList(ctx context.Context, userID string, seqList []uint32) (totalUnExistSeqList []uint32, err error)
DelMsgLogic(ctx context.Context, uid string, seqList []uint32) error
// logic delete
DelMsgLogic(ctx context.Context, userID string, seqList []uint32) error
DelMsgBySeqListInOneDoc(ctx context.Context, docID string, seqList []uint32) (unExistSeqList []uint32, err error)
ReplaceMsgToBlankByIndex(suffixID string, index int) (replaceMaxSeq uint32, err error)
ReplaceMsgToBlankByIndex(docID string, index int) (replaceMaxSeq uint32, err error)
}
type MsgDatabaseInterface interface {
+5 -5
View File
@@ -30,11 +30,11 @@ type UserController struct {
}
// 获取指定用户的信息 如有userID未找到 也返回错误
func (u *UserController) FindWithError(ctx context.Context, userIDs []string) (users []*relation2.UserModel, err error) {
func (u *UserController) FindWithError(ctx context.Context, userIDs []string) (users []*relationTb.UserModel, err error) {
return u.database.FindWithError(ctx, userIDs)
}
func (u *UserController) Find(ctx context.Context, userIDs []string) (users []*relation2.UserModel, err error) {
func (u *UserController) Find(ctx context.Context, userIDs []string) (users []*relationTb.UserModel, err error) {
return u.database.Find(ctx, userIDs)
}
func (u *UserController) Create(ctx context.Context, users []*relationTb.UserModel) error {
@@ -90,7 +90,7 @@ func newUserDatabase(db *gorm.DB) *UserDatabase {
}
// 获取指定用户的信息 如有userID未找到 也返回错误
func (u *UserDatabase) FindWithError(ctx context.Context, userIDs []string) (users []*relation2.UserModel, err error) {
func (u *UserDatabase) FindWithError(ctx context.Context, userIDs []string) (users []*relationTb.UserModel, err error) {
users, err = u.user.Find(ctx, userIDs)
if err != nil {
return
@@ -102,7 +102,7 @@ func (u *UserDatabase) FindWithError(ctx context.Context, userIDs []string) (use
}
// 获取指定用户的信息 如有userID未找到 不返回错误
func (u *UserDatabase) Find(ctx context.Context, userIDs []string) (users []*relation2.UserModel, err error) {
func (u *UserDatabase) Find(ctx context.Context, userIDs []string) (users []*relationTb.UserModel, err error) {
users, err = u.user.Find(ctx, userIDs)
return
}
@@ -123,7 +123,7 @@ func (u *UserDatabase) UpdateByMap(ctx context.Context, userID string, args map[
}
// 获取,如果没找到,不返回错误
func (u *UserDatabase) Page(ctx context.Context, showNumber, pageNumber int32) (users []*relation2.UserModel, count int64, err error) {
func (u *UserDatabase) Page(ctx context.Context, showNumber, pageNumber int32) (users []*relationTb.UserModel, count int64, err error) {
return u.user.Page(ctx, showNumber, pageNumber)
}
-100
View File
@@ -1,100 +0,0 @@
package relation
import (
"Open_IM/pkg/common/config"
"fmt"
"time"
"gorm.io/driver/mysql"
"gorm.io/gorm"
"gorm.io/gorm/logger"
)
type Mysql struct {
gormConn *gorm.DB
}
func (m *Mysql) GormConn() *gorm.DB {
return m.gormConn
}
func (m *Mysql) SetGormConn(gormConn *gorm.DB) {
m.gormConn = gormConn
}
func (m *Mysql) InitConn() *Mysql {
dsn := fmt.Sprintf("%s:%s@tcp(%s)/%s?charset=utf8mb4&parseTime=true&loc=Local",
config.Config.Mysql.DBUserName, config.Config.Mysql.DBPassword, config.Config.Mysql.DBAddress[0], "mysql")
var db *gorm.DB
db, err := gorm.Open(mysql.Open(dsn), nil)
if err != nil {
time.Sleep(time.Duration(30) * time.Second)
db, err = gorm.Open(mysql.Open(dsn), nil)
if err != nil {
panic(err.Error() + " open failed " + dsn)
}
}
sql := fmt.Sprintf("CREATE DATABASE IF NOT EXISTS %s default charset utf8 COLLATE utf8_general_ci;", config.Config.Mysql.DBDatabaseName)
err = db.Exec(sql).Error
if err != nil {
panic(err.Error() + " Exec failed:" + sql)
}
dsn = fmt.Sprintf("%s:%s@tcp(%s)/%s?charset=utf8mb4&parseTime=true&loc=Local",
config.Config.Mysql.DBUserName, config.Config.Mysql.DBPassword, config.Config.Mysql.DBAddress[0], config.Config.Mysql.DBDatabaseName)
newLogger := logger.New(
Writer{},
logger.Config{
SlowThreshold: time.Duration(config.Config.Mysql.SlowThreshold) * time.Millisecond, // Slow SQL threshold
LogLevel: logger.LogLevel(config.Config.Mysql.LogLevel), // Log level
IgnoreRecordNotFoundError: true, // Ignore ErrRecordNotFound error for logger
Colorful: true, // Disable color
},
)
db, err = gorm.Open(mysql.Open(dsn), &gorm.Config{
Logger: newLogger,
})
if err != nil {
panic(err.Error() + " Open failed " + dsn)
}
sqlDB, err := db.DB()
if err != nil {
panic(err.Error() + " DB.DB() failed ")
}
sqlDB.SetConnMaxLifetime(time.Second * time.Duration(config.Config.Mysql.DBMaxLifeTime))
sqlDB.SetMaxOpenConns(config.Config.Mysql.DBMaxOpenConns)
sqlDB.SetMaxIdleConns(config.Config.Mysql.DBMaxIdleConns)
if db == nil {
panic("db is nil")
}
m.SetGormConn(db)
return m
}
//models := []interface{}{&Friend{}, &FriendRequest{}, &Group{}, &GroupMember{}, &GroupRequest{},
// &User{}, &Black{}, &ChatLog{}, &Conversation{}, &AppVersion{}}
func (m *Mysql) AutoMigrateModel(model interface{}) error {
err := m.gormConn.AutoMigrate(model)
if err != nil {
return err
}
m.gormConn.Set("gorm:table_options", "CHARSET=utf8")
m.gormConn.Set("gorm:table_options", "collation=utf8_unicode_ci")
_ = m.gormConn.Migrator().CreateTable(model)
return nil
}
type Writer struct{}
func (w Writer) Printf(format string, args ...interface{}) {
fmt.Printf(format, args...)
}
func getDBConn(db *gorm.DB, tx []any) *gorm.DB {
if len(tx) > 0 {
if txDB, ok := tx[0].(*gorm.DB); ok {
return txDB
}
}
return db
}
-101
View File
@@ -1,101 +0,0 @@
package relation
import (
"Open_IM/pkg/common/constant"
"gorm.io/gorm"
"time"
)
type Statistics struct {
DB *gorm.DB
}
func NewStatistics(db *gorm.DB) *Statistics {
return &Statistics{DB: db}
}
func (s *Statistics) getUserModel() *gorm.DB {
return s.DB.Model(&User{})
}
func (s *Statistics) getChatLogModel() *gorm.DB {
return s.DB.Model(&ChatLog{})
}
func (s *Statistics) getGroupModel() *gorm.DB {
return s.DB.Model(&Group{})
}
func (s *Statistics) GetActiveUserNum(from, to time.Time) (num int64, err error) {
err = s.getChatLogModel().Select("count(distinct(send_id))").Where("send_time >= ? and send_time <= ?", from, to).Count(&num).Error
return num, err
}
func (s *Statistics) GetIncreaseUserNum(from, to time.Time) (num int64, err error) {
err = s.getUserModel().Where("create_time >= ? and create_time <= ?", from, to).Count(&num).Error
return num, err
}
func (s *Statistics) GetTotalUserNum() (num int64, err error) {
err = s.getUserModel().Count(&num).Error
return num, err
}
func (s *Statistics) GetTotalUserNumByDate(to time.Time) (num int64, err error) {
err = s.getUserModel().Where("create_time <= ?", to).Count(&num).Error
return num, err
}
func (s *Statistics) GetSingleChatMessageNum(from, to time.Time) (num int64, err error) {
err = s.getChatLogModel().Where("send_time >= ? and send_time <= ? and session_type = ?", from, to, constant.SingleChatType).Count(&num).Error
return num, err
}
func (s *Statistics) GetGroupMessageNum(from, to time.Time) (num int64, err error) {
err = s.getChatLogModel().Where("send_time >= ? and send_time <= ? and session_type in (?)", from, to, []int{constant.GroupChatType, constant.SuperGroupChatType}).Count(&num).Error
return num, err
}
func (s *Statistics) GetIncreaseGroupNum(from, to time.Time) (num int64, err error) {
err = s.getGroupModel().Where("create_time >= ? and create_time <= ?", from, to).Count(&num).Error
return num, err
}
func (s *Statistics) GetTotalGroupNum() (num int64, err error) {
err = s.getGroupModel().Count(&num).Error
return num, err
}
func (s *Statistics) GetGroupNum(to time.Time) (num int64, err error) {
err = s.getGroupModel().Where("create_time <= ?", to).Count(&num).Error
return num, err
}
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
for _, activeGroup := range activeGroups {
group := Group{
GroupID: activeGroup.ID,
}
s.getGroupModel().Where("group_id= ? ", group.GroupID).Find(&group)
activeGroup.Name = group.GroupName
}
return activeGroups, err
}
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 {
user := User{
UserID: activeUser.ID,
}
err = s.getUserModel().Select("user_id, name").Find(&user).Error
if err != nil {
return nil, err
}
activeUser.Name = user.Nickname
activeUser.ID = user.UserID
}
return activeUsers, err
}
+14
View File
@@ -49,6 +49,20 @@ func (u UserMsgDocModel) GetSeqUid(uid string, seq uint32) string {
return u.getSeqUid(uid, seq)
}
func (u UserMsgDocModel) GetDocIDSeqsMap(uid string, seqs []uint32) map[string][]uint32 {
t := make(map[string][]uint32)
for i := 0; i < len(seqs); i++ {
seqUid := u.getSeqUid(uid, seqs[i])
if value, ok := t[seqUid]; !ok {
var temp []uint32
t[seqUid] = append(temp, seqs[i])
} else {
t[seqUid] = append(value, seqs[i])
}
}
return t
}
func (UserMsgDocModel) getMsgIndex(seq uint32) int {
seqSuffix := seq / singleGocMsgNum
var index uint32
-42
View File
@@ -1,42 +0,0 @@
package unrelation
import "context"
const (
CTag = "tag"
CSendLog = "send_log"
)
type TagModel struct {
UserID string `bson:"user_id"`
TagID string `bson:"tag_id"`
TagName string `bson:"tag_name"`
UserList []string `bson:"user_list"`
}
func (TagModel) TableName() string {
return CTag
}
type TagSendLogModel struct {
UserList []CommonUserModel `bson:"tag_list"`
SendID string `bson:"send_id"`
SenderPlatformID int32 `bson:"sender_platform_id"`
Content string `bson:"content"`
SendTime int64 `bson:"send_time"`
}
func (TagSendLogModel) TableName() string {
return CSendLog
}
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,48 +0,0 @@
package unrelation
import "context"
const (
CWorkMoment = "work_moment"
)
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 []*CommonUserModel `bson:"like_user_list"`
AtUserList []*CommonUserModel `bson:"at_user_list"`
PermissionUserList []*CommonUserModel `bson:"permission_user_list"`
Comments []*CommonUserModel `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 (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)
}
+2 -26
View File
@@ -61,20 +61,8 @@ func (m *Mongo) GetClient() *mongo.Client {
return m.db
}
func (m *Mongo) CreateTagIndex() {
if err := m.createMongoIndex(unrelation.CSendLog, false, "send_id", "-send_time"); err != nil {
panic(err.Error() + " index create failed " + unrelation.CSendLog + " send_id, -send_time")
}
if err := m.createMongoIndex(unrelation.CTag, false, "user_id", "-create_time"); err != nil {
panic(err.Error() + "index create failed " + unrelation.CTag + " user_id, -create_time")
}
if err := m.createMongoIndex(unrelation.CTag, true, "tag_id"); err != nil {
panic(err.Error() + "index create failed " + unrelation.CTag + " tag_id")
}
}
func (m *Mongo) CreateMsgIndex() {
if err := m.createMongoIndex(unrelation.CChat, false, "uid"); err != nil {
if err := m.createMongoIndex(unrelation, false, "uid"); err != nil {
fmt.Println(err.Error() + " index create failed " + unrelation.CChat + " uid, please create index by yourself in field uid")
}
}
@@ -88,21 +76,9 @@ func (m *Mongo) CreateSuperGroupIndex() {
}
}
func (m *Mongo) CreateWorkMomentIndex() {
if err := m.createMongoIndex(unrelation.CWorkMoment, true, "-create_time", "work_moment_id"); err != nil {
panic(err.Error() + "index create failed " + unrelation.CWorkMoment + " -create_time, work_moment_id")
}
if err := m.createMongoIndex(unrelation.CWorkMoment, true, "work_moment_id"); err != nil {
panic(err.Error() + "index create failed " + unrelation.CWorkMoment + " work_moment_id ")
}
if err := m.createMongoIndex(unrelation.CWorkMoment, false, "user_id", "-create_time"); err != nil {
panic(err.Error() + "index create failed " + unrelation.CWorkMoment + "user_id, -create_time")
}
}
func (m *Mongo) CreateExtendMsgSetIndex() {
if err := m.createMongoIndex(unrelation.CExtendMsgSet, true, "-create_time", "work_moment_id"); err != nil {
panic(err.Error() + "index create failed " + unrelation.CWorkMoment + " -create_time, work_moment_id")
panic(err.Error() + "index create failed " + unrelation.CExtendMsgSet + " -create_time, work_moment_id")
}
}
+20 -26
View File
@@ -69,7 +69,7 @@ package unrelation
// return nil
//}
//func (d *db.DataBases) ReplaceMsgByIndex(suffixUserID string, msg *open_im_sdk.MsgData, operationID string, seqIndex int) error {
//func (d *db.DataBases) ReplaceMsgByIndex(suffixUserID string, msg *sdkws.MsgData, operationID string, seqIndex int) error {
// log.NewInfo(operationID, utils.GetSelfFuncName(), suffixUserID, *msg)
// ctx, _ := context.WithTimeout(context.Background(), time.Duration(config.Config.Mongo.DBTimeout)*time.Second)
// c := d.mongoClient.Database(config.Config.Mongo.DBDatabase).Collection(cChat)
@@ -90,7 +90,7 @@ package unrelation
// return nil
//}
//func (d *db.DataBases) ReplaceMsgBySeq(uid string, msg *open_im_sdk.MsgData, operationID string) error {
//func (d *db.DataBases) ReplaceMsgBySeq(uid string, msg *sdkws.MsgData, operationID string) error {
// log.NewInfo(operationID, utils.GetSelfFuncName(), uid, *msg)
// ctx, _ := context.WithTimeout(context.Background(), time.Duration(config.Config.Mongo.DBTimeout)*time.Second)
// c := d.mongoClient.Database(config.Config.Mongo.DBDatabase).Collection(cChat)
@@ -122,7 +122,7 @@ package unrelation
// return err
//}
//
//func (d *db.DataBases) GetMsgBySeqList(uid string, seqList []uint32, operationID string) (seqMsg []*open_im_sdk.MsgData, err error) {
//func (d *db.DataBases) GetMsgBySeqList(uid string, seqList []uint32, operationID string) (seqMsg []*sdkws.MsgData, err error) {
// log.NewInfo(operationID, utils.GetSelfFuncName(), uid, seqList)
// var hasSeqList []uint32
// singleCount := 0
@@ -153,7 +153,7 @@ package unrelation
// }
// singleCount = 0
// for i := 0; i < len(sChat.Msg); i++ {
// msg := new(open_im_sdk.MsgData)
// msg := new(sdkws.MsgData)
// if err = proto.Unmarshal(sChat.Msg[i].Msg, msg); err != nil {
// log.NewError(operationID, "Unmarshal err", seqUid, value, uid, seqList, err.Error())
// return nil, err
@@ -217,11 +217,11 @@ package unrelation
// }
// for i, msg := range userChat.Msg {
// if i <= index {
// msgPb := &open_im_sdk.MsgData{}
// msgPb := &sdkws.MsgData{}
// if err = proto.Unmarshal(msg.Msg, msgPb); err != nil {
// continue
// }
// newMsgPb := &open_im_sdk.MsgData{Seq: msgPb.Seq}
// newMsgPb := &sdkws.MsgData{Seq: msgPb.Seq}
// bytes, err := proto.Marshal(newMsgPb)
// if err != nil {
// continue
@@ -235,7 +235,7 @@ package unrelation
// return replaceMaxSeq, err
//}
//
//func (d *db.DataBases) GetNewestMsg(ID string) (msg *open_im_sdk.MsgData, err error) {
//func (d *db.DataBases) GetNewestMsg(ID string) (msg *sdkws.MsgData, err error) {
// ctx, _ := context.WithTimeout(context.Background(), time.Duration(config.Config.Mongo.DBTimeout)*time.Second)
// c := d.mongoClient.Database(config.Config.Mongo.DBDatabase).Collection(cChat)
// regex := fmt.Sprintf("^%s", ID)
@@ -251,7 +251,7 @@ package unrelation
// }
// if len(userChats) > 0 {
// if len(userChats[0].Msg) > 0 {
// msgPb := &open_im_sdk.MsgData{}
// msgPb := &sdkws.MsgData{}
// err = proto.Unmarshal(userChats[0].Msg[len(userChats[0].Msg)-1].Msg, msgPb)
// if err != nil {
// return nil, utils.Wrap(err, "")
@@ -263,7 +263,7 @@ package unrelation
// return nil, nil
//}
//
//func (d *db.DataBases) GetOldestMsg(ID string) (msg *open_im_sdk.MsgData, err error) {
//func (d *db.DataBases) GetOldestMsg(ID string) (msg *sdkws.MsgData, err error) {
// ctx, _ := context.WithTimeout(context.Background(), time.Duration(config.Config.Mongo.DBTimeout)*time.Second)
// c := d.mongoClient.Database(config.Config.Mongo.DBDatabase).Collection(cChat)
// regex := fmt.Sprintf("^%s", ID)
@@ -288,7 +288,7 @@ package unrelation
// if len(oldestMsg) == 0 {
// oldestMsg = userChats[0].Msg[len(userChats[0].Msg)-1].Msg
// }
// msgPb := &open_im_sdk.MsgData{}
// msgPb := &sdkws.MsgData{}
// err = proto.Unmarshal(oldestMsg, msgPb)
// if err != nil {
// return nil, utils.Wrap(err, "")
@@ -298,7 +298,7 @@ package unrelation
// return nil, nil
//}
//
//func (d *db.DataBases) GetMsgBySeqListMongo2(uid string, seqList []uint32, operationID string) (seqMsg []*open_im_sdk.MsgData, err error) {
//func (d *db.DataBases) GetMsgBySeqListMongo2(uid string, seqList []uint32, operationID string) (seqMsg []*sdkws.MsgData, err error) {
// var hasSeqList []uint32
// singleCount := 0
// ctx, _ := context.WithTimeout(context.Background(), time.Duration(config.Config.Mongo.DBTimeout)*time.Second)
@@ -325,7 +325,7 @@ package unrelation
// }
// singleCount = 0
// for i := 0; i < len(sChat.Msg); i++ {
// msg := new(open_im_sdk.MsgData)
// msg := new(sdkws.MsgData)
// if err = proto.Unmarshal(sChat.Msg[i].Msg, msg); err != nil {
// log.NewError(operationID, "Unmarshal err", seqUid, value, uid, seqList, err.Error())
// return nil, err
@@ -349,7 +349,7 @@ package unrelation
// }
// return seqMsg, nil
//}
//func (d *db.DataBases) GetSuperGroupMsgBySeqListMongo(groupID string, seqList []uint32, operationID string) (seqMsg []*open_im_sdk.MsgData, err error) {
//func (d *db.DataBases) GetSuperGroupMsgBySeqListMongo(groupID string, seqList []uint32, operationID string) (seqMsg []*sdkws.MsgData, err error) {
// var hasSeqList []uint32
// singleCount := 0
// ctx, _ := context.WithTimeout(context.Background(), time.Duration(config.Config.Mongo.DBTimeout)*time.Second)
@@ -376,7 +376,7 @@ package unrelation
// }
// singleCount = 0
// for i := 0; i < len(sChat.Msg); i++ {
// msg := new(open_im_sdk.MsgData)
// msg := new(sdkws.MsgData)
// if err = proto.Unmarshal(sChat.Msg[i].Msg, msg); err != nil {
// log.NewError(operationID, "Unmarshal err", seqUid, value, groupID, seqList, err.Error())
// return nil, err
@@ -401,7 +401,7 @@ package unrelation
// return seqMsg, nil
//}
//
//func (d *db.DataBases) GetMsgAndIndexBySeqListInOneMongo2(suffixUserID string, seqList []uint32, operationID string) (seqMsg []*open_im_sdk.MsgData, indexList []int, unexistSeqList []uint32, err error) {
//func (d *db.DataBases) GetMsgAndIndexBySeqListInOneMongo2(suffixUserID string, seqList []uint32, operationID string) (seqMsg []*sdkws.MsgData, indexList []int, unexistSeqList []uint32, err error) {
// ctx, _ := context.WithTimeout(context.Background(), time.Duration(config.Config.Mongo.DBTimeout)*time.Second)
// c := d.mongoClient.Database(config.Config.Mongo.DBDatabase).Collection(cChat)
// sChat := UserChat{}
@@ -412,7 +412,7 @@ package unrelation
// singleCount := 0
// var hasSeqList []uint32
// for i := 0; i < len(sChat.Msg); i++ {
// msg := new(open_im_sdk.MsgData)
// msg := new(sdkws.MsgData)
// if err = proto.Unmarshal(sChat.Msg[i].Msg, msg); err != nil {
// log.NewError(operationID, "Unmarshal err", msg.String(), err.Error())
// return nil, nil, nil, err
@@ -436,18 +436,18 @@ package unrelation
// return seqMsg, indexList, unexistSeqList, nil
//}
//
//func genExceptionMessageBySeqList(seqList []uint32) (exceptionMsg []*open_im_sdk.MsgData) {
//func genExceptionMessageBySeqList(seqList []uint32) (exceptionMsg []*sdkws.MsgData) {
// for _, v := range seqList {
// msg := new(open_im_sdk.MsgData)
// msg := new(sdkws.MsgData)
// msg.Seq = v
// exceptionMsg = append(exceptionMsg, msg)
// }
// return exceptionMsg
//}
//
//func genExceptionSuperGroupMessageBySeqList(seqList []uint32, groupID string) (exceptionMsg []*open_im_sdk.MsgData) {
//func genExceptionSuperGroupMessageBySeqList(seqList []uint32, groupID string) (exceptionMsg []*sdkws.MsgData) {
// for _, v := range seqList {
// msg := new(open_im_sdk.MsgData)
// msg := new(sdkws.MsgData)
// msg.Seq = v
// msg.GroupID = groupID
// msg.SessionType = constant.SuperGroupChatType
@@ -598,13 +598,7 @@ package unrelation
// return utils.Md5(tagName + userID + strconv.Itoa(rand.Int()) + time.Now().String())
//}
//func generateWorkMomentID(userID string) string {
// return utils.Md5(userID + strconv.Itoa(rand.Int()) + time.Now().String())
//}
//func generateWorkMomentCommentID(workMomentID string) string {
// return utils.Md5(workMomentID + strconv.Itoa(rand.Int()) + time.Now().String())
//}
//func getCurrentTimestampByMill() int64 {
// return time.Now().UnixNano() / 1e6
+24 -21
View File
@@ -121,7 +121,7 @@ func (m *MsgMongoDriver) ReplaceMsgByIndex(ctx context.Context, suffixUserID str
return nil
}
func (d *db.DataBases) ReplaceMsgBySeq(uid string, msg *open_im_sdk.MsgData, operationID string) error {
func (d *db.DataBases) ReplaceMsgBySeq(uid string, msg *sdkws.MsgData, operationID string) error {
log.NewInfo(operationID, utils.GetSelfFuncName(), uid, *msg)
ctx, _ := context.WithTimeout(context.Background(), time.Duration(config.Config.Mongo.DBTimeout)*time.Second)
c := d.mongoClient.Database(config.Config.Mongo.DBDatabase).Collection(cChat)
@@ -153,7 +153,7 @@ func (d *db.DataBases) UpdateOneMsgList(msg *UserChat) error {
return err
}
func (d *db.DataBases) GetMsgBySeqList(uid string, seqList []uint32, operationID string) (seqMsg []*open_im_sdk.MsgData, err error) {
func (d *db.DataBases) GetMsgBySeqList(uid string, seqList []uint32, operationID string) (seqMsg []*sdkws.MsgData, err error) {
log.NewInfo(operationID, utils.GetSelfFuncName(), uid, seqList)
var hasSeqList []uint32
singleCount := 0
@@ -184,7 +184,7 @@ func (d *db.DataBases) GetMsgBySeqList(uid string, seqList []uint32, operationID
}
singleCount = 0
for i := 0; i < len(sChat.Msg); i++ {
msg := new(open_im_sdk.MsgData)
msg := new(sdkws.MsgData)
if err = proto.Unmarshal(sChat.Msg[i].Msg, msg); err != nil {
log.NewError(operationID, "Unmarshal err", seqUid, value, uid, seqList, err.Error())
return nil, err
@@ -209,10 +209,11 @@ func (d *db.DataBases) GetMsgBySeqList(uid string, seqList []uint32, operationID
return seqMsg, nil
}
func (d *db.DataBases) GetUserMsgListByIndex(ID string, index int64) (*UserChat, error) {
// model
func (d *db.DataBases) GetUserMsgListByIndex(docID string, index int64) (*UserChat, error) {
ctx, _ := context.WithTimeout(context.Background(), time.Duration(config.Config.Mongo.DBTimeout)*time.Second)
c := d.mongoClient.Database(config.Config.Mongo.DBDatabase).Collection(cChat)
regex := fmt.Sprintf("^%s", ID)
regex := fmt.Sprintf("^%s", docID)
findOpts := options.Find().SetLimit(1).SetSkip(index).SetSort(bson.M{"uid": 1})
var msgs []UserChat
//primitive.Regex{Pattern: regex}
@@ -231,6 +232,7 @@ func (d *db.DataBases) GetUserMsgListByIndex(ID string, index int64) (*UserChat,
}
}
// model
func (d *db.DataBases) DelMongoMsgs(IDList []string) error {
ctx, _ := context.WithTimeout(context.Background(), time.Duration(config.Config.Mongo.DBTimeout)*time.Second)
c := d.mongoClient.Database(config.Config.Mongo.DBDatabase).Collection(cChat)
@@ -238,6 +240,7 @@ func (d *db.DataBases) DelMongoMsgs(IDList []string) error {
return err
}
// model
func (d *db.DataBases) ReplaceMsgToBlankByIndex(suffixID string, index int) (replaceMaxSeq uint32, err error) {
ctx, _ := context.WithTimeout(context.Background(), time.Duration(config.Config.Mongo.DBTimeout)*time.Second)
c := d.mongoClient.Database(config.Config.Mongo.DBDatabase).Collection(cChat)
@@ -248,11 +251,11 @@ func (d *db.DataBases) ReplaceMsgToBlankByIndex(suffixID string, index int) (rep
}
for i, msg := range userChat.Msg {
if i <= index {
msgPb := &open_im_sdk.MsgData{}
msgPb := &sdkws.MsgData{}
if err = proto.Unmarshal(msg.Msg, msgPb); err != nil {
continue
}
newMsgPb := &open_im_sdk.MsgData{Seq: msgPb.Seq}
newMsgPb := &sdkws.MsgData{Seq: msgPb.Seq}
bytes, err := proto.Marshal(newMsgPb)
if err != nil {
continue
@@ -266,7 +269,7 @@ func (d *db.DataBases) ReplaceMsgToBlankByIndex(suffixID string, index int) (rep
return replaceMaxSeq, err
}
func (d *db.DataBases) GetNewestMsg(ID string) (msg *open_im_sdk.MsgData, err error) {
func (d *db.DataBases) GetNewestMsg(ID string) (msg *sdkws.MsgData, err error) {
ctx, _ := context.WithTimeout(context.Background(), time.Duration(config.Config.Mongo.DBTimeout)*time.Second)
c := d.mongoClient.Database(config.Config.Mongo.DBDatabase).Collection(cChat)
regex := fmt.Sprintf("^%s", ID)
@@ -282,7 +285,7 @@ func (d *db.DataBases) GetNewestMsg(ID string) (msg *open_im_sdk.MsgData, err er
}
if len(userChats) > 0 {
if len(userChats[0].Msg) > 0 {
msgPb := &open_im_sdk.MsgData{}
msgPb := &sdkws.MsgData{}
err = proto.Unmarshal(userChats[0].Msg[len(userChats[0].Msg)-1].Msg, msgPb)
if err != nil {
return nil, utils.Wrap(err, "")
@@ -294,7 +297,7 @@ func (d *db.DataBases) GetNewestMsg(ID string) (msg *open_im_sdk.MsgData, err er
return nil, nil
}
func (d *db.DataBases) GetOldestMsg(ID string) (msg *open_im_sdk.MsgData, err error) {
func (d *db.DataBases) GetOldestMsg(ID string) (msg *sdkws.MsgData, err error) {
ctx, _ := context.WithTimeout(context.Background(), time.Duration(config.Config.Mongo.DBTimeout)*time.Second)
c := d.mongoClient.Database(config.Config.Mongo.DBDatabase).Collection(cChat)
regex := fmt.Sprintf("^%s", ID)
@@ -319,7 +322,7 @@ func (d *db.DataBases) GetOldestMsg(ID string) (msg *open_im_sdk.MsgData, err er
if len(oldestMsg) == 0 {
oldestMsg = userChats[0].Msg[len(userChats[0].Msg)-1].Msg
}
msgPb := &open_im_sdk.MsgData{}
msgPb := &sdkws.MsgData{}
err = proto.Unmarshal(oldestMsg, msgPb)
if err != nil {
return nil, utils.Wrap(err, "")
@@ -329,7 +332,7 @@ func (d *db.DataBases) GetOldestMsg(ID string) (msg *open_im_sdk.MsgData, err er
return nil, nil
}
func (d *db.DataBases) GetMsgBySeqListMongo2(uid string, seqList []uint32, operationID string) (seqMsg []*open_im_sdk.MsgData, err error) {
func (d *db.DataBases) GetMsgBySeqListMongo2(uid string, seqList []uint32, operationID string) (seqMsg []*sdkws.MsgData, err error) {
var hasSeqList []uint32
singleCount := 0
ctx, _ := context.WithTimeout(context.Background(), time.Duration(config.Config.Mongo.DBTimeout)*time.Second)
@@ -356,7 +359,7 @@ func (d *db.DataBases) GetMsgBySeqListMongo2(uid string, seqList []uint32, opera
}
singleCount = 0
for i := 0; i < len(sChat.Msg); i++ {
msg := new(open_im_sdk.MsgData)
msg := new(sdkws.MsgData)
if err = proto.Unmarshal(sChat.Msg[i].Msg, msg); err != nil {
log.NewError(operationID, "Unmarshal err", seqUid, value, uid, seqList, err.Error())
return nil, err
@@ -380,7 +383,7 @@ func (d *db.DataBases) GetMsgBySeqListMongo2(uid string, seqList []uint32, opera
}
return seqMsg, nil
}
func (d *db.DataBases) GetSuperGroupMsgBySeqListMongo(groupID string, seqList []uint32, operationID string) (seqMsg []*open_im_sdk.MsgData, err error) {
func (d *db.DataBases) GetSuperGroupMsgBySeqListMongo(groupID string, seqList []uint32, operationID string) (seqMsg []*sdkws.MsgData, err error) {
var hasSeqList []uint32
singleCount := 0
ctx, _ := context.WithTimeout(context.Background(), time.Duration(config.Config.Mongo.DBTimeout)*time.Second)
@@ -407,7 +410,7 @@ func (d *db.DataBases) GetSuperGroupMsgBySeqListMongo(groupID string, seqList []
}
singleCount = 0
for i := 0; i < len(sChat.Msg); i++ {
msg := new(open_im_sdk.MsgData)
msg := new(sdkws.MsgData)
if err = proto.Unmarshal(sChat.Msg[i].Msg, msg); err != nil {
log.NewError(operationID, "Unmarshal err", seqUid, value, groupID, seqList, err.Error())
return nil, err
@@ -432,7 +435,7 @@ func (d *db.DataBases) GetSuperGroupMsgBySeqListMongo(groupID string, seqList []
return seqMsg, nil
}
func (d *db.DataBases) GetMsgAndIndexBySeqListInOneMongo2(suffixUserID string, seqList []uint32, operationID string) (seqMsg []*open_im_sdk.MsgData, indexList []int, unexistSeqList []uint32, err error) {
func (d *db.DataBases) GetMsgAndIndexBySeqListInOneMongo2(suffixUserID string, seqList []uint32, operationID string) (seqMsg []*sdkws.MsgData, indexList []int, unexistSeqList []uint32, err error) {
ctx, _ := context.WithTimeout(context.Background(), time.Duration(config.Config.Mongo.DBTimeout)*time.Second)
c := d.mongoClient.Database(config.Config.Mongo.DBDatabase).Collection(cChat)
sChat := UserChat{}
@@ -443,7 +446,7 @@ func (d *db.DataBases) GetMsgAndIndexBySeqListInOneMongo2(suffixUserID string, s
singleCount := 0
var hasSeqList []uint32
for i := 0; i < len(sChat.Msg); i++ {
msg := new(open_im_sdk.MsgData)
msg := new(sdkws.MsgData)
if err = proto.Unmarshal(sChat.Msg[i].Msg, msg); err != nil {
log.NewError(operationID, "Unmarshal err", msg.String(), err.Error())
return nil, nil, nil, err
@@ -467,18 +470,18 @@ func (d *db.DataBases) GetMsgAndIndexBySeqListInOneMongo2(suffixUserID string, s
return seqMsg, indexList, unexistSeqList, nil
}
func genExceptionMessageBySeqList(seqList []uint32) (exceptionMsg []*open_im_sdk.MsgData) {
func genExceptionMessageBySeqList(seqList []uint32) (exceptionMsg []*sdkws.MsgData) {
for _, v := range seqList {
msg := new(open_im_sdk.MsgData)
msg := new(sdkws.MsgData)
msg.Seq = v
exceptionMsg = append(exceptionMsg, msg)
}
return exceptionMsg
}
func genExceptionSuperGroupMessageBySeqList(seqList []uint32, groupID string) (exceptionMsg []*open_im_sdk.MsgData) {
func genExceptionSuperGroupMessageBySeqList(seqList []uint32, groupID string) (exceptionMsg []*sdkws.MsgData) {
for _, v := range seqList {
msg := new(open_im_sdk.MsgData)
msg := new(sdkws.MsgData)
msg.Seq = v
msg.GroupID = groupID
msg.SessionType = constant.SuperGroupChatType
-117
View File
@@ -1,117 +0,0 @@
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"
"math/rand"
"strconv"
"time"
)
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) generateTagID(tagName, userID string) string {
return utils.Md5(tagName + userID + strconv.Itoa(rand.Int()) + time.Now().String())
}
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
}
-151
View File
@@ -1,151 +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"
"math/rand"
"strconv"
"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) generateWorkMomentID(userID string) string {
return utils.Md5(userID + strconv.Itoa(rand.Int()) + time.Now().String())
}
func (db *WorkMomentMongoDriver) generateWorkMomentCommentID(workMomentID string) string {
return utils.Md5(workMomentID + strconv.Itoa(rand.Int()) + time.Now().String())
}
func (db *WorkMomentMongoDriver) CreateOneWorkMoment(ctx context.Context, workMoment *unrelation.WorkMoment) error {
workMomentID := db.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
}
File diff suppressed because it is too large Load Diff
-175
View File
@@ -1,175 +0,0 @@
syntax = "proto3";
option go_package = "Open_IM/pkg/proto/admincms;admincms";
import "Open-IM-Server/pkg/proto/sdkws/ws.proto";
package admincms;
message AdminLoginReq {
string adminID = 2;
string secret = 3;
}
message AdminLoginResp {
string token = 1;
string userName = 2;
string faceURL = 3;
}
message GetChatLogsReq {
string content = 1;
string sendID = 2;
string recvID = 3;
string sendTime = 4;
int32 sessionType = 5;
int32 contentType = 6;
sdkws.RequestPagination pagination = 7;
}
message ChatLog {
string serverMsgID = 1;
string clientMsgID = 2;
string sendID = 3;
string recvID = 4;
string groupID = 5;
string recvNickname = 6;
int32 senderPlatformID = 7;
string senderNickname = 8;
string senderFaceURL = 9;
string groupName = 10;
int32 sessionType = 11;
int32 msgFrom = 12;
int32 contentType = 13;
string content = 14;
int32 status = 15;
int64 sendTime = 16;
int64 createTime = 17;
string ex = 18;
}
message GetChatLogsResp {
repeated ChatLog chatLogs = 1;
int32 chatLogsNum = 2;
}
message StatisticsReq {
string from = 1;
string to = 2;
}
message GetActiveUserReq{
StatisticsReq statisticsReq = 1;
}
message UserResp{
string nickName = 1;
string userID = 2;
int32 messageNum = 3;
}
message GetActiveUserResp {
repeated UserResp Users = 1;
}
message GetActiveGroupReq{
StatisticsReq statisticsReq = 1;
}
message GroupResp {
string GroupName = 1;
string GroupID = 2;
int32 MessageNum = 3;
}
message GetActiveGroupResp {
repeated GroupResp Groups = 1;
}
message DateNumList {
string Date = 1;
int32 Num = 2;
}
message GetMessageStatisticsReq {
StatisticsReq StatisticsReq = 1;
}
message GetMessageStatisticsResp {
int32 PrivateMessageNum = 1;
int32 GroupMessageNum = 2;
repeated DateNumList PrivateMessageNumList = 3;
repeated DateNumList GroupMessageNumList = 4;
}
message GetGroupStatisticsReq {
StatisticsReq StatisticsReq = 1;
}
message GetGroupStatisticsResp {
int32 IncreaseGroupNum = 1;
int32 TotalGroupNum = 2;
repeated DateNumList IncreaseGroupNumList = 3;
repeated DateNumList TotalGroupNumList = 4;
}
message GetUserStatisticsReq {
StatisticsReq StatisticsReq = 1;
string OperationID = 2;
}
message GetUserStatisticsResp {
int32 IncreaseUserNum = 1;
int32 ActiveUserNum = 2;
int32 TotalUserNum = 3;
repeated DateNumList IncreaseUserNumList = 4;
repeated DateNumList ActiveUserNumList = 5;
repeated DateNumList TotalUserNumList = 6;
}
message GetUserFriendsReq {
string operationID = 1;
string userID = 2;
string friendUserID = 3;
string friendUserName = 4;
sdkws.RequestPagination pagination = 5;
}
message GetUserFriendsResp {
repeated sdkws.FriendInfo friendInfoList = 2;
int32 friendNums = 3;
}
message GetUserIDByEmailAndPhoneNumberReq{
string email = 2;
string phoneNumber = 3;
}
message GetUserIDByEmailAndPhoneNumberResp{
repeated string userIDList = 1;
}
message GetUserTokenReq {
string userID = 1;
int32 platformID = 2;
}
message GetUserTokenResp {
string token = 1;
int64 expTime = 2;
}
service adminCMS {
rpc AdminLogin(AdminLoginReq) returns(AdminLoginResp);
rpc GetChatLogs(GetChatLogsReq) returns(GetChatLogsResp);
rpc GetActiveUser(GetActiveUserReq) returns(GetActiveUserResp);
rpc GetActiveGroup(GetActiveGroupReq) returns(GetActiveGroupResp);
rpc GetMessageStatistics(GetMessageStatisticsReq) returns(GetMessageStatisticsResp);
rpc GetGroupStatistics(GetGroupStatisticsReq) returns(GetGroupStatisticsResp);
rpc GetUserStatistics(GetUserStatisticsReq) returns(GetUserStatisticsResp);
rpc GetUserFriends(GetUserFriendsReq) returns(GetUserFriendsResp);
rpc GetUserIDByEmailAndPhoneNumber(GetUserIDByEmailAndPhoneNumberReq) returns(GetUserIDByEmailAndPhoneNumberResp);
rpc GetUserToken(GetUserTokenReq) returns(GetUserTokenResp);
}
File diff suppressed because it is too large Load Diff
-303
View File
@@ -1,303 +0,0 @@
syntax = "proto3";
import "Open-IM-Server/pkg/proto/sdkws/ws.proto";
option go_package = "Open_IM/pkg/proto/office;office";
package office;
message CommonResp{
int32 errCode = 1;
string errMsg = 2;
}
message TagUser {
string userID = 1;
string userName = 2;
}
message Tag {
string tagID = 1;
string tagName = 2;
repeated TagUser userList = 3;
}
message GetUserTagsReq{
string userID = 1;
string operationID = 2;
}
message GetUserTagsResp{
CommonResp commonResp = 1;
repeated Tag tags = 2;
}
message CreateTagReq {
string tagName = 1;
string userID = 2;
repeated string userIDList = 3;
string operationID = 4;
}
message CreateTagResp {
CommonResp commonResp = 1;
}
message DeleteTagReq {
string userID = 1;
string tagID = 2;
string operationID = 3;
}
message DeleteTagResp {
CommonResp commonResp = 1;
}
message SetTagReq {
string userID = 1;
string tagID = 2;
string newName = 3;
repeated string increaseUserIDList = 4;
repeated string reduceUserIDList = 5;
string operationID = 6;
}
message SetTagResp {
CommonResp commonResp = 1;
}
message SendMsg2TagReq {
repeated string tagList = 1;
repeated string UserList = 2;
repeated string GroupList = 3;
string sendID = 4;
int32 senderPlatformID = 5;
string content = 6;
string operationID = 7;
}
message SendMsg2TagResp {
CommonResp commonResp = 1;
}
message GetTagSendLogsReq {
sdkws.RequestPagination Pagination = 1;
string userID = 2;
string operationID = 3;
}
message TagSendLog {
repeated TagUser userList = 1;
string content = 2;
int64 sendTime = 3;
}
message GetTagSendLogsResp {
CommonResp commonResp = 1;
sdkws.ResponsePagination Pagination = 2;
repeated TagSendLog tagSendLogs = 3;
}
message GetUserTagByIDReq {
string userID = 1;
string tagID = 2;
string operationID = 3;
}
message GetUserTagByIDResp {
CommonResp commonResp = 1;
Tag tag = 2;
}
/// WorkMoment
message LikeUser {
string userID = 1;
string userName = 2;
}
message NotificationUser {
string userID = 1;
string userName = 2;
}
message Comment {
string userID = 1;
string userName = 2;
string faceURL = 3;
string replyUserID = 4;
string replyUserName = 5;
string contentID = 6;
string content = 7;
int32 createTime = 8;
}
message PermissionGroup {
string groupName = 1;
string groupID = 2;
}
message WorkMomentUser {
string userID = 1;
string userName = 2;
}
message WorkMoment {
string workMomentID = 1;
string userID = 2;
string userName = 3;
string faceURL = 4;
string content = 5;
repeated WorkMomentUser likeUserList = 6;
repeated Comment comments = 7;
int32 permission = 8;
repeated WorkMomentUser permissionUserList = 9;
repeated PermissionGroup permissionGroupList = 10;
repeated WorkMomentUser atUserList = 11;
int32 createTime = 12;
}
message CreateOneWorkMomentReq {
WorkMoment workMoment = 1;
string operationID = 2;
}
message CreateOneWorkMomentResp {
CommonResp commonResp = 1;
}
message DeleteOneWorkMomentReq {
string workMomentID = 1;
string userID = 2;
string operationID = 3;
}
message DeleteOneWorkMomentResp {
CommonResp commonResp = 1;
}
message LikeOneWorkMomentReq {
string userID = 1;
string WorkMomentID = 2;
string operationID = 3;
}
message LikeOneWorkMomentResp {
CommonResp commonResp = 1;
}
message CommentOneWorkMomentReq {
string userID = 1;
string workMomentID = 2;
string replyUserID = 3;
string content = 4;
string operationID = 5;
}
message CommentOneWorkMomentResp {
CommonResp commonResp = 1;
}
message DeleteCommentReq {
string workMomentID = 1;
string contentID = 2;
string opUserID = 3;
string operationID = 4;
}
message DeleteCommentResp {
CommonResp commonResp = 1;
}
message GetWorkMomentByIDReq {
string workMomentID = 1;
string opUserID = 2;
string operationID = 3;
}
message GetWorkMomentByIDResp {
CommonResp commonResp = 1;
WorkMoment workMoment = 2;
}
message ChangeWorkMomentPermissionReq {
string workMomentID = 1;
string opUserID = 2;
int32 permission = 3;
repeated string permissionUserIDList = 4;
string operationID = 5;
}
message ChangeWorkMomentPermissionResp {
CommonResp commonResp = 1;
}
message GetUserWorkMomentsReq {
string userID = 1;
string opUserID = 2;
sdkws.RequestPagination Pagination = 3;
string operationID = 4;
}
message GetUserWorkMomentsResp {
CommonResp commonResp = 1;
repeated WorkMoment workMoments = 2;
sdkws.ResponsePagination Pagination = 3;
}
message GetUserFriendWorkMomentsReq {
string userID = 1;
sdkws.RequestPagination Pagination = 2;
string operationID = 3;
}
message GetUserFriendWorkMomentsResp {
CommonResp commonResp = 1;
repeated WorkMoment workMoments = 2;
sdkws.ResponsePagination Pagination = 3;
}
message WorkMomentNotificationMsg {
int32 notificationMsgType = 1;
string replyUserName = 2;
string replyUserID = 3;
string content = 4;
string contentID = 5;
string workMomentID = 6;
string userID = 7;
string userName = 8;
string faceURL = 9;
string workMomentContent = 10;
int32 createTime = 11;
}
message SetUserWorkMomentsLevelReq {
string userID = 1;
int32 level = 2;
string operationID = 3;
}
message SetUserWorkMomentsLevelResp {
CommonResp commonResp = 1;
}
service OfficeService {
rpc GetUserTags(GetUserTagsReq) returns(GetUserTagsResp);
rpc CreateTag(CreateTagReq) returns(CreateTagResp);
rpc DeleteTag(DeleteTagReq) returns(DeleteTagResp);
rpc SetTag(SetTagReq) returns(SetTagResp);
rpc SendMsg2Tag(SendMsg2TagReq) returns(SendMsg2TagResp);
rpc GetTagSendLogs(GetTagSendLogsReq) returns(GetTagSendLogsResp);
rpc GetUserTagByID(GetUserTagByIDReq) returns(GetUserTagByIDResp);
rpc CreateOneWorkMoment(CreateOneWorkMomentReq) returns(CreateOneWorkMomentResp);
rpc DeleteOneWorkMoment(DeleteOneWorkMomentReq) returns(DeleteOneWorkMomentResp);
rpc LikeOneWorkMoment(LikeOneWorkMomentReq) returns(LikeOneWorkMomentResp);
rpc CommentOneWorkMoment(CommentOneWorkMomentReq) returns(CommentOneWorkMomentResp);
rpc DeleteComment(DeleteCommentReq) returns(DeleteCommentResp);
rpc GetWorkMomentByID(GetWorkMomentByIDReq) returns(GetWorkMomentByIDResp);
rpc ChangeWorkMomentPermission(ChangeWorkMomentPermissionReq) returns(ChangeWorkMomentPermissionResp);
/// user self
rpc GetUserWorkMoments(GetUserWorkMomentsReq) returns(GetUserWorkMomentsResp);
/// users friend
rpc GetUserFriendWorkMoments(GetUserFriendWorkMomentsReq) returns(GetUserFriendWorkMomentsResp);
rpc SetUserWorkMomentsLevel(SetUserWorkMomentsLevelReq) returns(SetUserWorkMomentsLevelResp);
}
-2
View File
@@ -1,6 +1,5 @@
all_proto=(
admin_cms/admin_cms.proto
auth/auth.proto
friend/friend.proto
group/group.proto
@@ -11,5 +10,4 @@ all_proto=(
relay/relay.proto
sdkws/ws.proto
conversation/conversation.proto
office/office.proto
)
-6
View File
@@ -349,12 +349,6 @@ message GroupMemberInfoSetTips{
}
message OrganizationChangedTips{
UserInfo opUser = 2;
int64 operationTime = 3;
}
//////////////////////friend/////////////////////
message FriendApplication{
+13
View File
@@ -412,3 +412,16 @@ func (o *sortSlice[E]) Swap(i, j int) {
type Ordered interface {
~int | ~int8 | ~int16 | ~int32 | ~int64 | ~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~uintptr | ~float32 | ~float64 | ~string
}
func Unwrap(err error) error {
for err != nil {
unwrap, ok := err.(interface {
Unwrap() error
})
if !ok {
break
}
err = unwrap.Unwrap()
}
return err
}