RevokeMsg

This commit is contained in:
withchao
2023-05-23 17:11:56 +08:00
parent 9e7bc1b769
commit 5061047164
9 changed files with 854 additions and 692 deletions
+2
View File
@@ -84,6 +84,8 @@ const (
ConversationPrivateChatNotification = 1701
ConversationUnreadNotification = 1702
MsgRevokeNotification = 1750
BusinessNotificationBegin = 2000
BusinessNotification = 2001
BusinessNotificationEnd = 2099
+8
View File
@@ -32,6 +32,8 @@ import (
type CommonMsgDatabase interface {
// 批量插入消息
BatchInsertChat2DB(ctx context.Context, conversationID string, msgs []*sdkws.MsgData, currentMaxSeq int64) error
// 撤回消息
RevokeMsg(ctx context.Context, conversationID string, seq int64, msg []byte) error
// 刪除redis中消息缓存
DeleteMessageFromCache(ctx context.Context, conversationID string, msgs []*sdkws.MsgData) error
// incrSeq然后批量插入缓存
@@ -222,6 +224,12 @@ func (db *commonMsgDatabase) BatchInsertChat2DB(ctx context.Context, conversatio
return nil
}
func (db *commonMsgDatabase) RevokeMsg(ctx context.Context, conversationID string, seq int64, msg []byte) error {
index := seq / db.msg.GetSingleGocMsgNum()
docID := db.msg.IndexDocID(conversationID, index)
return db.msgDocDatabase.UpdateMsgContent(ctx, docID, seq%db.msg.GetSingleGocMsgNum(), msg)
}
func (db *commonMsgDatabase) DeleteMessageFromCache(ctx context.Context, conversationID string, msgs []*sdkws.MsgData) error {
return db.cache.DeleteMessageFromCache(ctx, conversationID, msgs)
}
+1
View File
@@ -29,6 +29,7 @@ type MsgDocModelInterface interface {
PushMsgsToDoc(ctx context.Context, docID string, msgsToMongo []MsgInfoModel) error
Create(ctx context.Context, model *MsgDocModel) error
UpdateMsg(ctx context.Context, docID string, index int64, info *MsgInfoModel) error
UpdateMsgContent(ctx context.Context, docID string, index int64, msg []byte) error
IsExistDocID(ctx context.Context, docID string) (bool, error)
UpdateMsgStatusByIndexInOneDoc(ctx context.Context, docID string, msg *sdkws.MsgData, seqIndex int, status int32) error
FindOneByDocID(ctx context.Context, docID string) (*MsgDocModel, error)
+8
View File
@@ -46,6 +46,14 @@ func (m *MsgMongoDriver) UpdateMsg(ctx context.Context, docID string, index int6
return nil
}
func (m *MsgMongoDriver) UpdateMsgContent(ctx context.Context, docID string, index int64, msg []byte) error {
_, err := m.MsgCollection.UpdateOne(ctx, bson.M{"doc_id": docID}, bson.M{"$set": bson.M{fmt.Sprintf("msgs.%d.msg", index): msg}})
if err != nil {
return utils.Wrap(err, "")
}
return nil
}
func (m *MsgMongoDriver) UpdateMsgStatusByIndexInOneDoc(ctx context.Context, docID string, msg *sdkws.MsgData, seqIndex int, status int32) error {
msg.Status = status
bytes, err := proto.Marshal(msg)
File diff suppressed because it is too large Load Diff
+10 -7
View File
@@ -138,8 +138,8 @@ message PullMsgs {
}
message PullMessageBySeqsResp {
map<string, PullMsgs> msgs = 1;
map<string, PullMsgs> notificationMsgs = 2;
map<string, PullMsgs> msgs = 1;
map<string, PullMsgs> notificationMsgs = 2;
}
message GetMaxSeqReq {
@@ -181,8 +181,8 @@ message MsgData {
string ex = 22;
}
message PushMessages{
map<string, PullMsgs> msgs = 1;
map<string, PullMsgs> notificationMsgs = 2;
map<string, PullMsgs> msgs = 1;
map<string, PullMsgs> notificationMsgs = 2;
}
message OfflinePushInfo{
string title = 1;
@@ -329,7 +329,6 @@ message GroupMemberInfoSetTips{
GroupMemberFullInfo changedUser = 4;
}
//////////////////////friend/////////////////////
message FriendApplication{
@@ -411,6 +410,10 @@ message ConversationHasReadTips {
int64 unreadCountTime = 4;
}
message NotificationElem {
string detail = 1;
}
////////////////////message///////////////////////
message seqs {
repeated int64 seqs = 1;
@@ -423,11 +426,11 @@ message DeleteMessageTips{
}
message RevokeMsgTip{
message RevokeMsgTips{
string revokerUserID = 1;
string clientMsgID = 2;
int64 revokeTime = 3;
int64 sesstionType = 5;
int32 sesstionType = 5;
int64 seq = 6;
string conversationID = 7;
}
+2 -6
View File
@@ -134,13 +134,9 @@ func (m *MsgClient) PullMessageBySeqList(ctx context.Context, req *sdkws.PullMes
return resp, err
}
type NotificationElem struct {
Detail string `json:"detail,omitempty"`
}
func (c *MsgClient) Notification(ctx context.Context, sendID, recvID string, contentType int32, m proto.Message, opts ...utils.OptionsOpt) error {
n := NotificationElem{Detail: utils.StructToJsonString(m)}
content, err := json.Marshal(n)
n := sdkws.NotificationElem{Detail: utils.StructToJsonString(m)}
content, err := json.Marshal(&n)
if err != nil {
log.ZError(ctx, "MsgClient Notification json.Marshal failed", err, "sendID", sendID, "recvID", recvID, "contentType", contentType, "msg", m)
return err