From a5324fac14ac59b07722a1200ab60169f2442d13 Mon Sep 17 00:00:00 2001 From: Monet Lee Date: Thu, 14 Nov 2024 16:14:11 +0800 Subject: [PATCH] refactor: improve createMessage and sendMessage interface. (#734) * add .gitignore content. * refactor: improve createMessage and sendMessage interface. * fix interface args. * fix nil pointer error. * fix test error. --- .gitignore | 1 + internal/conversation_msg/api.go | 10 +- internal/conversation_msg/create_message.go | 421 ++++++++------------ open_im_sdk/conversation_msg.go | 44 +- pkg/ccontext/context.go | 10 +- test/conversation_test.go | 11 +- test/create_msg_test.go | 53 +-- test/init.go | 2 +- wasm/cmd/main.go | 11 - wasm/wasm_wrapper/wasm_conversation_msg.go | 31 -- 10 files changed, 200 insertions(+), 394 deletions(-) diff --git a/.gitignore b/.gitignore index dff4f47e1..d86809e7b 100644 --- a/.gitignore +++ b/.gitignore @@ -4,6 +4,7 @@ components logs out-test *.db +open-im-sdk-core.* ### Backup ### *.bak diff --git a/internal/conversation_msg/api.go b/internal/conversation_msg/api.go index 15f0a5434..6375311a6 100644 --- a/internal/conversation_msg/api.go +++ b/internal/conversation_msg/api.go @@ -278,6 +278,14 @@ func (c *Conversation) GetConversationIDBySessionType(_ context.Context, sourceI } func (c *Conversation) SendMessage(ctx context.Context, s *sdk_struct.MsgStruct, recvID, groupID string, p *sdkws.OfflinePushInfo, isOnlineOnly bool) (*sdk_struct.MsgStruct, error) { + // Message is created by URL + if (s.FileElem != nil && s.FileElem.SourceURL != "") || + (s.SoundElem != nil && s.SoundElem.SourceURL != "") || + (s.VideoElem != nil && s.VideoElem.VideoURL != "") || + (s.PictureElem != nil && (s.PictureElem.SourcePicture.Url != "" || s.PictureElem.BigPicture.Url != "" || s.PictureElem.SnapshotPicture.Url != "")) { + return c.sendMessageNotOss(ctx, s, recvID, groupID, p, isOnlineOnly) + } + filepathExt := func(name ...string) string { for _, path := range name { if ext := filepath.Ext(path); ext != "" { @@ -531,7 +539,7 @@ func (c *Conversation) SendMessage(ctx context.Context, s *sdk_struct.MsgStruct, return c.sendMessageToServer(ctx, s, lc, callback, delFile, p, options, isOnlineOnly) } -func (c *Conversation) SendMessageNotOss(ctx context.Context, s *sdk_struct.MsgStruct, recvID, groupID string, +func (c *Conversation) sendMessageNotOss(ctx context.Context, s *sdk_struct.MsgStruct, recvID, groupID string, p *sdkws.OfflinePushInfo, isOnlineOnly bool) (*sdk_struct.MsgStruct, error) { options := make(map[string]bool, 2) lc, err := c.checkID(ctx, s, recvID, groupID, options) diff --git a/internal/conversation_msg/create_message.go b/internal/conversation_msg/create_message.go index ead0c7f1b..2212ee8af 100644 --- a/internal/conversation_msg/create_message.go +++ b/internal/conversation_msg/create_message.go @@ -156,303 +156,212 @@ func (c *Conversation) CreateCardMessage(ctx context.Context, card *sdk_struct.C return &s, nil } -func (c *Conversation) CreateVideoMessageFromFullPath(ctx context.Context, videoFullPath string, videoType string, - duration int64, snapshotFullPath string) (*sdk_struct.MsgStruct, error) { - dstFile := utils.FileTmpPath(videoFullPath, c.DataDir) //a->b - written, err := utils.CopyFile(videoFullPath, dstFile) - if err != nil { - //log.Error("internal", "open file failed: ", err, videoFullPath) - return nil, err - } - log.ZDebug(ctx, "videoFullPath dstFile", "videoFullPath", videoFullPath, - "dstFile", dstFile, "written", written) - - dstFile = utils.FileTmpPath(snapshotFullPath, c.DataDir) //a->b - sWritten, err := utils.CopyFile(snapshotFullPath, dstFile) - if err != nil { - //log.Error("internal", "open file failed: ", err, snapshotFullPath) - return nil, err - } - log.ZDebug(ctx, "snapshotFullPath dstFile", "snapshotFullPath", snapshotFullPath, - "dstFile", dstFile, "sWritten", sWritten) - +func (c *Conversation) CreateImageMessage(ctx context.Context, imageSourcePath string, sourcePicture, bigPicture, snapshotPicture *sdk_struct.PictureBaseInfo) (*sdk_struct.MsgStruct, error) { s := sdk_struct.MsgStruct{} - err = c.initBasicInfo(ctx, &s, constant.UserMsgType, constant.Video) - if err != nil { - return nil, err - } - s.VideoElem = &sdk_struct.VideoElem{ - VideoPath: videoFullPath, - VideoType: videoType, - Duration: duration, - } - if snapshotFullPath == "" { - s.VideoElem.SnapshotPath = "" - } else { - s.VideoElem.SnapshotPath = snapshotFullPath - } - fi, err := os.Stat(s.VideoElem.VideoPath) + err := c.initBasicInfo(ctx, &s, constant.UserMsgType, constant.Picture) if err != nil { - //log.Error("internal", "get file Attributes error", err.Error()) return nil, err } - s.VideoElem.VideoSize = fi.Size() - if snapshotFullPath != "" { - imageInfo, err := getImageInfo(s.VideoElem.SnapshotPath) + + // Create by file path + if sourcePicture != nil || bigPicture != nil || snapshotPicture != nil { + dstFile := utils.FileTmpPath(imageSourcePath, c.DataDir) //a->b + _, err := utils.CopyFile(imageSourcePath, dstFile) if err != nil { - log.ZError(ctx, "getImageInfo err:", err, "snapshotFullPath", snapshotFullPath) + //log.Error(operationID, "open file failed: ", err, imageFullPath) return nil, err } - s.VideoElem.SnapshotHeight = imageInfo.Height - s.VideoElem.SnapshotWidth = imageInfo.Width - s.VideoElem.SnapshotSize = imageInfo.Size - } - return &s, nil -} -func (c *Conversation) CreateFileMessageFromFullPath(ctx context.Context, fileFullPath string, fileName string) (*sdk_struct.MsgStruct, error) { - dstFile := utils.FileTmpPath(fileFullPath, c.DataDir) - _, err := utils.CopyFile(fileFullPath, dstFile) - if err != nil { - //log.Error("internal", "open file failed: ", err.Error(), fileFullPath) - return nil, err + imageInfo, err := getImageInfo(imageSourcePath) + if err != nil { + //log.Error(operationID, "getImageInfo err:", err.Error()) + return nil, err + } - } - s := sdk_struct.MsgStruct{} - err = c.initBasicInfo(ctx, &s, constant.UserMsgType, constant.File) - if err != nil { - return nil, err - } - fi, err := os.Stat(fileFullPath) - if err != nil { - //log.Error("internal", "get file Attributes error", err.Error()) - return nil, err - } - s.FileElem = &sdk_struct.FileElem{ - FilePath: fileFullPath, - FileName: fileName, - FileSize: fi.Size(), - } - return &s, nil -} -func (c *Conversation) CreateImageMessageFromFullPath(ctx context.Context, imageFullPath string) (*sdk_struct.MsgStruct, error) { - dstFile := utils.FileTmpPath(imageFullPath, c.DataDir) //a->b - _, err := utils.CopyFile(imageFullPath, dstFile) - if err != nil { - //log.Error(operationID, "open file failed: ", err, imageFullPath) - return nil, err - } - s := sdk_struct.MsgStruct{} - err = c.initBasicInfo(ctx, &s, constant.UserMsgType, constant.Picture) - if err != nil { - return nil, err - } - imageInfo, err := getImageInfo(imageFullPath) - if err != nil { - //log.Error(operationID, "getImageInfo err:", err.Error()) - return nil, err - } - s.PictureElem = &sdk_struct.PictureElem{ - SourcePath: imageFullPath, - SourcePicture: &sdk_struct.PictureBaseInfo{ - Width: imageInfo.Width, - Height: imageInfo.Height, - Type: imageInfo.Type, - }, - } - return &s, nil -} -func (c *Conversation) CreateSoundMessageFromFullPath(ctx context.Context, soundPath string, duration int64) (*sdk_struct.MsgStruct, error) { - dstFile := utils.FileTmpPath(soundPath, c.DataDir) //a->b - _, err := utils.CopyFile(soundPath, dstFile) - if err != nil { - //log.Error("internal", "open file failed: ", err, soundPath) - return nil, err + s.PictureElem = &sdk_struct.PictureElem{ + SourcePath: imageSourcePath, + SourcePicture: &sdk_struct.PictureBaseInfo{ + Width: imageInfo.Width, + Height: imageInfo.Height, + Type: imageInfo.Type, + }, + } + } else { // Create by URL + s.PictureElem = &sdk_struct.PictureElem{ + SourcePath: imageSourcePath, + SourcePicture: sourcePicture, + BigPicture: bigPicture, + SnapshotPicture: snapshotPicture, + } } - s := sdk_struct.MsgStruct{} - err = c.initBasicInfo(ctx, &s, constant.UserMsgType, constant.Sound) - if err != nil { - return nil, err - } - fi, err := os.Stat(soundPath) - if err != nil { - //log.Error("internal", "getSoundInfo err:", err.Error(), s.SoundElem.SoundPath) - return nil, err - } - s.SoundElem = &sdk_struct.SoundElem{ - SoundPath: soundPath, - Duration: duration, - DataSize: fi.Size(), - SoundType: strings.Replace(filepath.Ext(fi.Name()), ".", "", 1), - } return &s, nil } -func (c *Conversation) CreateImageMessage(ctx context.Context, imagePath string) (*sdk_struct.MsgStruct, error) { - s := sdk_struct.MsgStruct{} - err := c.initBasicInfo(ctx, &s, constant.UserMsgType, constant.Picture) - if err != nil { - return nil, err - } - path := c.DataDir + imagePath - //path := imagePath - imageInfo, err := getImageInfo(path) - if err != nil { - //log.Error("internal", "get imageInfo err", err.Error()) - return nil, err - } - s.PictureElem = &sdk_struct.PictureElem{ - SourcePath: path, - SourcePicture: &sdk_struct.PictureBaseInfo{ - Width: imageInfo.Width, - Height: imageInfo.Height, - Type: imageInfo.Type, - }, - } - return &s, nil -} -func (c *Conversation) CreateImageMessageByURL(ctx context.Context, sourcePath string, sourcePicture, bigPicture, snapshotPicture sdk_struct.PictureBaseInfo) (*sdk_struct.MsgStruct, error) { - s := sdk_struct.MsgStruct{} - err := c.initBasicInfo(ctx, &s, constant.UserMsgType, constant.Picture) - if err != nil { - return nil, err - } - s.PictureElem = &sdk_struct.PictureElem{ - SourcePath: sourcePath, - SourcePicture: &sourcePicture, - BigPicture: &bigPicture, - SnapshotPicture: &snapshotPicture, - } - return &s, nil -} -func (c *Conversation) CreateSoundMessageByURL(ctx context.Context, soundElem *sdk_struct.SoundBaseInfo) (*sdk_struct.MsgStruct, error) { - s := sdk_struct.MsgStruct{} - err := c.initBasicInfo(ctx, &s, constant.UserMsgType, constant.Sound) - if err != nil { - return nil, err - } - s.SoundElem = &sdk_struct.SoundElem{ - UUID: soundElem.UUID, - SoundPath: soundElem.SoundPath, - SourceURL: soundElem.SourceURL, - DataSize: soundElem.DataSize, - Duration: soundElem.Duration, - SoundType: soundElem.SoundType, - } - return &s, nil -} -func (c *Conversation) CreateSoundMessage(ctx context.Context, soundPath string, duration int64) (*sdk_struct.MsgStruct, error) { +func (c *Conversation) CreateSoundMessage(ctx context.Context, soundPath string, duration int64, soundElem *sdk_struct.SoundBaseInfo) (*sdk_struct.MsgStruct, error) { s := sdk_struct.MsgStruct{} + err := c.initBasicInfo(ctx, &s, constant.UserMsgType, constant.Sound) if err != nil { return nil, err } - path := c.DataDir + soundPath - fi, err := os.Stat(path) - if err != nil { - //log.Error("internal", "get sound info err", err.Error()) - return nil, err - } - s.SoundElem = &sdk_struct.SoundElem{ - SoundPath: path, - Duration: duration, - DataSize: fi.Size(), - } - if typ := strings.Replace(filepath.Ext(fi.Name()), ".", "", 1); typ != "" { - s.SoundElem.SoundType = "audio/" + strings.ToLower(typ) - } - return &s, nil -} -func (c *Conversation) CreateVideoMessageByURL(ctx context.Context, videoElem sdk_struct.VideoBaseInfo) (*sdk_struct.MsgStruct, error) { - s := sdk_struct.MsgStruct{} - err := c.initBasicInfo(ctx, &s, constant.UserMsgType, constant.Video) - if err != nil { - return nil, err - } - s.VideoElem = &sdk_struct.VideoElem{ - VideoPath: videoElem.VideoPath, - VideoUUID: videoElem.VideoUUID, - VideoURL: videoElem.VideoURL, - VideoType: videoElem.VideoType, - VideoSize: videoElem.VideoSize, - Duration: videoElem.Duration, - SnapshotPath: videoElem.SnapshotPath, - SnapshotUUID: videoElem.SnapshotUUID, - SnapshotSize: videoElem.SnapshotSize, - SnapshotURL: videoElem.SnapshotURL, - SnapshotWidth: videoElem.SnapshotWidth, - SnapshotHeight: videoElem.SnapshotHeight, - SnapshotType: videoElem.SnapshotType, + + // Create by file path + if soundElem == nil { + dstFile := utils.FileTmpPath(soundPath, c.DataDir) //a->b + _, err := utils.CopyFile(soundPath, dstFile) + if err != nil { + //log.Error("internal", "open file failed: ", err, soundPath) + return nil, err + } + + fi, err := os.Stat(soundPath) + if err != nil { + //log.Error("internal", "getSoundInfo err:", err.Error(), s.SoundElem.SoundPath) + return nil, err + } + + s.SoundElem = &sdk_struct.SoundElem{ + SoundPath: soundPath, + Duration: duration, + DataSize: fi.Size(), + SoundType: strings.Replace(filepath.Ext(fi.Name()), ".", "", 1), + } + } else { // Create by URL + s.SoundElem = &sdk_struct.SoundElem{ + UUID: soundElem.UUID, + SoundPath: soundElem.SoundPath, + SourceURL: soundElem.SourceURL, + DataSize: soundElem.DataSize, + Duration: soundElem.Duration, + SoundType: soundElem.SoundType, + } } return &s, nil } -func (c *Conversation) CreateVideoMessage(ctx context.Context, videoPath string, videoType string, duration int64, snapshotPath string) (*sdk_struct.MsgStruct, error) { + +func (c *Conversation) CreateVideoMessage(ctx context.Context, videoSourcePath string, videoType string, duration int64, snapshotSourcePath string, videoElem *sdk_struct.VideoBaseInfo) (*sdk_struct.MsgStruct, error) { s := sdk_struct.MsgStruct{} err := c.initBasicInfo(ctx, &s, constant.UserMsgType, constant.Video) if err != nil { return nil, err } - s.VideoElem = &sdk_struct.VideoElem{} - s.VideoElem.VideoPath = c.DataDir + videoPath - s.VideoElem.VideoType = videoType - s.VideoElem.Duration = duration - if snapshotPath == "" { - s.VideoElem.SnapshotPath = "" - } else { - s.VideoElem.SnapshotPath = c.DataDir + snapshotPath - } - fi, err := os.Stat(s.VideoElem.VideoPath) - if err != nil { - log.ZDebug(ctx, "get video file error", "videoPath", videoPath, "snapshotPath", snapshotPath) - return nil, err - } - s.VideoElem.VideoSize = fi.Size() - if snapshotPath != "" { - imageInfo, err := getImageInfo(s.VideoElem.SnapshotPath) + + // Create by file path + if videoElem == nil { + dstFile := utils.FileTmpPath(videoSourcePath, c.DataDir) //a->b + written, err := utils.CopyFile(videoSourcePath, dstFile) if err != nil { - //log.Error("internal", "get snapshot info ", err.Error()) + //log.Error("internal", "open file failed: ", err, videoFullPath) return nil, err } - s.VideoElem.SnapshotHeight = imageInfo.Height - s.VideoElem.SnapshotWidth = imageInfo.Width - s.VideoElem.SnapshotSize = imageInfo.Size + + log.ZDebug(ctx, "videoFullPath dstFile", "videoFullPath", videoSourcePath, + "dstFile", dstFile, "written", written) + + dstFile = utils.FileTmpPath(snapshotSourcePath, c.DataDir) //a->b + sWritten, err := utils.CopyFile(snapshotSourcePath, dstFile) + if err != nil { + //log.Error("internal", "open file failed: ", err, snapshotFullPath) + return nil, err + } + + log.ZDebug(ctx, "snapshotFullPath dstFile", "snapshotFullPath", snapshotSourcePath, + "dstFile", dstFile, "sWritten", sWritten) + + s.VideoElem = &sdk_struct.VideoElem{ + VideoPath: videoSourcePath, + VideoType: videoType, + Duration: duration, + } + + if snapshotSourcePath == "" { + s.VideoElem.SnapshotPath = "" + } else { + s.VideoElem.SnapshotPath = snapshotSourcePath + } + + fi, err := os.Stat(s.VideoElem.VideoPath) + if err != nil { + //log.Error("internal", "get file Attributes error", err.Error()) + return nil, err + } + + s.VideoElem.VideoSize = fi.Size() + if snapshotSourcePath != "" { + imageInfo, err := getImageInfo(s.VideoElem.SnapshotPath) + if err != nil { + log.ZError(ctx, "getImageInfo err:", err, "snapshotFullPath", snapshotSourcePath) + return nil, err + } + + s.VideoElem.SnapshotHeight = imageInfo.Height + s.VideoElem.SnapshotWidth = imageInfo.Width + s.VideoElem.SnapshotSize = imageInfo.Size + } + } else { // Create by URL + s.VideoElem = &sdk_struct.VideoElem{ + VideoPath: videoElem.VideoPath, + VideoUUID: videoElem.VideoUUID, + VideoURL: videoElem.VideoURL, + VideoType: videoElem.VideoType, + VideoSize: videoElem.VideoSize, + Duration: videoElem.Duration, + SnapshotPath: videoElem.SnapshotPath, + SnapshotUUID: videoElem.SnapshotUUID, + SnapshotSize: videoElem.SnapshotSize, + SnapshotURL: videoElem.SnapshotURL, + SnapshotWidth: videoElem.SnapshotWidth, + SnapshotHeight: videoElem.SnapshotHeight, + SnapshotType: videoElem.SnapshotType, + } } + return &s, nil } -func (c *Conversation) CreateFileMessageByURL(ctx context.Context, fileElem sdk_struct.FileBaseInfo) (*sdk_struct.MsgStruct, error) { + +func (c *Conversation) CreateFileMessage(ctx context.Context, fileSourcePath string, fileName string, fileElem *sdk_struct.FileBaseInfo) (*sdk_struct.MsgStruct, error) { s := sdk_struct.MsgStruct{} err := c.initBasicInfo(ctx, &s, constant.UserMsgType, constant.File) if err != nil { return nil, err } - s.FileElem = &sdk_struct.FileElem{ - FilePath: fileElem.FilePath, - UUID: fileElem.UUID, - SourceURL: fileElem.SourceURL, - FileName: fileElem.FileName, - FileSize: fileElem.FileSize, - FileType: fileElem.FileType, - } - return &s, nil -} -func (c *Conversation) CreateFileMessage(ctx context.Context, filePath string, fileName string) (*sdk_struct.MsgStruct, error) { - s := sdk_struct.MsgStruct{FileElem: &sdk_struct.FileElem{}} - err := c.initBasicInfo(ctx, &s, constant.UserMsgType, constant.File) - if err != nil { - return nil, err - } - s.FileElem.FilePath = c.DataDir + filePath - s.FileElem.FileName = fileName - fi, err := os.Stat(s.FileElem.FilePath) - if err != nil { - //log.Error("internal", "get file message err", err.Error()) - return nil, err + + // Create by file path + if fileElem == nil { + dstFile := utils.FileTmpPath(fileSourcePath, c.DataDir) + _, err := utils.CopyFile(fileSourcePath, dstFile) + if err != nil { + //log.Error("internal", "open file failed: ", err.Error(), fileFullPath) + return nil, err + + } + + fi, err := os.Stat(fileSourcePath) + if err != nil { + //log.Error("internal", "get file Attributes error", err.Error()) + return nil, err + } + + s.FileElem = &sdk_struct.FileElem{ + FilePath: fileSourcePath, + FileName: fileName, + FileSize: fi.Size(), + } + } else { // Create by URL + s.FileElem = &sdk_struct.FileElem{ + FilePath: fileElem.FilePath, + UUID: fileElem.UUID, + SourceURL: fileElem.SourceURL, + FileName: fileElem.FileName, + FileSize: fileElem.FileSize, + FileType: fileElem.FileType, + } } - s.FileElem.FileSize = fi.Size() - s.Content = utils.StructToJsonString(s.FileElem) + return &s, nil } + func (c *Conversation) CreateMergerMessage(ctx context.Context, messages []*sdk_struct.MsgStruct, title string, summaries []string) (*sdk_struct.MsgStruct, error) { s := sdk_struct.MsgStruct{MergeElem: &sdk_struct.MergeElem{}} err := c.initBasicInfo(ctx, &s, constant.UserMsgType, constant.Merger) diff --git a/open_im_sdk/conversation_msg.go b/open_im_sdk/conversation_msg.go index 34bf1b4e2..4ee6cbecb 100644 --- a/open_im_sdk/conversation_msg.go +++ b/open_im_sdk/conversation_msg.go @@ -79,42 +79,17 @@ func CreateCardMessage(operationID string, cardInfo string) string { return syncCall(operationID, UserForSDK.Conversation().CreateCardMessage, cardInfo) } -func CreateVideoMessageFromFullPath(operationID string, videoFullPath string, videoType string, duration int64, snapshotFullPath string) string { - return syncCall(operationID, UserForSDK.Conversation().CreateVideoMessageFromFullPath, videoFullPath, videoType, duration, snapshotFullPath) +func CreateImageMessage(operationID string, imageSourcePath string, sourcePicture, bigPicture, snapshotPicture string) string { + return syncCall(operationID, UserForSDK.Conversation().CreateImageMessage, imageSourcePath, sourcePicture, bigPicture, snapshotPicture) } -func CreateImageMessageFromFullPath(operationID string, imageFullPath string) string { - return syncCall(operationID, UserForSDK.Conversation().CreateImageMessageFromFullPath, imageFullPath) +func CreateSoundMessage(operationID string, soundPath string, duration int64, soundBaseInfo string) string { + return syncCall(operationID, UserForSDK.Conversation().CreateSoundMessage, soundPath, duration, soundBaseInfo) } -func CreateSoundMessageFromFullPath(operationID string, soundPath string, duration int64) string { - return syncCall(operationID, UserForSDK.Conversation().CreateSoundMessageFromFullPath, soundPath, duration) +func CreateVideoMessage(operationID string, videoSourcePath string, videoType string, duration int64, snapshotSourcePath string, videoBaseInfo string) string { + return syncCall(operationID, UserForSDK.Conversation().CreateVideoMessage, videoSourcePath, videoType, duration, snapshotSourcePath, videoBaseInfo) } -func CreateFileMessageFromFullPath(operationID string, fileFullPath, fileName string) string { - return syncCall(operationID, UserForSDK.Conversation().CreateFileMessageFromFullPath, fileFullPath, fileName) -} -func CreateImageMessage(operationID string, imagePath string) string { - return syncCall(operationID, UserForSDK.Conversation().CreateImageMessage, imagePath) -} -func CreateImageMessageByURL(operationID string, sourcePath string, sourcePicture, bigPicture, snapshotPicture string) string { - return syncCall(operationID, UserForSDK.Conversation().CreateImageMessageByURL, sourcePath, sourcePicture, bigPicture, snapshotPicture) -} - -func CreateSoundMessageByURL(operationID string, soundBaseInfo string) string { - return syncCall(operationID, UserForSDK.Conversation().CreateSoundMessageByURL, soundBaseInfo) -} -func CreateSoundMessage(operationID string, soundPath string, duration int64) string { - return syncCall(operationID, UserForSDK.Conversation().CreateSoundMessage, soundPath, duration) -} -func CreateVideoMessageByURL(operationID string, videoBaseInfo string) string { - return syncCall(operationID, UserForSDK.Conversation().CreateVideoMessageByURL, videoBaseInfo) -} -func CreateVideoMessage(operationID string, videoPath string, videoType string, duration int64, snapshotPath string) string { - return syncCall(operationID, UserForSDK.Conversation().CreateVideoMessage, videoPath, videoType, duration, snapshotPath) -} -func CreateFileMessageByURL(operationID string, fileBaseInfo string) string { - return syncCall(operationID, UserForSDK.Conversation().CreateFileMessageByURL, fileBaseInfo) -} -func CreateFileMessage(operationID string, filePath string, fileName string) string { - return syncCall(operationID, UserForSDK.Conversation().CreateFileMessage, filePath, fileName) +func CreateFileMessage(operationID string, fileSourcePath string, fileName string, fileBaseInfo string) string { + return syncCall(operationID, UserForSDK.Conversation().CreateFileMessage, fileSourcePath, fileName, fileBaseInfo) } func CreateMergerMessage(operationID string, messageList, title, summaryList string) string { return syncCall(operationID, UserForSDK.Conversation().CreateMergerMessage, messageList, title, summaryList) @@ -131,9 +106,6 @@ func GetConversationIDBySessionType(operationID string, sourceID string, session func SendMessage(callback open_im_sdk_callback.SendMsgCallBack, operationID, message, recvID, groupID, offlinePushInfo string, isOnlineOnly bool) { messageCall(callback, operationID, UserForSDK.Conversation().SendMessage, message, recvID, groupID, offlinePushInfo, isOnlineOnly) } -func SendMessageNotOss(callback open_im_sdk_callback.SendMsgCallBack, operationID string, message, recvID, groupID string, offlinePushInfo string, isOnlineOnly bool) { - messageCall(callback, operationID, UserForSDK.Conversation().SendMessageNotOss, message, recvID, groupID, offlinePushInfo, isOnlineOnly) -} func FindMessageList(callback open_im_sdk_callback.Base, operationID string, findMessageOptions string) { call(callback, operationID, UserForSDK.Conversation().FindMessageList, findMessageOptions) diff --git a/pkg/ccontext/context.go b/pkg/ccontext/context.go index 67855a596..8e83304cd 100644 --- a/pkg/ccontext/context.go +++ b/pkg/ccontext/context.go @@ -23,8 +23,14 @@ import ( "github.com/openimsdk/tools/mcontext" ) +type ctxKey string + +const ( + CtxCallback ctxKey = "callback" +) + const ( - Callback = "callback" + CtxApiToken ctxKey = "api-token" ) type GlobalConfig struct { @@ -62,7 +68,7 @@ func WithOperationID(ctx context.Context, operationID string) context.Context { return mcontext.SetOperationID(ctx, operationID) } func WithSendMessageCallback(ctx context.Context, callback open_im_sdk_callback.SendMsgCallBack) context.Context { - return context.WithValue(ctx, Callback, callback) + return context.WithValue(ctx, CtxCallback, callback) } func WithApiErrCode(ctx context.Context, cb ApiErrCodeCallback) context.Context { diff --git a/test/conversation_test.go b/test/conversation_test.go index 46d8f01ce..1daec28c4 100644 --- a/test/conversation_test.go +++ b/test/conversation_test.go @@ -110,15 +110,6 @@ func Test_SendMessage(t *testing.T) { } } -func Test_SendMessageNotOss(t *testing.T) { - ctx = context.WithValue(ctx, "callback", TestSendMsg{}) - msg, _ := open_im_sdk.UserForSDK.Conversation().CreateTextMessage(ctx, "textMsg") - _, err := open_im_sdk.UserForSDK.Conversation().SendMessageNotOss(ctx, msg, "3411008330", "", nil, false) - if err != nil { - t.Fatal(err) - } -} - func Test_FindMessageList(t *testing.T) { msgs, err := open_im_sdk.UserForSDK.Conversation().FindMessageList(ctx, []*sdk_params_callback.ConversationArgs{}) if err != nil { @@ -260,7 +251,7 @@ func Test_MarkMsgsAsRead(t *testing.T) { func Test_SendImgMsg(t *testing.T) { ctx = context.WithValue(ctx, "callback", TestSendMsg{}) - msg, err := open_im_sdk.UserForSDK.Conversation().CreateImageMessage(ctx, "C:\\Users\\Admin\\Desktop\\test.png") + msg, err := open_im_sdk.UserForSDK.Conversation().CreateImageMessage(ctx, "C:\\Users\\Admin\\Desktop\\test.png", &sdk_struct.PictureBaseInfo{}, &sdk_struct.PictureBaseInfo{}, &sdk_struct.PictureBaseInfo{}) if err != nil { t.Fatal(err) } diff --git a/test/create_msg_test.go b/test/create_msg_test.go index 7542acbf2..b5d8fa721 100644 --- a/test/create_msg_test.go +++ b/test/create_msg_test.go @@ -15,9 +15,10 @@ package test import ( + "testing" + "github.com/openimsdk/openim-sdk-core/v3/open_im_sdk" "github.com/openimsdk/openim-sdk-core/v3/sdk_struct" - "testing" ) func Test_CreateTextMessage(t *testing.T) { @@ -60,14 +61,6 @@ func Test_CreateAdvancedQuoteMessage(t *testing.T) { t.Log(message) } -func Test_CreateVideoMessageFromFullPath(t *testing.T) { - message, err := open_im_sdk.UserForSDK.Conversation().CreateVideoMessageFromFullPath(ctx, ".\\test.png", "mp4", 10, ".\\test.png") - if err != nil { - t.Error(err) - } - t.Log(message) -} - func Test_CreateCardMessage(t *testing.T) { message, err := open_im_sdk.UserForSDK.Conversation().CreateCardMessage(ctx, &sdk_struct.CardElem{ UserID: "123456", @@ -81,24 +74,8 @@ func Test_CreateCardMessage(t *testing.T) { } func Test_CreateImageMessage(t *testing.T) { - message, err := open_im_sdk.UserForSDK.Conversation().CreateImageMessage(ctx, ".\\test.png") - if err != nil { - t.Error(err) - } - t.Log(message) -} - -func Test_CreateImageMessageByURL(t *testing.T) { - message, err := open_im_sdk.UserForSDK.Conversation().CreateImageMessageByURL(ctx, "", - sdk_struct.PictureBaseInfo{}, sdk_struct.PictureBaseInfo{}, sdk_struct.PictureBaseInfo{}) - if err != nil { - t.Error(err) - } - t.Log(message) -} - -func Test_CreateSoundMessageByURL(t *testing.T) { - message, err := open_im_sdk.UserForSDK.Conversation().CreateSoundMessageByURL(ctx, &sdk_struct.SoundBaseInfo{}) + message, err := open_im_sdk.UserForSDK.Conversation().CreateImageMessage(ctx, ".\\test.png", + &sdk_struct.PictureBaseInfo{}, &sdk_struct.PictureBaseInfo{}, &sdk_struct.PictureBaseInfo{}) if err != nil { t.Error(err) } @@ -106,7 +83,7 @@ func Test_CreateSoundMessageByURL(t *testing.T) { } func Test_CreateSoundMessage(t *testing.T) { - message, err := open_im_sdk.UserForSDK.Conversation().CreateSoundMessage(ctx, ".\\test.png", 20) + message, err := open_im_sdk.UserForSDK.Conversation().CreateSoundMessage(ctx, ".\\test.png", 20, &sdk_struct.SoundBaseInfo{}) if err != nil { t.Error(err) } @@ -114,15 +91,7 @@ func Test_CreateSoundMessage(t *testing.T) { } func Test_CreateVideoMessage(t *testing.T) { - message, err := open_im_sdk.UserForSDK.Conversation().CreateVideoMessage(ctx, ".\\test.png", "mp4", 10, "") - if err != nil { - t.Error(err) - } - t.Log(message) -} - -func Test_CreateVideoMessageByURL(t *testing.T) { - message, err := open_im_sdk.UserForSDK.Conversation().CreateVideoMessageByURL(ctx, sdk_struct.VideoBaseInfo{}) + message, err := open_im_sdk.UserForSDK.Conversation().CreateVideoMessage(ctx, ".\\test.png", "mp4", 10, ".\\test.png", &sdk_struct.VideoBaseInfo{}) if err != nil { t.Error(err) } @@ -130,15 +99,7 @@ func Test_CreateVideoMessageByURL(t *testing.T) { } func Test_CreateFileMessage(t *testing.T) { - message, err := open_im_sdk.UserForSDK.Conversation().CreateFileMessage(ctx, ".\\test.png", "png") - if err != nil { - t.Error(err) - } - t.Log(message) -} - -func Test_CreateFileMessageByURL(t *testing.T) { - message, err := open_im_sdk.UserForSDK.Conversation().CreateFileMessageByURL(ctx, sdk_struct.FileBaseInfo{}) + message, err := open_im_sdk.UserForSDK.Conversation().CreateFileMessage(ctx, ".\\test.png", "png", &sdk_struct.FileBaseInfo{}) if err != nil { t.Error(err) } diff --git a/test/init.go b/test/init.go index db0432850..9f97aa850 100644 --- a/test/init.go +++ b/test/init.go @@ -98,4 +98,4 @@ func GetUserToken(ctx context.Context, userID string, platformID int32, secret s IMConfig: imConf, }) return api.ExtractField(ctx, api.GetUsersToken.Invoke, userReq, (*auth.GetUserTokenResp).GetToken) -} +} \ No newline at end of file diff --git a/wasm/cmd/main.go b/wasm/cmd/main.go index efe7e5efc..153a6e28d 100644 --- a/wasm/cmd/main.go +++ b/wasm/cmd/main.go @@ -54,10 +54,6 @@ func registerFunc() { wrapperConMsg := wasm_wrapper.NewWrapperConMsg(globalFuc) js.Global().Set("createTextMessage", js.FuncOf(wrapperConMsg.CreateTextMessage)) js.Global().Set("createImageMessage", js.FuncOf(wrapperConMsg.CreateImageMessage)) - js.Global().Set("createImageMessageByURL", js.FuncOf(wrapperConMsg.CreateImageMessageByURL)) - js.Global().Set("createSoundMessageByURL", js.FuncOf(wrapperConMsg.CreateSoundMessageByURL)) - js.Global().Set("createVideoMessageByURL", js.FuncOf(wrapperConMsg.CreateVideoMessageByURL)) - js.Global().Set("createFileMessageByURL", js.FuncOf(wrapperConMsg.CreateFileMessageByURL)) js.Global().Set("createCustomMessage", js.FuncOf(wrapperConMsg.CreateCustomMessage)) js.Global().Set("createQuoteMessage", js.FuncOf(wrapperConMsg.CreateQuoteMessage)) js.Global().Set("createAdvancedQuoteMessage", js.FuncOf(wrapperConMsg.CreateAdvancedQuoteMessage)) @@ -70,22 +66,15 @@ func registerFunc() { js.Global().Set("createFaceMessage", js.FuncOf(wrapperConMsg.CreateFaceMessage)) js.Global().Set("createForwardMessage", js.FuncOf(wrapperConMsg.CreateForwardMessage)) js.Global().Set("createLocationMessage", js.FuncOf(wrapperConMsg.CreateLocationMessage)) - js.Global().Set("createVideoMessageFromFullPath", js.FuncOf(wrapperConMsg.CreateVideoMessageFromFullPath)) - js.Global().Set("createImageMessageFromFullPath", js.FuncOf(wrapperConMsg.CreateImageMessageFromFullPath)) - js.Global().Set("createSoundMessageFromFullPath", js.FuncOf(wrapperConMsg.CreateSoundMessageFromFullPath)) - js.Global().Set("createFileMessageFromFullPath", js.FuncOf(wrapperConMsg.CreateFileMessageFromFullPath)) js.Global().Set("createSoundMessage", js.FuncOf(wrapperConMsg.CreateSoundMessage)) js.Global().Set("createForwardMessage", js.FuncOf(wrapperConMsg.CreateForwardMessage)) js.Global().Set("createLocationMessage", js.FuncOf(wrapperConMsg.CreateLocationMessage)) - js.Global().Set("createVideoMessageFromFullPath", js.FuncOf(wrapperConMsg.CreateVideoMessageFromFullPath)) - js.Global().Set("createImageMessageFromFullPath", js.FuncOf(wrapperConMsg.CreateImageMessageFromFullPath)) js.Global().Set("getAtAllTag", js.FuncOf(wrapperConMsg.GetAtAllTag)) js.Global().Set("markConversationMessageAsRead", js.FuncOf(wrapperConMsg.MarkConversationMessageAsRead)) js.Global().Set("markAllConversationMessageAsRead", js.FuncOf(wrapperConMsg.MarkAllConversationMessageAsRead)) js.Global().Set("markMessagesAsReadByMsgID", js.FuncOf(wrapperConMsg.MarkMessagesAsReadByMsgID)) js.Global().Set("sendMessage", js.FuncOf(wrapperConMsg.SendMessage)) - js.Global().Set("sendMessageNotOss", js.FuncOf(wrapperConMsg.SendMessageNotOss)) //js.Global().Set("setMessageReactionExtensions", js.FuncOf(wrapperConMsg.SetMessageReactionExtensions)) //js.Global().Set("addMessageReactionExtensions", js.FuncOf(wrapperConMsg.AddMessageReactionExtensions)) //js.Global().Set("deleteMessageReactionExtensions", js.FuncOf(wrapperConMsg.DeleteMessageReactionExtensions)) diff --git a/wasm/wasm_wrapper/wasm_conversation_msg.go b/wasm/wasm_wrapper/wasm_conversation_msg.go index de19706e2..a1f236e00 100644 --- a/wasm/wasm_wrapper/wasm_conversation_msg.go +++ b/wasm/wasm_wrapper/wasm_conversation_msg.go @@ -40,18 +40,6 @@ func (w *WrapperConMsg) CreateTextMessage(_ js.Value, args []js.Value) interface func (w *WrapperConMsg) CreateImageMessage(_ js.Value, args []js.Value) interface{} { return event_listener.NewCaller(open_im_sdk.CreateImageMessage, nil, &args).AsyncCallWithOutCallback() } -func (w *WrapperConMsg) CreateImageMessageByURL(_ js.Value, args []js.Value) interface{} { - return event_listener.NewCaller(open_im_sdk.CreateImageMessageByURL, nil, &args).AsyncCallWithOutCallback() -} -func (w *WrapperConMsg) CreateSoundMessageByURL(_ js.Value, args []js.Value) interface{} { - return event_listener.NewCaller(open_im_sdk.CreateSoundMessageByURL, nil, &args).AsyncCallWithOutCallback() -} -func (w *WrapperConMsg) CreateVideoMessageByURL(_ js.Value, args []js.Value) interface{} { - return event_listener.NewCaller(open_im_sdk.CreateVideoMessageByURL, nil, &args).AsyncCallWithOutCallback() -} -func (w *WrapperConMsg) CreateFileMessageByURL(_ js.Value, args []js.Value) interface{} { - return event_listener.NewCaller(open_im_sdk.CreateFileMessageByURL, nil, &args).AsyncCallWithOutCallback() -} func (w *WrapperConMsg) CreateCustomMessage(_ js.Value, args []js.Value) interface{} { return event_listener.NewCaller(open_im_sdk.CreateCustomMessage, nil, &args).AsyncCallWithOutCallback() } @@ -95,21 +83,6 @@ func (w *WrapperConMsg) CreateLocationMessage(_ js.Value, args []js.Value) inter return event_listener.NewCaller(open_im_sdk.CreateLocationMessage, nil, &args).AsyncCallWithOutCallback() } -func (w *WrapperConMsg) CreateVideoMessageFromFullPath(_ js.Value, args []js.Value) interface{} { - return event_listener.NewCaller(open_im_sdk.CreateVideoMessageFromFullPath, nil, &args).AsyncCallWithOutCallback() -} - -func (w *WrapperConMsg) CreateImageMessageFromFullPath(_ js.Value, args []js.Value) interface{} { - return event_listener.NewCaller(open_im_sdk.CreateImageMessageFromFullPath, nil, &args).AsyncCallWithOutCallback() -} -func (w *WrapperConMsg) CreateSoundMessageFromFullPath(_ js.Value, args []js.Value) interface{} { - return event_listener.NewCaller(open_im_sdk.CreateSoundMessageFromFullPath, nil, &args).AsyncCallWithOutCallback() -} - -func (w *WrapperConMsg) CreateFileMessageFromFullPath(_ js.Value, args []js.Value) interface{} { - return event_listener.NewCaller(open_im_sdk.CreateFileMessageFromFullPath, nil, &args).AsyncCallWithOutCallback() -} - func (w *WrapperConMsg) CreateSoundMessage(_ js.Value, args []js.Value) interface{} { return event_listener.NewCaller(open_im_sdk.CreateSoundMessage, nil, &args).AsyncCallWithOutCallback() } @@ -136,10 +109,6 @@ func (w *WrapperConMsg) SendMessage(_ js.Value, args []js.Value) interface{} { callback := event_listener.NewSendMessageCallback(utils.FirstLower(utils.GetSelfFuncName()), w.commonFunc).SetClientMsgID(&args) return event_listener.NewCaller(open_im_sdk.SendMessage, callback, &args).AsyncCallWithCallback() } -func (w *WrapperConMsg) SendMessageNotOss(_ js.Value, args []js.Value) interface{} { - callback := event_listener.NewSendMessageCallback(utils.FirstLower(utils.GetSelfFuncName()), w.commonFunc).SetClientMsgID(&args) - return event_listener.NewCaller(open_im_sdk.SendMessageNotOss, callback, &args).AsyncCallWithCallback() -} //func (w *WrapperConMsg) SetMessageReactionExtensions(_ js.Value, args []js.Value) interface{} { // callback := event_listener.NewBaseCallback(utils.FirstLower(utils.GetSelfFuncName()), w.commonFunc)