Skip to content

Commit 7751f20

Browse files
OpenIM-RobotqmarliuFGadvancer
authored
deps: Merge #771 #773 PRs into pre-release-v3.8.2 (#774)
* fix: deleting the last message in a conversation will prompt failure (#771) * fix: the bug where isEnd for fetching message history is not working correctly. (#773) * fix: the bug where isEnd for fetching message history is not working correctly. Signed-off-by: Gordon <[email protected]> * fix: the bug where isEnd for fetching message history is not working correctly. Signed-off-by: Gordon <[email protected]> * fix: the bug where isEnd for fetching message history is not working correctly. Signed-off-by: Gordon <[email protected]> * fix: the bug where isEnd for fetching message history is not working correctly. Signed-off-by: Gordon <[email protected]> * fix: the bug where isEnd for fetching message history is not working correctly. Signed-off-by: Gordon <[email protected]> --------- Signed-off-by: Gordon <[email protected]> --------- Signed-off-by: Gordon <[email protected]> Co-authored-by: qmarliu <[email protected]> Co-authored-by: OpenIM-Gordon <[email protected]>
1 parent 174880b commit 7751f20

20 files changed

+887
-793
lines changed

internal/conversation_msg/api.go

+8-90
Original file line numberDiff line numberDiff line change
@@ -150,56 +150,6 @@ func (c *Conversation) SetConversationListener(listener func() open_im_sdk_callb
150150
c.ConversationListener = listener
151151
}
152152

153-
func (c *Conversation) msgStructToLocalChatLog(src *sdk_struct.MsgStruct) *model_struct.LocalChatLog {
154-
var lc model_struct.LocalChatLog
155-
copier.Copy(&lc, src)
156-
switch src.ContentType {
157-
case constant.Text:
158-
lc.Content = utils.StructToJsonString(src.TextElem)
159-
case constant.Picture:
160-
lc.Content = utils.StructToJsonString(src.PictureElem)
161-
case constant.Sound:
162-
lc.Content = utils.StructToJsonString(src.SoundElem)
163-
case constant.Video:
164-
lc.Content = utils.StructToJsonString(src.VideoElem)
165-
case constant.File:
166-
lc.Content = utils.StructToJsonString(src.FileElem)
167-
case constant.AtText:
168-
lc.Content = utils.StructToJsonString(src.AtTextElem)
169-
case constant.Merger:
170-
lc.Content = utils.StructToJsonString(src.MergeElem)
171-
case constant.Card:
172-
lc.Content = utils.StructToJsonString(src.CardElem)
173-
case constant.Location:
174-
lc.Content = utils.StructToJsonString(src.LocationElem)
175-
case constant.Custom:
176-
lc.Content = utils.StructToJsonString(src.CustomElem)
177-
case constant.Quote:
178-
lc.Content = utils.StructToJsonString(src.QuoteElem)
179-
case constant.Face:
180-
lc.Content = utils.StructToJsonString(src.FaceElem)
181-
case constant.AdvancedText:
182-
lc.Content = utils.StructToJsonString(src.AdvancedTextElem)
183-
default:
184-
lc.Content = utils.StructToJsonString(src.NotificationElem)
185-
}
186-
if src.SessionType == constant.WriteGroupChatType || src.SessionType == constant.ReadGroupChatType {
187-
lc.RecvID = src.GroupID
188-
}
189-
lc.AttachedInfo = utils.StructToJsonString(src.AttachedInfoElem)
190-
return &lc
191-
}
192-
func (c *Conversation) msgDataToLocalChatLog(src *sdkws.MsgData) *model_struct.LocalChatLog {
193-
var lc model_struct.LocalChatLog
194-
copier.Copy(&lc, src)
195-
lc.Content = string(src.Content)
196-
if src.SessionType == constant.WriteGroupChatType || src.SessionType == constant.ReadGroupChatType {
197-
lc.RecvID = src.GroupID
198-
199-
}
200-
return &lc
201-
202-
}
203153
func (c *Conversation) msgDataToLocalErrChatLog(src *model_struct.LocalChatLog) *model_struct.LocalErrChatLog {
204154
var lc model_struct.LocalErrChatLog
205155
copier.Copy(&lc, src)
@@ -345,7 +295,7 @@ func (c *Conversation) SendMessage(ctx context.Context, s *sdk_struct.MsgStruct,
345295
if !isOnlineOnly {
346296
oldMessage, err := c.db.GetMessage(ctx, lc.ConversationID, s.ClientMsgID)
347297
if err != nil {
348-
localMessage := c.msgStructToLocalChatLog(s)
298+
localMessage := MsgStructToLocalChatLog(s)
349299
err := c.db.InsertMessage(ctx, lc.ConversationID, localMessage)
350300
if err != nil {
351301
return nil, err
@@ -566,7 +516,7 @@ func (c *Conversation) SendMessage(ctx context.Context, s *sdk_struct.MsgStruct,
566516
}
567517
if utils.IsContainInt(int(s.ContentType), []int{constant.Picture, constant.Sound, constant.Video, constant.File}) {
568518
if !isOnlineOnly {
569-
localMessage := c.msgStructToLocalChatLog(s)
519+
localMessage := MsgStructToLocalChatLog(s)
570520
log.ZDebug(ctx, "update message is ", "localMessage", localMessage)
571521
err = c.db.UpdateMessage(ctx, lc.ConversationID, localMessage)
572522
if err != nil {
@@ -589,7 +539,7 @@ func (c *Conversation) SendMessageNotOss(ctx context.Context, s *sdk_struct.MsgS
589539
if !isOnlineOnly {
590540
oldMessage, err := c.db.GetMessage(ctx, lc.ConversationID, s.ClientMsgID)
591541
if err != nil {
592-
localMessage := c.msgStructToLocalChatLog(s)
542+
localMessage := MsgStructToLocalChatLog(s)
593543
err := c.db.InsertMessage(ctx, lc.ConversationID, localMessage)
594544
if err != nil {
595545
return nil, err
@@ -650,7 +600,7 @@ func (c *Conversation) SendMessageNotOss(ctx context.Context, s *sdk_struct.MsgS
650600
}
651601
if utils.IsContainInt(int(s.ContentType), []int{constant.Picture, constant.Sound, constant.Video, constant.File}) {
652602
if isOnlineOnly {
653-
localMessage := c.msgStructToLocalChatLog(s)
603+
localMessage := MsgStructToLocalChatLog(s)
654604
err = c.db.UpdateMessage(ctx, lc.ConversationID, localMessage)
655605
if err != nil {
656606
return nil, err
@@ -750,39 +700,8 @@ func (c *Conversation) FindMessageList(ctx context.Context, req []*sdk_params_ca
750700
if err == nil {
751701
var tempMessageList []*sdk_struct.MsgStruct
752702
for _, message := range messages {
753-
temp := sdk_struct.MsgStruct{}
754-
temp.ClientMsgID = message.ClientMsgID
755-
temp.ServerMsgID = message.ServerMsgID
756-
temp.CreateTime = message.CreateTime
757-
temp.SendTime = message.SendTime
758-
temp.SessionType = message.SessionType
759-
temp.SendID = message.SendID
760-
temp.RecvID = message.RecvID
761-
temp.MsgFrom = message.MsgFrom
762-
temp.ContentType = message.ContentType
763-
temp.SenderPlatformID = message.SenderPlatformID
764-
temp.SenderNickname = message.SenderNickname
765-
temp.SenderFaceURL = message.SenderFaceURL
766-
temp.Content = message.Content
767-
temp.Seq = message.Seq
768-
temp.IsRead = message.IsRead
769-
temp.Status = message.Status
770-
temp.AttachedInfo = message.AttachedInfo
771-
temp.Ex = message.Ex
772-
temp.LocalEx = message.LocalEx
773-
err := c.msgHandleByContentType(&temp)
774-
if err != nil {
775-
log.ZError(ctx, "msgHandleByContentType err", err, "message", temp)
776-
continue
777-
}
778-
switch message.SessionType {
779-
case constant.WriteGroupChatType:
780-
fallthrough
781-
case constant.ReadGroupChatType:
782-
temp.GroupID = temp.RecvID
783-
temp.RecvID = c.loginUserID
784-
}
785-
tempMessageList = append(tempMessageList, &temp)
703+
temp := LocalChatLogToMsgStruct(message)
704+
tempMessageList = append(tempMessageList, temp)
786705
}
787706
findResultItem := sdk_params_callback.SearchByConversationResult{}
788707
findResultItem.ConversationID = v.conversation.ConversationID
@@ -916,7 +835,7 @@ func (c *Conversation) InsertSingleMessageToLocalStorage(ctx context.Context, s
916835
s.SendTime = utils.GetCurrentTimestampByMill()
917836
s.SessionType = constant.SingleChatType
918837
s.Status = constant.MsgStatusSendSuccess
919-
localMessage := c.msgStructToLocalChatLog(s)
838+
localMessage := MsgStructToLocalChatLog(s)
920839
conversation.LatestMsg = utils.StructToJsonString(s)
921840
conversation.ConversationType = constant.SingleChatType
922841
conversation.LatestMsgSendTime = s.SendTime
@@ -956,7 +875,7 @@ func (c *Conversation) InsertGroupMessageToLocalStorage(ctx context.Context, s *
956875
s.SendTime = utils.GetCurrentTimestampByMill()
957876
s.SessionType = conversation.ConversationType
958877
s.Status = constant.MsgStatusSendSuccess
959-
localMessage := c.msgStructToLocalChatLog(s)
878+
localMessage := MsgStructToLocalChatLog(s)
960879
conversation.LatestMsg = utils.StructToJsonString(s)
961880
conversation.LatestMsgSendTime = s.SendTime
962881
conversation.FaceURL = s.SenderFaceURL
@@ -1015,7 +934,6 @@ func (c *Conversation) initBasicInfo(ctx context.Context, message *sdk_struct.Ms
1015934
message.MsgFrom = msgFrom
1016935
message.ContentType = contentType
1017936
message.SenderPlatformID = c.platformID
1018-
message.IsExternalExtensions = c.IsExternalExtensions
1019937
return nil
1020938
}
1021939

0 commit comments

Comments
 (0)