mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-04-06 04:15:46 +08:00
office
This commit is contained in:
parent
243f5fcda4
commit
3c68ecb7f1
@ -299,6 +299,7 @@ func GetUserWorkMoments(c *gin.Context) {
|
||||
Comments: make([]*apiStruct.Comment, len(v.Comments)),
|
||||
LikeUserList: make([]*apiStruct.WorkMomentUser, len(v.LikeUserList)),
|
||||
AtUserList: make([]*apiStruct.WorkMomentUser, len(v.AtUserList)),
|
||||
PermissionUserList: make([]*apiStruct.WorkMomentUser, len(v.PermissionUserList)),
|
||||
Permission: v.Permission,
|
||||
}
|
||||
for i, comment := range v.Comments {
|
||||
@ -324,6 +325,12 @@ func GetUserWorkMoments(c *gin.Context) {
|
||||
UserName: atUser.UserName,
|
||||
}
|
||||
}
|
||||
for i, permissionUser := range v.PermissionUserList {
|
||||
workMoment.PermissionUserList[i] = &apiStruct.WorkMomentUser{
|
||||
UserID: permissionUser.UserID,
|
||||
UserName: permissionUser.UserName,
|
||||
}
|
||||
}
|
||||
resp.Data.WorkMoments = append(resp.Data.WorkMoments, &workMoment)
|
||||
}
|
||||
resp.Data.ShowNumber = respPb.Pagination.ShowNumber
|
||||
@ -383,6 +390,7 @@ func GetUserFriendWorkMoments(c *gin.Context) {
|
||||
Comments: make([]*apiStruct.Comment, len(v.Comments)),
|
||||
LikeUserList: make([]*apiStruct.WorkMomentUser, len(v.LikeUserList)),
|
||||
AtUserList: make([]*apiStruct.WorkMomentUser, len(v.AtUserList)),
|
||||
PermissionUserList: make([]*apiStruct.WorkMomentUser, len(v.PermissionUserList)),
|
||||
Permission: v.Permission,
|
||||
}
|
||||
for i, comment := range v.Comments {
|
||||
@ -408,6 +416,12 @@ func GetUserFriendWorkMoments(c *gin.Context) {
|
||||
UserName: atUser.UserName,
|
||||
}
|
||||
}
|
||||
for i, permissionUser := range v.PermissionUserList {
|
||||
workMoment.PermissionUserList[i] = &apiStruct.WorkMomentUser{
|
||||
UserID: permissionUser.UserID,
|
||||
UserName: permissionUser.UserName,
|
||||
}
|
||||
}
|
||||
resp.Data.WorkMoments = append(resp.Data.WorkMoments, &workMoment)
|
||||
}
|
||||
resp.Data.ShowNumber = respPb.Pagination.ShowNumber
|
||||
|
@ -272,7 +272,8 @@ func (s *officeServer) CreateOneWorkMoment(_ context.Context, req *pbOffice.Crea
|
||||
resp = &pbOffice.CreateOneWorkMomentResp{CommonResp: &pbOffice.CommonResp{}}
|
||||
workMoment := db.WorkMoment{
|
||||
Comments: []*db.Comment{},
|
||||
LikeUserList: []*db.LikeUser{},
|
||||
LikeUserList: []*db.WorkMomentUser{},
|
||||
PermissionUserList: []*db.WorkMomentUser{},
|
||||
}
|
||||
createUser, err := imdb.GetUserByUserID(req.WorkMoment.UserID)
|
||||
if err != nil {
|
||||
@ -286,6 +287,17 @@ func (s *officeServer) CreateOneWorkMoment(_ context.Context, req *pbOffice.Crea
|
||||
workMoment.UserName = createUser.Nickname
|
||||
workMoment.FaceURL = createUser.FaceURL
|
||||
workMoment.PermissionUserIDList = s.getPermissionUserIDList(req.OperationID, req.WorkMoment.PermissionGroupList, req.WorkMoment.PermissionUserList)
|
||||
for _, userID := range workMoment.PermissionUserIDList {
|
||||
userName, err := imdb.GetUserNameByUserID(userID)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetUserNameByUserID failed", err.Error())
|
||||
continue
|
||||
}
|
||||
workMoment.PermissionUserList = append(workMoment.PermissionUserList, &db.WorkMomentUser{
|
||||
UserID: userID,
|
||||
UserName: userName,
|
||||
})
|
||||
}
|
||||
log.NewDebug(req.OperationID, utils.GetSelfFuncName(), "workMoment to create", workMoment)
|
||||
err = db.DB.CreateOneWorkMoment(&workMoment)
|
||||
if err != nil {
|
||||
|
@ -66,6 +66,7 @@ type WorkMoment struct {
|
||||
FaceURL string `json:"faceURL"`
|
||||
UserName string `json:"userName"`
|
||||
AtUserList []*WorkMomentUser `json:"atUsers"`
|
||||
PermissionUserList []*WorkMomentUser `json:"permissionUsers"`
|
||||
CreateTime int32 `json:"createTime"`
|
||||
Permission int32 `json:"permission"`
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ package db
|
||||
import (
|
||||
"Open_IM/pkg/common/config"
|
||||
"go.mongodb.org/mongo-driver/bson"
|
||||
"go.mongodb.org/mongo-driver/x/bsonx"
|
||||
|
||||
//"Open_IM/pkg/common/log"
|
||||
"Open_IM/pkg/utils"
|
||||
@ -73,12 +74,25 @@ func init() {
|
||||
|
||||
cSendLogModels := []mongo.IndexModel{
|
||||
{
|
||||
Keys: bson.M{"user_id": -1},
|
||||
Keys: bsonx.Doc{
|
||||
{
|
||||
Key: "send_id",
|
||||
},
|
||||
},
|
||||
Options: options.Index().SetUnique(true),
|
||||
},
|
||||
{
|
||||
Keys: bsonx.Doc{
|
||||
{
|
||||
Key: "send_time",
|
||||
Value: bsonx.Int32(-1),
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
result, err := dataBase.Collection(cSendLog).Indexes().CreateMany(context.Background(), cSendLogModels, opts)
|
||||
if err != nil {
|
||||
//fmt.Println("mongodb create cSendLogModels failed", result, err.Error())
|
||||
fmt.Println("mongodb create cSendLogModels failed", result, err.Error())
|
||||
}
|
||||
|
||||
cChatModels := []mongo.IndexModel{
|
||||
@ -93,28 +107,68 @@ func init() {
|
||||
|
||||
cWorkMomentModels := []mongo.IndexModel{
|
||||
{
|
||||
Keys: bson.M{"work_moment_id": -1},
|
||||
Keys: bsonx.Doc{
|
||||
{
|
||||
Key: "create_time",
|
||||
Value: bsonx.Int32(-1),
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
Keys: bson.M{"user_id": -1},
|
||||
Keys: bsonx.Doc{
|
||||
{
|
||||
Key: "work_moment_id",
|
||||
},
|
||||
},
|
||||
Options: options.Index().SetUnique(true),
|
||||
},
|
||||
}
|
||||
cWorkMomentModel2 := []mongo.IndexModel{
|
||||
{
|
||||
Keys: bsonx.Doc{
|
||||
{
|
||||
Key: "work_moment_id",
|
||||
},
|
||||
},
|
||||
Options: options.Index().SetUnique(true),
|
||||
},
|
||||
}
|
||||
result, err = dataBase.Collection(cWorkMoment).Indexes().CreateMany(context.Background(), cWorkMomentModels, opts)
|
||||
if err != nil {
|
||||
//fmt.Println("mongodb create cWorkMomentModels failed", result, err.Error())
|
||||
fmt.Println("mongodb create cWorkMomentModels failed", result, err.Error())
|
||||
}
|
||||
result, err = dataBase.Collection(cWorkMoment).Indexes().CreateMany(context.Background(), cWorkMomentModel2, opts)
|
||||
if err != nil {
|
||||
fmt.Println("mongodb create cWorkMomentModels failed", result, err.Error())
|
||||
}
|
||||
|
||||
cTagModels := []mongo.IndexModel{
|
||||
cTagModel1 := []mongo.IndexModel{
|
||||
{
|
||||
Keys: bson.M{"tag_id": -1},
|
||||
Keys: bsonx.Doc{
|
||||
{
|
||||
Key: "tag_id",
|
||||
},
|
||||
{
|
||||
Keys: bson.M{"user_id": -1},
|
||||
},
|
||||
Options: options.Index().SetUnique(true),
|
||||
},
|
||||
}
|
||||
result, err = dataBase.Collection(cTag).Indexes().CreateMany(context.Background(), cTagModels, opts)
|
||||
cTagModel2 := []mongo.IndexModel{
|
||||
{
|
||||
Keys: bsonx.Doc{
|
||||
{
|
||||
Key: "user_id",
|
||||
},
|
||||
},
|
||||
Options: options.Index().SetUnique(true),
|
||||
},
|
||||
}
|
||||
result, err = dataBase.Collection(cTag).Indexes().CreateMany(context.Background(), cTagModel1, opts)
|
||||
if err != nil {
|
||||
//fmt.Println("mongodb create cTagModels failed", result, err.Error())
|
||||
fmt.Println("mongodb create cTagModel1 failed", result, err.Error())
|
||||
}
|
||||
result, err = dataBase.Collection(cTag).Indexes().CreateMany(context.Background(), cTagModel2, opts)
|
||||
if err != nil {
|
||||
fmt.Println("mongodb create cTagModel2 failed", result, err.Error())
|
||||
}
|
||||
DB.mongoClient = mongoClient
|
||||
|
||||
|
@ -671,20 +671,16 @@ type WorkMoment struct {
|
||||
UserName string `bson:"user_name"`
|
||||
FaceURL string `bson:"face_url"`
|
||||
Content string `bson:"content"`
|
||||
LikeUserList []*LikeUser `bson:"like_user_list"`
|
||||
AtUserList []*AtUser `bson:"at_user_list"`
|
||||
LikeUserList []*WorkMomentUser `bson:"like_user_list"`
|
||||
AtUserList []*WorkMomentUser `bson:"at_user_list"`
|
||||
PermissionUserList []*WorkMomentUser `bson:"permission_user_list"`
|
||||
Comments []*Comment `bson:"comments"`
|
||||
PermissionUserIDList []string `bson:"permission_user_id_list"`
|
||||
Permission int32 `bson:"permission"`
|
||||
CreateTime int32 `bson:"create_time"`
|
||||
}
|
||||
|
||||
type AtUser struct {
|
||||
UserID string `bson:"user_id"`
|
||||
UserName string `bson:"user_name"`
|
||||
}
|
||||
|
||||
type LikeUser struct {
|
||||
type WorkMomentUser struct {
|
||||
UserID string `bson:"user_id"`
|
||||
UserName string `bson:"user_name"`
|
||||
}
|
||||
@ -749,7 +745,7 @@ func (d *DataBases) LikeOneWorkMoment(likeUserID, userName, workMomentID string)
|
||||
}
|
||||
}
|
||||
if !isAlreadyLike {
|
||||
workMoment.LikeUserList = append(workMoment.LikeUserList, &LikeUser{UserID: likeUserID, UserName: userName})
|
||||
workMoment.LikeUserList = append(workMoment.LikeUserList, &WorkMomentUser{UserID: likeUserID, UserName: userName})
|
||||
}
|
||||
log.NewDebug("", utils.GetSelfFuncName(), workMoment)
|
||||
ctx, _ := context.WithTimeout(context.Background(), time.Duration(config.Config.Mongo.DBTimeout)*time.Second)
|
||||
|
Loading…
x
Reference in New Issue
Block a user