mirror of
https://github.com/openimsdk/open-im-server.git
synced 2026-05-10 12:05:58 +08:00
EX MSG
This commit is contained in:
@@ -1,8 +1,17 @@
|
||||
package db
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/config"
|
||||
"context"
|
||||
"strconv"
|
||||
"time"
|
||||
)
|
||||
|
||||
const cExtendMsgSet = "extend_msg_set"
|
||||
|
||||
type ExtendMsgSet struct {
|
||||
ID string `bson:"id" json:"ID"`
|
||||
ExtendMsg []*ExtendMsg `bson:"extend_msg" json:"extendMsg"`
|
||||
ExtendMsgs []*ExtendMsg `bson:"extend_msg" json:"extendMsg"`
|
||||
LatestUpdateTime int32 `bson:"latest_update_time" json:"latestUpdateTime"`
|
||||
AttachedInfo string `bson:"attached_info" json:"attachedInfo"`
|
||||
Ex string `bson:"ex" json:"ex"`
|
||||
@@ -10,40 +19,82 @@ type ExtendMsgSet struct {
|
||||
CreateTime int32 `bson:"create_time" json:"createTime"`
|
||||
}
|
||||
|
||||
type ReactionExtendMsgSet struct {
|
||||
TypeKey string `bson:"type_key" json:"typeKey"`
|
||||
Value string `bson:"value" json:"value"`
|
||||
}
|
||||
|
||||
type ExtendMsg struct {
|
||||
SendID string `bson:"send_id" json:"sendID"`
|
||||
ServerMsgID string `bson:"server_msg_id" json:"serverMsgID"`
|
||||
Ex string `bson:"ex" json:"ex"`
|
||||
AttachedInfo string `bson:"attached_info" json:"attachedInfo"`
|
||||
LikeUserIDList []string `bson:"like_user_id_list" json:"likeUserIDList"`
|
||||
Content string `bson:"content" json:"content"`
|
||||
ExtendMsgComments []*ExtendMsgComment `bson:"extend_msg_comments" json:"extendMsgComment"`
|
||||
Vote *Vote `bson:"vote" json:"vote"`
|
||||
Urls []string `bson:"urls" json:"urls"`
|
||||
CreateTime int32 `bson:"create_time" json:"createTime"`
|
||||
Content []*ReactionExtendMsgSet `bson:"content" json:"content"`
|
||||
ClientMsgID string `bson:"client_msg_id" json:"clientMsgID"`
|
||||
CreateTime int32 `bson:"create_time" json:"createTime"`
|
||||
}
|
||||
|
||||
type Vote struct {
|
||||
Content string `bson:"content" json:"content"`
|
||||
AttachedInfo string `bson:"attached_info" json:"attachedInfo"`
|
||||
Ex string `bson:"ex" json:"ex"`
|
||||
Options []*Options `bson:"options" json:"options"`
|
||||
//type Vote struct {
|
||||
// Content string `bson:"content" json:"content"`
|
||||
// AttachedInfo string `bson:"attached_info" json:"attachedInfo"`
|
||||
// Ex string `bson:"ex" json:"ex"`
|
||||
// Options []*Options `bson:"options" json:"options"`
|
||||
//}
|
||||
//
|
||||
//type Options struct {
|
||||
// Content string `bson:"content" json:"content"`
|
||||
// AttachedInfo string `bson:"attached_info" json:"attachedInfo"`
|
||||
// Ex string `bson:"ex" json:"ex"`
|
||||
// VoteUserIDList []string `bson:"vote_user_id_list" json:"voteUserIDList"`
|
||||
//}
|
||||
//
|
||||
//type ExtendMsgComment struct {
|
||||
// UserID string `bson:"user_id" json:"userID"`
|
||||
// ReplyUserID string `bson:"reply_user_id" json:"replyUserID"`
|
||||
// ReplyContentID string `bson:"reply_content_id" json:"replyContentID"`
|
||||
// ContentID string `bson:"content_id" json:"contentID"`
|
||||
// Content string `bson:"content" json:"content"`
|
||||
// CreateTime int32 `bson:"create_time" json:"createTime"`
|
||||
// AttachedInfo string `bson:"attached_info" json:"attachedInfo"`
|
||||
// Ex string `bson:"ex" json:"ex"`
|
||||
//}
|
||||
|
||||
func GetExtendMsgSetID(ID string, index int32) string {
|
||||
return ID + ":" + strconv.Itoa(int(index))
|
||||
}
|
||||
|
||||
type Options struct {
|
||||
Content string `bson:"content" json:"content"`
|
||||
AttachedInfo string `bson:"attached_info" json:"attachedInfo"`
|
||||
Ex string `bson:"ex" json:"ex"`
|
||||
VoteUserIDList []string `bson:"vote_user_id_list" json:"voteUserIDList"`
|
||||
func (d *DataBases) CreateExtendMsgSet(set *ExtendMsgSet) error {
|
||||
ctx, _ := context.WithTimeout(context.Background(), time.Duration(config.Config.Mongo.DBTimeout)*time.Second)
|
||||
c := d.mongoClient.Database(config.Config.Mongo.DBDatabase).Collection(cExtendMsgSet)
|
||||
_, err := c.InsertOne(ctx, set)
|
||||
return err
|
||||
}
|
||||
|
||||
type ExtendMsgComment struct {
|
||||
UserID string `bson:"user_id" json:"userID"`
|
||||
ReplyUserID string `bson:"reply_user_id" json:"replyUserID"`
|
||||
ReplyContentID string `bson:"reply_content_id" json:"replyContentID"`
|
||||
ContentID string `bson:"content_id" json:"contentID"`
|
||||
Content string `bson:"content" json:"content"`
|
||||
CreateTime int32 `bson:"create_time" json:"createTime"`
|
||||
AttachedInfo string `bson:"attached_info" json:"attachedInfo"`
|
||||
Ex string `bson:"ex" json:"ex"`
|
||||
func (d *DataBases) GetAllExtendMsgSet(ID string) ([]*ExtendMsgSet, error) {
|
||||
//ctx, _ := context.WithTimeout(context.Background(), time.Duration(config.Config.Mongo.DBTimeout)*time.Second)
|
||||
//c := d.mongoClient.Database(config.Config.Mongo.DBDatabase).Collection(cExtendMsgSet)
|
||||
|
||||
}
|
||||
|
||||
type GetExtendMsgSetOpts struct {
|
||||
IncludeExtendMsgs bool
|
||||
}
|
||||
|
||||
func (d *DataBases) GetExtendMsgSet(ID string, index int32, opts *GetExtendMsgSetOpts) (*ExtendMsgSet, error) {
|
||||
//ctx, _ := context.WithTimeout(context.Background(), time.Duration(config.Config.Mongo.DBTimeout)*time.Second)
|
||||
//c := d.mongoClient.Database(config.Config.Mongo.DBDatabase).Collection(cExtendMsgSet)
|
||||
}
|
||||
|
||||
func (d *DataBases) InsertExtendMsg(ID string, msg *ExtendMsg) error {
|
||||
//ctx, _ := context.WithTimeout(context.Background(), time.Duration(config.Config.Mongo.DBTimeout)*time.Second)
|
||||
//c := d.mongoClient.Database(config.Config.Mongo.DBDatabase).Collection(cExtendMsgSet)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (d *DataBases) UpdateOneExtendMsgSet(ID string, index, MsgIndex int32, msg *ExtendMsg, msgSet *ExtendMsgSet) error {
|
||||
//ctx, _ := context.WithTimeout(context.Background(), time.Duration(config.Config.Mongo.DBTimeout)*time.Second)
|
||||
//c := d.mongoClient.Database(config.Config.Mongo.DBDatabase).Collection(cExtendMsgSet)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (d *DataBases) GetExtendMsgList(ID string, index, msgStartIndex, msgEndIndex int32) ([]*ExtendMsgSet, error) {
|
||||
//ctx, _ := context.WithTimeout(context.Background(), time.Duration(config.Config.Mongo.DBTimeout)*time.Second)
|
||||
//c := d.mongoClient.Database(config.Config.Mongo.DBDatabase).Collection(cExtendMsgSet)
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
@@ -291,13 +291,13 @@ func (d *DataBases) DelMongoMsgs(IDList []string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
func (d *DataBases) ReplaceMsgToBlankByIndex(suffixID string, index int) error {
|
||||
func (d *DataBases) ReplaceMsgToBlankByIndex(suffixID string, index int) (replaceMaxSeq uint32, err error) {
|
||||
ctx, _ := context.WithTimeout(context.Background(), time.Duration(config.Config.Mongo.DBTimeout)*time.Second)
|
||||
c := d.mongoClient.Database(config.Config.Mongo.DBDatabase).Collection(cChat)
|
||||
userChat := &UserChat{}
|
||||
err := c.FindOne(ctx, bson.M{"uid": suffixID}).Decode(&userChat)
|
||||
err = c.FindOne(ctx, bson.M{"uid": suffixID}).Decode(&userChat)
|
||||
if err != nil {
|
||||
return err
|
||||
return 0, err
|
||||
}
|
||||
for i, msg := range userChat.Msg {
|
||||
if i <= index {
|
||||
@@ -312,10 +312,11 @@ func (d *DataBases) ReplaceMsgToBlankByIndex(suffixID string, index int) error {
|
||||
}
|
||||
msg.Msg = bytes
|
||||
msg.SendTime = 0
|
||||
replaceMaxSeq = msgPb.Seq
|
||||
}
|
||||
}
|
||||
_, err = c.UpdateOne(ctx, bson.M{"uid": suffixID}, bson.M{"$set": bson.M{"msg": userChat.Msg}})
|
||||
return err
|
||||
return replaceMaxSeq, err
|
||||
}
|
||||
|
||||
func (d *DataBases) GetNewestMsg(ID string) (msg *open_im_sdk.MsgData, err error) {
|
||||
|
||||
@@ -33,6 +33,8 @@ const (
|
||||
groupMemberNumCache = "GROUP_MEMBER_NUM_CACHE:"
|
||||
conversationCache = "CONVERSATION_CACHE:"
|
||||
conversationIDListCache = "CONVERSATION_ID_LIST_CACHE:"
|
||||
extendMsgSetCache = "EXTEND_MSG_SET_CACHE:"
|
||||
extendMsgCache = "EXTEND_MSG_CACHE:"
|
||||
)
|
||||
|
||||
func DelKeys() {
|
||||
@@ -564,3 +566,63 @@ func GetUserAllConversationList(ownerUserID string) ([]db.Conversation, error) {
|
||||
func DelConversationFromCache(ownerUserID, conversationID string) error {
|
||||
return utils.Wrap(db.DB.Rc.TagAsDeleted(conversationCache+ownerUserID+":"+conversationID), "DelConversationFromCache err")
|
||||
}
|
||||
|
||||
func GetExtendMsgSetFromCache(ID string, index int32) (*db.ExtendMsgSet, error) {
|
||||
getExtendMsgSet := func() (string, error) {
|
||||
extendMsgSet, err := db.DB.GetExtendMsgSet(ID, index, &db.GetExtendMsgSetOpts{IncludeExtendMsgs: false})
|
||||
if err != nil {
|
||||
return "", utils.Wrap(err, "GetExtendMsgSet failed")
|
||||
}
|
||||
bytes, err := json.Marshal(extendMsgSet)
|
||||
if err != nil {
|
||||
return "", utils.Wrap(err, "Marshal failed")
|
||||
}
|
||||
return string(bytes), nil
|
||||
}
|
||||
extendMsgSetStr, err := db.DB.Rc.Fetch(extendMsgSetCache+db.GetExtendMsgSetID(ID, index), time.Second*30*60, getExtendMsgSet)
|
||||
if err != nil {
|
||||
return nil, utils.Wrap(err, "Fetch failed")
|
||||
}
|
||||
extendMsgSet := &db.ExtendMsgSet{}
|
||||
err = json.Unmarshal([]byte(extendMsgSetStr), extendMsgSet)
|
||||
if err != nil {
|
||||
return nil, utils.Wrap(err, "Unmarshal failed")
|
||||
}
|
||||
return extendMsgSet, nil
|
||||
}
|
||||
|
||||
func DelExtendMsgSetFromCache(ID string, index int32) error {
|
||||
return utils.Wrap(db.DB.Rc.TagAsDeleted(extendMsgSetCache+db.GetExtendMsgSetID(ID, index)), "DelExtendMsgSetFromCache err")
|
||||
}
|
||||
|
||||
func GetExtendMsg(ID string, index, extendMsgIndex int32) (*db.ExtendMsg, error) {
|
||||
getExtendMsg := func() (string, error) {
|
||||
extendMsg, err := db.DB.GetExtendMsgList(ID, index, extendMsgIndex, extendMsgIndex+1)
|
||||
if err != nil {
|
||||
return "", utils.Wrap(err, "GetExtendMsgList failed")
|
||||
}
|
||||
if len(extendMsg) == 0 {
|
||||
return "", nil
|
||||
}
|
||||
bytes, err := json.Marshal(extendMsg[0])
|
||||
if err != nil {
|
||||
return "", utils.Wrap(err, "Marshal failed")
|
||||
}
|
||||
return string(bytes), nil
|
||||
}
|
||||
|
||||
extendMsgStr, err := db.DB.Rc.Fetch(extendMsgCache+db.GetExtendMsgSetID(ID, index)+":"+strconv.Itoa(int(extendMsgIndex)), time.Second*30*60, getExtendMsg)
|
||||
if err != nil {
|
||||
return nil, utils.Wrap(err, "Fetch failed")
|
||||
}
|
||||
extendMsg := &db.ExtendMsg{}
|
||||
err = json.Unmarshal([]byte(extendMsgStr), extendMsg)
|
||||
if err != nil {
|
||||
return nil, utils.Wrap(err, "Unmarshal failed")
|
||||
}
|
||||
return extendMsg, nil
|
||||
}
|
||||
|
||||
func DelExtendMsg(ID string, index, extendMsgIndex int32) error {
|
||||
return utils.Wrap(db.DB.Rc.TagAsDeleted(extendMsgCache+db.GetExtendMsgSetID(ID, index)+":"+strconv.Itoa(int(extendMsgIndex))), "DelExtendMsg err")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user