From 48ff4d51ea93d20641c70b01963ddc75768454cd Mon Sep 17 00:00:00 2001 From: OpenIM-Gordon <46924906+FGadvancer@users.noreply.github.com> Date: Wed, 18 Sep 2024 17:18:52 +0800 Subject: [PATCH] refactor: friend and conversation update. (#708) * fix: remove the conversation trigger to prevent waiting in a circular queue. Signed-off-by: Gordon <46924906+FGadvancer@users.noreply.github.com> * refactor: remove files to pkg. Signed-off-by: Gordon <46924906+FGadvancer@users.noreply.github.com> * optimizing the code * refactor: restruct friend module to relation. * refactor: conversation structure and code change. Signed-off-by: Gordon <46924906+FGadvancer@users.noreply.github.com> * optimizing the code * optimizing the code * optimizing the code * new call * feat: new api call * db success log * new api invoke * fix: Bug fix for clearing unread messages. Signed-off-by: Gordon <46924906+FGadvancer@users.noreply.github.com> * refactor: user package * refactor: full package * refactor: del license * test: fix statistics * refactor: user package * remove unused code * remove unused code * feat: api format * feat: api format * refactor: merge opensource code main into local branch. Signed-off-by: Gordon <46924906+FGadvancer@users.noreply.github.com> * refactor: merge opensource code main into local branch. Signed-off-by: Gordon <46924906+FGadvancer@users.noreply.github.com> * refactor: merge opensource code main into local branch. Signed-off-by: Gordon <46924906+FGadvancer@users.noreply.github.com> * feat: api format * refactor: user * refactor: full module remove. Signed-off-by: Gordon <46924906+FGadvancer@users.noreply.github.com> * feat: update setGroupInfo API to correct. * refactor: rename api function and add ExtractField function comment * refactor: update logging initialization to use constant from protocol package - Renamed the `log.InitLoggerFromConfig` function call in `init_login.go` to use the `pbConstant.PlatformID2Name` constant from the `protocol` package instead of the `constant.PlatformID2Name` constant from the `openim-sdk-core` package. This ensures consistency and avoids potential conflicts. feat: improve error handling in HTTP client - Updated the `get` and `postLogic` functions in `http_client.go` to use the `io.ReadAll` function instead of `ioutil.ReadAll` for reading the response body. This change improves error handling and ensures proper resource cleanup. refactor: remove unused import in new_http.go - Removed the unused import of `github.com/openimsdk/tools/errs` in `new_http.go` to clean up the code and improve maintainability. * refactor: full * refactor: update logging initialization to use constant from protocol package * feat: format code * Refactor: Update function name in conversation_msg package Rename the function `revokeMessageFromSvr` to `revokeMessageFromServer` in the `revoke.go` file of the `conversation_msg` package. This change ensures consistency with the naming convention used in the codebase. Refactor: Update function name in group package Rename the function `getGroupsInfoFromSvr` to `getGroupsInfoFromServer` in the `group.go` file of the `group` package. This change aligns with the naming convention used in the codebase. Refactor: Update function name in conversation_msg package Rename the function `getConversationsByIDsFromSvr` to `getConversationsByIDsFromServer` in the `sync.go` file of the `conversation_msg` package. This change ensures consistency with the naming convention used in the codebase. Refactor: Update function name in group package Rename the function `getGroupsInfoFromSvr` to `getGroupsInfoFromServer` in the `api.go` file of the `group` package. This change aligns with the naming convention used in the codebase. Refactor: Update function name in conversation_msg package Rename the function `clearConversationFromLocalAndSvr` to `clearConversationFromLocalAndServer` in the `delete.go` file of the `conversation_msg` package. This change ensures consistency with the naming convention used in the codebase. Refactor: Update function name in conversation_msg package Rename the function `deleteAllMsgFromLocalAndSvr` to `deleteAllMsgFromLocalAndServer` in the `delete.go` file of the `conversation_msg` package. This change ensures consistency with the naming convention used in the codebase. Refactor: Update function name in conversation_msg package Rename the function `deleteMessagesFromSvr` to `deleteMessagesFromServer` in the `delete.go` file of the `conversation_msg` package. This change ensures consistency with the naming convention used in the codebase. Refactor: Update function name in conversation_msg package Rename the function `getIncrementalConversationFromSvr` to `getIncrementalConversationFromServer` in the `incremental_sync.go` file of the `conversation_msg` package. This change ensures consistency with the naming convention used in the codebase. Refactor: Update function name in conversation_msg package Rename the function `getAllConversationListFromSvr` to `getAllConversationListFromServer` in the `incremental_sync.go` file of the `conversation_msg` package. This change ensures consistency with the naming convention used in the codebase. Refactor: Update function name in conversation_msg package Rename the function `getAllConversationIDsFromSvr` to `getAllConversationIDsFromServer` in the `incremental_sync.go` file of the `conversation_msg` package. This change ensures consistency with the naming convention used in the codebase. Refactor: Update function name in conversation_msg package Rename the function `syncMsgFromSvr` to `syncMsgFromServer` in the `msg_sync.go` file of the `interaction` package. This change ensures consistency with the naming convention used in the codebase. Refactor: Update function name in conversation_msg package Rename the function `syncMsgFromSvrSplit` to `syncMsgFromServerSplit` in the `msg_sync.go` file of the `interaction` package. This change ensures consistency with the naming convention used in the codebase. * Refactor function names in conversation_msg package * Refactor import paths in conversation_msg and indexdb packages * refactor: user * Refactor variable names and comments for clarity * refactor: full module remove. Signed-off-by: Gordon <46924906+FGadvancer@users.noreply.github.com> * refactor: full module remove. Signed-off-by: Gordon <46924906+FGadvancer@users.noreply.github.com> * Refactor import statements in api.go * feat: format code * feat: format code * feat: format code * Refactor database initialization and remove unused modules * remove unused import pkg. * feat: format code * Refactor conversation_msg package and remove unused imports * refactor: full module remove. Signed-off-by: Gordon <46924906+FGadvancer@users.noreply.github.com> * Refactor file imports in conversation_msg package * Refactor file imports in conversation_msg package * Refactor file imports in event_listener package * Refactor file imports in conversation_msg package * refactor: cache * refactor: cache * refactor: cache * feat: add UpdateFriends interface in wasm. * move test to db folder. * replece olderst const. * refactor: del SetGlobalRecvMessageOpt * refactor: move user * refactor: http module remove. Signed-off-by: Gordon <46924906+FGadvancer@users.noreply.github.com> * refactor: http module remove. Signed-off-by: Gordon <46924906+FGadvancer@users.noreply.github.com> * refactor: http module remove. Signed-off-by: Gordon <46924906+FGadvancer@users.noreply.github.com> * refactor: http module remove. Signed-off-by: Gordon <46924906+FGadvancer@users.noreply.github.com> * remove main test. * refactor: http module remove. Signed-off-by: Gordon <46924906+FGadvancer@users.noreply.github.com> * refactor: http module remove. Signed-off-by: Gordon <46924906+FGadvancer@users.noreply.github.com> * refactor: http module remove. Signed-off-by: Gordon <46924906+FGadvancer@users.noreply.github.com> * refactor: http module remove. Signed-off-by: Gordon <46924906+FGadvancer@users.noreply.github.com> * refactor: remove chinese * refactor: remove chinese * Refactor group API to use simplified SetGroupInfo method * refactor: constant add. Signed-off-by: Gordon <46924906+FGadvancer@users.noreply.github.com> * refactor: constant add. Signed-off-by: Gordon <46924906+FGadvancer@users.noreply.github.com> * refactor: fix msgtest route * refactor: friend info update. Signed-off-by: Gordon <46924906+FGadvancer@users.noreply.github.com> * feat: GetFriendListPage * fix: update router path in setGroupInfoEX. * refactor: friend info update. Signed-off-by: Gordon <46924906+FGadvancer@users.noreply.github.com> * refactor: audio/mp4 update. Signed-off-by: Gordon <46924906+FGadvancer@users.noreply.github.com> --------- Signed-off-by: Gordon <46924906+FGadvancer@users.noreply.github.com> Co-authored-by: Monet Lee Co-authored-by: withchao <993506633@qq.com> Co-authored-by: icey-yu <1186114839@qq.com> Co-authored-by: icey-yu <119291641+icey-yu@users.noreply.github.com> --- .DS_Store | Bin 6148 -> 0 bytes .../internal/manager/msg_manager.go | 7 +- integration_test/internal/sdk/relation.go | 11 +- internal/conversation_msg/api.go | 2 +- internal/group/api.go | 4 +- internal/relation/api.go | 99 ++++++++++++------ internal/user/api.go | 27 +---- internal/user/user.go | 27 +++++ open_im_sdk/conversation_msg.go | 4 +- open_im_sdk/relation.go | 4 +- open_im_sdk/user.go | 1 - pkg/api/api.go | 2 +- pkg/content_type/content_type.go | 1 + pkg/server_api_params/public_struct.go | 33 ------ test/conversation_test.go | 4 +- wasm/cmd/main.go | 2 +- wasm/wasm_wrapper/wasm_conversation_msg.go | 4 +- 17 files changed, 115 insertions(+), 117 deletions(-) delete mode 100644 .DS_Store delete mode 100644 pkg/server_api_params/public_struct.go diff --git a/.DS_Store b/.DS_Store deleted file mode 100644 index 40a6cf7bbeddb6c3188f94c8a87c010b201a3091..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 6148 zcmeHK%}(1u5S|U8*o}l-i3625ti*v!4nd*K)e1kSN<}q-18t3sEn>;CBgesqD3a9& z=mXGe3-1Aa2wsFcGrJp96naIanu%t=@$Ag3{W;q40)Xg`qfGz@04!9(hK<7$Li40^ z(l8!Ep=ty$#9s_WSj|PV<6mTe-klAn;6nuk{PF%q!!XT5oV^Q&X)-E1omk+pNnH8P%66WWL6XIVs;6swK1#AEulo5oi$*Hm6j%0sP!6z;weI?^V%4^6-&vhZ zy4`ne+1=_*+j7$Db=q>P`+hpLE$i*Z-lwnQZ{II|{QPx!b$z3IOB zw48fImgdJ@c(H1I)nlFhKi*L?v_$)*98;fdhR$ z(tMMU1Z_G?5K4ot!CE8Epa`9cs8fYGVhEj%ere)dgSAGT4nnPrbX9sN>; zgK#zS$P6$8j~Q6dmk#y+-M^pzA1Cn@Gr$b|R}6^ej4&2?%}A{O4Jin5{j!e lKBS= len(friends) { - return friends[:0], nil + if (!filterBlack) || len(localBlackList) == 0 { + return dataFetcher.FetchWithPagination(ctx, int(offset), int(count)) + } + localFriendList, err := dataFetcher.FetchWithPagination(ctx, int(offset), int(count*2)) + if err != nil { + return nil, err } - friends = friends[offset:] - if len(friends) > count { - return friends[:count], nil - } else { - return friends, nil + blackUserIDs := datautil.SliceSetAny(localBlackList, func(e *model_struct.LocalBlack) string { + return e.BlockUserID + }) + res := localFriendList[:0] + for _, friend := range localFriendList { + if _, ok := blackUserIDs[friend.FriendUserID]; !ok { + res = append(res, friend) + } + if len(res) == int(count) { + break + } } + return res, nil } func (r *Relation) SearchFriends(ctx context.Context, param *sdk.SearchFriendsParam) ([]*sdk.SearchFriendItem, error) { @@ -256,6 +288,7 @@ func (r *Relation) GetBlackList(ctx context.Context) ([]*model_struct.LocalBlack } func (r *Relation) UpdateFriends(ctx context.Context, req *relation.UpdateFriendsReq) error { + req.OwnerUserID = r.loginUserID if err := r.updateFriends(ctx, req); err != nil { return err } diff --git a/internal/user/api.go b/internal/user/api.go index 3fbe39ff5..6fef37300 100644 --- a/internal/user/api.go +++ b/internal/user/api.go @@ -85,6 +85,7 @@ func (u *User) GetSelfUserInfo(ctx context.Context) (*model_struct.LocalUser, er func (u *User) SetSelfInfo(ctx context.Context, userInfo *sdkws.UserInfoWithEx) error { // updateSelfUserInfo updates the user's information with Ex field. + userInfo.UserID = u.loginUserID if err := u.updateUserInfo(ctx, userInfo); err != nil { return err } @@ -178,29 +179,3 @@ func (u *User) GetUsersInfoFromSvr(ctx context.Context, userIDs []string) ([]*mo } return datautil.Batch(ServerUserToLocalUser, users), nil } - -func (u *User) GetUserInfoWithCache(ctx context.Context, cacheKey string) (*model_struct.LocalUser, error) { - return u.UserCache.FetchGet(ctx, cacheKey) -} - -func (u *User) GetUserInfoWithCacheFunc(ctx context.Context, cacheKey string, fetchFunc func(ctx context.Context, key string) (*model_struct.LocalUser, error)) (*model_struct.LocalUser, error) { - if userInfo, ok := u.UserCache.Load(cacheKey); ok { - return userInfo, nil - } - - fetchedData, err := fetchFunc(ctx, cacheKey) - if err != nil { - return nil, err - } - - u.UserCache.Store(cacheKey, fetchedData) - return fetchedData, nil -} - -func (u *User) GetUsersInfoWithCache(ctx context.Context, cacheKeys []string) ([]*model_struct.LocalUser, error) { - m, err := u.UserCache.MultiFetchGet(ctx, cacheKeys) - if err != nil { - return nil, err - } - return datautil.MapToSlice(m), nil -} diff --git a/internal/user/user.go b/internal/user/user.go index 89fa518ae..d80fef1dc 100644 --- a/internal/user/user.go +++ b/internal/user/user.go @@ -26,6 +26,7 @@ import ( "github.com/openimsdk/openim-sdk-core/v3/pkg/db/model_struct" "github.com/openimsdk/openim-sdk-core/v3/pkg/syncer" "github.com/openimsdk/openim-sdk-core/v3/pkg/utils" + "github.com/openimsdk/tools/utils/datautil" ) // NewUser creates a new User object. @@ -132,3 +133,29 @@ func (u *User) initSyncer() { }, ) } + +func (u *User) GetUserInfoWithCache(ctx context.Context, cacheKey string) (*model_struct.LocalUser, error) { + return u.UserCache.FetchGet(ctx, cacheKey) +} + +func (u *User) GetUserInfoWithCacheFunc(ctx context.Context, cacheKey string, fetchFunc func(ctx context.Context, key string) (*model_struct.LocalUser, error)) (*model_struct.LocalUser, error) { + if userInfo, ok := u.UserCache.Load(cacheKey); ok { + return userInfo, nil + } + + fetchedData, err := fetchFunc(ctx, cacheKey) + if err != nil { + return nil, err + } + + u.UserCache.Store(cacheKey, fetchedData) + return fetchedData, nil +} + +func (u *User) GetUsersInfoWithCache(ctx context.Context, cacheKeys []string) ([]*model_struct.LocalUser, error) { + m, err := u.UserCache.MultiFetchGet(ctx, cacheKeys) + if err != nil { + return nil, err + } + return datautil.MapToSlice(m), nil +} diff --git a/open_im_sdk/conversation_msg.go b/open_im_sdk/conversation_msg.go index 1cb870eee..8d14a5c87 100644 --- a/open_im_sdk/conversation_msg.go +++ b/open_im_sdk/conversation_msg.go @@ -34,8 +34,8 @@ func GetMultipleConversation(callback open_im_sdk_callback.Base, operationID str call(callback, operationID, UserForSDK.Conversation().GetMultipleConversation, conversationIDList) } -func SetConversations(callback open_im_sdk_callback.Base, operationID string, conversationID string, req string) { - call(callback, operationID, UserForSDK.Conversation().SetConversations, conversationID, req) +func SetConversation(callback open_im_sdk_callback.Base, operationID string, conversationID string, req string) { + call(callback, operationID, UserForSDK.Conversation().SetConversation, conversationID, req) } func HideConversation(callback open_im_sdk_callback.Base, operationID string, conversationID string) { diff --git a/open_im_sdk/relation.go b/open_im_sdk/relation.go index 3dddd5328..c68b14850 100644 --- a/open_im_sdk/relation.go +++ b/open_im_sdk/relation.go @@ -16,8 +16,8 @@ package open_im_sdk import "github.com/openimsdk/openim-sdk-core/v3/open_im_sdk_callback" -func GetSpecifiedFriendsInfo(callback open_im_sdk_callback.Base, operationID string, userIDList string) { - call(callback, operationID, UserForSDK.Relation().GetSpecifiedFriendsInfo, userIDList) +func GetSpecifiedFriendsInfo(callback open_im_sdk_callback.Base, operationID string, userIDList string, filterBlack bool) { + call(callback, operationID, UserForSDK.Relation().GetSpecifiedFriendsInfo, userIDList, filterBlack) } func GetFriendList(callback open_im_sdk_callback.Base, operationID string, filterBlack bool) { diff --git a/open_im_sdk/user.go b/open_im_sdk/user.go index a3cd6b0e3..1b9d293f6 100644 --- a/open_im_sdk/user.go +++ b/open_im_sdk/user.go @@ -51,4 +51,3 @@ func DeleteUserCommand(callback open_im_sdk_callback.Base, operationID string, T func GetAllUserCommands(callback open_im_sdk_callback.Base, operationID string, Type int32) { call(callback, operationID, UserForSDK.User().ProcessUserCommandGetAll, Type) } - diff --git a/pkg/api/api.go b/pkg/api/api.go index fc945b483..d3f7a3b0f 100644 --- a/pkg/api/api.go +++ b/pkg/api/api.go @@ -60,7 +60,7 @@ var ( var ( CreateGroup = newApi[group.CreateGroupReq, group.CreateGroupResp]("/group/create_group") - SetGroupInfoEX = newApi[group.SetGroupInfoEXReq, group.SetGroupInfoEXResp]("/group/set_group_info_EX") + SetGroupInfoEX = newApi[group.SetGroupInfoEXReq, group.SetGroupInfoEXResp]("/group/set_group_info_ex") JoinGroup = newApi[group.JoinGroupReq, group.JoinGroupResp]("/group/join_group") QuitGroup = newApi[group.QuitGroupReq, group.QuitGroupResp]("/group/quit_group") GetGroupsInfo = newApi[group.GetGroupsInfoReq, group.GetGroupsInfoResp]("/group/get_groups_info") diff --git a/pkg/content_type/content_type.go b/pkg/content_type/content_type.go index 76c1788bc..2c741c80a 100644 --- a/pkg/content_type/content_type.go +++ b/pkg/content_type/content_type.go @@ -29,6 +29,7 @@ var ext = map[string]string{ "flv": "video/x-flv", "webm": "video/webm", "3gp": "video/3gpp", + "m4a": "audio/mp4", "mp3": "audio/mpeg", "wav": "audio/wav", "ogg": "audio/ogg", diff --git a/pkg/server_api_params/public_struct.go b/pkg/server_api_params/public_struct.go deleted file mode 100644 index a07db5f73..000000000 --- a/pkg/server_api_params/public_struct.go +++ /dev/null @@ -1,33 +0,0 @@ -// 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 server_api_params - -import ( - "github.com/openimsdk/openim-sdk-core/v3/pkg/db/model_struct" - "github.com/openimsdk/openim-sdk-core/v3/sdk_struct" -) - -type FullUserInfo struct { - PublicInfo *sdk_struct.PublicUser `json:"publicInfo"` - FriendInfo *model_struct.LocalFriend `json:"friendInfo"` - BlackInfo *model_struct.LocalBlack `json:"blackInfo"` -} - -type FullUserInfoWithCache struct { - PublicInfo *sdk_struct.PublicUser `json:"publicInfo"` - FriendInfo *model_struct.LocalFriend `json:"friendInfo"` - BlackInfo *model_struct.LocalBlack `json:"blackInfo"` - GroupMemberInfo *model_struct.LocalGroupMember `json:"groupMemberInfo"` -} diff --git a/test/conversation_test.go b/test/conversation_test.go index 6af9c0181..f50abb706 100644 --- a/test/conversation_test.go +++ b/test/conversation_test.go @@ -86,8 +86,8 @@ func Test_SetConversationDraft(t *testing.T) { } } -func Test_SetConversations(t *testing.T) { - err := open_im_sdk.UserForSDK.Conversation().SetConversations(ctx, "group_17729585012", &conversation.ConversationReq{}) +func Test_SetConversation(t *testing.T) { + err := open_im_sdk.UserForSDK.Conversation().SetConversation(ctx, "group_17729585012", &conversation.ConversationReq{}) if err != nil { t.Fatal(err) } diff --git a/wasm/cmd/main.go b/wasm/cmd/main.go index 08927599f..9b7f242dc 100644 --- a/wasm/cmd/main.go +++ b/wasm/cmd/main.go @@ -99,7 +99,7 @@ func registerFunc() { js.Global().Set("getMultipleConversation", js.FuncOf(wrapperConMsg.GetMultipleConversation)) js.Global().Set("hideConversation", js.FuncOf(wrapperConMsg.HideConversation)) js.Global().Set("setConversationDraft", js.FuncOf(wrapperConMsg.SetConversationDraft)) - js.Global().Set("setConversations", js.FuncOf(wrapperConMsg.SetConversations)) + js.Global().Set("setConversation", js.FuncOf(wrapperConMsg.SetConversation)) js.Global().Set("getTotalUnreadMsgCount", js.FuncOf(wrapperConMsg.GetTotalUnreadMsgCount)) js.Global().Set("findMessageList", js.FuncOf(wrapperConMsg.FindMessageList)) diff --git a/wasm/wasm_wrapper/wasm_conversation_msg.go b/wasm/wasm_wrapper/wasm_conversation_msg.go index 2e92a3aab..c0d467a6e 100644 --- a/wasm/wasm_wrapper/wasm_conversation_msg.go +++ b/wasm/wasm_wrapper/wasm_conversation_msg.go @@ -267,9 +267,9 @@ func (w *WrapperConMsg) HideConversation(_ js.Value, args []js.Value) interface{ callback := event_listener.NewBaseCallback(utils.FirstLower(utils.GetSelfFuncName()), w.commonFunc) return event_listener.NewCaller(open_im_sdk.HideConversation, callback, &args).AsyncCallWithCallback() } -func (w *WrapperConMsg) SetConversations(_ js.Value, args []js.Value) interface{} { +func (w *WrapperConMsg) SetConversation(_ js.Value, args []js.Value) interface{} { callback := event_listener.NewBaseCallback(utils.FirstLower(utils.GetSelfFuncName()), w.commonFunc) - return event_listener.NewCaller(open_im_sdk.SetConversations, callback, &args).AsyncCallWithCallback() + return event_listener.NewCaller(open_im_sdk.SetConversation, callback, &args).AsyncCallWithCallback() } func (w *WrapperConMsg) SetConversationDraft(_ js.Value, args []js.Value) interface{} { callback := event_listener.NewBaseCallback(utils.FirstLower(utils.GetSelfFuncName()), w.commonFunc)