mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-04-25 11:06:43 +08:00
workMoments
This commit is contained in:
parent
9c62f38345
commit
4ba87e3349
@ -4,6 +4,7 @@ import (
|
|||||||
"Open_IM/pkg/common/constant"
|
"Open_IM/pkg/common/constant"
|
||||||
"Open_IM/pkg/common/log"
|
"Open_IM/pkg/common/log"
|
||||||
pbOffice "Open_IM/pkg/proto/office"
|
pbOffice "Open_IM/pkg/proto/office"
|
||||||
|
sdk "Open_IM/pkg/proto/sdk_ws"
|
||||||
"Open_IM/pkg/utils"
|
"Open_IM/pkg/utils"
|
||||||
"github.com/golang/protobuf/jsonpb"
|
"github.com/golang/protobuf/jsonpb"
|
||||||
"github.com/golang/protobuf/proto"
|
"github.com/golang/protobuf/proto"
|
||||||
@ -11,17 +12,21 @@ import (
|
|||||||
|
|
||||||
func WorkMomentSendNotification(operationID, sendID, recvID string, notificationMsg *pbOffice.WorkMomentNotificationMsg) {
|
func WorkMomentSendNotification(operationID, sendID, recvID string, notificationMsg *pbOffice.WorkMomentNotificationMsg) {
|
||||||
log.NewInfo(operationID, utils.GetSelfFuncName(), sendID, recvID, notificationMsg)
|
log.NewInfo(operationID, utils.GetSelfFuncName(), sendID, recvID, notificationMsg)
|
||||||
|
//if sendID == recvID {
|
||||||
|
// return
|
||||||
|
//}
|
||||||
WorkMomentNotification(operationID, sendID, recvID, notificationMsg)
|
WorkMomentNotification(operationID, sendID, recvID, notificationMsg)
|
||||||
}
|
}
|
||||||
|
|
||||||
func WorkMomentNotification(operationID, sendID, recvID string, m proto.Message) {
|
func WorkMomentNotification(operationID, sendID, recvID string, m proto.Message) {
|
||||||
//var tips open_im_sdk.TipsComm
|
var tips sdk.TipsComm
|
||||||
|
var err error
|
||||||
marshaler := jsonpb.Marshaler{
|
marshaler := jsonpb.Marshaler{
|
||||||
OrigName: true,
|
OrigName: true,
|
||||||
EnumsAsInts: false,
|
EnumsAsInts: false,
|
||||||
EmitDefaults: false,
|
EmitDefaults: false,
|
||||||
}
|
}
|
||||||
JsonDetail, _ := marshaler.MarshalToString(m)
|
tips.JsonDetail, _ = marshaler.MarshalToString(m)
|
||||||
n := &NotificationMsg{
|
n := &NotificationMsg{
|
||||||
SendID: sendID,
|
SendID: sendID,
|
||||||
RecvID: recvID,
|
RecvID: recvID,
|
||||||
@ -30,7 +35,11 @@ func WorkMomentNotification(operationID, sendID, recvID string, m proto.Message)
|
|||||||
SessionType: constant.SingleChatType,
|
SessionType: constant.SingleChatType,
|
||||||
OperationID: operationID,
|
OperationID: operationID,
|
||||||
}
|
}
|
||||||
n.Content = []byte(JsonDetail)
|
n.Content, err = proto.Marshal(&tips)
|
||||||
log.NewInfo(operationID, utils.GetSelfFuncName(), JsonDetail)
|
if err != nil {
|
||||||
|
log.NewError(operationID, utils.GetSelfFuncName(), "proto.Marshal failed")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
log.NewInfo(operationID, utils.GetSelfFuncName(), string(n.Content))
|
||||||
Notification(n)
|
Notification(n)
|
||||||
}
|
}
|
||||||
|
@ -381,7 +381,7 @@ func (s *officeServer) LikeOneWorkMoment(_ context.Context, req *pbOffice.LikeOn
|
|||||||
resp.CommonResp = &pbOffice.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}
|
resp.CommonResp = &pbOffice.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}
|
||||||
return resp, nil
|
return resp, nil
|
||||||
}
|
}
|
||||||
workMoment, err := db.DB.LikeOneWorkMoment(req.UserID, userName, req.WorkMomentID)
|
workMoment, like, err := db.DB.LikeOneWorkMoment(req.UserID, userName, req.WorkMomentID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "LikeOneWorkMoment failed ", err.Error())
|
log.NewError(req.OperationID, utils.GetSelfFuncName(), "LikeOneWorkMoment failed ", err.Error())
|
||||||
resp.CommonResp = &pbOffice.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}
|
resp.CommonResp = &pbOffice.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}
|
||||||
@ -392,9 +392,13 @@ func (s *officeServer) LikeOneWorkMoment(_ context.Context, req *pbOffice.LikeOn
|
|||||||
WorkMomentID: workMoment.WorkMomentID,
|
WorkMomentID: workMoment.WorkMomentID,
|
||||||
WorkMomentContent: workMoment.Content,
|
WorkMomentContent: workMoment.Content,
|
||||||
UserID: workMoment.UserID,
|
UserID: workMoment.UserID,
|
||||||
|
FaceURL: workMoment.FaceURL,
|
||||||
|
UserName: workMoment.UserName,
|
||||||
}
|
}
|
||||||
// send notification
|
// send notification
|
||||||
|
if like {
|
||||||
msg.WorkMomentSendNotification(req.OperationID, req.UserID, workMoment.UserID, workMomentNotificationMsg)
|
msg.WorkMomentSendNotification(req.OperationID, req.UserID, workMoment.UserID, workMomentNotificationMsg)
|
||||||
|
}
|
||||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp: ", resp.String())
|
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp: ", resp.String())
|
||||||
return resp, nil
|
return resp, nil
|
||||||
}
|
}
|
||||||
@ -436,6 +440,8 @@ func (s *officeServer) CommentOneWorkMoment(_ context.Context, req *pbOffice.Com
|
|||||||
WorkMomentID: workMoment.WorkMomentID,
|
WorkMomentID: workMoment.WorkMomentID,
|
||||||
WorkMomentContent: workMoment.Content,
|
WorkMomentContent: workMoment.Content,
|
||||||
UserID: workMoment.UserID,
|
UserID: workMoment.UserID,
|
||||||
|
FaceURL: workMoment.FaceURL,
|
||||||
|
UserName: workMoment.UserName,
|
||||||
Comment: &pbOffice.Comment{
|
Comment: &pbOffice.Comment{
|
||||||
UserID: comment.UserID,
|
UserID: comment.UserID,
|
||||||
UserName: comment.UserName,
|
UserName: comment.UserName,
|
||||||
|
@ -624,10 +624,10 @@ func (d *DataBases) GetWorkMomentByID(workMomentID string) (*WorkMoment, error)
|
|||||||
return workMoment, err
|
return workMoment, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *DataBases) LikeOneWorkMoment(likeUserID, userName, workMomentID string) (*WorkMoment, error) {
|
func (d *DataBases) LikeOneWorkMoment(likeUserID, userName, workMomentID string) (*WorkMoment, bool, error) {
|
||||||
workMoment, err := d.GetWorkMomentByID(workMomentID)
|
workMoment, err := d.GetWorkMomentByID(workMomentID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, false, err
|
||||||
}
|
}
|
||||||
var isAlreadyLike bool
|
var isAlreadyLike bool
|
||||||
for i, user := range workMoment.LikeUserList {
|
for i, user := range workMoment.LikeUserList {
|
||||||
@ -643,7 +643,7 @@ func (d *DataBases) LikeOneWorkMoment(likeUserID, userName, workMomentID string)
|
|||||||
ctx, _ := context.WithTimeout(context.Background(), time.Duration(config.Config.Mongo.DBTimeout)*time.Second)
|
ctx, _ := context.WithTimeout(context.Background(), time.Duration(config.Config.Mongo.DBTimeout)*time.Second)
|
||||||
c := d.mongoClient.Database(config.Config.Mongo.DBDatabase).Collection(cWorkMoment)
|
c := d.mongoClient.Database(config.Config.Mongo.DBDatabase).Collection(cWorkMoment)
|
||||||
_, err = c.UpdateOne(ctx, bson.M{"work_moment_id": workMomentID}, bson.M{"$set": bson.M{"like_user_list": workMoment.LikeUserList}})
|
_, err = c.UpdateOne(ctx, bson.M{"work_moment_id": workMomentID}, bson.M{"$set": bson.M{"like_user_list": workMoment.LikeUserList}})
|
||||||
return workMoment, err
|
return workMoment, !isAlreadyLike, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *DataBases) SetUserWorkMomentsLevel(userID string, level int32) error {
|
func (d *DataBases) SetUserWorkMomentsLevel(userID string, level int32) error {
|
||||||
@ -672,30 +672,17 @@ func (d *DataBases) GetUserWorkMoments(userID string, showNumber, pageNumber int
|
|||||||
return workMomentList, err
|
return workMomentList, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// recursion
|
|
||||||
func (d *DataBases) GetUserFriendWorkMomentsRecursion(friendIDList []string, showNumber, pageNumber int32, userID string) ([]WorkMoment, error) {
|
|
||||||
ctx, _ := context.WithTimeout(context.Background(), time.Duration(config.Config.Mongo.DBTimeout)*time.Second)
|
|
||||||
c := d.mongoClient.Database(config.Config.Mongo.DBDatabase).Collection(cWorkMoment)
|
|
||||||
var workMomentList []WorkMoment
|
|
||||||
findOpts := options.Find().SetLimit(int64(showNumber)).SetSkip(int64(showNumber) * (int64(pageNumber) - 1)).SetSort(bson.M{"create_time": -1})
|
|
||||||
result, err := c.Find(ctx, bson.M{"user_id": friendIDList, "is_private": false, "who_can_see_user_id_list": bson.M{"$elemMatch": bson.M{"$eq": userID}}, "who_cant_see_user_id_list": ""}, findOpts)
|
|
||||||
if err != nil {
|
|
||||||
return workMomentList, nil
|
|
||||||
}
|
|
||||||
err = result.All(ctx, &workMomentList)
|
|
||||||
return workMomentList, err
|
|
||||||
}
|
|
||||||
|
|
||||||
func (d *DataBases) GetUserFriendWorkMoments(friendIDList []*string, showNumber, pageNumber int32, userID string) ([]WorkMoment, error) {
|
func (d *DataBases) GetUserFriendWorkMoments(friendIDList []*string, showNumber, pageNumber int32, userID string) ([]WorkMoment, error) {
|
||||||
ctx, _ := context.WithTimeout(context.Background(), time.Duration(config.Config.Mongo.DBTimeout)*time.Second)
|
ctx, _ := context.WithTimeout(context.Background(), time.Duration(config.Config.Mongo.DBTimeout)*time.Second)
|
||||||
c := d.mongoClient.Database(config.Config.Mongo.DBDatabase).Collection(cWorkMoment)
|
c := d.mongoClient.Database(config.Config.Mongo.DBDatabase).Collection(cWorkMoment)
|
||||||
var workMomentList []WorkMoment
|
var workMomentList []WorkMoment
|
||||||
findOpts := options.Find().SetLimit(int64(showNumber)).SetSkip(int64(showNumber) * (int64(pageNumber) - 1)).SetSort(bson.M{"create_time": -1})
|
findOpts := options.Find().SetLimit(int64(showNumber)).SetSkip(int64(showNumber) * (int64(pageNumber) - 1)).SetSort(bson.M{"create_time": -1})
|
||||||
result, err := c.Find(ctx, bson.M{"user_id": friendIDList, "is_private": false, "$or": bson.M{"who_can_see_user_id_list": bson.M{"$elemMatch": bson.M{"$eq": userID}},
|
result, err := c.Find(ctx,
|
||||||
|
bson.M{"user_id": friendIDList, "$or": bson.M{"who_can_see_user_id_list": bson.M{"$elemMatch": bson.M{"$eq": userID}},
|
||||||
"who_cant_see_user_id_list": bson.M{"$nin": userID}},
|
"who_cant_see_user_id_list": bson.M{"$nin": userID}},
|
||||||
}, findOpts)
|
}, findOpts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return workMomentList, nil
|
return workMomentList, err
|
||||||
}
|
}
|
||||||
err = result.All(ctx, &workMomentList)
|
err = result.All(ctx, &workMomentList)
|
||||||
return workMomentList, err
|
return workMomentList, err
|
||||||
|
Loading…
x
Reference in New Issue
Block a user