mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-04-06 04:15:46 +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/log"
|
||||
pbOffice "Open_IM/pkg/proto/office"
|
||||
sdk "Open_IM/pkg/proto/sdk_ws"
|
||||
"Open_IM/pkg/utils"
|
||||
"github.com/golang/protobuf/jsonpb"
|
||||
"github.com/golang/protobuf/proto"
|
||||
@ -11,17 +12,21 @@ import (
|
||||
|
||||
func WorkMomentSendNotification(operationID, sendID, recvID string, notificationMsg *pbOffice.WorkMomentNotificationMsg) {
|
||||
log.NewInfo(operationID, utils.GetSelfFuncName(), sendID, recvID, notificationMsg)
|
||||
//if sendID == recvID {
|
||||
// return
|
||||
//}
|
||||
WorkMomentNotification(operationID, sendID, recvID, notificationMsg)
|
||||
}
|
||||
|
||||
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{
|
||||
OrigName: true,
|
||||
EnumsAsInts: false,
|
||||
EmitDefaults: false,
|
||||
}
|
||||
JsonDetail, _ := marshaler.MarshalToString(m)
|
||||
tips.JsonDetail, _ = marshaler.MarshalToString(m)
|
||||
n := &NotificationMsg{
|
||||
SendID: sendID,
|
||||
RecvID: recvID,
|
||||
@ -30,7 +35,11 @@ func WorkMomentNotification(operationID, sendID, recvID string, m proto.Message)
|
||||
SessionType: constant.SingleChatType,
|
||||
OperationID: operationID,
|
||||
}
|
||||
n.Content = []byte(JsonDetail)
|
||||
log.NewInfo(operationID, utils.GetSelfFuncName(), JsonDetail)
|
||||
n.Content, err = proto.Marshal(&tips)
|
||||
if err != nil {
|
||||
log.NewError(operationID, utils.GetSelfFuncName(), "proto.Marshal failed")
|
||||
return
|
||||
}
|
||||
log.NewInfo(operationID, utils.GetSelfFuncName(), string(n.Content))
|
||||
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}
|
||||
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 {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "LikeOneWorkMoment failed ", err.Error())
|
||||
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,
|
||||
WorkMomentContent: workMoment.Content,
|
||||
UserID: workMoment.UserID,
|
||||
FaceURL: workMoment.FaceURL,
|
||||
UserName: workMoment.UserName,
|
||||
}
|
||||
// send notification
|
||||
msg.WorkMomentSendNotification(req.OperationID, req.UserID, workMoment.UserID, workMomentNotificationMsg)
|
||||
if like {
|
||||
msg.WorkMomentSendNotification(req.OperationID, req.UserID, workMoment.UserID, workMomentNotificationMsg)
|
||||
}
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp: ", resp.String())
|
||||
return resp, nil
|
||||
}
|
||||
@ -436,6 +440,8 @@ func (s *officeServer) CommentOneWorkMoment(_ context.Context, req *pbOffice.Com
|
||||
WorkMomentID: workMoment.WorkMomentID,
|
||||
WorkMomentContent: workMoment.Content,
|
||||
UserID: workMoment.UserID,
|
||||
FaceURL: workMoment.FaceURL,
|
||||
UserName: workMoment.UserName,
|
||||
Comment: &pbOffice.Comment{
|
||||
UserID: comment.UserID,
|
||||
UserName: comment.UserName,
|
||||
|
@ -624,10 +624,10 @@ func (d *DataBases) GetWorkMomentByID(workMomentID string) (*WorkMoment, error)
|
||||
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)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, false, err
|
||||
}
|
||||
var isAlreadyLike bool
|
||||
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)
|
||||
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}})
|
||||
return workMoment, err
|
||||
return workMoment, !isAlreadyLike, err
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
// 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) {
|
||||
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, "$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}},
|
||||
}, findOpts)
|
||||
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}},
|
||||
}, findOpts)
|
||||
if err != nil {
|
||||
return workMomentList, nil
|
||||
return workMomentList, err
|
||||
}
|
||||
err = result.All(ctx, &workMomentList)
|
||||
return workMomentList, err
|
||||
|
Loading…
x
Reference in New Issue
Block a user