Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: optimize v3.8 code #839

Open
wants to merge 4 commits into
base: pre-release-v3.8.4
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions integration_test/main.go
Original file line number Diff line number Diff line change
@@ -4,6 +4,10 @@ import (
"context"
"flag"
"fmt"
"os"
"runtime/debug"
"time"

"github.com/openimsdk/openim-sdk-core/v3/integration_test/internal/checker"
"github.com/openimsdk/openim-sdk-core/v3/integration_test/internal/config"
"github.com/openimsdk/openim-sdk-core/v3/integration_test/internal/manager"
@@ -14,9 +18,6 @@ import (
"github.com/openimsdk/openim-sdk-core/v3/integration_test/internal/vars"
"github.com/openimsdk/tools/log"
"github.com/openimsdk/tools/utils/formatutil"
"os"
"runtime/debug"
"time"
)

const runFailed = -1
4 changes: 1 addition & 3 deletions internal/conversation_msg/api.go
Original file line number Diff line number Diff line change
@@ -95,7 +95,6 @@ func (c *Conversation) GetMultipleConversation(ctx context.Context, conversation
return nil, err
}
return conversations, nil

}

func (c *Conversation) HideAllConversations(ctx context.Context) error {
@@ -150,7 +149,6 @@ func (c *Conversation) msgDataToLocalErrChatLog(src *model_struct.LocalChatLog)
var lc model_struct.LocalErrChatLog
copier.Copy(&lc, src)
return &lc

}

func (c *Conversation) updateMsgStatusAndTriggerConversation(ctx context.Context, clientMsgID, serverMsgID string, sendTime int64, status int32, s *sdk_struct.MsgStruct,
@@ -682,7 +680,6 @@ func (c *Conversation) sendMessageToServer(ctx context.Context, s *sdk_struct.Ms
c.updateMsgStatusAndTriggerConversation(ctx, sendMsgResp.ClientMsgID, sendMsgResp.ServerMsgID, sendMsgResp.SendTime, constant.MsgStatusSendSuccess, s, lc, isOnlineOnly)
}()
return s, nil

}

func (c *Conversation) FindMessageList(ctx context.Context, req []*sdk_params_callback.ConversationArgs) (*sdk_params_callback.FindMessageListCallback, error) {
@@ -998,6 +995,7 @@ func (c *Conversation) SearchConversation(ctx context.Context, searchParam strin
// Return the list of conversations
return apiConversations, nil
}

func (c *Conversation) GetInputStates(ctx context.Context, conversationID string, userID string) ([]int32, error) {
return c.typing.GetInputStates(conversationID, userID), nil
}
26 changes: 0 additions & 26 deletions internal/conversation_msg/conversation.go
Original file line number Diff line number Diff line change
@@ -1,17 +1,3 @@
// Copyright © 2023 OpenIM SDK. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package conversation_msg

import (
@@ -93,7 +79,6 @@ func (c *Conversation) getAdvancedHistoryMessageList(ctx context.Context, req sd
}
log.ZDebug(ctx, "sort", "sort cost time", time.Since(t))
messageListCallback.MessageList = messageList

return &messageListCallback, nil
}
func (c *Conversation) handleEndSeq(ctx context.Context, req sdk.GetAdvancedHistoryMessageListParams, isReverse bool, startMessage *model_struct.LocalChatLog) error {
@@ -113,7 +98,6 @@ func (c *Conversation) handleEndSeq(ctx context.Context, req sdk.GetAdvancedHist
}
}
}

} else {
if _, ok := c.messagePullForwardEndSeqMap.Load(req.ConversationID, req.ViewType); !ok {
if startMessage.Seq != 0 {
@@ -129,7 +113,6 @@ func (c *Conversation) handleEndSeq(ctx context.Context, req sdk.GetAdvancedHist
log.ZDebug(ctx, "no valid server message", "conversationID", req.ConversationID, "startTime", startMessage.SendTime)
}
}

}
}
return nil
@@ -292,7 +275,6 @@ func (c *Conversation) typingStatusUpdate(ctx context.Context, recvID, msgTip st
return err
}
return nil

}

func (c *Conversation) insertMessageToLocalStorage(ctx context.Context, conversationID string, s *model_struct.LocalChatLog) error {
@@ -397,14 +379,6 @@ func (c *Conversation) searchLocalMessages(ctx context.Context, searchParam *sdk
}

// Logging and processing each message in the search results
//localChatLogToMsgStruct(&messageList, list)

//log.Debug("hahh",utils.KMP("SSSsdf3434","s"))
//log.Debug("hahh",utils.KMP("SSSsdf3434","g"))
//log.Debug("hahh",utils.KMP("SSSsdf3434","3434"))
//log.Debug("hahh",utils.KMP("SSSsdf3434","F3434"))
//log.Debug("hahh",utils.KMP("SSSsdf3434","SDF3"))
// log.Debug("", "get raw data length is", len(list))
log.ZDebug(ctx, "get raw data length is", "len", len(list))

for _, v := range list {
24 changes: 1 addition & 23 deletions internal/conversation_msg/conversation_msg.go
Original file line number Diff line number Diff line change
@@ -595,24 +595,6 @@ func (c *Conversation) diff(ctx context.Context, local, generated, cc, nc map[st
}
}

func (c *Conversation) genConversationGroupAtType(lc *model_struct.LocalConversation, s *sdk_struct.MsgStruct) {
if s.ContentType == constant.AtText {
tagMe := utils.IsContain(c.loginUserID, s.AtTextElem.AtUserList)
tagAll := utils.IsContain(constant.AtAllString, s.AtTextElem.AtUserList)
if tagAll {
if tagMe {
lc.GroupAtType = constant.AtAllAtMe
return
}
lc.GroupAtType = constant.AtAll
return
}
if tagMe {
lc.GroupAtType = constant.AtMe
}
}
}

func (c *Conversation) msgStructToLocalErrChatLog(m *sdk_struct.MsgStruct) *model_struct.LocalErrChatLog {
var lc model_struct.LocalErrChatLog
copier.Copy(&lc, m)
@@ -691,9 +673,6 @@ func (c *Conversation) batchInsertMessageList(ctx context.Context, insertMsg map
return nil
}

func (c *Conversation) DoMsgReaction(msgReactionList []*sdk_struct.MsgStruct) {
}

func (c *Conversation) newMessage(ctx context.Context, newMessagesList sdk_struct.NewMsgList, cc, nc map[string]*model_struct.LocalConversation, onlineMsg map[onlineMsgKey]struct{}) {
sort.Sort(newMessagesList)
if c.GetBackground() {
@@ -855,8 +834,7 @@ func (c *Conversation) batchAddFaceURLAndName(ctx context.Context, conversations
return nil
}

func (c *Conversation) batchGetUserNameAndFaceURL(ctx context.Context, userIDs ...string) (map[string]*model_struct.LocalUser,
error) {
func (c *Conversation) batchGetUserNameAndFaceURL(ctx context.Context, userIDs ...string) (map[string]*model_struct.LocalUser, error) {
m := make(map[string]*model_struct.LocalUser)
var notInFriend []string

32 changes: 0 additions & 32 deletions internal/conversation_msg/conversion.go
Original file line number Diff line number Diff line change
@@ -1,17 +1,3 @@
// Copyright © 2023 OpenIM SDK. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package conversation_msg

import (
@@ -46,24 +32,6 @@ func ServerConversationToLocal(conversation *pbConversation.Conversation) *model
}
}

func LocalConversationToServer(conversation *model_struct.LocalConversation) *pbConversation.Conversation {
return &pbConversation.Conversation{
ConversationID: conversation.ConversationID,
ConversationType: conversation.ConversationType,
UserID: conversation.UserID,
GroupID: conversation.GroupID,
RecvMsgOpt: conversation.RecvMsgOpt,
GroupAtType: conversation.GroupAtType,
IsPinned: conversation.IsPinned,
BurnDuration: conversation.BurnDuration,
IsPrivateChat: conversation.IsPrivateChat,
AttachedInfo: conversation.AttachedInfo,
MsgDestructTime: conversation.MsgDestructTime,
Ex: conversation.Ex,
IsMsgDestruct: conversation.IsMsgDestruct,
}
}

func MsgDataToLocalChatLog(serverMessage *sdkws.MsgData) *model_struct.LocalChatLog {
localMessage := &model_struct.LocalChatLog{
ClientMsgID: serverMessage.ClientMsgID,
41 changes: 19 additions & 22 deletions internal/conversation_msg/create_message.go
Original file line number Diff line number Diff line change
@@ -1,17 +1,3 @@
// Copyright © 2023 OpenIM SDK. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package conversation_msg

import (
@@ -39,6 +25,7 @@ func (c *Conversation) CreateTextMessage(ctx context.Context, text string) (*sdk
s.TextElem = &sdk_struct.TextElem{Content: text}
return &s, nil
}

func (c *Conversation) CreateAdvancedTextMessage(ctx context.Context, text string, messageEntities []*sdk_struct.MessageEntity) (*sdk_struct.MsgStruct, error) {
s := sdk_struct.MsgStruct{}
err := c.initBasicInfo(ctx, &s, constant.UserMsgType, constant.AdvancedText)
@@ -79,6 +66,7 @@ func (c *Conversation) CreateTextAtMessage(ctx context.Context, text string, use
}
return &s, nil
}

func (c *Conversation) CreateLocationMessage(ctx context.Context, description string, longitude, latitude float64) (*sdk_struct.MsgStruct, error) {
s := sdk_struct.MsgStruct{}
err := c.initBasicInfo(ctx, &s, constant.UserMsgType, constant.Location)
@@ -105,8 +93,8 @@ func (c *Conversation) CreateCustomMessage(ctx context.Context, data, extension
Description: description,
}
return &s, nil

}

func (c *Conversation) CreateQuoteMessage(ctx context.Context, text string, qs *sdk_struct.MsgStruct) (*sdk_struct.MsgStruct, error) {
s := sdk_struct.MsgStruct{}
err := c.initBasicInfo(ctx, &s, constant.UserMsgType, constant.Quote)
@@ -123,8 +111,8 @@ func (c *Conversation) CreateQuoteMessage(ctx context.Context, text string, qs *
QuoteMessage: qs,
}
return &s, nil

}

func (c *Conversation) CreateAdvancedQuoteMessage(ctx context.Context, text string, qs *sdk_struct.MsgStruct, messageEntities []*sdk_struct.MessageEntity) (*sdk_struct.MsgStruct, error) {
s := sdk_struct.MsgStruct{}
err := c.initBasicInfo(ctx, &s, constant.UserMsgType, constant.Quote)
@@ -145,8 +133,7 @@ func (c *Conversation) CreateAdvancedQuoteMessage(ctx context.Context, text stri
return &s, nil
}

func (c *Conversation) CreateCardMessage(ctx context.Context, card *sdk_struct.CardElem) (*sdk_struct.MsgStruct,
error) {
func (c *Conversation) CreateCardMessage(ctx context.Context, card *sdk_struct.CardElem) (*sdk_struct.MsgStruct, error) {
s := sdk_struct.MsgStruct{}
err := c.initBasicInfo(ctx, &s, constant.UserMsgType, constant.Card)
if err != nil {
@@ -156,8 +143,7 @@ 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) {
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 {
@@ -208,8 +194,8 @@ func (c *Conversation) CreateVideoMessageFromFullPath(ctx context.Context, video
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)
@@ -235,6 +221,7 @@ func (c *Conversation) CreateFileMessageFromFullPath(ctx context.Context, fileFu
}
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)
@@ -262,6 +249,7 @@ func (c *Conversation) CreateImageMessageFromFullPath(ctx context.Context, image
}
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)
@@ -288,6 +276,7 @@ func (c *Conversation) CreateSoundMessageFromFullPath(ctx context.Context, sound
}
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)
@@ -310,8 +299,8 @@ func (c *Conversation) CreateImageMessage(ctx context.Context, imagePath string)
},
}
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)
@@ -326,6 +315,7 @@ func (c *Conversation) CreateImageMessageByURL(ctx context.Context, sourcePath s
}
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)
@@ -342,6 +332,7 @@ func (c *Conversation) CreateSoundMessageByURL(ctx context.Context, soundElem *s
}
return &s, nil
}

func (c *Conversation) CreateSoundMessage(ctx context.Context, soundPath string, duration int64) (*sdk_struct.MsgStruct, error) {
s := sdk_struct.MsgStruct{}
err := c.initBasicInfo(ctx, &s, constant.UserMsgType, constant.Sound)
@@ -364,6 +355,7 @@ func (c *Conversation) CreateSoundMessage(ctx context.Context, soundPath string,
}
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)
@@ -387,6 +379,7 @@ func (c *Conversation) CreateVideoMessageByURL(ctx context.Context, videoElem sd
}
return &s, nil
}

func (c *Conversation) CreateVideoMessage(ctx context.Context, videoPath string, videoType string, duration int64, snapshotPath string) (*sdk_struct.MsgStruct, error) {
s := sdk_struct.MsgStruct{}
err := c.initBasicInfo(ctx, &s, constant.UserMsgType, constant.Video)
@@ -420,6 +413,7 @@ func (c *Conversation) CreateVideoMessage(ctx context.Context, videoPath string,
}
return &s, nil
}

func (c *Conversation) CreateFileMessageByURL(ctx context.Context, fileElem sdk_struct.FileBaseInfo) (*sdk_struct.MsgStruct, error) {
s := sdk_struct.MsgStruct{}
err := c.initBasicInfo(ctx, &s, constant.UserMsgType, constant.File)
@@ -436,6 +430,7 @@ func (c *Conversation) CreateFileMessageByURL(ctx context.Context, fileElem sdk_
}
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)
@@ -453,6 +448,7 @@ func (c *Conversation) CreateFileMessage(ctx context.Context, filePath string, f
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)
@@ -465,6 +461,7 @@ func (c *Conversation) CreateMergerMessage(ctx context.Context, messages []*sdk_
s.Content = utils.StructToJsonString(s.MergeElem)
return &s, nil
}

func (c *Conversation) CreateFaceMessage(ctx context.Context, index int, data string) (*sdk_struct.MsgStruct, error) {
s := sdk_struct.MsgStruct{FaceElem: &sdk_struct.FaceElem{}}
err := c.initBasicInfo(ctx, &s, constant.UserMsgType, constant.Face)
Loading