Skip to content

Commit 267a0d3

Browse files
authoredJul 5, 2024··
feat: update wasm feature implement to v3.8 (#570)
* fix: add go build tags. * feat: dump wasm feature to v3.8 * fix: update method to correct call args. * fix uncorrect error implement. * update method call args. * update wasm interface implement. * update test in new interface. * update import pkg. * update new db implement in chat log. * fix uncorrect type transfer. * fix method implement to correct.
1 parent 6441b20 commit 267a0d3

29 files changed

+639
-85
lines changed
 

‎go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ require golang.org/x/net v0.22.0
1818
require (
1919
github.com/google/go-cmp v0.6.0
2020
github.com/openimsdk/protocol v0.0.69-alpha.16
21-
github.com/openimsdk/tools v0.0.49-alpha.40
21+
github.com/openimsdk/tools v0.0.49-alpha.44
2222
github.com/patrickmn/go-cache v2.1.0+incompatible
2323
golang.org/x/image v0.15.0
2424
gorm.io/gorm v1.25.10

‎go.sum

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ github.com/mattn/go-sqlite3 v1.14.22 h1:2gZY6PC6kBnID23Tichd1K+Z0oS6nE/XwU+Vz/5o
2727
github.com/mattn/go-sqlite3 v1.14.22/go.mod h1:Uh1q+B4BYcTPb+yiD3kU8Ct7aC0hY9fxUwlHK0RXw+Y=
2828
github.com/openimsdk/protocol v0.0.69-alpha.16 h1:ciSqm2rjBdpScpkQm3wPjAFv0YbIRp8MITRkDZWVv6c=
2929
github.com/openimsdk/protocol v0.0.69-alpha.16/go.mod h1:OZQA9FR55lseYoN2Ql1XAHYKHJGu7OMNkUbuekrKCM8=
30-
github.com/openimsdk/tools v0.0.49-alpha.40 h1:f7BVjJo30MC64diHiaRSmbJ6Uu0/CpZrohctkd3T4f0=
31-
github.com/openimsdk/tools v0.0.49-alpha.40/go.mod h1:zc0maZ2ohXlHd0ylY5JnCE8uqq/hslhcfcKa6iO5PCU=
30+
github.com/openimsdk/tools v0.0.49-alpha.44 h1:anefO8hvQwJrYL+V4ifSge/CveZHIpjPeik6BgETuG8=
31+
github.com/openimsdk/tools v0.0.49-alpha.44/go.mod h1:zc0maZ2ohXlHd0ylY5JnCE8uqq/hslhcfcKa6iO5PCU=
3232
github.com/patrickmn/go-cache v2.1.0+incompatible h1:HRMgzkcYKYpi3C8ajMPV8OFXaaRUnok+kx1WdO15EQc=
3333
github.com/patrickmn/go-cache v2.1.0+incompatible/go.mod h1:3Qf8kWWT7OJRJbdiICTKqZju1ZixQ/KpMGzzAfe6+WQ=
3434
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=

‎msgtest/module/manager.go

+11-10
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,18 @@ import (
55
"context"
66
"encoding/json"
77
"fmt"
8+
"io"
9+
"net/http"
10+
811
"github.com/openimsdk/openim-sdk-core/v3/internal/util"
912
"github.com/openimsdk/openim-sdk-core/v3/pkg/constant"
1013
"github.com/openimsdk/openim-sdk-core/v3/pkg/sdkerrs"
1114
"github.com/openimsdk/openim-sdk-core/v3/pkg/utils"
1215
authPB "github.com/openimsdk/protocol/auth"
1316
"github.com/openimsdk/protocol/msg"
17+
"github.com/openimsdk/tools/errs"
1418
"github.com/openimsdk/tools/log"
1519
"github.com/openimsdk/tools/mcontext"
16-
"io"
17-
"net/http"
1820
)
1921

2022
const (
@@ -55,17 +57,16 @@ func (m *MetaManager) NewApiMsgSender() *ApiMsgSender {
5557
func (m *MetaManager) apiPost(ctx context.Context, route string, req, resp any) (err error) {
5658
operationID, _ := ctx.Value("operationID").(string)
5759
if operationID == "" {
58-
err := sdkerrs.ErrArgs.Wrap("call api operationID is empty")
59-
return err
60+
return errs.ErrArgs.WrapMsg("call api operationID is empty")
6061
}
6162
reqBody, err := json.Marshal(req)
6263
if err != nil {
63-
return sdkerrs.ErrSdkInternal.Wrap("json.Marshal(req) failed " + err.Error())
64+
return errs.ErrArgs.WrapMsg("json.Marshal(req) failed " + err.Error())
6465
}
6566
reqUrl := m.apiAddr + route
6667
request, err := http.NewRequestWithContext(ctx, http.MethodPost, reqUrl, bytes.NewReader(reqBody))
6768
if err != nil {
68-
return sdkerrs.ErrSdkInternal.Wrap("sdk http.NewRequestWithContext failed " + err.Error())
69+
return errs.ErrArgs.WrapMsg("sdk http.NewRequestWithContext failed " + err.Error())
6970
}
7071
log.ZDebug(ctx, "ApiRequest", "url", reqUrl, "body", string(reqBody))
7172
request.ContentLength = int64(len(reqBody))
@@ -76,18 +77,18 @@ func (m *MetaManager) apiPost(ctx context.Context, route string, req, resp any)
7677
}
7778
response, err := new(http.Client).Do(request)
7879
if err != nil {
79-
return sdkerrs.ErrNetwork.Wrap("ApiPost http.Client.Do failed " + err.Error())
80+
return errs.ErrArgs.WrapMsg("ApiPost http.Client.Do failed " + err.Error())
8081
}
8182
defer response.Body.Close()
8283
respBody, err := io.ReadAll(response.Body)
8384
if err != nil {
8485
log.ZError(ctx, "ApiResponse", err, "type", "read body", "status", response.Status)
85-
return sdkerrs.ErrSdkInternal.Wrap("io.ReadAll(ApiResponse) failed " + err.Error())
86+
return errs.ErrArgs.WrapMsg("io.ReadAll(ApiResponse) failed " + err.Error())
8687
}
8788
log.ZDebug(ctx, "ApiResponse", "url", reqUrl, "status", response.Status, "body", string(respBody))
8889
var baseApi util.ApiResponse
8990
if err := json.Unmarshal(respBody, &baseApi); err != nil {
90-
return sdkerrs.ErrSdkInternal.Wrap(fmt.Sprintf("api %s json.Unmarshal(%q, %T) failed %s", m.apiAddr, string(respBody), &baseApi, err.Error()))
91+
return errs.ErrArgs.WrapMsg(fmt.Sprintf("api %s json.Unmarshal(%q, %T) failed %s", m.apiAddr, string(respBody), &baseApi, err.Error()))
9192
}
9293
if baseApi.ErrCode != 0 {
9394
err := sdkerrs.New(baseApi.ErrCode, baseApi.ErrMsg, baseApi.ErrDlt)
@@ -97,7 +98,7 @@ func (m *MetaManager) apiPost(ctx context.Context, route string, req, resp any)
9798
return nil
9899
}
99100
if err := json.Unmarshal(baseApi.Data, resp); err != nil {
100-
return sdkerrs.ErrSdkInternal.Wrap(fmt.Sprintf("json.Unmarshal(%q, %T) failed %s", string(baseApi.Data), resp, err.Error()))
101+
return errs.ErrArgs.WrapMsg(fmt.Sprintf("json.Unmarshal(%q, %T) failed %s", string(baseApi.Data), resp, err.Error()))
101102
}
102103
return nil
103104
}

‎msgtest/module/msg_sender.go

+6-3
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,16 @@ package module
33
import (
44
"context"
55
"fmt"
6+
67
"github.com/openimsdk/openim-sdk-core/v3/internal/interaction"
78
"github.com/openimsdk/openim-sdk-core/v3/pkg/ccontext"
89

10+
"time"
11+
912
"github.com/openimsdk/openim-sdk-core/v3/pkg/common"
1013
"github.com/openimsdk/openim-sdk-core/v3/pkg/constant"
1114
"github.com/openimsdk/openim-sdk-core/v3/pkg/utils"
1215
"github.com/openimsdk/openim-sdk-core/v3/sdk_struct"
13-
"time"
1416

1517
"github.com/openimsdk/protocol/sdkws"
1618
"github.com/openimsdk/tools/log"
@@ -179,5 +181,6 @@ func (c *ConnListner) OnConnectSuccess() {}
179181
func (c *ConnListner) OnConnectFailed(errCode int32, errMsg string) {
180182
// log.ZError(context.Background(), "connect failed", nil, "errCode", errCode, "errMsg", errMsg)
181183
}
182-
func (c *ConnListner) OnKickedOffline() {}
183-
func (c *ConnListner) OnUserTokenExpired() {}
184+
func (c *ConnListner) OnKickedOffline() {}
185+
func (c *ConnListner) OnUserTokenExpired() {}
186+
func (c *ConnListner) OnUserTokenInvalid(errMsg string) {}

‎msgtest/sdk_user_simulator/listener.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
type conversationCallBack struct {
1010
}
1111

12-
func (c *conversationCallBack) OnSyncServerFailed() {
12+
func (c *conversationCallBack) OnSyncServerFailed(reinstalled bool) {
1313
}
1414

1515
func (c *conversationCallBack) OnNewConversation(conversationList string) {
@@ -30,11 +30,11 @@ func (c *conversationCallBack) OnRecvMessageExtensionsDeleted(msgID string, reac
3030
func (c *conversationCallBack) OnSyncServerProgress(progress int) {
3131
}
3232

33-
func (c *conversationCallBack) OnSyncServerStart() {
33+
func (c *conversationCallBack) OnSyncServerStart(reinstalled bool) {
3434

3535
}
3636

37-
func (c *conversationCallBack) OnSyncServerFinish() {
37+
func (c *conversationCallBack) OnSyncServerFinish(reinstalled bool) {
3838

3939
}
4040

‎open_im_sdk/userRelated.go

+5-4
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ import (
1919
"encoding/json"
2020
"errors"
2121
"fmt"
22+
"strings"
23+
"sync"
24+
"time"
25+
"unsafe"
26+
2227
"github.com/openimsdk/openim-sdk-core/v3/internal/business"
2328
conv "github.com/openimsdk/openim-sdk-core/v3/internal/conversation_msg"
2429
"github.com/openimsdk/openim-sdk-core/v3/internal/file"
@@ -41,10 +46,6 @@ import (
4146
"github.com/openimsdk/protocol/push"
4247
"github.com/openimsdk/protocol/sdkws"
4348
"github.com/openimsdk/tools/log"
44-
"strings"
45-
"sync"
46-
"time"
47-
"unsafe"
4849
)
4950

5051
const (

‎pkg/db/app_version.go

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
//go:build !js
2+
// +build !js
3+
14
package db
25

36
import (

‎pkg/db/db_js.go

+5
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ package db
1717
import (
1818
"context"
1919
"errors"
20+
2021
"github.com/openimsdk/openim-sdk-core/v3/wasm/exec"
2122
"github.com/openimsdk/openim-sdk-core/v3/wasm/indexdb"
2223
)
@@ -43,6 +44,8 @@ type IndexDB struct {
4344
*indexdb.LocalStrangers
4445
*indexdb.LocalSendingMessages
4546
*indexdb.LocalUserCommand
47+
*indexdb.LocalVersionSync
48+
*indexdb.LocalAppSDKVersion
4649
loginUserID string
4750
}
4851

@@ -77,6 +80,8 @@ func NewDataBase(ctx context.Context, loginUserID string, dbDir string, logLevel
7780
LocalStrangers: indexdb.NewLocalStrangers(),
7881
LocalSendingMessages: indexdb.NewLocalSendingMessages(),
7982
LocalUserCommand: indexdb.NewLocalUserCommand(),
83+
LocalVersionSync: indexdb.NewLocalVersionSync(),
84+
LocalAppSDKVersion: indexdb.NewLocalAppSDKVersion(),
8085
loginUserID: loginUserID,
8186
}
8287
err := i.InitDB(ctx, loginUserID, dbDir)

‎pkg/db/version_sync.go

+4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
1+
//go:build !js
2+
// +build !js
3+
14
package db
25

36
import (
47
"context"
8+
59
"github.com/openimsdk/openim-sdk-core/v3/pkg/db/model_struct"
610
"github.com/openimsdk/tools/errs"
711
"gorm.io/gorm"

‎testv2/app_version_test.go

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package testv2
2+
3+
import (
4+
"context"
5+
"testing"
6+
7+
"github.com/openimsdk/openim-sdk-core/v3/pkg/db"
8+
"github.com/openimsdk/openim-sdk-core/v3/pkg/db/model_struct"
9+
"github.com/openimsdk/tools/log"
10+
)
11+
12+
func Test_GetAppSDKVersion(t *testing.T) {
13+
ctx := context.Background()
14+
db, err := db.NewDataBase(ctx, "1695766238", "./", 6)
15+
if err != nil {
16+
return
17+
}
18+
// log.ZError(ctx, "DB err test", nil, "key", "vale")
19+
20+
info, err := db.GetAppSDKVersion(ctx)
21+
if err != nil {
22+
t.Fatal(err)
23+
}
24+
log.ZDebug(ctx, "info is ", "info", info)
25+
}
26+
27+
func Test_SetAppSDKVersion(t *testing.T) {
28+
ctx := context.Background()
29+
db, err := db.NewDataBase(ctx, "1695766238", "./", 6)
30+
if err != nil {
31+
return
32+
}
33+
34+
newVersion := &model_struct.LocalAppSDKVersion{
35+
Version: "4.0.0",
36+
}
37+
38+
err = db.SetAppSDKVersion(ctx, newVersion)
39+
if err != nil {
40+
t.Fatal(err)
41+
}
42+
}

‎testv2/friend_db_test.go

+108
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
package testv2
2+
3+
import (
4+
"context"
5+
"testing"
6+
7+
"github.com/openimsdk/openim-sdk-core/v3/pkg/db"
8+
"github.com/openimsdk/openim-sdk-core/v3/pkg/db/model_struct"
9+
"github.com/openimsdk/tools/log"
10+
)
11+
12+
func Test_GetFriendListCount(t *testing.T) {
13+
ctx := context.Background()
14+
db, err := db.NewDataBase(ctx, "1695766238", "./", 6)
15+
if err != nil {
16+
return
17+
}
18+
19+
info, err := db.GetFriendListCount(ctx)
20+
if err != nil {
21+
t.Fatal(err)
22+
}
23+
log.ZDebug(ctx, "info is ", "info", info)
24+
}
25+
26+
func Test_BatchInsertFriend(t *testing.T) {
27+
ctx := context.Background()
28+
db, err := db.NewDataBase(ctx, "1695766238", "./", 6)
29+
if err != nil {
30+
return
31+
}
32+
localFriends := []*model_struct.LocalFriend{
33+
{
34+
OwnerUserID: "1695766238",
35+
FriendUserID: "1234567890",
36+
Remark: "hello",
37+
CreateTime: 1666778999,
38+
AddSource: 0,
39+
OperatorUserID: "789",
40+
Nickname: "hhhh",
41+
FaceURL: "",
42+
Ex: "",
43+
AttachedInfo: "",
44+
IsPinned: false,
45+
},
46+
{
47+
OwnerUserID: "1695766238",
48+
FriendUserID: "1234567891",
49+
Remark: "hi",
50+
CreateTime: 1666779000,
51+
AddSource: 1,
52+
OperatorUserID: "790",
53+
Nickname: "aaaa",
54+
FaceURL: "https://example.com/face.png",
55+
Ex: "example",
56+
AttachedInfo: "info",
57+
IsPinned: true,
58+
},
59+
{
60+
OwnerUserID: "1695766238",
61+
FriendUserID: "1234567892",
62+
Remark: "hey",
63+
CreateTime: 1666779001,
64+
AddSource: 2,
65+
OperatorUserID: "791",
66+
Nickname: "bbbb",
67+
FaceURL: "https://example.com/face2.png",
68+
Ex: "example2",
69+
AttachedInfo: "info2",
70+
IsPinned: false,
71+
},
72+
}
73+
74+
err = db.BatchInsertFriend(ctx, localFriends)
75+
if err != nil {
76+
t.Fatal(err)
77+
}
78+
}
79+
80+
func Test_DeleteAllFriend(t *testing.T) {
81+
ctx := context.Background()
82+
db, err := db.NewDataBase(ctx, "1695766238", "./", 6)
83+
if err != nil {
84+
return
85+
}
86+
// log.ZError(ctx, "DB err test", nil, "key", "vale")
87+
88+
err = db.DeleteAllFriend(ctx)
89+
if err != nil {
90+
t.Fatal(err)
91+
}
92+
93+
}
94+
95+
// func Test_UpdateColumnsFriend(t *testing.T) {
96+
// ctx := context.Background()
97+
// db, err := db.NewDataBase(ctx, "1695766238", "./", 6)
98+
// if err != nil {
99+
// return
100+
// }
101+
// // log.ZError(ctx, "DB err test", nil, "key", "vale")
102+
103+
// err = db.UpdateColumnsFriend(ctx)
104+
// if err != nil {
105+
// t.Fatal(err)
106+
// }
107+
108+
// }

‎testv2/friend_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -180,3 +180,4 @@ func Test_SetFriendsEx(t *testing.T) {
180180
t.Fatal(err)
181181
}
182182
}
183+

0 commit comments

Comments
 (0)
Please sign in to comment.