Skip to content

Commit e06cb0a

Browse files
committed
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]>
1 parent 174880b commit e06cb0a

20 files changed

+904
-795
lines changed

internal/conversation_msg/api.go

+15-90
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package conversation_msg
33
import (
44
"context"
55
"fmt"
6+
pconstant "github.com/openimsdk/protocol/constant"
67
"net/url"
78
"os"
89
"path/filepath"
@@ -150,56 +151,6 @@ func (c *Conversation) SetConversationListener(listener func() open_im_sdk_callb
150151
c.ConversationListener = listener
151152
}
152153

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-
}
203154
func (c *Conversation) msgDataToLocalErrChatLog(src *model_struct.LocalChatLog) *model_struct.LocalErrChatLog {
204155
var lc model_struct.LocalErrChatLog
205156
copier.Copy(&lc, src)
@@ -345,7 +296,7 @@ func (c *Conversation) SendMessage(ctx context.Context, s *sdk_struct.MsgStruct,
345296
if !isOnlineOnly {
346297
oldMessage, err := c.db.GetMessage(ctx, lc.ConversationID, s.ClientMsgID)
347298
if err != nil {
348-
localMessage := c.msgStructToLocalChatLog(s)
299+
localMessage := MsgStructToLocalChatLog(s)
349300
err := c.db.InsertMessage(ctx, lc.ConversationID, localMessage)
350301
if err != nil {
351302
return nil, err
@@ -561,12 +512,14 @@ func (c *Conversation) SendMessage(ctx context.Context, s *sdk_struct.MsgStruct,
561512
s.Content = utils.StructToJsonString(s.FaceElem)
562513
case constant.AdvancedText:
563514
s.Content = utils.StructToJsonString(s.AdvancedTextElem)
515+
case pconstant.Stream:
516+
s.Content = utils.StructToJsonString(s.StreamElem)
564517
default:
565518
return nil, sdkerrs.ErrMsgContentTypeNotSupport
566519
}
567520
if utils.IsContainInt(int(s.ContentType), []int{constant.Picture, constant.Sound, constant.Video, constant.File}) {
568521
if !isOnlineOnly {
569-
localMessage := c.msgStructToLocalChatLog(s)
522+
localMessage := MsgStructToLocalChatLog(s)
570523
log.ZDebug(ctx, "update message is ", "localMessage", localMessage)
571524
err = c.db.UpdateMessage(ctx, lc.ConversationID, localMessage)
572525
if err != nil {
@@ -589,7 +542,7 @@ func (c *Conversation) SendMessageNotOss(ctx context.Context, s *sdk_struct.MsgS
589542
if !isOnlineOnly {
590543
oldMessage, err := c.db.GetMessage(ctx, lc.ConversationID, s.ClientMsgID)
591544
if err != nil {
592-
localMessage := c.msgStructToLocalChatLog(s)
545+
localMessage := MsgStructToLocalChatLog(s)
593546
err := c.db.InsertMessage(ctx, lc.ConversationID, localMessage)
594547
if err != nil {
595548
return nil, err
@@ -645,12 +598,14 @@ func (c *Conversation) SendMessageNotOss(ctx context.Context, s *sdk_struct.MsgS
645598
s.Content = utils.StructToJsonString(s.FaceElem)
646599
case constant.AdvancedText:
647600
s.Content = utils.StructToJsonString(s.AdvancedTextElem)
601+
case pconstant.Stream:
602+
s.Content = utils.StructToJsonString(s.StreamElem)
648603
default:
649604
return nil, sdkerrs.ErrMsgContentTypeNotSupport
650605
}
651606
if utils.IsContainInt(int(s.ContentType), []int{constant.Picture, constant.Sound, constant.Video, constant.File}) {
652607
if isOnlineOnly {
653-
localMessage := c.msgStructToLocalChatLog(s)
608+
localMessage := MsgStructToLocalChatLog(s)
654609
err = c.db.UpdateMessage(ctx, lc.ConversationID, localMessage)
655610
if err != nil {
656611
return nil, err
@@ -750,39 +705,8 @@ func (c *Conversation) FindMessageList(ctx context.Context, req []*sdk_params_ca
750705
if err == nil {
751706
var tempMessageList []*sdk_struct.MsgStruct
752707
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)
708+
temp := LocalChatLogToMsgStruct(message)
709+
tempMessageList = append(tempMessageList, temp)
786710
}
787711
findResultItem := sdk_params_callback.SearchByConversationResult{}
788712
findResultItem.ConversationID = v.conversation.ConversationID
@@ -810,6 +734,7 @@ func (c *Conversation) GetAdvancedHistoryMessageList(ctx context.Context, req sd
810734
s := make([]*sdk_struct.MsgStruct, 0)
811735
result.MessageList = s
812736
}
737+
c.streamMsgReplace(ctx, req.ConversationID, result.MessageList)
813738
return result, nil
814739
}
815740

@@ -822,6 +747,7 @@ func (c *Conversation) GetAdvancedHistoryMessageListReverse(ctx context.Context,
822747
s := make([]*sdk_struct.MsgStruct, 0)
823748
result.MessageList = s
824749
}
750+
c.streamMsgReplace(ctx, req.ConversationID, result.MessageList)
825751
return result, nil
826752
}
827753

@@ -916,7 +842,7 @@ func (c *Conversation) InsertSingleMessageToLocalStorage(ctx context.Context, s
916842
s.SendTime = utils.GetCurrentTimestampByMill()
917843
s.SessionType = constant.SingleChatType
918844
s.Status = constant.MsgStatusSendSuccess
919-
localMessage := c.msgStructToLocalChatLog(s)
845+
localMessage := MsgStructToLocalChatLog(s)
920846
conversation.LatestMsg = utils.StructToJsonString(s)
921847
conversation.ConversationType = constant.SingleChatType
922848
conversation.LatestMsgSendTime = s.SendTime
@@ -956,7 +882,7 @@ func (c *Conversation) InsertGroupMessageToLocalStorage(ctx context.Context, s *
956882
s.SendTime = utils.GetCurrentTimestampByMill()
957883
s.SessionType = conversation.ConversationType
958884
s.Status = constant.MsgStatusSendSuccess
959-
localMessage := c.msgStructToLocalChatLog(s)
885+
localMessage := MsgStructToLocalChatLog(s)
960886
conversation.LatestMsg = utils.StructToJsonString(s)
961887
conversation.LatestMsgSendTime = s.SendTime
962888
conversation.FaceURL = s.SenderFaceURL
@@ -1015,7 +941,6 @@ func (c *Conversation) initBasicInfo(ctx context.Context, message *sdk_struct.Ms
1015941
message.MsgFrom = msgFrom
1016942
message.ContentType = contentType
1017943
message.SenderPlatformID = c.platformID
1018-
message.IsExternalExtensions = c.IsExternalExtensions
1019944
return nil
1020945
}
1021946

0 commit comments

Comments
 (0)