mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-05-24 22:09:17 +08:00
cms
This commit is contained in:
parent
c7d544685e
commit
6774a8594f
63
internal/cms_api/friend/friend.go
Normal file
63
internal/cms_api/friend/friend.go
Normal file
@ -0,0 +1,63 @@
|
||||
package friend
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/cms_api_struct"
|
||||
"Open_IM/pkg/common/config"
|
||||
"Open_IM/pkg/common/log"
|
||||
"Open_IM/pkg/grpc-etcdv3/getcdv3"
|
||||
pbAdmin "Open_IM/pkg/proto/admin_cms"
|
||||
pbCommon "Open_IM/pkg/proto/sdk_ws"
|
||||
"Open_IM/pkg/utils"
|
||||
"context"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
func GetUserFriends(c *gin.Context) {
|
||||
var (
|
||||
req cms_api_struct.GetFriendsReq
|
||||
resp cms_api_struct.GetFriendsResp
|
||||
reqPb pbAdmin.GetUserFriendsReq
|
||||
)
|
||||
if err := c.BindJSON(&req); err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "ShouldBindQuery failed ", err.Error())
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
|
||||
return
|
||||
}
|
||||
log.NewInfo(reqPb.OperationID, utils.GetSelfFuncName(), "req: ", req)
|
||||
reqPb.Pagination = &pbCommon.RequestPagination{}
|
||||
utils.CopyStructFields(&reqPb.Pagination, req)
|
||||
etcdConn := getcdv3.GetDefaultConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImAdminCMSName, reqPb.OperationID)
|
||||
if etcdConn == nil {
|
||||
errMsg := reqPb.OperationID + "getcdv3.GetDefaultConn == nil"
|
||||
log.NewError(reqPb.OperationID, errMsg)
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": errMsg})
|
||||
return
|
||||
}
|
||||
reqPb.OperationID = req.OperationID
|
||||
reqPb.UserID = req.UserID
|
||||
reqPb.FriendUserName = req.FriendUserName
|
||||
reqPb.FriendUserID = req.FriendUserID
|
||||
|
||||
client := pbAdmin.NewAdminCMSClient(etcdConn)
|
||||
respPb, err := client.GetUserFriends(context.Background(), &reqPb)
|
||||
if err != nil {
|
||||
log.NewError(reqPb.OperationID, utils.GetSelfFuncName(), "GetUserInfo failed ", err.Error())
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": err.Error()})
|
||||
return
|
||||
}
|
||||
for _, v := range respPb.FriendInfoList {
|
||||
friend := &cms_api_struct.FriendInfo{}
|
||||
utils.CopyStructFields(friend, v)
|
||||
friend.Nickname = v.FriendUser.Nickname
|
||||
friend.UserID = v.FriendUser.UserID
|
||||
resp.FriendInfoList = append(resp.FriendInfoList, friend)
|
||||
}
|
||||
resp.FriendNums = respPb.FriendNums
|
||||
resp.CurrentPage = int(respPb.Pagination.CurrentPage)
|
||||
resp.ShowNumber = int(respPb.Pagination.ShowNumber)
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp: ", resp)
|
||||
c.JSON(http.StatusOK, gin.H{"errCode": respPb.CommonResp.ErrCode, "errMsg": respPb.CommonResp.ErrMsg, "data": resp})
|
||||
}
|
@ -47,7 +47,7 @@ func GetChatLogs(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
for _, v := range respPb.ChatLogs {
|
||||
chatLog := pbCommon.MsgData{}
|
||||
chatLog := cms_api_struct.ChatLog{}
|
||||
utils.CopyStructFields(&chatLog, v)
|
||||
resp.ChatLogs = append(resp.ChatLogs, &chatLog)
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ package cms_api
|
||||
|
||||
import (
|
||||
"Open_IM/internal/cms_api/admin"
|
||||
"Open_IM/internal/cms_api/friend"
|
||||
"Open_IM/internal/cms_api/group"
|
||||
messageCMS "Open_IM/internal/cms_api/message_cms"
|
||||
"Open_IM/internal/cms_api/middleware"
|
||||
@ -63,5 +64,9 @@ func NewGinRouter() *gin.Engine {
|
||||
{
|
||||
messageCMSRouterGroup.POST("/get_chat_logs", messageCMS.GetChatLogs)
|
||||
}
|
||||
friendCMSRouterGroup := r2.Group("friend")
|
||||
{
|
||||
friendCMSRouterGroup.POST("/get_friends", friend.GetUserFriends)
|
||||
}
|
||||
return baseRouter
|
||||
}
|
||||
|
@ -12,6 +12,7 @@ import (
|
||||
server_api_params "Open_IM/pkg/proto/sdk_ws"
|
||||
"Open_IM/pkg/utils"
|
||||
"context"
|
||||
"errors"
|
||||
"net"
|
||||
"strconv"
|
||||
"strings"
|
||||
@ -19,6 +20,7 @@ import (
|
||||
"time"
|
||||
|
||||
"google.golang.org/grpc"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type adminCMSServer struct {
|
||||
@ -296,7 +298,7 @@ func (s *adminCMSServer) GetActiveUser(_ context.Context, req *pbAdminCMS.GetAct
|
||||
for _, activeUser := range activeUsers {
|
||||
resp.Users = append(resp.Users,
|
||||
&pbAdminCMS.UserResp{
|
||||
UserId: activeUser.ID,
|
||||
UserID: activeUser.ID,
|
||||
NickName: activeUser.Name,
|
||||
MessageNum: int32(activeUser.MessageNum),
|
||||
},
|
||||
@ -584,3 +586,80 @@ func (s *adminCMSServer) GetUserStatistics(_ context.Context, req *pbAdminCMS.Ge
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp: ", resp)
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (s *adminCMSServer) GetUserFriends(_ context.Context, req *pbAdminCMS.GetUserFriendsReq) (*pbAdminCMS.GetUserFriendsResp, error) {
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req.String())
|
||||
resp := &pbAdminCMS.GetUserFriendsResp{CommonResp: &pbAdminCMS.CommonResp{}, Pagination: &server_api_params.ResponsePagination{CurrentPage: req.Pagination.PageNumber, ShowNumber: req.Pagination.ShowNumber}}
|
||||
var friendList []*imdb.FriendUser
|
||||
var err error
|
||||
if req.FriendUserID != "" {
|
||||
friend, err := imdb.GetFriendByIDCMS(req.UserID, req.FriendUserID)
|
||||
if err != nil {
|
||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
return resp, nil
|
||||
}
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error(), req.UserID, req.FriendUserID)
|
||||
resp.CommonResp.ErrCode = constant.ErrDB.ErrCode
|
||||
resp.CommonResp.ErrMsg = err.Error()
|
||||
return resp, nil
|
||||
}
|
||||
friendList = append(friendList, friend)
|
||||
} else {
|
||||
friendList, err = imdb.GetUserFriendsCMS(req.UserID, req.FriendUserName, req.Pagination.PageNumber, req.Pagination.ShowNumber)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error(), req.UserID, req.FriendUserName, req.Pagination.PageNumber, req.Pagination.ShowNumber)
|
||||
resp.CommonResp.ErrCode = constant.ErrDB.ErrCode
|
||||
resp.CommonResp.ErrMsg = err.Error()
|
||||
return resp, nil
|
||||
}
|
||||
}
|
||||
for _, v := range friendList {
|
||||
friendInfo := &server_api_params.FriendInfo{}
|
||||
userInfo := &server_api_params.UserInfo{UserID: v.FriendUserID, Nickname: v.Nickname}
|
||||
utils.CopyStructFields(friendInfo, v)
|
||||
friendInfo.FriendUser = userInfo
|
||||
resp.FriendInfoList = append(resp.FriendInfoList, friendInfo)
|
||||
}
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp: ", resp.String())
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (s *adminCMSServer) GenerateInvitationCode(_ context.Context, req *pbAdminCMS.GenerateInvitationCodeReq) (*pbAdminCMS.GenerateInvitationCodeResp, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (s *adminCMSServer) GetInvitationCodes(_ context.Context, req *pbAdminCMS.GetInvitationCodesReq) (*pbAdminCMS.GetInvitationCodesResp, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (s *adminCMSServer) QueryIPRegister(_ context.Context, req *pbAdminCMS.QueryIPRegisterReq) (*pbAdminCMS.QueryIPRegisterResp, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (s *adminCMSServer) AddIPLimit(_ context.Context, req *pbAdminCMS.AddIPLimitReq) (*pbAdminCMS.AddIPLimitResp, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (s *adminCMSServer) RemoveIPLimit(_ context.Context, req *pbAdminCMS.RemoveIPLimitReq) (*pbAdminCMS.RemoveIPLimitResp, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (s *adminCMSServer) QueryUserIDIPLimitLogin(_ context.Context, req *pbAdminCMS.QueryUserIDIPLimitLoginReq) (*pbAdminCMS.QueryUserIDIPLimitLoginResp, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (s *adminCMSServer) AddUserIPLimitLogin(_ context.Context, req *pbAdminCMS.AddUserIPLimitLoginReq) (*pbAdminCMS.AddUserIPLimitLoginResp, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (s *adminCMSServer) RemoveUserIPLimit(_ context.Context, req *pbAdminCMS.RemoveUserIPLimitReq) (*pbAdminCMS.RemoveUserIPLimitResp, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (s *adminCMSServer) GetClientInitConfig(_ context.Context, req *pbAdminCMS.GetClientInitConfigReq) (*pbAdminCMS.GetClientInitConfigResp, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (s *adminCMSServer) SetClientInitConfig(_ context.Context, req *pbAdminCMS.SetClientInitConfigReq) (*pbAdminCMS.SetClientInitConfigResp, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
@ -52,11 +52,38 @@ func (rpc *rpcAuth) UserRegister(_ context.Context, req *pbAuth.UserRegisterReq)
|
||||
|
||||
func (rpc *rpcAuth) UserToken(_ context.Context, req *pbAuth.UserTokenReq) (*pbAuth.UserTokenResp, error) {
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), " rpc args ", req.String())
|
||||
_, err := imdb.GetUserByUserID(req.FromUserID)
|
||||
if err != nil {
|
||||
errMsg := req.OperationID + " imdb.GetUserByUserID failed " + err.Error() + req.FromUserID
|
||||
log.NewError(req.OperationID, errMsg)
|
||||
return &pbAuth.UserTokenResp{CommonResp: &pbAuth.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: errMsg}}, nil
|
||||
|
||||
if config.Config.Demo.UseIPLimit {
|
||||
user, err := imdb.GetUserIPLimit(req.FromUserID)
|
||||
if err != nil {
|
||||
errMsg := req.OperationID + " imdb.GetUserByUserID failed " + err.Error() + req.FromUserID
|
||||
log.NewError(req.OperationID, errMsg)
|
||||
return &pbAuth.UserTokenResp{CommonResp: &pbAuth.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: errMsg}}, nil
|
||||
}
|
||||
|
||||
var Limited bool
|
||||
var LimitError error
|
||||
Limited, LimitError = imdb.IsLimitLoginIp(req.LoginIp)
|
||||
if LimitError != nil {
|
||||
return &pbAuth.UserTokenResp{CommonResp: &pbAuth.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: LimitError.Error()}}, nil
|
||||
}
|
||||
if Limited {
|
||||
return &pbAuth.UserTokenResp{CommonResp: &pbAuth.CommonResp{ErrCode: constant.LoginLimit, ErrMsg: "limited Login"}}, nil
|
||||
}
|
||||
Limited, LimitError = imdb.IsLimitUserLoginIp(user.UserID, req.LoginIp)
|
||||
if LimitError != nil {
|
||||
return &pbAuth.UserTokenResp{CommonResp: &pbAuth.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: LimitError.Error()}}, nil
|
||||
}
|
||||
if Limited {
|
||||
return &pbAuth.UserTokenResp{CommonResp: &pbAuth.CommonResp{ErrCode: constant.LoginLimit, ErrMsg: "limited Login"}}, nil
|
||||
}
|
||||
Limited, LimitError = imdb.UserIsBlock(user.UserID)
|
||||
if LimitError != nil {
|
||||
return &pbAuth.UserTokenResp{CommonResp: &pbAuth.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: LimitError.Error()}}, nil
|
||||
}
|
||||
if Limited {
|
||||
return &pbAuth.UserTokenResp{CommonResp: &pbAuth.CommonResp{ErrCode: constant.LoginLimit, ErrMsg: "limited Login"}}, nil
|
||||
}
|
||||
}
|
||||
|
||||
tokens, expTime, err := token_verify.CreateToken(req.FromUserID, int(req.Platform))
|
||||
|
@ -1353,8 +1353,6 @@ func (s *groupServer) GetGroups(_ context.Context, req *pbGroup.GetGroupsReq) (*
|
||||
resp.CommonResp.ErrCode = constant.ErrDB.ErrCode
|
||||
resp.CommonResp.ErrMsg = err.Error()
|
||||
return resp, nil
|
||||
} else {
|
||||
|
||||
}
|
||||
resp.GroupNum = 1
|
||||
groupInfo := &open_im_sdk.GroupInfo{}
|
||||
|
@ -634,7 +634,7 @@ func (s *userServer) GetUsers(ctx context.Context, req *pbUser.GetUsersReq) (*pb
|
||||
|
||||
func (s *userServer) AddUser(ctx context.Context, req *pbUser.AddUserReq) (*pbUser.AddUserResp, error) {
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req.String())
|
||||
resp := &pbUser.AddUserResp{}
|
||||
resp := &pbUser.AddUserResp{CommonResp: &pbUser.CommonResp{}}
|
||||
err := imdb.AddUser(req.UserInfo.UserID, req.UserInfo.PhoneNumber, req.UserInfo.Nickname, req.UserInfo.Email, req.UserInfo.Gender, req.UserInfo.FaceURL, req.UserInfo.Birth)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "AddUser", err.Error(), req.String())
|
||||
|
25
pkg/cms_api_struct/friend.go
Normal file
25
pkg/cms_api_struct/friend.go
Normal file
@ -0,0 +1,25 @@
|
||||
package cms_api_struct
|
||||
|
||||
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"`
|
||||
}
|
@ -16,8 +16,33 @@ type GetChatLogsReq struct {
|
||||
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 []*pbCommon.MsgData `json:"chatLogs"`
|
||||
ChatLogsNum int `json:"logNums"`
|
||||
ChatLogs []*ChatLog `json:"chatLogs"`
|
||||
ChatLogsNum int `json:"logNums"`
|
||||
ResponsePagination
|
||||
}
|
||||
|
@ -508,6 +508,8 @@ type config struct {
|
||||
JoinDepartmentIDList []string `yaml:"joinDepartmentIDList"`
|
||||
JoinDepartmentGroups bool `yaml:"joinDepartmentGroups"`
|
||||
OaNotification bool `yaml:"oaNotification"`
|
||||
|
||||
UseIPLimit bool `yaml:"useIPLimit"`
|
||||
}
|
||||
Rtc struct {
|
||||
SignalTimeout string `yaml:"signalTimeout"`
|
||||
|
@ -15,7 +15,7 @@ type Register struct {
|
||||
type Invitation struct {
|
||||
InvitationCode string `gorm:"column:invitation_code;primary_key;type:varchar(32)"`
|
||||
CreateTime time.Time `gorm:"column:create_time"`
|
||||
UserID string `gorm:"column:user_id"`
|
||||
UserID string `gorm:"column:user_id;index:userID"`
|
||||
LastTime time.Time `gorm:"column:last_time"`
|
||||
Status int32 `gorm:"column:status"`
|
||||
}
|
||||
@ -179,8 +179,8 @@ type User struct {
|
||||
CreateTime time.Time `gorm:"column:create_time;index:create_time"`
|
||||
AppMangerLevel int32 `gorm:"column:app_manger_level"`
|
||||
GlobalRecvMsgOpt int32 `gorm:"column:global_recv_msg_opt"`
|
||||
InvitationCode string `gorm:"column:invitation_code"`
|
||||
status int32 `gorm:"column:status"`
|
||||
|
||||
status int32 `gorm:"column:status"`
|
||||
}
|
||||
|
||||
type UserIpRecord struct {
|
||||
|
@ -3,6 +3,7 @@ package im_mysql_model
|
||||
import (
|
||||
"Open_IM/pkg/common/db"
|
||||
"errors"
|
||||
|
||||
_ "gorm.io/gorm"
|
||||
)
|
||||
|
||||
@ -74,3 +75,10 @@ func DeleteAllRegisterAddFriendIDList() error {
|
||||
err := db.DB.MysqlDB.DefaultGormDB().Where("1 = 1").Delete(&db.RegisterAddFriend{}).Error
|
||||
return err
|
||||
}
|
||||
|
||||
func GetUserIPLimit(userID string) (db.UserIpLimit, error) {
|
||||
var limit db.UserIpLimit
|
||||
limit.UserID = userID
|
||||
err := db.DB.MysqlDB.DefaultGormDB().Model(&db.UserIpLimit{}).Take(&limit).Error
|
||||
return limit, err
|
||||
}
|
||||
|
@ -2,8 +2,10 @@ package im_mysql_model
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/db"
|
||||
_ "github.com/jinzhu/gorm/dialects/mysql"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
_ "github.com/jinzhu/gorm/dialects/mysql"
|
||||
)
|
||||
|
||||
func InsertToFriend(toInsertFollow *db.Friend) error {
|
||||
@ -51,3 +53,31 @@ func UpdateFriendComment(OwnerUserID, FriendUserID, Remark string) error {
|
||||
func DeleteSingleFriendInfo(OwnerUserID, FriendUserID string) error {
|
||||
return db.DB.MysqlDB.DefaultGormDB().Table("friends").Where("owner_user_id=? and friend_user_id=?", OwnerUserID, FriendUserID).Delete(db.Friend{}).Error
|
||||
}
|
||||
|
||||
type FriendUser struct {
|
||||
db.Friend
|
||||
Nickname string `gorm:"column:name;size:255"`
|
||||
}
|
||||
|
||||
func GetUserFriendsCMS(ownerUserID, friendUserName string, pageNumber, showNumber int32) (friendUserList []*FriendUser, err error) {
|
||||
db := db.DB.MysqlDB.DefaultGormDB().Table("friends").
|
||||
Select("friends.*, users.name").
|
||||
Where("friends.owner_user_id=?", ownerUserID).Limit(int(showNumber)).
|
||||
Joins("left join friends on friends.friend_user_id = users.user_id").
|
||||
Offset(int(showNumber * (pageNumber - 1)))
|
||||
if friendUserName != "" {
|
||||
db = db.Where("users.name like ?", fmt.Sprintf("%%%s%%", friendUserName))
|
||||
}
|
||||
err = db.Find(&friendUserList).Error
|
||||
return
|
||||
}
|
||||
|
||||
func GetFriendByIDCMS(ownerUserID, friendUserID string) (friendUser *FriendUser, err error) {
|
||||
friendUser = &FriendUser{}
|
||||
err = db.DB.MysqlDB.DefaultGormDB().Table("friends").
|
||||
Select("friends.*, users.name").
|
||||
Where("friends.owner_user_id=? and friends.friend_user_id=?", ownerUserID, friendUserID).
|
||||
Joins("left join friends on friends.friend_user_id = users.user_id").
|
||||
Take(friendUser).Error
|
||||
return friendUser, err
|
||||
}
|
||||
|
@ -1,9 +1,11 @@
|
||||
package im_mysql_model
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/constant"
|
||||
"Open_IM/pkg/common/db"
|
||||
"Open_IM/pkg/utils"
|
||||
"fmt"
|
||||
|
||||
"time"
|
||||
)
|
||||
|
||||
@ -54,7 +56,7 @@ type GroupWithNum struct {
|
||||
func GetGroupsByName(groupName string, pageNumber, showNumber int32) ([]GroupWithNum, error) {
|
||||
var groups []GroupWithNum
|
||||
err := db.DB.MysqlDB.DefaultGormDB().Table("groups").Select("groups.*, (select count(*) from group_members where group_members.group_id=groups.group_id) as num").
|
||||
Where(" name like ? ", fmt.Sprintf("%%%s%%", groupName)).Limit(int(showNumber)).Offset(int(showNumber * (pageNumber - 1))).Find(&groups).Error
|
||||
Where(" name like ? and status != ?", fmt.Sprintf("%%%s%%", groupName), constant.GroupStatusDismissed).Limit(int(showNumber)).Offset(int(showNumber * (pageNumber - 1))).Find(&groups).Error
|
||||
return groups, err
|
||||
}
|
||||
|
||||
|
@ -11,16 +11,18 @@ import (
|
||||
func GetChatLog(chatLog db.ChatLog, pageNumber, showNumber int32) ([]db.ChatLog, error) {
|
||||
var chatLogs []db.ChatLog
|
||||
db := db.DB.MysqlDB.DefaultGormDB().Table("chat_logs").
|
||||
Where(fmt.Sprintf(" content like '%%%s%%'", chatLog.Content)).
|
||||
Limit(int(showNumber)).Offset(int(showNumber * (pageNumber - 1)))
|
||||
if chatLog.SessionType != 0 {
|
||||
db = db.Where("session_type = ?", chatLog.SessionType)
|
||||
if chatLog.Content != "" {
|
||||
db = db.Where(" name like ? ", fmt.Sprintf("%%%s%%", chatLog.Content))
|
||||
}
|
||||
if chatLog.ContentType == 1 {
|
||||
db = db.Where("content_type = ?", chatLog.ContentType)
|
||||
} else if chatLog.ContentType == 2 {
|
||||
if chatLog.SessionType == 1 {
|
||||
db = db.Where("session_type = ?", chatLog.SessionType)
|
||||
} else if chatLog.SessionType == 2 {
|
||||
db = db.Where("content_type in (?)", []int{constant.GroupChatType, constant.SuperGroupChatType})
|
||||
}
|
||||
if chatLog.ContentType != 0 {
|
||||
db = db.Where("content_type = ?", chatLog.ContentType)
|
||||
}
|
||||
if chatLog.SendID != "" {
|
||||
db = db.Where("send_id = ?", chatLog.SendID)
|
||||
}
|
||||
@ -37,13 +39,17 @@ func GetChatLog(chatLog db.ChatLog, pageNumber, showNumber int32) ([]db.ChatLog,
|
||||
func GetChatLogCount(chatLog db.ChatLog) (int64, error) {
|
||||
var chatLogs []db.ChatLog
|
||||
var count int64
|
||||
db := db.DB.MysqlDB.DefaultGormDB().Table("chat_logs").
|
||||
Where(fmt.Sprintf(" content like '%%%s%%'", chatLog.Content))
|
||||
db := db.DB.MysqlDB.DefaultGormDB().Table("chat_logs")
|
||||
if chatLog.Content != "" {
|
||||
db = db.Where(" name like ? ", fmt.Sprintf("%%%s%%", chatLog.Content))
|
||||
}
|
||||
if chatLog.SessionType != 0 {
|
||||
db = db.Where("session_type = ?", chatLog.SessionType)
|
||||
}
|
||||
if chatLog.ContentType != 0 {
|
||||
if chatLog.ContentType == 1 {
|
||||
db = db.Where("content_type = ?", chatLog.ContentType)
|
||||
} else if chatLog.ContentType == 2 {
|
||||
db = db.Where("content_type in (?)", []int{constant.GroupChatType, constant.SuperGroupChatType})
|
||||
}
|
||||
if chatLog.SendID != "" {
|
||||
db = db.Where("send_id = ?", chatLog.SendID)
|
||||
|
@ -130,21 +130,29 @@ func AddUser(userID string, phoneNumber string, name string, email string, gende
|
||||
_birth = time.Now()
|
||||
}
|
||||
user := db.User{
|
||||
UserID: userID,
|
||||
Nickname: name,
|
||||
FaceURL: faceURL,
|
||||
Gender: gender,
|
||||
PhoneNumber: phoneNumber,
|
||||
Birth: _birth,
|
||||
Email: email,
|
||||
Ex: "",
|
||||
CreateTime: time.Now(),
|
||||
InvitationCode: "",
|
||||
UserID: userID,
|
||||
Nickname: name,
|
||||
FaceURL: faceURL,
|
||||
Gender: gender,
|
||||
PhoneNumber: phoneNumber,
|
||||
Birth: _birth,
|
||||
Email: email,
|
||||
Ex: "",
|
||||
CreateTime: time.Now(),
|
||||
}
|
||||
result := db.DB.MysqlDB.DefaultGormDB().Table("users").Create(&user)
|
||||
return result.Error
|
||||
}
|
||||
|
||||
func UserIsBlock(userId string) (bool, error) {
|
||||
var user db.BlackList
|
||||
rows := db.DB.MysqlDB.DefaultGormDB().Table("black_lists").Where("uid=?", userId).First(&user).RowsAffected
|
||||
if rows >= 1 {
|
||||
return user.EndDisableTime.After(time.Now()), nil
|
||||
}
|
||||
return false, nil
|
||||
}
|
||||
|
||||
func UsersIsBlock(userIDList []string) (inBlockUserIDList []string, err error) {
|
||||
err = db.DB.MysqlDB.DefaultGormDB().Table("black_lists").Where("uid in (?) and end_disable_time > now()", userIDList).Pluck("uid", &inBlockUserIDList).Error
|
||||
return inBlockUserIDList, err
|
||||
|
@ -6,10 +6,8 @@ import (
|
||||
imdb "Open_IM/pkg/common/db/mysql_model/im_mysql_model"
|
||||
"Open_IM/pkg/common/log"
|
||||
"Open_IM/pkg/utils"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"math/big"
|
||||
"sort"
|
||||
"strconv"
|
||||
@ -36,38 +34,6 @@ const (
|
||||
conversationIDListCache = "CONVERSATION_ID_LIST_CACHE:"
|
||||
)
|
||||
|
||||
func init() {
|
||||
fmt.Println("init to del old keys")
|
||||
for _, key := range []string{groupCache, friendRelationCache, blackListCache, userInfoCache, groupInfoCache, groupOwnerIDCache, joinedGroupListCache,
|
||||
groupMemberInfoCache, groupAllMemberInfoCache, allFriendInfoCache} {
|
||||
fName := utils.GetSelfFuncName()
|
||||
var cursor uint64
|
||||
var n int
|
||||
for {
|
||||
var keys []string
|
||||
var err error
|
||||
keys, cursor, err = db.DB.RDB.Scan(context.Background(), cursor, key+"*", 3000).Result()
|
||||
if err != nil {
|
||||
panic(err.Error())
|
||||
}
|
||||
n += len(keys)
|
||||
// for each for redis cluster
|
||||
for _, key := range keys {
|
||||
if err = db.DB.RDB.Del(context.Background(), key).Err(); err != nil {
|
||||
log.NewError("", fName, key, err.Error())
|
||||
err = db.DB.RDB.Del(context.Background(), key).Err()
|
||||
if err != nil {
|
||||
panic(err.Error())
|
||||
}
|
||||
}
|
||||
}
|
||||
if cursor == 0 {
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func GetFriendIDListFromCache(userID string) ([]string, error) {
|
||||
getFriendIDList := func() (string, error) {
|
||||
friendIDList, err := imdb.GetFriendIDListByUserID(userID)
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -10,9 +10,9 @@ message CommonResp {
|
||||
}
|
||||
|
||||
message AdminLoginReq {
|
||||
string OperationID = 1;
|
||||
string AdminID = 2;
|
||||
string Secret = 3;
|
||||
string operationID = 1;
|
||||
string adminID = 2;
|
||||
string secret = 3;
|
||||
}
|
||||
|
||||
|
||||
@ -52,43 +52,43 @@ message GetUserRegisterAddFriendIDListResp {
|
||||
}
|
||||
|
||||
message GetChatLogsReq {
|
||||
string Content = 1;
|
||||
string SendID = 2;
|
||||
string RecvID = 3;
|
||||
string SendTime = 4;
|
||||
int32 SessionType = 5;
|
||||
int32 ContentType = 6;
|
||||
server_api_params.RequestPagination Pagination = 7;
|
||||
string OperationID = 8;
|
||||
string content = 1;
|
||||
string sendID = 2;
|
||||
string recvID = 3;
|
||||
string sendTime = 4;
|
||||
int32 sessionType = 5;
|
||||
int32 contentType = 6;
|
||||
server_api_params.RequestPagination pagination = 7;
|
||||
string operationID = 8;
|
||||
|
||||
}
|
||||
|
||||
message ChatLog {
|
||||
string ServerMsgID = 1;
|
||||
string ClientMsgID = 2;
|
||||
string SendID = 3;
|
||||
string RecvID = 4;
|
||||
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;
|
||||
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;
|
||||
server_api_params.ResponsePagination Pagination = 2;
|
||||
int32 ChatLogsNum = 3;
|
||||
CommonResp CommonResp = 4;
|
||||
repeated ChatLog chatLogs = 1;
|
||||
server_api_params.ResponsePagination pagination = 2;
|
||||
int32 chatLogsNum = 3;
|
||||
CommonResp commonResp = 4;
|
||||
}
|
||||
|
||||
|
||||
@ -98,36 +98,36 @@ message StatisticsReq {
|
||||
}
|
||||
|
||||
message GetActiveUserReq{
|
||||
StatisticsReq StatisticsReq = 1;
|
||||
string OperationID = 2;
|
||||
StatisticsReq statisticsReq = 1;
|
||||
string operationID = 2;
|
||||
}
|
||||
|
||||
message UserResp{
|
||||
string NickName = 1;
|
||||
string UserId = 2;
|
||||
int32 MessageNum = 3;
|
||||
string nickName = 1;
|
||||
string userID = 2;
|
||||
int32 messageNum = 3;
|
||||
}
|
||||
|
||||
message GetActiveUserResp {
|
||||
repeated UserResp Users = 1;
|
||||
CommonResp CommonResp = 2;
|
||||
CommonResp commonResp = 2;
|
||||
}
|
||||
|
||||
message GetActiveGroupReq{
|
||||
StatisticsReq StatisticsReq = 1;
|
||||
string OperationID = 2;
|
||||
StatisticsReq statisticsReq = 1;
|
||||
string operationID = 2;
|
||||
}
|
||||
|
||||
message GroupResp {
|
||||
string GroupName = 1;
|
||||
string GroupId = 2;
|
||||
int32 MessageNum = 3;
|
||||
CommonResp CommonResp = 4;
|
||||
CommonResp commonResp = 4;
|
||||
}
|
||||
|
||||
message GetActiveGroupResp {
|
||||
repeated GroupResp Groups = 1;
|
||||
CommonResp CommonResp = 2;
|
||||
CommonResp commonResp = 2;
|
||||
}
|
||||
|
||||
message DateNumList {
|
||||
@ -147,7 +147,7 @@ message GetMessageStatisticsResp {
|
||||
int32 GroupMessageNum = 2;
|
||||
repeated DateNumList PrivateMessageNumList = 3;
|
||||
repeated DateNumList GroupMessageNumList = 4;
|
||||
CommonResp CommonResp = 5;
|
||||
CommonResp commonResp = 5;
|
||||
}
|
||||
|
||||
message GetGroupStatisticsReq {
|
||||
@ -161,7 +161,7 @@ message GetGroupStatisticsResp {
|
||||
int32 TotalGroupNum = 2;
|
||||
repeated DateNumList IncreaseGroupNumList = 3;
|
||||
repeated DateNumList TotalGroupNumList = 4;
|
||||
CommonResp CommonResp = 5;
|
||||
CommonResp commonResp = 5;
|
||||
}
|
||||
|
||||
message GetUserStatisticsReq {
|
||||
@ -176,7 +176,139 @@ message GetUserStatisticsResp {
|
||||
repeated DateNumList IncreaseUserNumList = 4;
|
||||
repeated DateNumList ActiveUserNumList = 5;
|
||||
repeated DateNumList TotalUserNumList = 6;
|
||||
CommonResp CommonResp = 7;
|
||||
CommonResp commonResp = 7;
|
||||
}
|
||||
|
||||
message GenerateInvitationCodeReq {
|
||||
string operationID = 1;
|
||||
int32 codeLen = 2;
|
||||
int32 codeNum = 3;
|
||||
}
|
||||
|
||||
message GenerateInvitationCodeResp {
|
||||
CommonResp commonResp = 1;
|
||||
}
|
||||
|
||||
message GetInvitationCodesReq {
|
||||
string operationID = 1;
|
||||
string code = 2;
|
||||
int32 status = 3;
|
||||
server_api_params.RequestPagination pagination = 4;
|
||||
}
|
||||
|
||||
message invitationCode {
|
||||
string invitationCode = 1;
|
||||
int32 createTime = 2;
|
||||
int32 lastTime = 3;
|
||||
string userID = 4;
|
||||
int32 status = 5;
|
||||
}
|
||||
|
||||
message GetInvitationCodesResp {
|
||||
repeated invitationCode invitationCodes = 1;
|
||||
server_api_params.ResponsePagination Pagination = 2;
|
||||
CommonResp commonResp = 3;
|
||||
}
|
||||
|
||||
message QueryIPRegisterReq {
|
||||
string operationID = 1;
|
||||
string IP = 2;
|
||||
}
|
||||
|
||||
message QueryIPRegisterResp {
|
||||
string IP = 1;
|
||||
int32 RegisterNum = 2;
|
||||
int32 Status = 3;
|
||||
repeated string userIDList = 4;
|
||||
CommonResp commonResp = 5;
|
||||
}
|
||||
|
||||
message AddIPLimitReq {
|
||||
string operationID = 1;
|
||||
string IP = 2;
|
||||
int32 limitTime = 3;
|
||||
}
|
||||
|
||||
message AddIPLimitResp {
|
||||
CommonResp commonResp = 1;
|
||||
}
|
||||
|
||||
message RemoveIPLimitReq {
|
||||
string operationID = 1;
|
||||
string IP = 2;
|
||||
}
|
||||
|
||||
message RemoveIPLimitResp {
|
||||
CommonResp commonResp = 1;
|
||||
}
|
||||
|
||||
message QueryUserIDIPLimitLoginReq {
|
||||
string operationID = 1;
|
||||
string userID = 2;
|
||||
}
|
||||
|
||||
message UserIPLimit {
|
||||
string userID = 1;
|
||||
string IP = 2;
|
||||
int32 createTime = 3;
|
||||
}
|
||||
|
||||
message QueryUserIDIPLimitLoginResp {
|
||||
repeated UserIPLimit UserIPLimits = 1;
|
||||
CommonResp commonResp = 2;
|
||||
}
|
||||
|
||||
message AddUserIPLimitLoginReq {
|
||||
string userID = 1;
|
||||
string operationID = 2;
|
||||
string IP = 3;
|
||||
}
|
||||
|
||||
message AddUserIPLimitLoginResp {
|
||||
CommonResp commonResp = 1;
|
||||
}
|
||||
|
||||
message RemoveUserIPLimitReq {
|
||||
string userID = 1;
|
||||
string operationID = 2;
|
||||
string IP = 3;
|
||||
}
|
||||
|
||||
message RemoveUserIPLimitResp {
|
||||
CommonResp commonResp = 1;
|
||||
}
|
||||
|
||||
message GetClientInitConfigReq {
|
||||
string operationID = 1;
|
||||
}
|
||||
|
||||
message GetClientInitConfigResp {
|
||||
CommonResp commonResp = 1;
|
||||
}
|
||||
|
||||
message SetClientInitConfigReq {
|
||||
string operationID = 1;
|
||||
string discoverPageURL = 2;
|
||||
}
|
||||
|
||||
message SetClientInitConfigResp {
|
||||
CommonResp commonResp = 1;
|
||||
}
|
||||
|
||||
message GetUserFriendsReq {
|
||||
string operationID = 1;
|
||||
string userID = 2;
|
||||
string friendUserID = 3;
|
||||
string friendUserName = 4;
|
||||
server_api_params.RequestPagination pagination = 5;
|
||||
}
|
||||
|
||||
|
||||
message GetUserFriendsResp {
|
||||
server_api_params.ResponsePagination pagination = 1;
|
||||
repeated server_api_params.FriendInfo friendInfoList = 2;
|
||||
int32 friendNums = 3;
|
||||
CommonResp commonResp = 4;
|
||||
}
|
||||
|
||||
service adminCMS {
|
||||
@ -193,4 +325,19 @@ service adminCMS {
|
||||
rpc GetMessageStatistics(GetMessageStatisticsReq) returns(GetMessageStatisticsResp);
|
||||
rpc GetGroupStatistics(GetGroupStatisticsReq) returns(GetGroupStatisticsResp);
|
||||
rpc GetUserStatistics(GetUserStatisticsReq) returns(GetUserStatisticsResp);
|
||||
|
||||
rpc GenerateInvitationCode(GenerateInvitationCodeReq) returns(GenerateInvitationCodeResp);
|
||||
rpc GetInvitationCodes(GetInvitationCodesReq) returns(GetInvitationCodesResp);
|
||||
|
||||
rpc QueryIPRegister(QueryIPRegisterReq) returns(QueryIPRegisterResp);
|
||||
rpc AddIPLimit(AddIPLimitReq) returns(AddIPLimitResp);
|
||||
rpc RemoveIPLimit(RemoveIPLimitReq) returns(RemoveIPLimitResp);
|
||||
rpc QueryUserIDIPLimitLogin(QueryUserIDIPLimitLoginReq) returns(QueryUserIDIPLimitLoginResp);
|
||||
rpc AddUserIPLimitLogin(AddUserIPLimitLoginReq) returns(AddUserIPLimitLoginResp);
|
||||
rpc RemoveUserIPLimit(RemoveUserIPLimitReq) returns(RemoveUserIPLimitResp);
|
||||
|
||||
rpc GetClientInitConfig(GetClientInitConfigReq) returns(GetClientInitConfigResp);
|
||||
rpc SetClientInitConfig(SetClientInitConfigReq) returns(SetClientInitConfigResp);
|
||||
|
||||
rpc GetUserFriends(GetUserFriendsReq) returns(GetUserFriendsResp);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user