@@ -3,6 +3,7 @@ package conversation_msg
3
3
import (
4
4
"context"
5
5
"fmt"
6
+ pconstant "github.com/openimsdk/protocol/constant"
6
7
"net/url"
7
8
"os"
8
9
"path/filepath"
@@ -150,56 +151,6 @@ func (c *Conversation) SetConversationListener(listener func() open_im_sdk_callb
150
151
c .ConversationListener = listener
151
152
}
152
153
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
- }
203
154
func (c * Conversation ) msgDataToLocalErrChatLog (src * model_struct.LocalChatLog ) * model_struct.LocalErrChatLog {
204
155
var lc model_struct.LocalErrChatLog
205
156
copier .Copy (& lc , src )
@@ -345,7 +296,7 @@ func (c *Conversation) SendMessage(ctx context.Context, s *sdk_struct.MsgStruct,
345
296
if ! isOnlineOnly {
346
297
oldMessage , err := c .db .GetMessage (ctx , lc .ConversationID , s .ClientMsgID )
347
298
if err != nil {
348
- localMessage := c . msgStructToLocalChatLog (s )
299
+ localMessage := MsgStructToLocalChatLog (s )
349
300
err := c .db .InsertMessage (ctx , lc .ConversationID , localMessage )
350
301
if err != nil {
351
302
return nil , err
@@ -561,12 +512,14 @@ func (c *Conversation) SendMessage(ctx context.Context, s *sdk_struct.MsgStruct,
561
512
s .Content = utils .StructToJsonString (s .FaceElem )
562
513
case constant .AdvancedText :
563
514
s .Content = utils .StructToJsonString (s .AdvancedTextElem )
515
+ case pconstant .Stream :
516
+ s .Content = utils .StructToJsonString (s .StreamElem )
564
517
default :
565
518
return nil , sdkerrs .ErrMsgContentTypeNotSupport
566
519
}
567
520
if utils .IsContainInt (int (s .ContentType ), []int {constant .Picture , constant .Sound , constant .Video , constant .File }) {
568
521
if ! isOnlineOnly {
569
- localMessage := c . msgStructToLocalChatLog (s )
522
+ localMessage := MsgStructToLocalChatLog (s )
570
523
log .ZDebug (ctx , "update message is " , "localMessage" , localMessage )
571
524
err = c .db .UpdateMessage (ctx , lc .ConversationID , localMessage )
572
525
if err != nil {
@@ -589,7 +542,7 @@ func (c *Conversation) SendMessageNotOss(ctx context.Context, s *sdk_struct.MsgS
589
542
if ! isOnlineOnly {
590
543
oldMessage , err := c .db .GetMessage (ctx , lc .ConversationID , s .ClientMsgID )
591
544
if err != nil {
592
- localMessage := c . msgStructToLocalChatLog (s )
545
+ localMessage := MsgStructToLocalChatLog (s )
593
546
err := c .db .InsertMessage (ctx , lc .ConversationID , localMessage )
594
547
if err != nil {
595
548
return nil , err
@@ -645,12 +598,14 @@ func (c *Conversation) SendMessageNotOss(ctx context.Context, s *sdk_struct.MsgS
645
598
s .Content = utils .StructToJsonString (s .FaceElem )
646
599
case constant .AdvancedText :
647
600
s .Content = utils .StructToJsonString (s .AdvancedTextElem )
601
+ case pconstant .Stream :
602
+ s .Content = utils .StructToJsonString (s .StreamElem )
648
603
default :
649
604
return nil , sdkerrs .ErrMsgContentTypeNotSupport
650
605
}
651
606
if utils .IsContainInt (int (s .ContentType ), []int {constant .Picture , constant .Sound , constant .Video , constant .File }) {
652
607
if isOnlineOnly {
653
- localMessage := c . msgStructToLocalChatLog (s )
608
+ localMessage := MsgStructToLocalChatLog (s )
654
609
err = c .db .UpdateMessage (ctx , lc .ConversationID , localMessage )
655
610
if err != nil {
656
611
return nil , err
@@ -750,39 +705,8 @@ func (c *Conversation) FindMessageList(ctx context.Context, req []*sdk_params_ca
750
705
if err == nil {
751
706
var tempMessageList []* sdk_struct.MsgStruct
752
707
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 )
786
710
}
787
711
findResultItem := sdk_params_callback.SearchByConversationResult {}
788
712
findResultItem .ConversationID = v .conversation .ConversationID
@@ -810,6 +734,7 @@ func (c *Conversation) GetAdvancedHistoryMessageList(ctx context.Context, req sd
810
734
s := make ([]* sdk_struct.MsgStruct , 0 )
811
735
result .MessageList = s
812
736
}
737
+ c .streamMsgReplace (ctx , req .ConversationID , result .MessageList )
813
738
return result , nil
814
739
}
815
740
@@ -822,6 +747,7 @@ func (c *Conversation) GetAdvancedHistoryMessageListReverse(ctx context.Context,
822
747
s := make ([]* sdk_struct.MsgStruct , 0 )
823
748
result .MessageList = s
824
749
}
750
+ c .streamMsgReplace (ctx , req .ConversationID , result .MessageList )
825
751
return result , nil
826
752
}
827
753
@@ -916,7 +842,7 @@ func (c *Conversation) InsertSingleMessageToLocalStorage(ctx context.Context, s
916
842
s .SendTime = utils .GetCurrentTimestampByMill ()
917
843
s .SessionType = constant .SingleChatType
918
844
s .Status = constant .MsgStatusSendSuccess
919
- localMessage := c . msgStructToLocalChatLog (s )
845
+ localMessage := MsgStructToLocalChatLog (s )
920
846
conversation .LatestMsg = utils .StructToJsonString (s )
921
847
conversation .ConversationType = constant .SingleChatType
922
848
conversation .LatestMsgSendTime = s .SendTime
@@ -956,7 +882,7 @@ func (c *Conversation) InsertGroupMessageToLocalStorage(ctx context.Context, s *
956
882
s .SendTime = utils .GetCurrentTimestampByMill ()
957
883
s .SessionType = conversation .ConversationType
958
884
s .Status = constant .MsgStatusSendSuccess
959
- localMessage := c . msgStructToLocalChatLog (s )
885
+ localMessage := MsgStructToLocalChatLog (s )
960
886
conversation .LatestMsg = utils .StructToJsonString (s )
961
887
conversation .LatestMsgSendTime = s .SendTime
962
888
conversation .FaceURL = s .SenderFaceURL
@@ -1015,7 +941,6 @@ func (c *Conversation) initBasicInfo(ctx context.Context, message *sdk_struct.Ms
1015
941
message .MsgFrom = msgFrom
1016
942
message .ContentType = contentType
1017
943
message .SenderPlatformID = c .platformID
1018
- message .IsExternalExtensions = c .IsExternalExtensions
1019
944
return nil
1020
945
}
1021
946
0 commit comments