idb_wasm.mx raw
1 //:build wasm
2
3 package idb
4
5 import (
6 "git.smesh.lol/musiquay/web/common/jsbridge/callback"
7 "unsafe"
8 )
9
10 //:wasmimport bridge idb_set_enc_key
11 func wasmSetEncKey(ptr *byte, length int32, capacity int32)
12
13 //:wasmimport bridge idb_open
14 func wasmOpen(cbID int32)
15
16 //:wasmimport bridge idb_save_event
17 func wasmSaveEvent(ptr *byte, length int32, capacity int32, cbID int32)
18
19 //:wasmimport bridge idb_query_events
20 func wasmQueryEvents(ptr *byte, length int32, capacity int32, cbID int32)
21
22 //:wasmimport bridge idb_save_dm
23 func wasmSaveDM(ptr *byte, length int32, capacity int32, cbID int32)
24
25 //:wasmimport bridge idb_query_dms
26 func wasmQueryDMs(peerPtr *byte, peerLen int32, peerCap int32, limit int32, until int64, cbID int32)
27
28 //:wasmimport bridge idb_get_conversation_list
29 func wasmGetConversationList(cbID int32)
30
31 //:wasmimport bridge idb_clear_dms_by_peer
32 func wasmClearDMsByPeer(ptr *byte, length int32, capacity int32, cbID int32)
33
34 //:wasmimport bridge idb_set_version
35 func wasmSetVersion(ptr *byte, length int32, capacity int32)
36
37 func SetEncKey(hexKey string) {
38 wasmSetEncKey(unsafe.StringData(hexKey), int32(len(hexKey)), int32(len(hexKey)))
39 }
40
41 func Open(fn func()) {
42 wasmOpen(callback.Register0Once(fn))
43 }
44
45 func SaveEvent(eventJSON string, fn func(bool)) {
46 wasmSaveEvent(unsafe.StringData(eventJSON), int32(len(eventJSON)), int32(len(eventJSON)), callback.RegisterBOnce(fn))
47 }
48
49 func QueryEvents(filterJSON string, fn func(string)) {
50 wasmQueryEvents(unsafe.StringData(filterJSON), int32(len(filterJSON)), int32(len(filterJSON)), callback.RegisterSOnce(fn))
51 }
52
53 func SaveDM(dmJSON string, fn func(string)) {
54 wasmSaveDM(unsafe.StringData(dmJSON), int32(len(dmJSON)), int32(len(dmJSON)), callback.RegisterSOnce(fn))
55 }
56
57 func QueryDMs(peer string, limit int, until int64, fn func(string)) {
58 wasmQueryDMs(unsafe.StringData(peer), int32(len(peer)), int32(len(peer)), int32(limit), until, callback.RegisterSOnce(fn))
59 }
60
61 func GetConversationList(fn func(string)) {
62 wasmGetConversationList(callback.RegisterSOnce(fn))
63 }
64
65 func ClearDMsByPeer(peer string, fn func()) {
66 wasmClearDMsByPeer(unsafe.StringData(peer), int32(len(peer)), int32(len(peer)), callback.Register0Once(fn))
67 }
68
69 func SetVersion(v string) {
70 wasmSetVersion(unsafe.StringData(v), int32(len(v)), int32(len(v)))
71 }
72
73 //:wasmimport bridge idb_mls_save_group
74 func wasmMlsSaveGroup(gPtr *byte, gLen int32, gCap int32, sPtr *byte, sLen int32, sCap int32, cbID int32)
75
76 //:wasmimport bridge idb_mls_load_group
77 func wasmMlsLoadGroup(gPtr *byte, gLen int32, gCap int32, cbID int32)
78
79 //:wasmimport bridge idb_mls_list_groups
80 func wasmMlsListGroups(cbID int32)
81
82 //:wasmimport bridge idb_mls_save_kpp
83 func wasmMlsSaveKPP(ptr *byte, length int32, capacity int32, cbID int32)
84
85 //:wasmimport bridge idb_mls_load_kpp
86 func wasmMlsLoadKPP(cbID int32)
87
88 func MlsSaveGroup(groupIDHex, stateBase64 string, fn func()) {
89 wasmMlsSaveGroup(
90 unsafe.StringData(groupIDHex), int32(len(groupIDHex)), int32(len(groupIDHex)),
91 unsafe.StringData(stateBase64), int32(len(stateBase64)), int32(len(stateBase64)),
92 callback.Register0Once(fn),
93 )
94 }
95
96 func MlsLoadGroup(groupIDHex string, fn func(string)) {
97 wasmMlsLoadGroup(unsafe.StringData(groupIDHex), int32(len(groupIDHex)), int32(len(groupIDHex)), callback.RegisterSOnce(fn))
98 }
99
100 func MlsListGroups(fn func(string)) {
101 wasmMlsListGroups(callback.RegisterSOnce(fn))
102 }
103
104 func MlsSaveKPP(kppBase64 string, fn func()) {
105 wasmMlsSaveKPP(unsafe.StringData(kppBase64), int32(len(kppBase64)), int32(len(kppBase64)), callback.Register0Once(fn))
106 }
107
108 func MlsLoadKPP(fn func(string)) {
109 wasmMlsLoadKPP(callback.RegisterSOnce(fn))
110 }
111
112 //:wasmimport bridge idb_kv_get
113 func wasmKVGet(sPtr *byte, sLen int32, sCap int32, kPtr *byte, kLen int32, kCap int32, cbID int32)
114
115 //:wasmimport bridge idb_kv_put
116 func wasmKVPut(sPtr *byte, sLen int32, sCap int32, kPtr *byte, kLen int32, kCap int32, vPtr *byte, vLen int32, vCap int32)
117
118 //:wasmimport bridge idb_kv_get_all
119 func wasmKVGetAll(sPtr *byte, sLen int32, sCap int32, fnID int32, doneID int32)
120
121 func KVGet(store, key string, fn func(string)) {
122 wasmKVGet(
123 unsafe.StringData(store), int32(len(store)), int32(len(store)),
124 unsafe.StringData(key), int32(len(key)), int32(len(key)),
125 callback.RegisterSOnce(fn),
126 )
127 }
128
129 func KVPut(store, key, value string) {
130 wasmKVPut(
131 unsafe.StringData(store), int32(len(store)), int32(len(store)),
132 unsafe.StringData(key), int32(len(key)), int32(len(key)),
133 unsafe.StringData(value), int32(len(value)), int32(len(value)),
134 )
135 }
136
137 func KVGetAll(store string, each func(string, string), done func()) {
138 fnID := callback.RegisterSS(each)
139 doneID := callback.Register0Once(done)
140 wasmKVGetAll(unsafe.StringData(store), int32(len(store)), int32(len(store)), fnID, doneID)
141 }
142