mirror of
https://github.com/openimsdk/open-im-server.git
synced 2026-05-09 19:45:58 +08:00
mongo
This commit is contained in:
@@ -13,8 +13,8 @@ type MiniostorageCredentialResp struct {
|
||||
}
|
||||
|
||||
type MinioUploadFileReq struct {
|
||||
OperationID string `form:"operationID"`
|
||||
FileType int `form:"fileType"`
|
||||
OperationID string `form:"operationID" binding:"required"`
|
||||
FileType int `form:"fileType" binding:"required"`
|
||||
}
|
||||
|
||||
type MinioUploadFileResp struct {
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
package base_info
|
||||
|
||||
import pbOffice "Open_IM/pkg/proto/office"
|
||||
|
||||
type GetUserTagsReq struct {
|
||||
pbOffice.GetUserTagsReq
|
||||
}
|
||||
|
||||
type GetUserTagsResp struct {
|
||||
CommResp
|
||||
Data struct {
|
||||
Tags []*pbOffice.Tag `json:"tags"`
|
||||
} `json:"data"`
|
||||
}
|
||||
|
||||
type CreateTagReq struct {
|
||||
pbOffice.CreateTagReq
|
||||
}
|
||||
|
||||
type CreateTagResp struct {
|
||||
CommResp
|
||||
}
|
||||
|
||||
type DeleteTagReq struct {
|
||||
pbOffice.DeleteTagReq
|
||||
}
|
||||
|
||||
type DeleteTagResp struct {
|
||||
CommResp
|
||||
}
|
||||
|
||||
type SetTagReq struct {
|
||||
pbOffice.SetTagReq
|
||||
}
|
||||
|
||||
type SetTagResp struct {
|
||||
CommResp
|
||||
}
|
||||
|
||||
type SendMsg2TagReq struct {
|
||||
pbOffice.SendMsg2TagReq
|
||||
}
|
||||
|
||||
type SendMsg2TagResp struct {
|
||||
CommResp
|
||||
}
|
||||
@@ -103,6 +103,7 @@ type config struct {
|
||||
OpenImAuthName string `yaml:"openImAuthName"`
|
||||
OpenImMessageCMSName string `yaml:"openImMessageCMSName"`
|
||||
OpenImAdminCMSName string `yaml:"openImAdminCMSName"`
|
||||
OpenImOfficeName string `yaml:"openImOfficeName"`
|
||||
}
|
||||
Etcd struct {
|
||||
EtcdSchema string `yaml:"etcdSchema"`
|
||||
|
||||
@@ -5,12 +5,14 @@ import (
|
||||
"Open_IM/pkg/common/constant"
|
||||
"Open_IM/pkg/common/log"
|
||||
pbMsg "Open_IM/pkg/proto/chat"
|
||||
officePb "Open_IM/pkg/proto/office"
|
||||
open_im_sdk "Open_IM/pkg/proto/sdk_ws"
|
||||
"Open_IM/pkg/utils"
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/gogo/protobuf/sortkeys"
|
||||
"math/rand"
|
||||
|
||||
//"github.com/garyburd/redigo/redis"
|
||||
"github.com/golang/protobuf/proto"
|
||||
@@ -22,6 +24,8 @@ import (
|
||||
|
||||
const cChat = "msg"
|
||||
const cGroup = "group"
|
||||
const cTag = "tag"
|
||||
const cSendLog = "sendLog"
|
||||
const singleGocMsgNum = 5000
|
||||
|
||||
type MsgInfo struct {
|
||||
@@ -430,9 +434,135 @@ func (d *DataBases) DelGroupMember(groupID, uid string) error {
|
||||
//return nil
|
||||
}
|
||||
|
||||
type Tag struct {
|
||||
TagID string `bson:"tagID"`
|
||||
TagName string `bson:"tagName"`
|
||||
UserList []string `bson:"userList"`
|
||||
}
|
||||
|
||||
type TagsStruct struct {
|
||||
Uid string `bson:"uid"`
|
||||
Tags map[string]Tag `bson:"tags"`
|
||||
}
|
||||
|
||||
type TagSendLogStruct struct {
|
||||
}
|
||||
|
||||
func (d *DataBases) GetUserTags(userID string) ([]Tag, error) {
|
||||
ctx, _ := context.WithTimeout(context.Background(), time.Duration(config.Config.Mongo.DBTimeout)*time.Second)
|
||||
c := d.mongoClient.Database(config.Config.Mongo.DBDatabase).Collection(cTag)
|
||||
var tagStruct TagsStruct
|
||||
var tags []Tag
|
||||
_ = c.FindOne(ctx, bson.M{"uid": userID}).Decode(&tagStruct)
|
||||
for _, v := range tagStruct.Tags {
|
||||
tags = append(tags, v)
|
||||
}
|
||||
return tags, nil
|
||||
}
|
||||
|
||||
func (d *DataBases) CreateTag(userID, tagName string, userList []string) error {
|
||||
ctx, _ := context.WithTimeout(context.Background(), time.Duration(config.Config.Mongo.DBTimeout)*time.Second)
|
||||
c := d.mongoClient.Database(config.Config.Mongo.DBDatabase).Collection(cTag)
|
||||
tagID := generateTagID(tagName, userID)
|
||||
tag := Tag{
|
||||
TagID: tagID,
|
||||
TagName: tagName,
|
||||
UserList: userList,
|
||||
}
|
||||
_, err := c.InsertOne(ctx, TagsStruct{
|
||||
Uid: userID,
|
||||
Tags: map[string]Tag{tagID: tag},
|
||||
})
|
||||
return err
|
||||
}
|
||||
|
||||
func (d *DataBases) DeleteTag(userID, tagID string) error {
|
||||
ctx, _ := context.WithTimeout(context.Background(), time.Duration(config.Config.Mongo.DBTimeout)*time.Second)
|
||||
c := d.mongoClient.Database(config.Config.Mongo.DBDatabase).Collection(cTag)
|
||||
_, err := c.DeleteOne(ctx, bson.M{"uid": userID, "tags": bson.M{"$unset": tagID}})
|
||||
return err
|
||||
}
|
||||
|
||||
func (d *DataBases) SetTag(userID, tagID, newName string, increaseUserList []string, reduceUserIDList []string) error {
|
||||
ctx, _ := context.WithTimeout(context.Background(), time.Duration(config.Config.Mongo.DBTimeout)*time.Second)
|
||||
c := d.mongoClient.Database(config.Config.Mongo.DBDatabase).Collection(cTag)
|
||||
_, err := c.UpdateOne(ctx, bson.M{"uid": userID, "tags": tagID}, bson.M{"tagName": newName})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = c.InsertOne(ctx, bson.M{"uid": userID, "tags": bson.M{tagID: ""}})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
//_, err = c.InsertOne(ctx)
|
||||
//if err != nil {
|
||||
// return err
|
||||
//}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (d *DataBases) GetUserIDListByTagID(userID, tagID string) ([]string, error) {
|
||||
var tagIDList []string
|
||||
var tagStruct TagsStruct
|
||||
ctx, _ := context.WithTimeout(context.Background(), time.Duration(config.Config.Mongo.DBTimeout)*time.Second)
|
||||
c := d.mongoClient.Database(config.Config.Mongo.DBDatabase).Collection(cTag)
|
||||
_ = c.FindOne(ctx, bson.M{"uid": userID}).Decode(&tagStruct)
|
||||
for k, tag := range tagStruct.Tags {
|
||||
if k == tagID {
|
||||
tagIDList = tag.UserList
|
||||
}
|
||||
}
|
||||
return tagIDList, nil
|
||||
}
|
||||
|
||||
type TagSendLog struct {
|
||||
TagID string `bson:"tagID"`
|
||||
SendID string `bson:"sendID"`
|
||||
SenderPlatformID int32 `bson:"senderPlatformID"`
|
||||
Content string `bson:"content"`
|
||||
ContentType int32 `bson:"contentType"`
|
||||
SendTime int64 `bson:"sendTime"`
|
||||
UserList []string `bson:"userList"`
|
||||
}
|
||||
|
||||
func (d *DataBases) SaveTagSendLog(sendReq *officePb.SendMsg2TagReq) error {
|
||||
ctx, _ := context.WithTimeout(context.Background(), time.Duration(config.Config.Mongo.DBTimeout)*time.Second)
|
||||
c := d.mongoClient.Database(config.Config.Mongo.DBDatabase).Collection(cSendLog)
|
||||
tagSendLog := TagSendLog{
|
||||
TagID: sendReq.TagID,
|
||||
SendID: sendReq.SendID,
|
||||
SenderPlatformID: sendReq.SenderPlatformID,
|
||||
Content: sendReq.Content,
|
||||
ContentType: sendReq.ContentType,
|
||||
SendTime: time.Now().Unix(),
|
||||
}
|
||||
_, err := c.InsertOne(ctx, tagSendLog)
|
||||
return err
|
||||
}
|
||||
|
||||
func (d *DataBases) GetTagSendLogs(userID string, showNumber, pageNumber int32) ([]*TagSendLog, error) {
|
||||
var tagSendLogs []*TagSendLog
|
||||
ctx, _ := context.WithTimeout(context.Background(), time.Duration(config.Config.Mongo.DBTimeout)*time.Second)
|
||||
c := d.mongoClient.Database(config.Config.Mongo.DBDatabase).Collection(cSendLog)
|
||||
cursor, err := c.Find(ctx, bson.M{"sendID": userID})
|
||||
if err != nil {
|
||||
return tagSendLogs, err
|
||||
}
|
||||
err = cursor.Decode(&tagSendLogs)
|
||||
if err != nil {
|
||||
return tagSendLogs, err
|
||||
}
|
||||
return tagSendLogs, nil
|
||||
}
|
||||
|
||||
func generateTagID(tagName, userID string) string {
|
||||
return utils.Md5(tagName + userID + strconv.Itoa(rand.Int()))
|
||||
}
|
||||
|
||||
func getCurrentTimestampByMill() int64 {
|
||||
return time.Now().UnixNano() / 1e6
|
||||
}
|
||||
|
||||
func getSeqUid(uid string, seq uint32) string {
|
||||
seqSuffix := seq / singleGocMsgNum
|
||||
return indexGen(uid, seqSuffix)
|
||||
|
||||
@@ -74,6 +74,19 @@ func GetUserByUserID(userID string) (*db.User, error) {
|
||||
return &user, nil
|
||||
}
|
||||
|
||||
func GetUserNameByUserID(userID string) (string, error) {
|
||||
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
var userName string
|
||||
err = dbConn.Table("users").Select("name").Where("user_id=?", userID).Find(&userName).Error
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return userName, nil
|
||||
}
|
||||
|
||||
func UpdateUserInfo(user db.User) error {
|
||||
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
|
||||
if err != nil {
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,108 @@
|
||||
syntax = "proto3";
|
||||
import "Open_IM/pkg/proto/sdk_ws/ws.proto";
|
||||
option go_package = "./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 {
|
||||
string tagID = 1;
|
||||
string sendID = 2;
|
||||
int32 senderPlatformID = 3;
|
||||
string content = 4;
|
||||
int32 contentType = 5;
|
||||
string operationID = 6;
|
||||
}
|
||||
|
||||
message SendMsg2TagResp {
|
||||
CommonResp commonResp = 1;
|
||||
}
|
||||
|
||||
message GetTagSendLogsReq {
|
||||
server_api_params.RequestPagination Pagination = 1;
|
||||
string userID = 2;
|
||||
string operationID = 3;
|
||||
}
|
||||
|
||||
message TagSendLog {
|
||||
string tagID = 1;
|
||||
string tagName = 2;
|
||||
int32 contentType = 3;
|
||||
string content = 4;
|
||||
int64 sendTime = 5;
|
||||
repeated string userList = 6;
|
||||
}
|
||||
|
||||
message GetTagSendLogsResp {
|
||||
CommonResp commonResp = 1;
|
||||
server_api_params.ResponsePagination Pagination = 2;
|
||||
repeated TagSendLog tagSendLogs = 3;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user