diff --git a/go.mod b/go.mod index 21df23f9c..dc4570c6c 100644 --- a/go.mod +++ b/go.mod @@ -20,13 +20,11 @@ require ( github.com/openimsdk/protocol v0.0.69-alpha.16 github.com/openimsdk/tools v0.0.49-alpha.40 github.com/patrickmn/go-cache v2.1.0+incompatible - go.etcd.io/etcd/api/v3 v3.5.13 golang.org/x/image v0.15.0 gorm.io/gorm v1.25.10 ) require ( - github.com/coreos/go-semver v0.3.0 // indirect github.com/jinzhu/inflection v1.0.0 // indirect github.com/jinzhu/now v1.1.5 // indirect github.com/lestrrat-go/strftime v1.0.6 // indirect @@ -39,5 +37,3 @@ require ( google.golang.org/genproto/googleapis/rpc v0.0.0-20240318140521-94a12d6c2237 // indirect google.golang.org/grpc v1.62.1 // indirect ) - -//replace github.com/openimsdk/protocol => /Users/chao/Desktop/project/protocol diff --git a/go.sum b/go.sum index 508a6491c..4adfb7955 100644 --- a/go.sum +++ b/go.sum @@ -1,7 +1,5 @@ github.com/benbjohnson/clock v1.1.0 h1:Q92kusRqC1XV2MjkWETPvjJVqKetz1OzxZB7mHJLju8= github.com/benbjohnson/clock v1.1.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA= -github.com/coreos/go-semver v0.3.0 h1:wkHLiw0WNATZnSG7epLsujiMCgPAc9xhjJ4tgnAxmfM= -github.com/coreos/go-semver v0.3.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= @@ -41,8 +39,6 @@ github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+ github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= -go.etcd.io/etcd/api/v3 v3.5.13 h1:8WXU2/NBge6AUF1K1gOexB6e07NgsN1hXK0rSTtgSp4= -go.etcd.io/etcd/api/v3 v3.5.13/go.mod h1:gBqlqkcMMZMVTMm4NDZloEVJzxQOQIls8splbqBDa0c= go.uber.org/atomic v1.7.0 h1:ADUqmZGgLDDfbSL9ZmPxKTybcoEYHgpYfELNoN+7hsw= go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc= go.uber.org/goleak v1.1.11 h1:wy28qYRKZgnJTxGxvye5/wgWr1EKjmUDGYox5mGlRlI= @@ -65,8 +61,6 @@ google.golang.org/grpc v1.62.1 h1:B4n+nfKzOICUXMgyrNd19h/I9oH0L1pizfk1d4zSgTk= google.golang.org/grpc v1.62.1/go.mod h1:IWTG0VlJLCh1SkC58F7np9ka9mx/WNkjl4PGJaiq+QE= google.golang.org/protobuf v1.33.0 h1:uNO2rsAINq/JlFpSdYEKIZ0uKD/R9cpdv0T+yoGwGmI= google.golang.org/protobuf v1.33.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos= -gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= -gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gorm.io/driver/sqlite v1.5.5 h1:7MDMtUZhV065SilG62E0MquljeArQZNfJnjd9i9gx3E= diff --git a/internal/friend/sdk.go b/internal/friend/sdk.go index ed74bff8d..77a382601 100644 --- a/internal/friend/sdk.go +++ b/internal/friend/sdk.go @@ -44,8 +44,9 @@ func (f *Friend) GetSpecifiedFriendsInfo(ctx context.Context, friendUserIDList [ func(ctx context.Context, values []*model_struct.LocalFriend) error { return f.db.BatchInsertFriend(ctx, values) }, - func(ctx context.Context, userIDs []string) ([]*model_struct.LocalFriend, error) { - return f.db.GetFriendInfoList(ctx, userIDs) + func(ctx context.Context, userIDs []string) ([]*model_struct.LocalFriend, bool, error) { + localFriends, err := f.db.GetFriendInfoList(ctx, userIDs) + return localFriends, true, err }, func(ctx context.Context, userIDs []string) ([]*model_struct.LocalFriend, error) { serverFriend, err := f.GetDesignatedFriends(ctx, userIDs) @@ -201,8 +202,9 @@ func (f *Friend) GetFriendListPage(ctx context.Context, offset, count int32) ([] func(ctx context.Context, values []*model_struct.LocalFriend) error { return f.db.BatchInsertFriend(ctx, values) }, - func(ctx context.Context, userIDs []string) ([]*model_struct.LocalFriend, error) { - return f.db.GetFriendInfoList(ctx, userIDs) + func(ctx context.Context, userIDs []string) ([]*model_struct.LocalFriend, bool, error) { + localFriendList, err := f.db.GetFriendInfoList(ctx, userIDs) + return localFriendList, true, err }, func(ctx context.Context, userIDs []string) ([]*model_struct.LocalFriend, error) { serverFriend, err := f.GetDesignatedFriends(ctx, userIDs) @@ -249,8 +251,9 @@ func (f *Friend) GetFriendListPageV2(ctx context.Context, offset, count int32) ( func(ctx context.Context, values []*model_struct.LocalFriend) error { return f.db.BatchInsertFriend(ctx, values) }, - func(ctx context.Context, userIDs []string) ([]*model_struct.LocalFriend, error) { - return f.db.GetFriendInfoList(ctx, userIDs) + func(ctx context.Context, userIDs []string) ([]*model_struct.LocalFriend, bool, error) { + localFriendList, err := f.db.GetFriendInfoList(ctx, userIDs) + return localFriendList, true, err }, func(ctx context.Context, userIDs []string) ([]*model_struct.LocalFriend, error) { serverFriend, err := f.GetDesignatedFriends(ctx, userIDs) diff --git a/internal/group/sdk.go b/internal/group/sdk.go index e4d32554c..178f87ed6 100644 --- a/internal/group/sdk.go +++ b/internal/group/sdk.go @@ -173,8 +173,9 @@ func (g *Group) GetJoinedGroupListPage(ctx context.Context, offset, count int32) func(ctx context.Context, values []*model_struct.LocalGroup) error { return g.db.BatchInsertGroup(ctx, values) }, - func(ctx context.Context, groupIDs []string) ([]*model_struct.LocalGroup, error) { - return g.db.GetGroups(ctx, groupIDs) + func(ctx context.Context, groupIDs []string) ([]*model_struct.LocalGroup, bool, error) { + localGroups, err := g.db.GetGroups(ctx, groupIDs) + return localGroups, true, err }, func(ctx context.Context, groupIDs []string) ([]*model_struct.LocalGroup, error) { serverGroupInfo, err := g.getGroupsInfoFromSvr(ctx, groupIDs) @@ -198,8 +199,9 @@ func (g *Group) GetSpecifiedGroupsInfo(ctx context.Context, groupIDs []string) ( func(ctx context.Context, values []*model_struct.LocalGroup) error { return g.db.BatchInsertGroup(ctx, values) }, - func(ctx context.Context, groupIDs []string) ([]*model_struct.LocalGroup, error) { - return g.db.GetGroups(ctx, groupIDs) + func(ctx context.Context, groupIDs []string) ([]*model_struct.LocalGroup, bool, error) { + localGroups, err := g.db.GetGroups(ctx, groupIDs) + return localGroups, true, err }, func(ctx context.Context, groupIDs []string) ([]*model_struct.LocalGroup, error) { serverGroupInfo, err := g.getGroupsInfoFromSvr(ctx, groupIDs) @@ -223,8 +225,9 @@ func (g *Group) GetJoinedGroupListPageV2(ctx context.Context, offset, count int3 func(ctx context.Context, values []*model_struct.LocalGroup) error { return g.db.BatchInsertGroup(ctx, values) }, - func(ctx context.Context, groupIDs []string) ([]*model_struct.LocalGroup, error) { - return g.db.GetGroups(ctx, groupIDs) + func(ctx context.Context, groupIDs []string) ([]*model_struct.LocalGroup, bool, error) { + localGroups, err := g.db.GetGroups(ctx, groupIDs) + return localGroups, true, err }, func(ctx context.Context, groupIDs []string) ([]*model_struct.LocalGroup, error) { serverGroupInfo, err := g.getGroupsInfoFromSvr(ctx, groupIDs) @@ -289,8 +292,9 @@ func (g *Group) GetGroupMemberListByJoinTimeFilter(ctx context.Context, groupID func(ctx context.Context, values []*model_struct.LocalGroupMember) error { return g.db.BatchInsertGroupMember(ctx, values) }, - func(ctx context.Context, userIDs []string) ([]*model_struct.LocalGroupMember, error) { - return g.db.GetGroupMemberListSplitByJoinTimeFilter(ctx, groupID, int(offset), int(count), joinTimeBegin, joinTimeEnd, userIDs) + func(ctx context.Context, userIDs []string) ([]*model_struct.LocalGroupMember, bool, error) { + localGroupMembers, err := g.db.GetGroupMemberListSplitByJoinTimeFilter(ctx, groupID, int(offset), int(count), joinTimeBegin, joinTimeEnd, userIDs) + return localGroupMembers, true, err }, func(ctx context.Context, userIDs []string) ([]*model_struct.LocalGroupMember, error) { serverGroupMember, err := g.GetDesignatedGroupMembers(ctx, groupID, userIDs) @@ -319,8 +323,9 @@ func (g *Group) GetGroupMemberListByJoinTimeFilterV2(ctx context.Context, groupI func(ctx context.Context, values []*model_struct.LocalGroupMember) error { return g.db.BatchInsertGroupMember(ctx, values) }, - func(ctx context.Context, userIDs []string) ([]*model_struct.LocalGroupMember, error) { - return g.db.GetGroupMemberListSplitByJoinTimeFilter(ctx, groupID, int(offset), int(count), joinTimeBegin, joinTimeEnd, userIDs) + func(ctx context.Context, userIDs []string) ([]*model_struct.LocalGroupMember, bool, error) { + localGroupMembers, err := g.db.GetGroupMemberListSplitByJoinTimeFilter(ctx, groupID, int(offset), int(count), joinTimeBegin, joinTimeEnd, userIDs) + return localGroupMembers, true, err }, func(ctx context.Context, userIDs []string) ([]*model_struct.LocalGroupMember, error) { serverGroupMember, err := g.GetDesignatedGroupMembers(ctx, groupID, userIDs) @@ -372,8 +377,9 @@ func (g *Group) GetSpecifiedGroupMembersInfo(ctx context.Context, groupID string func(ctx context.Context, values []*model_struct.LocalGroupMember) error { return g.db.BatchInsertGroupMember(ctx, values) }, - func(ctx context.Context, userIDs []string) ([]*model_struct.LocalGroupMember, error) { - return g.db.GetGroupSomeMemberInfo(ctx, groupID, userIDList) + func(ctx context.Context, userIDs []string) ([]*model_struct.LocalGroupMember, bool, error) { + localGroupMembers, err := g.db.GetGroupSomeMemberInfo(ctx, groupID, userIDList) + return localGroupMembers, true, err }, func(ctx context.Context, userIDs []string) ([]*model_struct.LocalGroupMember, error) { serverGroupMember, err := g.GetDesignatedGroupMembers(ctx, groupID, userIDs) @@ -420,8 +426,24 @@ func (g *Group) GetGroupMemberList(ctx context.Context, groupID string, filter, func(ctx context.Context, values []*model_struct.LocalGroupMember) error { return g.db.BatchInsertGroupMember(ctx, values) }, - func(ctx context.Context, userIDs []string) ([]*model_struct.LocalGroupMember, error) { - return g.db.GetGroupMemberListByUserIDs(ctx, groupID, filter, userIDs) + func(ctx context.Context, userIDs []string) ([]*model_struct.LocalGroupMember, bool, error) { + localGroupMembers, err := g.db.GetGroupMemberListByUserIDs(ctx, groupID, filter, userIDs) + if err != nil { + return nil, false, err + } + switch filter { + case constant.GroupFilterOwner: + fallthrough + case constant.GroupFilterAdmin: + fallthrough + case constant.GroupFilterOwnerAndAdmin: + return localGroupMembers, false, nil + case constant.GroupFilterAll: + case constant.GroupFilterOrdinaryUsers: + case constant.GroupFilterAdminAndOrdinaryUsers: + return localGroupMembers, true, nil + } + return nil, false, sdkerrs.ErrArgs }, func(ctx context.Context, userIDs []string) ([]*model_struct.LocalGroupMember, error) { serverGroupMember, err := g.GetDesignatedGroupMembers(ctx, groupID, userIDs) @@ -431,6 +453,20 @@ func (g *Group) GetGroupMemberList(ctx context.Context, groupID string, filter, return datautil.Batch(ServerGroupMemberToLocalGroupMember, serverGroupMember), nil }, ) + switch filter { + case constant.GroupFilterOrdinaryUsers: + groupOwnerAndGroupMember, err := g.db.GetGroupMemberListSplit(ctx, groupID, constant.GroupFilterOwnerAndAdmin, 0, 100) + if err != nil { + return nil, err + } + offset = offset + int32(len(groupOwnerAndGroupMember)) + case constant.GroupFilterAdminAndOrdinaryUsers: + groupOwnerAndGroupMember, err := g.db.GetGroupMemberListSplit(ctx, groupID, constant.GroupFilterOwner, 0, 100) + if err != nil { + return nil, err + } + offset = offset + int32(len(groupOwnerAndGroupMember)) + } return dataFetcher.FetchWithPagination(ctx, int(offset), int(count)) } @@ -445,8 +481,9 @@ func (g *Group) GetGroupMemberListV2(ctx context.Context, groupID string, filter func(ctx context.Context, values []*model_struct.LocalGroupMember) error { return g.db.BatchInsertGroupMember(ctx, values) }, - func(ctx context.Context, userIDs []string) ([]*model_struct.LocalGroupMember, error) { - return g.db.GetGroupMemberListByUserIDs(ctx, groupID, filter, userIDs) + func(ctx context.Context, userIDs []string) ([]*model_struct.LocalGroupMember, bool, error) { + localGroupMembers, err := g.db.GetGroupMemberListByUserIDs(ctx, groupID, filter, userIDs) + return localGroupMembers, true, err }, func(ctx context.Context, userIDs []string) ([]*model_struct.LocalGroupMember, error) { serverGroupMember, err := g.GetDesignatedGroupMembers(ctx, groupID, userIDs) diff --git a/msgtest/sdk_user_simulator/user.go b/msgtest/sdk_user_simulator/user.go index a92a1cc87..9dd6c1223 100644 --- a/msgtest/sdk_user_simulator/user.go +++ b/msgtest/sdk_user_simulator/user.go @@ -8,8 +8,8 @@ import ( "github.com/openimsdk/openim-sdk-core/v3/pkg/constant" "github.com/openimsdk/openim-sdk-core/v3/pkg/utils" "github.com/openimsdk/openim-sdk-core/v3/sdk_struct" + "github.com/openimsdk/openim-sdk-core/v3/version" "github.com/openimsdk/tools/log" - "go.etcd.io/etcd/api/v3/version" ) var ( diff --git a/open_im_sdk/init_login.go b/open_im_sdk/init_login.go index cb95e4675..63399272e 100644 --- a/open_im_sdk/init_login.go +++ b/open_im_sdk/init_login.go @@ -22,7 +22,7 @@ import ( "github.com/openimsdk/openim-sdk-core/v3/pkg/ccontext" "github.com/openimsdk/openim-sdk-core/v3/pkg/constant" "github.com/openimsdk/openim-sdk-core/v3/sdk_struct" - "go.etcd.io/etcd/api/v3/version" + "github.com/openimsdk/openim-sdk-core/v3/version" "strings" "github.com/openimsdk/tools/log" diff --git a/pkg/datafetcher/datafetcher.go b/pkg/datafetcher/datafetcher.go index 89f309951..14d96edce 100644 --- a/pkg/datafetcher/datafetcher.go +++ b/pkg/datafetcher/datafetcher.go @@ -20,7 +20,7 @@ type DataFetcher[T any] struct { } // FetchDataFunc is a function type for fetching data -type FetchDataFunc[T any] func(ctx context.Context, uids []string) ([]T, error) +type FetchDataFunc[T any] func(ctx context.Context, uids []string) ([]T, bool, error) // FetchFromServerFunc is a function type for fetching data from server type FetchFromServerFunc[T any] func(ctx context.Context, uids []string) ([]T, error) @@ -67,10 +67,13 @@ func (ds *DataFetcher[T]) FetchWithPagination(ctx context.Context, offset, limit // FetchMissingAndFillLocal fetches missing data from server and fills local database func (ds *DataFetcher[T]) FetchMissingAndFillLocal(ctx context.Context, uids []string) ([]T, error) { - localData, err := ds.FetchFromLocal(ctx, uids) + localData, needServer, err := ds.FetchFromLocal(ctx, uids) if err != nil { return nil, err } + if !needServer { + return localData, nil + } localUIDSet := datautil.SliceSetAny(localData, ds.Key) @@ -101,11 +104,15 @@ func (ds *DataFetcher[T]) FetchMissingAndFillLocal(ctx context.Context, uids []s // FetchMissingAndCombineLocal fetches missing data from the server and combines it with local data without inserting it into the local database func (ds *DataFetcher[T]) FetchMissingAndCombineLocal(ctx context.Context, uids []string) ([]T, error) { - localData, err := ds.FetchFromLocal(ctx, uids) + localData, needServer, err := ds.FetchFromLocal(ctx, uids) if err != nil { return nil, err } + if !needServer { + return localData, nil + } + localUIDSet := datautil.SliceSetAny(localData, ds.Key) var missingUIDs []string @@ -154,7 +161,7 @@ func (ds *DataFetcher[T]) FetchWithPaginationV2(ctx context.Context, offset, lim } func (ds *DataFetcher[T]) FetchMissingAndFillLocalV2(ctx context.Context, uids []string, isEnd bool) ([]T, bool, error) { - localData, err := ds.FetchFromLocal(ctx, uids) + localData, _, err := ds.FetchFromLocal(ctx, uids) if err != nil { return nil, false, err } diff --git a/version/version b/version/version index 240bba906..0be1fc7d2 100644 --- a/version/version +++ b/version/version @@ -1 +1 @@ -3.7.0 \ No newline at end of file +3.8.0 \ No newline at end of file