mirror of
https://github.com/chatmail/core.git
synced 2026-04-02 05:22:14 +03:00
Compare commits
712 Commits
1.66.0
...
integrate-
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c14e5086d7 | ||
|
|
4779383401 | ||
|
|
47d30ef6d3 | ||
|
|
3a38ffdfe0 | ||
|
|
33d548eccc | ||
|
|
1700af2c8d | ||
|
|
01920a1a00 | ||
|
|
7c67ea0b8a | ||
|
|
0c64701984 | ||
|
|
d2d35fe26b | ||
|
|
a0b4d016d5 | ||
|
|
3ce70ee244 | ||
|
|
c43c9b9107 | ||
|
|
638d2ff932 | ||
|
|
0213bb372f | ||
|
|
d54fa65ff3 | ||
|
|
564d283852 | ||
|
|
8357b3a98c | ||
|
|
177f89f678 | ||
|
|
372425f38f | ||
|
|
53f8274c6f | ||
|
|
65b242aa5c | ||
|
|
bb6d7767b5 | ||
|
|
227a75a5f7 | ||
|
|
8fb46d0b56 | ||
|
|
0291094c62 | ||
|
|
6220724bf4 | ||
|
|
102f6d9719 | ||
|
|
aad94f12c1 | ||
|
|
065ef7ab38 | ||
|
|
008e78a022 | ||
|
|
548335082b | ||
|
|
a36885e886 | ||
|
|
0d1afe0938 | ||
|
|
7969249d89 | ||
|
|
52fc973ead | ||
|
|
96f53f5cd2 | ||
|
|
f234bc19a1 | ||
|
|
fcdf766769 | ||
|
|
525b04e69e | ||
|
|
377fa01e98 | ||
|
|
7ce291fac5 | ||
|
|
b88042a902 | ||
|
|
dc29ede6e3 | ||
|
|
becbb03d80 | ||
|
|
bc604d4c24 | ||
|
|
10f3ad6122 | ||
|
|
0ed3480258 | ||
|
|
8033966a70 | ||
|
|
2361042ede | ||
|
|
f1ded231ed | ||
|
|
fa54e8a8ac | ||
|
|
252ef4dbfb | ||
|
|
d2d788662a | ||
|
|
82454243fa | ||
|
|
d947479a60 | ||
|
|
8a4e07c83e | ||
|
|
776a3ecd1f | ||
|
|
1ae67c4549 | ||
|
|
7b369c9107 | ||
|
|
1823ee04ee | ||
|
|
5c0447ee29 | ||
|
|
29eb2cc68a | ||
|
|
1a171ad494 | ||
|
|
c0a17df344 | ||
|
|
e993b37f1e | ||
|
|
e280ca9db8 | ||
|
|
78f9383332 | ||
|
|
a96a4362cd | ||
|
|
1fb6d1b59d | ||
|
|
f94d7d9ea5 | ||
|
|
8eb04de748 | ||
|
|
521d14a6e0 | ||
|
|
e334b781fb | ||
|
|
d286872782 | ||
|
|
db28349703 | ||
|
|
e8ff020543 | ||
|
|
3a971315dc | ||
|
|
a37a38c79a | ||
|
|
b8cadaf8e6 | ||
|
|
05abaa8461 | ||
|
|
13e724c8ea | ||
|
|
0a51db3005 | ||
|
|
4f02c811a3 | ||
|
|
0d1d1a25da | ||
|
|
cd27c143c3 | ||
|
|
fcded63653 | ||
|
|
303c4f1f6d | ||
|
|
925b3e254c | ||
|
|
558850e68f | ||
|
|
ce47942ba3 | ||
|
|
aaf3a17ada | ||
|
|
1d568076df | ||
|
|
e2b3339475 | ||
|
|
80efaa0dfa | ||
|
|
24d967d6f4 | ||
|
|
ed5bbf6882 | ||
|
|
aa3974abaf | ||
|
|
8f8c375758 | ||
|
|
12dd092133 | ||
|
|
93b0a3c854 | ||
|
|
c90a358674 | ||
|
|
b6cd49c825 | ||
|
|
a89b405e16 | ||
|
|
e1e5803067 | ||
|
|
9e0decb6cb | ||
|
|
8ae3449a43 | ||
|
|
dac5460da0 | ||
|
|
df0513f4f4 | ||
|
|
d9535213dc | ||
|
|
a320817ee5 | ||
|
|
17aab01eaa | ||
|
|
d3e6cc5acb | ||
|
|
723d1828ec | ||
|
|
ef85b4c919 | ||
|
|
3bb12e4c3c | ||
|
|
eb29fdce63 | ||
|
|
3246dedbd8 | ||
|
|
1d22ca7d4d | ||
|
|
cd23abf19b | ||
|
|
3b420c7b43 | ||
|
|
16e0f0e986 | ||
|
|
d5c488cc7e | ||
|
|
62b50c87d4 | ||
|
|
3b63d40352 | ||
|
|
25fd404273 | ||
|
|
8cee14fa3a | ||
|
|
0f34ca8962 | ||
|
|
7def6e70ba | ||
|
|
82c190a0c5 | ||
|
|
7e5c22b6c7 | ||
|
|
c20c3db0ef | ||
|
|
64abe54b15 | ||
|
|
ba74a40b6d | ||
|
|
ba0f5ee81d | ||
|
|
eebd219414 | ||
|
|
27fd0dbaec | ||
|
|
b7af53c7d9 | ||
|
|
c762834e05 | ||
|
|
0725fe38f8 | ||
|
|
73341394ee | ||
|
|
9549aca48b | ||
|
|
9c41f0fdb9 | ||
|
|
1d522edb01 | ||
|
|
b7d2828f60 | ||
|
|
deece15648 | ||
|
|
d06683489f | ||
|
|
307063ade0 | ||
|
|
ed00adbecc | ||
|
|
2aaa850e25 | ||
|
|
8859da42c6 | ||
|
|
2968c2919c | ||
|
|
33b10fa719 | ||
|
|
6d189dab98 | ||
|
|
380d7e66b5 | ||
|
|
eb80fa4eb0 | ||
|
|
88b470e8e5 | ||
|
|
99f8785475 | ||
|
|
47db1349a9 | ||
|
|
1f8b04bd42 | ||
|
|
d790a5fba9 | ||
|
|
2fc0a0964b | ||
|
|
715664273b | ||
|
|
a9f707c398 | ||
|
|
8168bcece5 | ||
|
|
c9beaa2aa1 | ||
|
|
b238c7e743 | ||
|
|
e9511ebfc3 | ||
|
|
a786a1427d | ||
|
|
961612370d | ||
|
|
bd5b9573f6 | ||
|
|
e603a10ab4 | ||
|
|
984346d682 | ||
|
|
f4cecb61bc | ||
|
|
cffa101419 | ||
|
|
1d7d201b5b | ||
|
|
c0e4e12138 | ||
|
|
5a85255be9 | ||
|
|
60d3960f3a | ||
|
|
7bcb03f1ec | ||
|
|
01ef053a11 | ||
|
|
8988c775fe | ||
|
|
c8bfa98b6b | ||
|
|
34053c7608 | ||
|
|
785667ec07 | ||
|
|
9a0a3c4b00 | ||
|
|
e56c261c73 | ||
|
|
32a9db6922 | ||
|
|
77498c17a5 | ||
|
|
54c07f89f2 | ||
|
|
cd4d265055 | ||
|
|
81ee69010d | ||
|
|
138d5b7a02 | ||
|
|
95a54a43ff | ||
|
|
ca59cbc898 | ||
|
|
21f72ad845 | ||
|
|
40fd98d580 | ||
|
|
0422d751d8 | ||
|
|
e44f68db83 | ||
|
|
88cbf42c39 | ||
|
|
45157f79a3 | ||
|
|
f5157392b6 | ||
|
|
f631ec3a7c | ||
|
|
a9b2750ec9 | ||
|
|
7fbdb42695 | ||
|
|
026dd4480e | ||
|
|
b373e7acba | ||
|
|
d2ca54c167 | ||
|
|
e070284a09 | ||
|
|
e4e02ea3c0 | ||
|
|
a947980eb6 | ||
|
|
f11c3dd3e3 | ||
|
|
394067be63 | ||
|
|
2494613583 | ||
|
|
77c60e7450 | ||
|
|
04dd2d93d0 | ||
|
|
5e5710ecce | ||
|
|
c1b33a66c4 | ||
|
|
0e3165d724 | ||
|
|
3e12eab0b5 | ||
|
|
87365e4a43 | ||
|
|
3e16a47ff2 | ||
|
|
874054148e | ||
|
|
5e39a13bf6 | ||
|
|
720c1b5eca | ||
|
|
c7c1a04c6a | ||
|
|
fd5b224ba0 | ||
|
|
0b80ade3ae | ||
|
|
e1c3e95307 | ||
|
|
904e8966c0 | ||
|
|
3a10f0155f | ||
|
|
4c9cc4f3d4 | ||
|
|
48f2c4e14b | ||
|
|
f41df327a9 | ||
|
|
3f9e3038b7 | ||
|
|
c75c95afa9 | ||
|
|
d4e0009b89 | ||
|
|
b97b374487 | ||
|
|
e27345e489 | ||
|
|
032e644b2b | ||
|
|
b7ac81701a | ||
|
|
d59aa35b2f | ||
|
|
4c7c4e2a81 | ||
|
|
521fa58b75 | ||
|
|
a2e5c60683 | ||
|
|
5ef152fd84 | ||
|
|
e2ba338923 | ||
|
|
aae4f0bb7b | ||
|
|
43e3f8f08b | ||
|
|
9cc2fd555f | ||
|
|
c10dc7b25b | ||
|
|
9e1770316a | ||
|
|
0e595c9801 | ||
|
|
6ae9e43183 | ||
|
|
18126b42cb | ||
|
|
2b233fd810 | ||
|
|
a4f5d2b9b2 | ||
|
|
d29c09caf3 | ||
|
|
bc809986e7 | ||
|
|
5ee2f3696d | ||
|
|
df5eb546e7 | ||
|
|
684351c753 | ||
|
|
a8342e37b9 | ||
|
|
3b6fc9959f | ||
|
|
3ffc985968 | ||
|
|
369609b26c | ||
|
|
d033dcf395 | ||
|
|
5ef2a85c10 | ||
|
|
8c0bc9080c | ||
|
|
6bf2c5415f | ||
|
|
2f31033a88 | ||
|
|
ceaed0f552 | ||
|
|
e9963ecc0d | ||
|
|
9ef0b43c36 | ||
|
|
801d636eb5 | ||
|
|
dfbfd4fe74 | ||
|
|
7455989729 | ||
|
|
8b2b9e1093 | ||
|
|
a8cf05ea5d | ||
|
|
969508ae36 | ||
|
|
f581ecc805 | ||
|
|
a63464765c | ||
|
|
e9fe8ce118 | ||
|
|
1fa892c239 | ||
|
|
1afbbbc737 | ||
|
|
66c4de2607 | ||
|
|
213e67dea2 | ||
|
|
86c884fe1e | ||
|
|
a4d5c8cd2f | ||
|
|
330665afbe | ||
|
|
be1d87c3c3 | ||
|
|
14ab3c8651 | ||
|
|
9c04ed483e | ||
|
|
a8a5e184ab | ||
|
|
c571595980 | ||
|
|
80f2ccc9ed | ||
|
|
b2e9e57859 | ||
|
|
3c75b36148 | ||
|
|
bcd8e330cb | ||
|
|
f75f8ad76d | ||
|
|
574b78cf31 | ||
|
|
92f0e8472b | ||
|
|
69bd5d2ab0 | ||
|
|
6eaf04107d | ||
|
|
d80fdb20c7 | ||
|
|
f618c87ee5 | ||
|
|
0721c22073 | ||
|
|
aba066b4d1 | ||
|
|
2562c726e6 | ||
|
|
6e3ec71c10 | ||
|
|
2932c1ed35 | ||
|
|
149b31a960 | ||
|
|
f1d09e4127 | ||
|
|
10bdbc95cd | ||
|
|
26c38070ec | ||
|
|
494a7f1db9 | ||
|
|
bba721654b | ||
|
|
36a17b0592 | ||
|
|
b7294d46cf | ||
|
|
d8977b5046 | ||
|
|
963bb7f7cf | ||
|
|
7d3a08599e | ||
|
|
345a4bc504 | ||
|
|
7bfdf2e2f5 | ||
|
|
d9ac5d88e9 | ||
|
|
2cf11bb2ea | ||
|
|
e29d008914 | ||
|
|
de91063fbe | ||
|
|
3d95272707 | ||
|
|
3c20d0902e | ||
|
|
f2c1e5c6e5 | ||
|
|
feb354725a | ||
|
|
35c0434dc7 | ||
|
|
918ee47c79 | ||
|
|
a8ab7c9c04 | ||
|
|
332892b468 | ||
|
|
6392300311 | ||
|
|
16d201faca | ||
|
|
ea0cf67f98 | ||
|
|
612132b7c8 | ||
|
|
26470c6047 | ||
|
|
93d3522f67 | ||
|
|
c6d901d799 | ||
|
|
4880f9ff32 | ||
|
|
aaa42a3412 | ||
|
|
3e5e852e20 | ||
|
|
0a3f44bd73 | ||
|
|
d4fed5f5f7 | ||
|
|
dce7b90fc2 | ||
|
|
4f94bdff3f | ||
|
|
ce1f2a6fd4 | ||
|
|
da292bb9b2 | ||
|
|
326a75d0e8 | ||
|
|
e47860bc2e | ||
|
|
6212151562 | ||
|
|
8c2b9f9901 | ||
|
|
e9a733a789 | ||
|
|
b2fe723570 | ||
|
|
33ba8dabe0 | ||
|
|
0842e54f52 | ||
|
|
08d34e41c6 | ||
|
|
e93c9f74c9 | ||
|
|
1ab81256e9 | ||
|
|
cb19de57bb | ||
|
|
e678e7df8f | ||
|
|
8487eefe46 | ||
|
|
86da1aa429 | ||
|
|
48b580b59e | ||
|
|
8b568d796e | ||
|
|
4b5af85094 | ||
|
|
8d0be06f45 | ||
|
|
26ae8accd4 | ||
|
|
321e3e27de | ||
|
|
7d26968bb3 | ||
|
|
83464a882e | ||
|
|
1e94ad25e1 | ||
|
|
a3ba19db96 | ||
|
|
d9e9c849e1 | ||
|
|
c162c23d9e | ||
|
|
90fd1c300f | ||
|
|
902a9cc812 | ||
|
|
c51e1805fa | ||
|
|
7a2b9e85e7 | ||
|
|
547c40cd52 | ||
|
|
e2d631097d | ||
|
|
cc55be0b0a | ||
|
|
64927190bd | ||
|
|
24515126fe | ||
|
|
7a56a93028 | ||
|
|
ea7fc3a171 | ||
|
|
ae36a26045 | ||
|
|
d6c9f5c64b | ||
|
|
c4f4f4295b | ||
|
|
a997322efb | ||
|
|
799688af76 | ||
|
|
260e95d027 | ||
|
|
f9ee70aa2e | ||
|
|
50f13cb84b | ||
|
|
fc7e08bb49 | ||
|
|
06ed3e5dfd | ||
|
|
4d792ad57b | ||
|
|
4fa78bfca0 | ||
|
|
2012833cb3 | ||
|
|
e48eef7e32 | ||
|
|
74ac9c3a92 | ||
|
|
a907d789d6 | ||
|
|
fc46c0b49c | ||
|
|
fef7862045 | ||
|
|
d9441a6bdd | ||
|
|
332cb0896b | ||
|
|
d1b0c28924 | ||
|
|
dce958aac4 | ||
|
|
438940219e | ||
|
|
f28fcec81d | ||
|
|
586d027f86 | ||
|
|
bd4fb7486d | ||
|
|
f9cd2b8f36 | ||
|
|
62e22236b7 | ||
|
|
8b157f427a | ||
|
|
f165c1d9b0 | ||
|
|
500e2d62a0 | ||
|
|
a06e8677ac | ||
|
|
b4d5783928 | ||
|
|
3ce7f45503 | ||
|
|
b436c2761a | ||
|
|
b586d3bb0e | ||
|
|
63688a2f95 | ||
|
|
379cb1b2e0 | ||
|
|
78429492f1 | ||
|
|
9875047674 | ||
|
|
5014b0a9cb | ||
|
|
ef841b1aa3 | ||
|
|
368f27ffbc | ||
|
|
0e50bc1443 | ||
|
|
7c4a6ddcdf | ||
|
|
7ab6d95b6c | ||
|
|
6c32b89906 | ||
|
|
056e659a20 | ||
|
|
62baff665c | ||
|
|
7c5eb0ae37 | ||
|
|
36bce6c468 | ||
|
|
65df02163d | ||
|
|
19a32cdfd3 | ||
|
|
d708f386a1 | ||
|
|
0f837f4bed | ||
|
|
242e8e2bb3 | ||
|
|
1d56b24b67 | ||
|
|
bb9138708a | ||
|
|
34f5510f1f | ||
|
|
6c6d47c89c | ||
|
|
196075c031 | ||
|
|
2e5e8f73c6 | ||
|
|
ada5d38272 | ||
|
|
c4b0f773db | ||
|
|
276daf631e | ||
|
|
fb19b58147 | ||
|
|
13a5e3cf6f | ||
|
|
1caf3caf1b | ||
|
|
564370f79a | ||
|
|
24e749a2c9 | ||
|
|
cccdc51ad4 | ||
|
|
99ddce6c3e | ||
|
|
f68088cfb5 | ||
|
|
c8f56d748a | ||
|
|
a43fc47bb6 | ||
|
|
8c1bfac53b | ||
|
|
97853c3660 | ||
|
|
f304a30193 | ||
|
|
7eadca3959 | ||
|
|
8aa6decbf9 | ||
|
|
7cf4bcaca2 | ||
|
|
9ccd9c3e0e | ||
|
|
c6773a6303 | ||
|
|
e858a32aa1 | ||
|
|
99f2680e2c | ||
|
|
7a9a323bac | ||
|
|
62aa234352 | ||
|
|
0cb9e7922a | ||
|
|
e73107006e | ||
|
|
ca389cc6fc | ||
|
|
60ec7f0cbf | ||
|
|
d342d59e65 | ||
|
|
2690fa2da5 | ||
|
|
e411c394ca | ||
|
|
d69f3ba225 | ||
|
|
739807b1a9 | ||
|
|
d029ea7f3f | ||
|
|
11098cb869 | ||
|
|
f6807d6b22 | ||
|
|
7fc9bacf54 | ||
|
|
57ea4c1d92 | ||
|
|
bcdd15ef3a | ||
|
|
5f939c3123 | ||
|
|
2446fc44ad | ||
|
|
9ba8dd91df | ||
|
|
10e1cdbc52 | ||
|
|
46eceb38d5 | ||
|
|
81de882e2f | ||
|
|
593e07cdff | ||
|
|
8ca54f616e | ||
|
|
f7f899f0a4 | ||
|
|
05a3c0c89b | ||
|
|
f21691c122 | ||
|
|
836e26d8d0 | ||
|
|
8a7c1fe4cb | ||
|
|
7f43d3bb37 | ||
|
|
11b975ab19 | ||
|
|
315e4215d9 | ||
|
|
e35e6c44cf | ||
|
|
260cb78e3a | ||
|
|
a1f04d2129 | ||
|
|
9b562eebcd | ||
|
|
1d175c4557 | ||
|
|
f755070080 | ||
|
|
1c6c72a0fe | ||
|
|
1755f2ea3d | ||
|
|
498cc6c80b | ||
|
|
8d3227a92b | ||
|
|
c6d855084e | ||
|
|
827b3f8aeb | ||
|
|
fb95573000 | ||
|
|
f026bd455f | ||
|
|
f0b92a5757 | ||
|
|
d7c6f1e63b | ||
|
|
1e9e308df3 | ||
|
|
c9a70f149d | ||
|
|
d4ff47b6ac | ||
|
|
8b4b241403 | ||
|
|
6dcd6947d7 | ||
|
|
327328412a | ||
|
|
42f9ef00b9 | ||
|
|
8c2ea0fa26 | ||
|
|
14e9afaf42 | ||
|
|
a3a101641a | ||
|
|
8bd93fe495 | ||
|
|
56df22bca7 | ||
|
|
5f32a6738a | ||
|
|
1c081935fb | ||
|
|
8fd4d00776 | ||
|
|
7d04ea58c3 | ||
|
|
2cc84a0f0d | ||
|
|
8f715532cb | ||
|
|
5a77df7cc5 | ||
|
|
59658f2b0b | ||
|
|
0b983906da | ||
|
|
cd1f164d18 | ||
|
|
e2a6ac6625 | ||
|
|
8e8c10c438 | ||
|
|
7ff25f282e | ||
|
|
b8dc608032 | ||
|
|
d7e699320b | ||
|
|
ef333da770 | ||
|
|
575a389b08 | ||
|
|
9bc0824be6 | ||
|
|
b656a60234 | ||
|
|
bd988d805c | ||
|
|
7ad7ccb8fe | ||
|
|
e30c535f18 | ||
|
|
de7706f622 | ||
|
|
de20e4c9dd | ||
|
|
41f9314e2a | ||
|
|
2280ce349a | ||
|
|
7aa05e1c9f | ||
|
|
69d174c9e8 | ||
|
|
3c38fa6b70 | ||
|
|
728c8b4663 | ||
|
|
fab9563cd5 | ||
|
|
20fe2473e1 | ||
|
|
3815062c11 | ||
|
|
581ea9fda0 | ||
|
|
bfa641cea8 | ||
|
|
29c58efeb3 | ||
|
|
27eb82c556 | ||
|
|
652d67a20f | ||
|
|
ce0984f02f | ||
|
|
b3e3b1e245 | ||
|
|
c69ee180af | ||
|
|
bba3a25371 | ||
|
|
095b358aca | ||
|
|
833e5f46cc | ||
|
|
3e0ce0e07a | ||
|
|
1f31dd12fc | ||
|
|
f63efc29bf | ||
|
|
3e394f14e8 | ||
|
|
ff6ffa1656 | ||
|
|
304c259a57 | ||
|
|
630754b52e | ||
|
|
afd8c0d879 | ||
|
|
6316ee7c9b | ||
|
|
b6b8d11881 | ||
|
|
8753fd5887 | ||
|
|
5aaafb5ac1 | ||
|
|
a043557c44 | ||
|
|
4af4914e32 | ||
|
|
e35b3f1e80 | ||
|
|
ff8859b9db | ||
|
|
937ff5a378 | ||
|
|
f3a716fac6 | ||
|
|
72659580de | ||
|
|
30cb0cbcfd | ||
|
|
4136217249 | ||
|
|
246cae5d9e | ||
|
|
12313543ca | ||
|
|
87e3dead14 | ||
|
|
9af36460c2 | ||
|
|
2e2d881e01 | ||
|
|
db58946312 | ||
|
|
9a02a58273 | ||
|
|
147f5c1e0d | ||
|
|
f0ca50ba27 | ||
|
|
83137b5968 | ||
|
|
12823c2213 | ||
|
|
0b810d7d65 | ||
|
|
7aebdc9b7b | ||
|
|
6859b651a8 | ||
|
|
d47680733b | ||
|
|
273a38d781 | ||
|
|
93d1162caf | ||
|
|
8d550a66a3 | ||
|
|
4c58e05be3 | ||
|
|
500563054e | ||
|
|
2a11f8f59d | ||
|
|
9e7bdc579e | ||
|
|
61af0c9ac4 | ||
|
|
91f02ad553 | ||
|
|
b20d3dfc10 | ||
|
|
3e7666021c | ||
|
|
ae58bceeb9 | ||
|
|
6665b9e13c | ||
|
|
367a9705e9 | ||
|
|
8d3a1e84c3 | ||
|
|
d009835210 | ||
|
|
83a664ca68 | ||
|
|
d98d1857a4 | ||
|
|
33a514aa54 | ||
|
|
0aefdc85e6 | ||
|
|
3ff0964f02 | ||
|
|
cf33db3dcb | ||
|
|
dae80cbe35 | ||
|
|
f8b4ef26b3 | ||
|
|
db991453b0 | ||
|
|
c11ce4c8d4 | ||
|
|
92e300cb9f | ||
|
|
d210e0bffe | ||
|
|
4d4968f358 | ||
|
|
8dfede148a | ||
|
|
6d125028f5 | ||
|
|
7ff3cf4af0 | ||
|
|
bb3353397d | ||
|
|
572260ec29 | ||
|
|
0b1faa0523 | ||
|
|
3b6c3e10d7 | ||
|
|
d3909a5483 | ||
|
|
645fd10446 | ||
|
|
ee7e29fb3a | ||
|
|
bdc3a4d24c | ||
|
|
88ccda139e | ||
|
|
63e78bae37 | ||
|
|
b50f211c28 | ||
|
|
5efbd9c7f5 | ||
|
|
7f1d2ea11f | ||
|
|
46eb391a1b | ||
|
|
b166cc5bf4 | ||
|
|
1d0f6aad95 | ||
|
|
764aa71770 | ||
|
|
21e9206a77 | ||
|
|
5f29977c50 | ||
|
|
ee4c9bc01e | ||
|
|
4a8259cb12 | ||
|
|
a6441d70f0 | ||
|
|
01db8d0130 | ||
|
|
8ad9db5572 | ||
|
|
607cd23014 | ||
|
|
220758d244 | ||
|
|
7ab71bb468 | ||
|
|
a74377b620 | ||
|
|
c9effa3c06 | ||
|
|
8b8102334b | ||
|
|
5dedb86472 | ||
|
|
d93f77f991 | ||
|
|
5409bc575e | ||
|
|
576d31206d | ||
|
|
86e3297414 | ||
|
|
ab4a947456 | ||
|
|
5ce2581b4c | ||
|
|
c0d6c6b882 | ||
|
|
2bc8c967b1 | ||
|
|
fee08f0eeb | ||
|
|
078c3d05d7 | ||
|
|
7f97768c56 | ||
|
|
ecd548a7aa | ||
|
|
62efb0795b | ||
|
|
53f042ee08 | ||
|
|
6ce97bd0cd | ||
|
|
c29149e74c | ||
|
|
487f7593ce | ||
|
|
6b3b33d2a0 | ||
|
|
2d70ccc2bf | ||
|
|
e90fc9504a | ||
|
|
5108314c03 | ||
|
|
c1e144d4db | ||
|
|
f2b86a1c0f | ||
|
|
9583d41446 | ||
|
|
e594064f93 | ||
|
|
7c52fd95ec | ||
|
|
d0d5ac6e87 | ||
|
|
416bf3a829 | ||
|
|
cc78347293 | ||
|
|
27e4ae992a | ||
|
|
eb610c27bf | ||
|
|
5b131cf77c | ||
|
|
ce6ec64069 |
4
.github/dependabot.yml
vendored
4
.github/dependabot.yml
vendored
@@ -3,7 +3,7 @@ updates:
|
||||
- package-ecosystem: "cargo"
|
||||
directory: "/"
|
||||
schedule:
|
||||
interval: "daily"
|
||||
interval: "monthly"
|
||||
commit-message:
|
||||
prefix: "cargo"
|
||||
open-pull-requests-limit: 10
|
||||
open-pull-requests-limit: 50
|
||||
|
||||
26
.github/mergeable.yml
vendored
Normal file
26
.github/mergeable.yml
vendored
Normal file
@@ -0,0 +1,26 @@
|
||||
version: 2
|
||||
mergeable:
|
||||
- when: pull_request.*
|
||||
name: "Changelog check"
|
||||
validate:
|
||||
- do: or
|
||||
validate:
|
||||
- do: description
|
||||
must_include:
|
||||
regex: '#skip-changelog'
|
||||
- do: and
|
||||
validate:
|
||||
- do: dependent
|
||||
changed:
|
||||
file: 'src/**'
|
||||
required: ['CHANGELOG.md']
|
||||
- do: dependent
|
||||
changed:
|
||||
file: 'deltachat-ffi/**'
|
||||
required: ['CHANGELOG.md']
|
||||
fail:
|
||||
- do: checks
|
||||
status: 'action_required'
|
||||
payload:
|
||||
title: Changelog might need an update
|
||||
summary: "Check if CHANGELOG.md needs an update or add #skip-changelog to the PR description."
|
||||
40
.github/workflows/ci.yml
vendored
40
.github/workflows/ci.yml
vendored
@@ -8,6 +8,9 @@ on:
|
||||
- staging
|
||||
- trying
|
||||
|
||||
env:
|
||||
RUSTFLAGS: -Dwarnings
|
||||
|
||||
jobs:
|
||||
|
||||
fmt:
|
||||
@@ -21,6 +24,8 @@ jobs:
|
||||
toolchain: stable
|
||||
override: true
|
||||
- run: rustup component add rustfmt
|
||||
- name: Cache rust cargo artifacts
|
||||
uses: swatinem/rust-cache@v1
|
||||
- uses: actions-rs/cargo@v1
|
||||
with:
|
||||
command: fmt
|
||||
@@ -35,10 +40,12 @@ jobs:
|
||||
toolchain: stable
|
||||
components: clippy
|
||||
override: true
|
||||
- name: Cache rust cargo artifacts
|
||||
uses: swatinem/rust-cache@v1
|
||||
- uses: actions-rs/clippy-check@v1
|
||||
with:
|
||||
token: ${{ secrets.GITHUB_TOKEN }}
|
||||
args: --workspace --tests --examples
|
||||
args: --workspace --tests --examples --benches
|
||||
|
||||
docs:
|
||||
name: Rust doc comments
|
||||
@@ -70,19 +77,19 @@ jobs:
|
||||
include:
|
||||
# Currently used Rust version, same as in `rust-toolchain` file.
|
||||
- os: ubuntu-latest
|
||||
rust: 1.54.0
|
||||
rust: 1.61.0
|
||||
python: 3.9
|
||||
- os: windows-latest
|
||||
rust: 1.54.0
|
||||
rust: 1.61.0
|
||||
python: false # Python bindings compilation on Windows is not supported.
|
||||
|
||||
# Minimum Supported Rust Version = 1.51.0
|
||||
# Minimum Supported Rust Version = 1.56.0
|
||||
#
|
||||
# Minimum Supported Python Version = 3.7
|
||||
# This is the minimum version for which manylinux Python wheels are
|
||||
# built.
|
||||
- os: ubuntu-latest
|
||||
rust: 1.51.0
|
||||
rust: 1.56.0
|
||||
python: 3.7
|
||||
runs-on: ${{ matrix.os }}
|
||||
steps:
|
||||
@@ -94,31 +101,14 @@ jobs:
|
||||
toolchain: ${{ matrix.rust }}
|
||||
override: true
|
||||
|
||||
- name: Cache cargo registry
|
||||
uses: actions/cache@v2
|
||||
with:
|
||||
path: ~/.cargo/registry
|
||||
key: ${{ matrix.os }}-${{ matrix.rust }}-cargo-registry-${{ hashFiles('**/Cargo.toml') }}
|
||||
|
||||
- name: Cache cargo index
|
||||
uses: actions/cache@v2
|
||||
with:
|
||||
path: ~/.cargo/git
|
||||
key: ${{ matrix.os }}-${{ matrix.rust }}-cargo-index-${{ hashFiles('**/Cargo.toml') }}
|
||||
|
||||
- name: Cache cargo build
|
||||
uses: actions/cache@v2
|
||||
with:
|
||||
path: target
|
||||
key: ${{ matrix.os }}-${{ matrix.rust }}-cargo-build-target-${{ hashFiles('**/Cargo.toml') }}
|
||||
- name: Cache rust cargo artifacts
|
||||
uses: swatinem/rust-cache@v1
|
||||
|
||||
- name: check
|
||||
uses: actions-rs/cargo@v1
|
||||
env:
|
||||
RUSTFLAGS: -D warnings
|
||||
with:
|
||||
command: check
|
||||
args: --all --bins --examples --tests --features repl
|
||||
args: --all --bins --examples --tests --features repl --benches
|
||||
|
||||
- name: tests
|
||||
uses: actions-rs/cargo@v1
|
||||
|
||||
21
.github/workflows/dependabot.yml
vendored
Normal file
21
.github/workflows/dependabot.yml
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
name: Dependabot auto-approve
|
||||
on: pull_request
|
||||
|
||||
permissions:
|
||||
pull-requests: write
|
||||
|
||||
jobs:
|
||||
dependabot:
|
||||
runs-on: ubuntu-latest
|
||||
if: ${{ github.actor == 'dependabot[bot]' }}
|
||||
steps:
|
||||
- name: Dependabot metadata
|
||||
id: metadata
|
||||
uses: dependabot/fetch-metadata@v1.1.1
|
||||
with:
|
||||
github-token: "${{ secrets.GITHUB_TOKEN }}"
|
||||
- name: Approve a PR
|
||||
run: gh pr review --approve "$PR_URL"
|
||||
env:
|
||||
PR_URL: ${{github.event.pull_request.html_url}}
|
||||
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
|
||||
66
.github/workflows/jsonrpc_api.yml
vendored
Normal file
66
.github/workflows/jsonrpc_api.yml
vendored
Normal file
@@ -0,0 +1,66 @@
|
||||
name: JSON-RPC API Test
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [master]
|
||||
pull_request:
|
||||
branches: [master]
|
||||
|
||||
env:
|
||||
CARGO_TERM_COLOR: always
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: actions-rs/toolchain@v1
|
||||
with:
|
||||
profile: minimal
|
||||
toolchain: 1.56.0
|
||||
override: true
|
||||
- name: Rust Cache
|
||||
uses: Swatinem/rust-cache@v1.3.0
|
||||
- name: Build
|
||||
run: cargo build --verbose --features webserver -p deltachat-jsonrpc
|
||||
- name: Run tests
|
||||
run: cargo test --verbose --features webserver -p deltachat-jsonrpc
|
||||
|
||||
ts_bindings:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- name: Use Node.js 16.x
|
||||
uses: actions/setup-node@v1
|
||||
with:
|
||||
node-version: 16.x
|
||||
- uses: actions-rs/toolchain@v1
|
||||
with:
|
||||
profile: minimal
|
||||
toolchain: 1.56.0
|
||||
override: true
|
||||
- name: Rust Cache
|
||||
uses: Swatinem/rust-cache@v1.3.0
|
||||
- name: npm i
|
||||
run: |
|
||||
cd deltachat-jsonrpc/typescript
|
||||
npm i
|
||||
- name: npm run generate-bindings
|
||||
run: |
|
||||
cd deltachat-jsonrpc/typescript
|
||||
npm run generate-bindings
|
||||
- name: npm run check ts
|
||||
run: |
|
||||
cd deltachat-jsonrpc/typescript
|
||||
npx tsc --noEmit
|
||||
- name: run integration tests
|
||||
run: |
|
||||
cd deltachat-jsonrpc/typescript
|
||||
npm run build
|
||||
cargo build --features webserver
|
||||
npm run test:integration
|
||||
- name: run prettier
|
||||
run: |
|
||||
cd deltachat-jsonrpc/typescript
|
||||
npm run prettier:check
|
||||
32
.github/workflows/node-delete-preview.yml
vendored
Normal file
32
.github/workflows/node-delete-preview.yml
vendored
Normal file
@@ -0,0 +1,32 @@
|
||||
# documentation: https://github.com/deltachat/sysadmin/tree/master/download.delta.chat
|
||||
name: Delete node PR previews
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
types: [closed]
|
||||
|
||||
jobs:
|
||||
delete:
|
||||
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- name: Get Pullrequest ID
|
||||
id: getid
|
||||
run: |
|
||||
export PULLREQUEST_ID=$(jq .number < $GITHUB_EVENT_PATH)
|
||||
echo ::set-output name=prid::$PULLREQUEST_ID
|
||||
- name: Renaming
|
||||
run: |
|
||||
# create empty file to copy it over the outdated deliverable on download.delta.chat
|
||||
echo "This preview build is outdated and has been removed." > empty
|
||||
cp empty deltachat-node-${{ steps.getid.outputs.prid }}.tar.gz
|
||||
- name: Replace builds with dummy files
|
||||
uses: horochx/deploy-via-scp@v1.0.1
|
||||
with:
|
||||
user: ${{ secrets.USERNAME }}
|
||||
key: ${{ secrets.SSH_KEY }}
|
||||
host: "download.delta.chat"
|
||||
port: 22
|
||||
local: "deltachat-node-${{ steps.getid.outputs.prid }}.tar.gz"
|
||||
remote: "/var/www/html/download/node/preview/"
|
||||
34
.github/workflows/node-docs.yml
vendored
Normal file
34
.github/workflows/node-docs.yml
vendored
Normal file
@@ -0,0 +1,34 @@
|
||||
name: Generate & upload node.js documentation
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- master
|
||||
|
||||
jobs:
|
||||
generate:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v1
|
||||
|
||||
- name: Use Node.js 16.x
|
||||
uses: actions/setup-node@v1
|
||||
with:
|
||||
node-version: 16.x
|
||||
|
||||
- name: npm install and generate documentation
|
||||
run: |
|
||||
cd node
|
||||
npm i --ignore-scripts
|
||||
npx typedoc
|
||||
mv docs js
|
||||
|
||||
- name: Upload
|
||||
uses: horochx/deploy-via-scp@v1.0.1
|
||||
with:
|
||||
user: ${{ secrets.USERNAME }}
|
||||
key: ${{ secrets.KEY }}
|
||||
host: "delta.chat"
|
||||
port: 22
|
||||
local: "node/js"
|
||||
remote: "/var/www/html/"
|
||||
165
.github/workflows/node-package.yml
vendored
Normal file
165
.github/workflows/node-package.yml
vendored
Normal file
@@ -0,0 +1,165 @@
|
||||
name: 'node.js build'
|
||||
on:
|
||||
pull_request:
|
||||
push:
|
||||
tags:
|
||||
- '*'
|
||||
- '!py-*'
|
||||
|
||||
|
||||
jobs:
|
||||
prebuild:
|
||||
name: 'prebuild'
|
||||
runs-on: ${{ matrix.os }}
|
||||
strategy:
|
||||
matrix:
|
||||
os: [ubuntu-18.04, macos-latest, windows-latest]
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v2
|
||||
- uses: actions/setup-node@v2
|
||||
with:
|
||||
node-version: '16'
|
||||
- name: System info
|
||||
run: |
|
||||
rustc -vV
|
||||
rustup -vV
|
||||
cargo -vV
|
||||
npm --version
|
||||
node --version
|
||||
|
||||
- name: Cache node modules
|
||||
uses: actions/cache@v2
|
||||
with:
|
||||
path: |
|
||||
${{ env.APPDATA }}/npm-cache
|
||||
~/.npm
|
||||
key: ${{ matrix.os }}-node-${{ hashFiles('**/package.json') }}
|
||||
|
||||
- name: Cache cargo index
|
||||
uses: actions/cache@v2
|
||||
with:
|
||||
path: |
|
||||
~/.cargo/registry/
|
||||
~/.cargo/git
|
||||
target
|
||||
key: ${{ matrix.os }}-cargo-index-${{ hashFiles('**/Cargo.lock') }}-2
|
||||
|
||||
- name: Install dependencies & build
|
||||
if: steps.cache.outputs.cache-hit != 'true'
|
||||
run: |
|
||||
cd node
|
||||
npm install --verbose
|
||||
|
||||
- name: Build Prebuild
|
||||
run: |
|
||||
cd node
|
||||
npm run prebuildify
|
||||
tar -zcvf "${{ matrix.os }}.tar.gz" -C prebuilds .
|
||||
|
||||
- name: Upload Prebuild
|
||||
uses: actions/upload-artifact@v1
|
||||
with:
|
||||
name: ${{ matrix.os }}
|
||||
path: node/${{ matrix.os }}.tar.gz
|
||||
|
||||
pack-module:
|
||||
needs: prebuild
|
||||
name: 'Package deltachat-node and upload to download.delta.chat'
|
||||
runs-on: ubuntu-18.04
|
||||
steps:
|
||||
- name: install tree
|
||||
run: sudo apt install tree
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v2
|
||||
- uses: actions/setup-node@v2
|
||||
with:
|
||||
node-version: '16'
|
||||
- name: get tag
|
||||
id: tag
|
||||
uses: dawidd6/action-get-tag@v1
|
||||
continue-on-error: true
|
||||
- name: Get Pullrequest ID
|
||||
id: prepare
|
||||
run: |
|
||||
tag=${{ steps.tag.outputs.tag }}
|
||||
if [ -z "$tag" ]; then
|
||||
node -e "console.log('DELTACHAT_NODE_TAR_GZ=deltachat-node-' + '${{ github.ref }}'.split('/')[2] + '.tar.gz')" >> $GITHUB_ENV
|
||||
else
|
||||
echo "DELTACHAT_NODE_TAR_GZ=deltachat-node-${{ steps.tag.outputs.tag }}.tar.gz" >> $GITHUB_ENV
|
||||
echo "No preview will be uploaded this time, but the $tag release"
|
||||
fi
|
||||
- name: System info
|
||||
run: |
|
||||
rustc -vV
|
||||
rustup -vV
|
||||
cargo -vV
|
||||
npm --version
|
||||
node --version
|
||||
echo $DELTACHAT_NODE_TAR_GZ
|
||||
- name: Download ubuntu prebuild
|
||||
uses: actions/download-artifact@v1
|
||||
with:
|
||||
name: ubuntu-18.04
|
||||
- name: Download macos prebuild
|
||||
uses: actions/download-artifact@v1
|
||||
with:
|
||||
name: macos-latest
|
||||
- name: Download windows prebuild
|
||||
uses: actions/download-artifact@v1
|
||||
with:
|
||||
name: windows-latest
|
||||
- shell: bash
|
||||
run: |
|
||||
mkdir node/prebuilds
|
||||
tar -xvzf ubuntu-18.04/ubuntu-18.04.tar.gz -C node/prebuilds
|
||||
tar -xvzf macos-latest/macos-latest.tar.gz -C node/prebuilds
|
||||
tar -xvzf windows-latest/windows-latest.tar.gz -C node/prebuilds
|
||||
tree node/prebuilds
|
||||
rm -rf ubuntu-18.04 macos-latest windows-latest
|
||||
- name: install dependencies without running scripts
|
||||
run: |
|
||||
npm install --ignore-scripts
|
||||
- name: build constants
|
||||
run: |
|
||||
npm run build:core:constants
|
||||
- name: build typescript part
|
||||
run: |
|
||||
npm run build:bindings:ts
|
||||
- name: package
|
||||
shell: bash
|
||||
run: |
|
||||
mv node/README.md README.md
|
||||
npm pack .
|
||||
ls -lah
|
||||
mv $(find deltachat-node-*) $DELTACHAT_NODE_TAR_GZ
|
||||
- name: Upload Prebuild
|
||||
uses: actions/upload-artifact@v1
|
||||
with:
|
||||
name: deltachat-node.tgz
|
||||
path: ${{ env.DELTACHAT_NODE_TAR_GZ }}
|
||||
# Upload to download.delta.chat/node/preview/
|
||||
- name: Upload deltachat-node preview to download.delta.chat/node/preview/
|
||||
if: ${{ ! steps.tag.outputs.tag }}
|
||||
id: upload-preview
|
||||
shell: bash
|
||||
run: |
|
||||
echo -e "${{ secrets.SSH_KEY }}" >__TEMP_INPUT_KEY_FILE
|
||||
chmod 600 __TEMP_INPUT_KEY_FILE
|
||||
scp -o StrictHostKeyChecking=no -v -i __TEMP_INPUT_KEY_FILE -P "22" -r $DELTACHAT_NODE_TAR_GZ "${{ secrets.USERNAME }}"@"download.delta.chat":"/var/www/html/download/node/preview/"
|
||||
continue-on-error: true
|
||||
- name: "Post links to details"
|
||||
if: steps.upload-preview.outcome == 'success'
|
||||
run: node ./node/scripts/postLinksToDetails.js
|
||||
env:
|
||||
URL: preview/${{ env.DELTACHAT_NODE_TAR_GZ }}
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
# Upload to download.delta.chat/node/
|
||||
- name: Upload deltachat-node build to download.delta.chat/node/
|
||||
if: ${{ steps.tag.outputs.tag }}
|
||||
id: upload
|
||||
shell: bash
|
||||
run: |
|
||||
echo -e "${{ secrets.SSH_KEY }}" >__TEMP_INPUT_KEY_FILE
|
||||
chmod 600 __TEMP_INPUT_KEY_FILE
|
||||
scp -o StrictHostKeyChecking=no -v -i __TEMP_INPUT_KEY_FILE -P "22" -r $DELTACHAT_NODE_TAR_GZ "${{ secrets.USERNAME }}"@"download.delta.chat":"/var/www/html/download/node/"
|
||||
67
.github/workflows/node-tests.yml
vendored
Normal file
67
.github/workflows/node-tests.yml
vendored
Normal file
@@ -0,0 +1,67 @@
|
||||
name: 'node.js tests'
|
||||
on:
|
||||
pull_request:
|
||||
push:
|
||||
branches:
|
||||
- master
|
||||
- staging
|
||||
- trying
|
||||
|
||||
jobs:
|
||||
tests:
|
||||
name: 'tests'
|
||||
runs-on: ${{ matrix.os }}
|
||||
strategy:
|
||||
matrix:
|
||||
os: [ubuntu-18.04, macos-latest, windows-latest]
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v2
|
||||
- uses: actions/setup-node@v2
|
||||
with:
|
||||
node-version: '16'
|
||||
- name: System info
|
||||
run: |
|
||||
rustc -vV
|
||||
rustup -vV
|
||||
cargo -vV
|
||||
npm --version
|
||||
node --version
|
||||
|
||||
- name: Cache node modules
|
||||
uses: actions/cache@v2
|
||||
with:
|
||||
path: |
|
||||
${{ env.APPDATA }}/npm-cache
|
||||
~/.npm
|
||||
key: ${{ matrix.os }}-node-${{ hashFiles('**/package.json') }}
|
||||
|
||||
- name: Cache cargo index
|
||||
uses: actions/cache@v2
|
||||
with:
|
||||
path: |
|
||||
~/.cargo/registry/
|
||||
~/.cargo/git
|
||||
target
|
||||
key: ${{ matrix.os }}-cargo-index-${{ hashFiles('**/Cargo.lock') }}-2
|
||||
|
||||
- name: Install dependencies & build
|
||||
if: steps.cache.outputs.cache-hit != 'true'
|
||||
run: |
|
||||
cd node
|
||||
npm install --verbose
|
||||
|
||||
- name: Test
|
||||
if: runner.os != 'Windows'
|
||||
run: |
|
||||
cd node
|
||||
npm run test
|
||||
env:
|
||||
DCC_NEW_TMP_EMAIL: ${{ secrets.DCC_NEW_TMP_EMAIL }}
|
||||
- name: Run tests on Windows, except lint
|
||||
if: runner.os == 'Windows'
|
||||
run: |
|
||||
cd node
|
||||
npm run test:mocha
|
||||
env:
|
||||
DCC_NEW_TMP_EMAIL: ${{ secrets.DCC_NEW_TMP_EMAIL }}
|
||||
28
.github/workflows/upload-docs.yml
vendored
Normal file
28
.github/workflows/upload-docs.yml
vendored
Normal file
@@ -0,0 +1,28 @@
|
||||
name: Build & Deploy Documentation on rs.delta.chat
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- master
|
||||
- docs-gh-action
|
||||
|
||||
jobs:
|
||||
build:
|
||||
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v1
|
||||
- uses: actions-rs/toolchain@v1
|
||||
- name: Build the documentation with cargo
|
||||
run: |
|
||||
cargo doc --package deltachat --no-deps
|
||||
- name: Upload to rs.delta.chat
|
||||
uses: up9cloud/action-rsync@v1.3
|
||||
env:
|
||||
USER: ${{ secrets.USERNAME }}
|
||||
KEY: ${{ secrets.KEY }}
|
||||
HOST: "delta.chat"
|
||||
SOURCE: "target/doc"
|
||||
TARGET: "/var/www/html/rs/"
|
||||
|
||||
28
.github/workflows/upload-ffi-docs.yml
vendored
Normal file
28
.github/workflows/upload-ffi-docs.yml
vendored
Normal file
@@ -0,0 +1,28 @@
|
||||
name: Build & Deploy Documentation on cffi.delta.chat
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- master
|
||||
- docs-gh-action
|
||||
|
||||
jobs:
|
||||
build:
|
||||
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v1
|
||||
- uses: actions-rs/toolchain@v1
|
||||
- name: Build the documentation with cargo
|
||||
run: |
|
||||
cargo doc --package deltachat_ffi --no-deps
|
||||
- name: Upload to cffi.delta.chat
|
||||
uses: up9cloud/action-rsync@v1.3
|
||||
env:
|
||||
USER: ${{ secrets.USERNAME }}
|
||||
KEY: ${{ secrets.KEY }}
|
||||
HOST: "delta.chat"
|
||||
SOURCE: "target/doc"
|
||||
TARGET: "/var/www/html/cffi/"
|
||||
|
||||
11
.gitignore
vendored
11
.gitignore
vendored
@@ -29,3 +29,14 @@ deltachat-ffi/xml
|
||||
|
||||
coverage/
|
||||
.DS_Store
|
||||
.vscode/launch.json
|
||||
python/accounts.txt
|
||||
python/all-testaccounts.txt
|
||||
tmp/
|
||||
|
||||
# from deltachat-node
|
||||
node_modules/
|
||||
node/build/
|
||||
node/dist/
|
||||
node/prebuilds/
|
||||
node/.nyc_output/
|
||||
|
||||
56
.npmignore
Normal file
56
.npmignore
Normal file
@@ -0,0 +1,56 @@
|
||||
.circleci/
|
||||
.gitmodules
|
||||
node/.nyc_output/
|
||||
.travis.yml
|
||||
appveyor.yml
|
||||
node/build/
|
||||
node/README.md
|
||||
rustfmt.toml
|
||||
spec.md
|
||||
test-data/
|
||||
build2/
|
||||
node_modules
|
||||
.git
|
||||
.idea/
|
||||
.pytest_cache
|
||||
CMakeLists.txt
|
||||
README.md
|
||||
contrib/
|
||||
node/ci_scripts/
|
||||
coverage/
|
||||
node/.circleci
|
||||
node/appveyor.yml
|
||||
ci/
|
||||
ci_scripts/
|
||||
python/
|
||||
target
|
||||
proptest-regressions
|
||||
deltachat-ffi/Doxyfile
|
||||
scripts
|
||||
webxdc.md
|
||||
standards.md
|
||||
draft/
|
||||
node/examples/
|
||||
# deltachat-core-rust/assets # don't exclude assets, otherwise it won't build
|
||||
node/images/
|
||||
node/test/
|
||||
node/windows.md
|
||||
node/*.tar.gz
|
||||
node/old_docs.md
|
||||
.vscode/
|
||||
.github/
|
||||
node/.prettierrc.yml
|
||||
|
||||
deltachat-jsonrpc/TODO.md
|
||||
deltachat-jsonrpc/README.MD
|
||||
deltachat-jsonrpc/.gitignore
|
||||
deltachat-jsonrpc/typescript/.gitignore
|
||||
deltachat-jsonrpc/typescript/.prettierignore
|
||||
deltachat-jsonrpc/typescript/accounts/
|
||||
deltachat-jsonrpc/typescript/index.html
|
||||
deltachat-jsonrpc/typescript/node-demo.js
|
||||
deltachat-jsonrpc/typescript/report_api_coverage.mjs
|
||||
deltachat-jsonrpc/typescript/test
|
||||
deltachat-jsonrpc/typescript/example.ts
|
||||
|
||||
.DS_Store
|
||||
370
CHANGELOG.md
370
CHANGELOG.md
@@ -1,5 +1,375 @@
|
||||
# Changelog
|
||||
|
||||
## Unreleased
|
||||
|
||||
### Changes
|
||||
- limit the rate of MDN sending #3402
|
||||
- ignore ratelimits for bots #3439
|
||||
- remove `msgs_mdns` references to deleted messages during housekeeping #3387
|
||||
- format message lines starting with `>` as quotes #3434
|
||||
- node: remove `split2` dependency #3418
|
||||
- node: add git installation info to readme #3418
|
||||
|
||||
### Fixes
|
||||
- set a default error if NDN does not provide an error
|
||||
- python: avoid exceptions when messages/contacts/chats are compared with `None`
|
||||
- node: wait for the event loop to stop before destroying contexts #3431 #3451
|
||||
- emit configuration errors via event on failure #3433
|
||||
- report configure and imex success/failure after freeing ongoing process #3442
|
||||
|
||||
### API-Changes
|
||||
- python: added `Message.get_status_updates()` #3416
|
||||
- python: added `Message.send_status_update()` #3416
|
||||
- python: added `Message.is_webxdc()` #3416
|
||||
- python: added `Message.is_videochat_invitation()` #3416
|
||||
- python: added support for "videochat" and "webxdc" view types to `Message.new_empty()` #3416
|
||||
|
||||
## 1.86.0
|
||||
|
||||
### API-Changes
|
||||
- python: added optional `closed` parameter to `Account` constructor #3394
|
||||
- python: added optional `passphrase` parameter to `Account.export_all()` and `Account.import_all()` #3394
|
||||
- python: added `Account.open()` #3394
|
||||
- python: added `Chat.is_single()` #3394
|
||||
- python: added `Chat.is_mailinglist()` #3394
|
||||
- python: added `Chat.is_broadcast()` #3394
|
||||
- python: added `Chat.is_multiuser()` #3394
|
||||
- python: added `Chat.is_self_talk()` #3394
|
||||
- python: added `Chat.is_device_talk()` #3394
|
||||
- python: added `Chat.is_pinned()` #3394
|
||||
- python: added `Chat.pin()` #3394
|
||||
- python: added `Chat.unpin()` #3394
|
||||
- python: added `Chat.archive()` #3394
|
||||
- python: added `Chat.unarchive()` #3394
|
||||
- python: added `Message.get_summarytext()` #3394
|
||||
- python: added optional `closed` parameter to `ACFactory.get_unconfigured_account()` (pytest plugin) #3394
|
||||
- python: added optional `passphrase` parameter to `ACFactory.get_pseudo_configured_account()` (pytest plugin) #3394
|
||||
|
||||
### Changes
|
||||
- clean up series of webxdc info messages;
|
||||
`DC_EVENT_MSGS_CHANGED` is emitted on changes of existing info messages #3395
|
||||
- update provider database #3399
|
||||
- refactorings #3375 #3403 #3398 #3404
|
||||
|
||||
### Fixes
|
||||
- do not reset our database if imported backup cannot be decrypted #3397
|
||||
- node: remove `npx` from build script, this broke flathub build #3396
|
||||
|
||||
|
||||
## 1.85.0
|
||||
|
||||
### Changes
|
||||
- refactorings #3373 #3345 #3380 #3382
|
||||
- node: move split2 to devDependencies
|
||||
- python: build Python 3.10 wheels #3392
|
||||
- update Rust dependencies
|
||||
|
||||
### Fixes
|
||||
- delete outgoing MDNs found in the Sent folder on Gmail #3372
|
||||
- fix searching one-to-one chats #3377
|
||||
- do not add legacy info-messages on resending webxdc #3389
|
||||
|
||||
|
||||
## 1.84.0
|
||||
|
||||
### Changes
|
||||
- refactorings #3354 #3347 #3353 #3346
|
||||
|
||||
### Fixes
|
||||
- do not unnecessarily SELECT folders if there are no operations planned on
|
||||
them #3333
|
||||
- trim chat encryption info #3350
|
||||
- fix failure to decrypt first message to self after key synchronization
|
||||
via Autocrypt Setup Message #3352
|
||||
- Keep pgp key when you change your own email address #3351
|
||||
- Do not ignore Sent and Spam folders on Gmail #3369
|
||||
- handle decryption errors explicitly and don't get confused by encrypted mail attachments #3374
|
||||
|
||||
|
||||
## 1.83.0
|
||||
|
||||
### Fixes
|
||||
- fix node prebuild & package ci #3337
|
||||
|
||||
|
||||
## 1.82.0
|
||||
|
||||
### API-Changes
|
||||
- re-add removed `DC_MSG_ID_MARKER1` as in use on iOS #3330
|
||||
|
||||
### Changes
|
||||
- refactorings #3328
|
||||
|
||||
### Fixes
|
||||
- fix node package ci #3331
|
||||
- fix race condition in ongoing process (import/export, configuration) allocation #3322
|
||||
|
||||
|
||||
## 1.81.0
|
||||
|
||||
### API-Changes
|
||||
- deprecate unused `marker1before` argument of `dc_get_chat_msgs`
|
||||
and remove `DC_MSG_ID_MARKER1` constant #3274
|
||||
|
||||
### Changes
|
||||
- now the node-bindings are also part of this repository 🎉 #3283
|
||||
- support `source_code_url` from Webxdc manifests #3314
|
||||
- support Webxdc document names and add `document` to `dc_msg_get_webxdc_info()` #3317 #3324
|
||||
- improve chat encryption info, make it easier to find contacts without keys #3318
|
||||
- improve error reporting when creating a folder fails #3325
|
||||
- node: remove unmaintained coverage scripts
|
||||
- send normal messages with higher priority than MDNs #3243
|
||||
- make Scheduler stateless #3302
|
||||
- abort instead of unwinding on panic #3259
|
||||
- improve python bindings #3297 #3298
|
||||
- improve documentation #3307 #3306 #3309 #3319 #3321
|
||||
- refactorings #3304 #3303 #3323
|
||||
|
||||
### Fixes
|
||||
- node: throw error when getting context with an invalid account id
|
||||
- node: throw error when instanciating a wrapper class on `null` (Context, Message, Chat, ChatList and so on)
|
||||
- use same contact-color if email address differ only in upper-/lowercase #3327
|
||||
- repair encrypted mails "mixed up" by Google Workspace "Append footer" function #3315
|
||||
|
||||
|
||||
## 1.80.0
|
||||
|
||||
### Changes
|
||||
- update provider database #3284
|
||||
- improve python bindings, tests and ci #3287 #3286 #3287 #3289 #3290 #3292
|
||||
|
||||
### Fixes
|
||||
- fix escaping in generated QR-code-SVG #3295
|
||||
|
||||
|
||||
## 1.79.0
|
||||
|
||||
### Changes
|
||||
- Send locations in the background regardless of SMTP loop activity #3247
|
||||
- refactorings #3268
|
||||
- improve tests and ci #3266 #3271
|
||||
|
||||
### Fixes
|
||||
- simplify `dc_stop_io()` and remove potential panics and race conditions #3273
|
||||
- fix correct message escaping consisting of a dot in SMTP protocol #3265
|
||||
|
||||
|
||||
## 1.78.0
|
||||
|
||||
### API-Changes
|
||||
- replaced stock string `DC_STR_ONE_MOMENT` by `DC_STR_NOT_CONNECTED` #3222
|
||||
- add `dc_resend_msgs()` #3238
|
||||
- `dc_provider_new_from_email()` does no longer do an DNS lookup for checking custom domains,
|
||||
this is done by `dc_provider_new_from_email_with_dns()` now #3256
|
||||
|
||||
### Changes
|
||||
- introduce multiple self addresses with the "configured" address always being the primary one #2896
|
||||
- Further improve finding the correct server after logging in #3208
|
||||
- `get_connectivity_html()` returns HTML as non-scalable #3213
|
||||
- add update-serial to `DC_EVENT_WEBXDC_STATUS_UPDATE` #3215
|
||||
- Speed up message receiving via IMAP a bit #3225
|
||||
- mark messages as seen on IMAP in batches #3223
|
||||
- remove Received: based draft detection heuristic #3230
|
||||
- Use pkgconfig for building Python package #2590
|
||||
- don't start io on unconfigured context #2664
|
||||
- do not assign group IDs to ad-hoc groups #2798
|
||||
- dynamic libraries use dylib extension on Darwin #3226
|
||||
- refactorings #3217 #3219 #3224 #3235 #3239 #3244 #3254
|
||||
- improve documentation #3214 #3220 #3237
|
||||
- improve tests and ci #3212 #3233 #3241 #3242 #3252 #3250 #3255 #3260
|
||||
|
||||
### Fixes
|
||||
- Take `delete_device_after` into account when calculating ephemeral loop timeout #3211 #3221
|
||||
- Fix a bug where a blocked contact could send a contact request #3218
|
||||
- Make sure, videochat-room-names are always URL-safe #3231
|
||||
- Try removing account folder multiple times in case of failure #3229
|
||||
- Ignore messages from all spam folders if there are many #3246
|
||||
- Hide location-only messages instead of displaying empty bubbles #3248
|
||||
|
||||
|
||||
## 1.77.0
|
||||
|
||||
### API changes
|
||||
- change semantics of `dc_get_webxdc_status_updates()` second parameter
|
||||
and remove update-id from `DC_EVENT_WEBXDC_STATUS_UPDATE` #3081
|
||||
|
||||
### Changes
|
||||
- add more SMTP logging #3093
|
||||
- place common headers like `From:` before the large `Autocrypt:` header #3079
|
||||
- keep track of securejoin joiner status in database to survive restarts #2920
|
||||
- remove never used `SentboxMove` option #3111
|
||||
- improve speed by caching config values #3131 #3145
|
||||
- optimize `markseen_msgs` #3141
|
||||
- automatically accept chats with outgoing messages #3143
|
||||
- `dc_receive_imf` refactorings #3154 #3156 #3159
|
||||
- add index to speedup deletion of expired ephemeral messages #3155
|
||||
- muted chats stay archived on new messages #3184
|
||||
- support `min_api` from Webxdc manifests #3206
|
||||
- do not read whole webxdc file into memory #3109
|
||||
- improve tests, refactorings #3073 #3096 #3102 #3108 #3139 #3128 #3133 #3142 #3153 #3151 #3174 #3170 #3148 #3179 #3185
|
||||
- improve documentation #2983 #3112 #3103 #3118 #3120
|
||||
|
||||
### Fixes
|
||||
- speed up loading of chat messages by a factor of 20 #3171 #3194 #3173
|
||||
- fix an issue where the app crashes when trying to export a backup #3195
|
||||
- hopefully fix a bug where outgoing messages appear twice with Amazon SES #3077
|
||||
- do not delete messages without Message-IDs as duplicates #3095
|
||||
- assign replies from a different email address to the correct chat #3119
|
||||
- assing outgoing private replies to the correct chat #3177
|
||||
- start ephemeral timer when seen status is synchronized via IMAP #3122
|
||||
- do not create empty contact requests with "setup changed" messages;
|
||||
instead, send a "setup changed" message into all chats we share with the peer #3187
|
||||
- do not delete duplicate messages on IMAP immediately to accidentally deleting
|
||||
the last copy #3138
|
||||
- clear more columns when message expires due to `delete_device_after` setting #3181
|
||||
- do not try to use stale SMTP connections #3180
|
||||
- slightly improve finding the correct server after logging in #3207
|
||||
- retry message sending automatically if loop is not interrupted #3183
|
||||
- fix a bug where sometimes the file extension of a long filename containing a dot was cropped #3098
|
||||
|
||||
|
||||
## 1.76.0
|
||||
|
||||
### Changes
|
||||
- move messages in batches #3058
|
||||
- delete messages in batches #3060
|
||||
- python: remove arbitrary timeouts from tests #3059
|
||||
- refactorings #3026
|
||||
|
||||
### Fixes
|
||||
- avoid archived, fresh chats #3053
|
||||
- Also resync UIDs in folders that are not configured #2289
|
||||
- treat "NO" IMAP response to MOVE and COPY commands as an error #3058
|
||||
- Fix a bug where messages in the Spam folder created contact requests #3015
|
||||
- Fix a bug where drafts disappeared after some days #3067
|
||||
- Parse MS Exchange read receipts and mark the original message as read #3075
|
||||
- do not retry message sending infinitely in case of permanent SMTP failure #3070
|
||||
- set message state to failed when retry limit is exceeded #3072
|
||||
|
||||
|
||||
## 1.75.0
|
||||
|
||||
### Changes
|
||||
- optimize `delete_expired_imap_messages()` #3047
|
||||
|
||||
|
||||
## 1.74.0
|
||||
|
||||
### Fixes
|
||||
- avoid reconnection loop when message without Message-ID is marked as seen #3044
|
||||
|
||||
|
||||
## 1.73.0
|
||||
|
||||
### API changes
|
||||
- added `only_fetch_mvbox` config #3028
|
||||
|
||||
### Changes
|
||||
- don't watch Sent folder by default #3025
|
||||
- use webxdc app name in chatlist/quotes/replies etc. #3027
|
||||
- make it possible to cancel message sending by removing the message #3034,
|
||||
this was previosuly removed in 1.71.0 #2939
|
||||
- synchronize Seen flags only on watched folders to speed up
|
||||
folder scanning #3041
|
||||
- remove direct dependency on `byteorder` crate #3031
|
||||
- refactorings #3023 #3013
|
||||
- update provider database #3043
|
||||
- improve documentation #3017 #3018 #3021
|
||||
|
||||
### Fixes
|
||||
- fix splitting off text from webxdc messages #3032
|
||||
- call slow `delete_expired_imap_messages()` less often #3037
|
||||
- make synchronization of Seen status more robust in case unsolicited FETCH
|
||||
result without UID is returned #3022
|
||||
- fetch Inbox before scanning folders to ensure iOS does
|
||||
not kill the app before it gets to fetch the Inbox in background #3040
|
||||
|
||||
|
||||
## 1.72.0
|
||||
|
||||
### Fixes
|
||||
- run migrations on backup import #3006
|
||||
|
||||
|
||||
## 1.71.0
|
||||
|
||||
### API Changes
|
||||
- added APIs to handle database passwords: `dc_context_new_closed()`, `dc_context_open()`,
|
||||
`dc_context_is_open()` and `dc_accounts_add_closed_account()` #2956 #2972
|
||||
- use second parameter of `dc_imex` to provide backup passphrase #2980
|
||||
- added `DC_MSG_WEBXDC`, `dc_send_webxdc_status_update()`,
|
||||
`dc_get_webxdc_status_updates()`, `dc_msg_get_webxdc_blob()`, `dc_msg_get_webxdc_info()`
|
||||
and `DC_EVENT_WEBXDC_STATUS_UPDATE` #2826 #2971 #2975 #2977 #2979 #2993 #2994 #2998 #3001 #3003
|
||||
- added `dc_msg_get_parent()` #2984
|
||||
- added `dc_msg_force_plaintext()` API for bots #2847
|
||||
- allow removing quotes on drafts `dc_msg_set_quote(msg, NULL)` #2950
|
||||
- removed `mvbox_watch` option; watching is enabled when `mvbox_move` is enabled #2906
|
||||
- removed `inbox_watch` option #2922
|
||||
- deprecated `os_name` in `dc_context_new()`, pass `NULL` or an empty string #2956
|
||||
|
||||
### Changes
|
||||
- start making it possible to write to mailing lists #2736
|
||||
- add `hop_info` to `dc_get_info()` #2751 #2914 #2923
|
||||
- add information about whether the database is encrypted or not to `dc_get_info()` #3000
|
||||
- selfstatus now defaults to empty #2951 #2960
|
||||
- validate detached cryptographic signatures as used eg. by Thunderbird #2865
|
||||
- do not change the draft's `msg_id` on updates and sending #2887
|
||||
- add `imap` table to keep track of message UIDs #2909 #2938
|
||||
- replace `SendMsgToSmtp` jobs which stored outgoing messages in blobdir with `smtp` SQL table #2939 #2996
|
||||
- sql: enable `auto_vacuum=INCREMENTAL` #2931
|
||||
- sql: build rusqlite with sqlcipher #2934
|
||||
- synchronize Seen status across devices #2942
|
||||
- `dc_preconfigure_keypair` now takes ascii armored keys instead of base64 #2862
|
||||
- put removed member in Bcc instead of To in the message about removal #2864
|
||||
- improve group updates #2889
|
||||
- re-write the blob filename creation loop #2981
|
||||
- update provider database (11 Jan 2022) #2959
|
||||
- python: allow timeout for internal configure tracker API #2967
|
||||
- python: remove API deprecated in Python 3.10 #2907
|
||||
- refactorings #2932 #2957 #2947
|
||||
- improve tests #2863 #2866 #2881 #2908 #2918 #2901 #2973
|
||||
- improve documentation #2880 #2886 #2895
|
||||
- improve ci #2919 #2926 #2969 #2999
|
||||
|
||||
### Fixes
|
||||
- fix leaving groups #2929
|
||||
- fix unread count #2861
|
||||
- make `add_parts()` not early-exit #2879
|
||||
- recognize MS Exchange read receipts as read receipts #2890
|
||||
- create parent directory if creating a new file fails #2978
|
||||
- save "configured" flag later #2974
|
||||
- improve log #2928
|
||||
- `dc_receive_imf`: don't fail on invalid address in the To field #2940
|
||||
|
||||
|
||||
## 1.70.0
|
||||
|
||||
### Fixes
|
||||
- fix: do not abort Param parsing on unknown keys #2856
|
||||
- fix: execute `Chat-Group-Member-Removed:` even when arriving disordered #2857
|
||||
|
||||
|
||||
## 1.69.0
|
||||
|
||||
### Fixes
|
||||
- fix group-related system messages in multi-device setups #2848
|
||||
- fix "Google Workspace" (former "G Suite") issues related to bad resolvers #2852
|
||||
|
||||
|
||||
## 1.68.0
|
||||
|
||||
### Fixes
|
||||
- fix chat assignment when forwarding #2843
|
||||
- fix layout issues with the generated QR code svg #2842
|
||||
|
||||
|
||||
## 1.67.0
|
||||
|
||||
### API changes
|
||||
- `dc_get_securejoin_qr_svg(chat_id)` added #2815
|
||||
- added stock-strings `DC_STR_SETUP_CONTACT_QR_DESC` and `DC_STR_SECURE_JOIN_GROUP_QR_DESC`
|
||||
|
||||
|
||||
## 1.66.0
|
||||
|
||||
### API changes
|
||||
|
||||
@@ -4,16 +4,24 @@ include(GNUInstallDirs)
|
||||
|
||||
find_program(CARGO cargo)
|
||||
|
||||
if(APPLE)
|
||||
set(DYNAMIC_EXT "dylib")
|
||||
elseif(UNIX)
|
||||
set(DYNAMIC_EXT "so")
|
||||
else()
|
||||
set(DYNAMIC_EXT "dll")
|
||||
endif()
|
||||
|
||||
add_custom_command(
|
||||
OUTPUT
|
||||
"target/release/libdeltachat.a"
|
||||
"target/release/libdeltachat.so"
|
||||
"target/release/libdeltachat.${DYNAMIC_EXT}"
|
||||
"target/release/pkgconfig/deltachat.pc"
|
||||
COMMAND
|
||||
PREFIX=${CMAKE_INSTALL_PREFIX}
|
||||
LIBDIR=${CMAKE_INSTALL_FULL_LIBDIR}
|
||||
INCLUDEDIR=${CMAKE_INSTALL_FULL_INCLUDEDIR}
|
||||
${CARGO} build --release --no-default-features
|
||||
${CARGO} build --release --no-default-features --features jsonrpc
|
||||
|
||||
# Build in `deltachat-ffi` directory instead of using
|
||||
# `--package deltachat_ffi` to avoid feature resolver version
|
||||
@@ -32,11 +40,11 @@ add_custom_target(
|
||||
ALL
|
||||
DEPENDS
|
||||
"target/release/libdeltachat.a"
|
||||
"target/release/libdeltachat.so"
|
||||
"target/release/libdeltachat.${DYNAMIC_EXT}"
|
||||
"target/release/pkgconfig/deltachat.pc"
|
||||
)
|
||||
|
||||
install(FILES "deltachat-ffi/deltachat.h" DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
|
||||
install(FILES "target/release/libdeltachat.a" DESTINATION ${CMAKE_INSTALL_LIBDIR})
|
||||
install(FILES "target/release/libdeltachat.so" DESTINATION ${CMAKE_INSTALL_LIBDIR})
|
||||
install(FILES "target/release/libdeltachat.${DYNAMIC_EXT}" DESTINATION ${CMAKE_INSTALL_LIBDIR})
|
||||
install(FILES "target/release/pkgconfig/deltachat.pc" DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
|
||||
|
||||
1761
Cargo.lock
generated
1761
Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
66
Cargo.toml
66
Cargo.toml
@@ -1,16 +1,18 @@
|
||||
[package]
|
||||
name = "deltachat"
|
||||
version = "1.66.0"
|
||||
version = "1.86.0"
|
||||
authors = ["Delta Chat Developers (ML) <delta@codespeak.net>"]
|
||||
edition = "2018"
|
||||
edition = "2021"
|
||||
license = "MPL-2.0"
|
||||
resolver = "2"
|
||||
rust-version = "1.56"
|
||||
|
||||
[profile.dev]
|
||||
debug = 0
|
||||
panic = 'abort'
|
||||
|
||||
[profile.release]
|
||||
lto = true
|
||||
panic = 'abort'
|
||||
|
||||
[dependencies]
|
||||
deltachat_derive = { path = "./deltachat_derive" }
|
||||
@@ -19,65 +21,66 @@ ansi_term = { version = "0.12.1", optional = true }
|
||||
anyhow = "1"
|
||||
async-imap = { git = "https://github.com/async-email/async-imap" }
|
||||
async-native-tls = { version = "0.3" }
|
||||
async-smtp = { git = "https://github.com/async-email/async-smtp", branch="master", features = ["socks5"] }
|
||||
async-std-resolver = "0.20"
|
||||
async-std = { version = "1", features = ["unstable"] }
|
||||
async-smtp = { git = "https://github.com/async-email/async-smtp", branch="master", default-features=false, features = ["smtp-transport", "socks5"] }
|
||||
async-std-resolver = "0.21"
|
||||
async-std = { version = "1" }
|
||||
async-tar = { version = "0.4", default-features=false }
|
||||
async-trait = "0.1"
|
||||
backtrace = "0.3"
|
||||
base64 = "0.13"
|
||||
bitflags = "1.3"
|
||||
byteorder = "1.3"
|
||||
chrono = "0.4"
|
||||
chrono = { version = "0.4", default-features=false, features = ["clock", "std"] }
|
||||
dirs = { version = "4", optional=true }
|
||||
email = { git = "https://github.com/deltachat/rust-email", branch = "master" }
|
||||
encoded-words = { git = "https://github.com/async-email/encoded-words", branch="master" }
|
||||
escaper = "0.1"
|
||||
futures = "0.3"
|
||||
hex = "0.4.0"
|
||||
image = { version = "0.23.5", default-features=false, features = ["gif", "jpeg", "ico", "png", "pnm", "webp", "bmp"] }
|
||||
image = { version = "0.24.1", default-features=false, features = ["gif", "jpeg", "ico", "png", "pnm", "webp", "bmp"] }
|
||||
kamadak-exif = "0.5"
|
||||
lettre_email = { git = "https://github.com/deltachat/lettre", branch = "master" }
|
||||
libc = "0.2"
|
||||
log = {version = "0.4.8", optional = true }
|
||||
log = {version = "0.4.16", optional = true }
|
||||
mailparse = "0.13"
|
||||
native-tls = "0.2"
|
||||
num_cpus = "1.13"
|
||||
num-derive = "0.3"
|
||||
num-traits = "0.2"
|
||||
once_cell = "1.8.0"
|
||||
once_cell = "1.12.0"
|
||||
percent-encoding = "2.0"
|
||||
pgp = { version = "0.7", default-features = false }
|
||||
pretty_env_logger = { version = "0.4", optional = true }
|
||||
quick-xml = "0.22"
|
||||
quick-xml = "0.23"
|
||||
r2d2 = "0.8"
|
||||
r2d2_sqlite = "0.19"
|
||||
r2d2_sqlite = "0.20"
|
||||
rand = "0.7"
|
||||
regex = "1.5"
|
||||
rusqlite = "0.26"
|
||||
rusqlite = { version = "0.27", features = ["sqlcipher"] }
|
||||
rust-hsluv = "0.1"
|
||||
rustyline = { version = "9.0", optional = true }
|
||||
sanitize-filename = "0.3"
|
||||
rustyline = { version = "9", optional = true }
|
||||
sanitize-filename = "0.4"
|
||||
serde_json = "1.0"
|
||||
serde = { version = "1.0", features = ["derive"] }
|
||||
sha-1 = "0.9"
|
||||
sha2 = "0.9"
|
||||
sha-1 = "0.10"
|
||||
sha2 = "0.10"
|
||||
smallvec = "1"
|
||||
stop-token = "0.6"
|
||||
strum = "0.23"
|
||||
strum_macros = "0.23"
|
||||
strum = "0.24"
|
||||
strum_macros = "0.24"
|
||||
surf = { version = "2.3", default-features = false, features = ["h1-client"] }
|
||||
thiserror = "1"
|
||||
toml = "0.5"
|
||||
url = "2"
|
||||
uuid = { version = "0.8", features = ["serde", "v4"] }
|
||||
uuid = { version = "1", features = ["serde", "v4"] }
|
||||
fast-socks5 = "0.4"
|
||||
humansize = "1"
|
||||
qrcodegen = "1.7.0"
|
||||
tagger = "4.3.3"
|
||||
textwrap = "0.15.0"
|
||||
zip = { version = "0.6.2", default-features = false, features = ["deflate"] }
|
||||
|
||||
[dev-dependencies]
|
||||
ansi_term = "0.12.0"
|
||||
async-std = { version = "1", features = ["unstable", "attributes"] }
|
||||
criterion = "0.3"
|
||||
criterion = { version = "0.3.4", features = ["async_std"] }
|
||||
futures-lite = "1.12"
|
||||
log = "0.4"
|
||||
pretty_env_logger = "0.4"
|
||||
@@ -88,6 +91,7 @@ tempfile = "3"
|
||||
members = [
|
||||
"deltachat-ffi",
|
||||
"deltachat_derive",
|
||||
"deltachat-jsonrpc"
|
||||
]
|
||||
|
||||
[[example]]
|
||||
@@ -113,9 +117,21 @@ harness = false
|
||||
name = "search_msgs"
|
||||
harness = false
|
||||
|
||||
[[bench]]
|
||||
name = "receive_emails"
|
||||
harness = false
|
||||
|
||||
[[bench]]
|
||||
name = "get_chat_msgs"
|
||||
harness = false
|
||||
|
||||
[[bench]]
|
||||
name = "get_chatlist"
|
||||
harness = false
|
||||
|
||||
[features]
|
||||
default = ["vendored"]
|
||||
internals = []
|
||||
repl = ["internals", "rustyline", "log", "pretty_env_logger", "ansi_term", "dirs"]
|
||||
vendored = ["async-native-tls/vendored", "async-smtp/native-tls-vendored", "rusqlite/bundled"]
|
||||
vendored = ["async-native-tls/vendored", "async-smtp/native-tls-vendored", "rusqlite/bundled-sqlcipher-vendored-openssl"]
|
||||
nightly = ["pgp/nightly"]
|
||||
|
||||
15
README.md
15
README.md
@@ -12,6 +12,8 @@ To download and install the official compiler for the Rust programming language,
|
||||
$ curl https://sh.rustup.rs -sSf | sh
|
||||
```
|
||||
|
||||
> On Windows, you may need to also install **Perl** to be able to compile deltachat-core.
|
||||
|
||||
## Using the CLI client
|
||||
|
||||
Compile and run Delta Chat Core command line utility, using `cargo`:
|
||||
@@ -100,9 +102,6 @@ $ cargo build -p deltachat_ffi --release
|
||||
|
||||
## Debugging environment variables
|
||||
|
||||
- `DCC_IMAP_DEBUG`: if set IMAP protocol commands and responses will be
|
||||
printed
|
||||
|
||||
- `DCC_MIME_DEBUG`: if set outgoing and incoming message will be printed
|
||||
|
||||
- `RUST_LOG=repl=info,async_imap=trace,async_smtp=trace`: enable IMAP and
|
||||
@@ -125,11 +124,11 @@ $ cargo test -- --ignored
|
||||
|
||||
Language bindings are available for:
|
||||
|
||||
- [C](https://c.delta.chat)
|
||||
- [Node.js](https://www.npmjs.com/package/deltachat-node)
|
||||
- [Python](https://py.delta.chat)
|
||||
- [Go](https://github.com/deltachat/go-deltachat/)
|
||||
- [Free Pascal](https://github.com/deltachat/deltachat-fp/)
|
||||
- **C** \[[📂 source](./deltachat-ffi) | [📚 docs](https://c.delta.chat)\]
|
||||
- **Node.js** \[[📂 source](./node) | [📦 npm](https://www.npmjs.com/package/deltachat-node) | [📚 docs](https://js.delta.chat)\]
|
||||
- **Python** \[[📂 source](./python) | [📦 pypi](https://pypi.org/project/deltachat) | [📚 docs](https://py.delta.chat)\]
|
||||
- **Go** \[[📂 source](https://github.com/deltachat/go-deltachat/)\]
|
||||
- **Free Pascal** \[[📂 source](https://github.com/deltachat/deltachat-fp/)\]
|
||||
- **Java** and **Swift** (contained in the Android/iOS repos)
|
||||
|
||||
The following "frontend" projects make use of the Rust-library
|
||||
|
||||
BIN
assets/icon-webxdc.png
Normal file
BIN
assets/icon-webxdc.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 6.9 KiB |
181
assets/icon-webxdc.svg
Normal file
181
assets/icon-webxdc.svg
Normal file
@@ -0,0 +1,181 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<svg
|
||||
xmlns:dc="http://purl.org/dc/elements/1.1/"
|
||||
xmlns:cc="http://creativecommons.org/ns#"
|
||||
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
|
||||
xmlns:svg="http://www.w3.org/2000/svg"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
|
||||
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
|
||||
width="80mm"
|
||||
height="297mm"
|
||||
viewBox="0 0 80 297"
|
||||
version="1.1"
|
||||
id="svg71"
|
||||
inkscape:version="1.0.2 (e86c8708, 2021-01-15)"
|
||||
sodipodi:docname="icon-webxdc.svg"
|
||||
inkscape:export-filename="C:\Users\user\OneDrive - BFW-Leipzig\Documents\LogoDC\finalohnerand.png"
|
||||
inkscape:export-xdpi="96"
|
||||
inkscape:export-ydpi="96">
|
||||
<metadata
|
||||
id="metadata856">
|
||||
<rdf:RDF>
|
||||
<cc:Work
|
||||
rdf:about="">
|
||||
<dc:format>image/svg+xml</dc:format>
|
||||
<dc:type
|
||||
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
|
||||
<dc:title></dc:title>
|
||||
</cc:Work>
|
||||
</rdf:RDF>
|
||||
</metadata>
|
||||
<sodipodi:namedview
|
||||
id="namedview73"
|
||||
pagecolor="#767676"
|
||||
bordercolor="#666666"
|
||||
borderopacity="1.0"
|
||||
inkscape:pageshadow="2"
|
||||
inkscape:pageopacity="0"
|
||||
inkscape:pagecheckerboard="true"
|
||||
inkscape:document-units="mm"
|
||||
showgrid="false"
|
||||
showborder="false"
|
||||
inkscape:snap-bbox="true"
|
||||
inkscape:bbox-paths="true"
|
||||
inkscape:bbox-nodes="true"
|
||||
inkscape:snap-bbox-edge-midpoints="true"
|
||||
inkscape:snap-bbox-midpoints="true"
|
||||
inkscape:object-paths="true"
|
||||
inkscape:snap-intersection-paths="true"
|
||||
inkscape:zoom="1.4142136"
|
||||
inkscape:cx="-90.271136"
|
||||
inkscape:cy="-1233.1209"
|
||||
inkscape:window-width="1864"
|
||||
inkscape:window-height="1027"
|
||||
inkscape:window-x="56"
|
||||
inkscape:window-y="25"
|
||||
inkscape:window-maximized="1"
|
||||
inkscape:current-layer="layer1"
|
||||
inkscape:snap-global="false"
|
||||
showguides="false"
|
||||
inkscape:guide-bbox="true"
|
||||
inkscape:document-rotation="0"
|
||||
units="px">
|
||||
<sodipodi:guide
|
||||
position="-154.76097,641.11689"
|
||||
orientation="0,-1"
|
||||
id="guide21118" />
|
||||
<sodipodi:guide
|
||||
position="-60.286487,633.36619"
|
||||
orientation="0,-1"
|
||||
id="guide21120" />
|
||||
</sodipodi:namedview>
|
||||
<defs
|
||||
id="defs68">
|
||||
<linearGradient
|
||||
id="linearGradient4375">
|
||||
<stop
|
||||
style="stop-color:#364e59;stop-opacity:1;"
|
||||
offset="0"
|
||||
id="stop4377" />
|
||||
<stop
|
||||
style="stop-color:#364e59;stop-opacity:0;"
|
||||
offset="1"
|
||||
id="stop4379" />
|
||||
</linearGradient>
|
||||
</defs>
|
||||
<g
|
||||
inkscape:label="Ebene 1"
|
||||
inkscape:groupmode="layer"
|
||||
id="layer1">
|
||||
<rect
|
||||
style="fill:#1a1a1a;stroke:#000000;stroke-width:0.167903"
|
||||
id="rect880"
|
||||
width="79.8321"
|
||||
height="79.8321"
|
||||
x="-64.03286"
|
||||
y="-375.9097"
|
||||
ry="0" />
|
||||
<path
|
||||
inkscape:connector-curvature="0"
|
||||
id="path3799-2"
|
||||
d="m -24.089585,-372.59579 c -19.986026,0.24336 -36.196903,16.666 -36.196903,36.67011 0,20.00409 16.210877,36.03233 36.196903,35.78912 19.0024236,-0.076 14.5340713,-10.6146 35.538854,-0.85693 -11.50627538,-17.97454 0.390097,-20.36737 0.658079,-35.81316 0,-20.00411 -16.2108788,-36.03235 -36.196911,-35.78914 z"
|
||||
style="fill:#364e59;fill-opacity:1;stroke:none;stroke-width:1.93355"
|
||||
sodipodi:nodetypes="sscccs" />
|
||||
<path
|
||||
style="fill:none;stroke:#000000;stroke-width:0.264583px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
|
||||
d="M -54.193871,-325.26419 Z"
|
||||
id="path3846" />
|
||||
<path
|
||||
style="fill:none;stroke:#000000;stroke-width:0.264583px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
|
||||
d="M -49.397951,-326.67773 Z"
|
||||
id="path3848" />
|
||||
<path
|
||||
style="fill:none;stroke:#000000;stroke-width:0.264583px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
|
||||
d="m -49.397951,-326.67773 v 0 0"
|
||||
id="path3850" />
|
||||
<path
|
||||
style="fill:none;stroke:#000000;stroke-width:0.01;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
|
||||
d="m -51.35133,-325.0334 -7.964067,5.98895 z"
|
||||
id="path3965" />
|
||||
<path
|
||||
inkscape:connector-curvature="0"
|
||||
id="path11037"
|
||||
d="m -24.089585,-372.19891 c -19.986026,0.24156 -36.196903,16.54352 -36.196903,36.40062 0,7.86524 2.543315,15.1113 6.857155,20.97971 6.577146,8.94734 11.123515,9.77363 11.123515,9.77363 1.343237,1.78324 10.270932,4.3223 10.270932,4.3223 l 16.791727,-70.86654 -0.468369,-0.33457 c 0.458597,0.26445 0.428277,-0.27515 -8.378035,-0.27515 z"
|
||||
style="fill:#7cc5cc;fill-opacity:1;stroke:none;stroke-width:1.92643"
|
||||
sodipodi:nodetypes="sssccccss" />
|
||||
<path
|
||||
style="fill:none;stroke:#000000;stroke-width:0.264583px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
|
||||
d="M -49.944239,-310.69957 Z"
|
||||
id="path13674" />
|
||||
<g
|
||||
id="g15178"
|
||||
transform="matrix(0.79975737,0,0,0.79975737,53.088959,-63.716396)">
|
||||
<rect
|
||||
style="fill:#364e59;fill-opacity:1;stroke-width:0.01;stroke-miterlimit:4;stroke-dasharray:none"
|
||||
id="rect15072"
|
||||
width="29.897917"
|
||||
height="6.8791666"
|
||||
x="-334.4964"
|
||||
y="-154.51025"
|
||||
transform="rotate(45)" />
|
||||
<rect
|
||||
style="fill:#364e59;fill-opacity:1;stroke-width:0.01;stroke-miterlimit:4;stroke-dasharray:none"
|
||||
id="rect15072-5"
|
||||
width="29.897917"
|
||||
height="6.8791666"
|
||||
x="147.63107"
|
||||
y="-334.4964"
|
||||
transform="rotate(-45)"
|
||||
inkscape:transform-center-x="-0.74835017"
|
||||
inkscape:transform-center-y="0.37417525" />
|
||||
</g>
|
||||
<g
|
||||
id="g22468"
|
||||
transform="translate(3.3033974)">
|
||||
<g
|
||||
id="g15178-0"
|
||||
transform="matrix(-0.79975737,0,0,0.79975737,-103.11028,-63.716404)"
|
||||
style="fill:#7cc5cc;fill-opacity:1">
|
||||
<rect
|
||||
style="fill:#7cc5cc;fill-opacity:1;stroke-width:0.01;stroke-miterlimit:4;stroke-dasharray:none"
|
||||
id="rect15072-2"
|
||||
width="29.897917"
|
||||
height="6.8791666"
|
||||
x="-334.4964"
|
||||
y="-154.51025"
|
||||
transform="rotate(45)" />
|
||||
<rect
|
||||
style="fill:#7cc5cc;fill-opacity:1;stroke-width:0.01;stroke-miterlimit:4;stroke-dasharray:none"
|
||||
id="rect15072-5-5"
|
||||
width="29.897917"
|
||||
height="6.8791666"
|
||||
x="147.63107"
|
||||
y="-334.4964"
|
||||
transform="rotate(-45)"
|
||||
inkscape:transform-center-x="-0.74835017"
|
||||
inkscape:transform-center-y="0.37417525" />
|
||||
</g>
|
||||
</g>
|
||||
</g>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 6.5 KiB |
10
assets/qrcode_logo_footer.svg
Normal file
10
assets/qrcode_logo_footer.svg
Normal file
@@ -0,0 +1,10 @@
|
||||
<text
|
||||
xml:space="preserve"
|
||||
style="font-weight:bold;font-size:24.4118px;line-height:1.25;font-family:sans-serif;fill:#aaaaaa;fill-opacity:1;stroke:none;stroke-width:0.915439"
|
||||
x="42.325161"
|
||||
y="23.32255"
|
||||
id="text72398">get.delta.chat</text>
|
||||
<path
|
||||
id="path84310"
|
||||
style="opacity:0.25;fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.915439"
|
||||
d="M 17.13769,0.00129321 C 7.6753075,0.11650893 0,7.8915283 0,17.362467 c 0,9.47094 7.6753075,17.059745 17.13769,16.944599 8.99669,-0.03598 6.880074,-5.025654 16.824785,-0.405885 -5.447648,-8.510047 0.184241,-9.642482 0.311117,-16.955289 0,-9.4709395 -7.673512,-17.0597453 -17.135895,-16.94459879 z M 17.0769,4.9986797 c 1.84214,0 3.447355,0.253959 4.815003,0.7616693 1.381603,0.5076411 2.072253,1.207862 2.072253,2.0990711 0,0.4286855 -0.167495,0.7836052 -0.50242,1.0656242 -0.334921,0.2819844 -0.724544,0.4237724 -1.171121,0.4237724 -0.641952,0 -1.396532,-0.3909376 -2.261778,-1.169353 C 19.14963,7.3898036 18.402555,6.83791 17.788507,6.5220182 17.188416,6.1950547 16.484552,6.0321266 15.675129,6.0321266 c -1.032717,0 -1.883352,0.1854523 -2.553215,0.5578447 -0.655913,0.372254 -0.98517,0.8460916 -0.98517,1.4214436 0,0.5414792 0.272815,1.0495355 0.817093,1.5233385 0.544275,0.4738026 1.946291,1.3367446 4.207097,2.5889976 2.414319,1.342419 4.117377,2.390985 5.108232,3.146807 1.004795,0.755857 1.821505,1.675853 2.449514,2.758846 0.628002,1.082993 0.942253,2.227607 0.942253,3.434674 0,2.120834 -0.929555,3.993314 -2.785656,5.617786 -1.84214,1.613228 -3.99694,2.41915 -6.467082,2.41915 -2.246845,0 -4.145607,-0.647976 -5.694677,-1.945312 -1.5490699,-1.297336 -2.3225722,-3.028063 -2.3225722,-5.194049 0,-2.087031 0.8506345,-3.83094 2.5532182,-5.229825 1.716541,-1.398884 3.824203,-2.245599 6.322256,-2.538897 -0.697774,-0.631749 -1.668763,-1.387225 -2.910816,-2.267155 -1.367648,-0.970199 -2.287914,-1.73045 -2.762402,-2.283243 -0.474491,-0.5640381 -0.711618,-1.1795944 -0.711618,-1.8451814 0,-0.9927581 0.572093,-1.7710351 1.716451,-2.3351077 1.144362,-0.5753173 2.636724,-0.8635642 4.478865,-0.8635642 z m 1.110327,10.3738083 c -4.005262,0.5302 -6.007576,2.75279 -6.007576,6.667322 0,2.01932 0.49495,3.587291 1.485805,4.704157 1.004806,1.116832 2.169696,1.675299 3.495479,1.675299 1.381602,0 2.520072,-0.535632 3.413229,-1.60738 0.893168,-1.082959 1.339187,-2.545264 1.339187,-4.384079 0,-2.662348 -1.242022,-5.013441 -3.726124,-7.055319 z" />
|
||||
@@ -2,13 +2,14 @@ use async_std::task::block_on;
|
||||
use criterion::{black_box, criterion_group, criterion_main, Criterion};
|
||||
use deltachat::contact::Contact;
|
||||
use deltachat::context::Context;
|
||||
use deltachat::Events;
|
||||
use tempfile::tempdir;
|
||||
|
||||
async fn address_book_benchmark(n: u32, read_count: u32) {
|
||||
let dir = tempdir().unwrap();
|
||||
let dbfile = dir.path().join("db.sqlite");
|
||||
let id = 100;
|
||||
let context = Context::new("FakeOS".into(), dbfile.into(), id)
|
||||
let context = Context::new(dbfile.into(), id, Events::new())
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ async fn create_accounts(n: u32) {
|
||||
let dir = tempdir().unwrap();
|
||||
let p: PathBuf = dir.path().join("accounts").into();
|
||||
|
||||
let accounts = Accounts::new("my_os".into(), p.clone()).await.unwrap();
|
||||
let mut accounts = Accounts::new(p.clone()).await.unwrap();
|
||||
|
||||
for expected_id in 2..n {
|
||||
let id = accounts.add_account().await.unwrap();
|
||||
|
||||
45
benches/get_chat_msgs.rs
Normal file
45
benches/get_chat_msgs.rs
Normal file
@@ -0,0 +1,45 @@
|
||||
use async_std::path::Path;
|
||||
|
||||
use criterion::async_executor::AsyncStdExecutor;
|
||||
use criterion::{black_box, criterion_group, criterion_main, Criterion};
|
||||
|
||||
use deltachat::chat::{self, ChatId};
|
||||
use deltachat::chatlist::Chatlist;
|
||||
use deltachat::context::Context;
|
||||
use deltachat::Events;
|
||||
|
||||
async fn get_chat_msgs_benchmark(dbfile: &Path, chats: &[ChatId]) {
|
||||
let id = 100;
|
||||
let context = Context::new(dbfile.into(), id, Events::new())
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
for c in chats.iter().take(10) {
|
||||
black_box(chat::get_chat_msgs(&context, *c, 0).await.ok());
|
||||
}
|
||||
}
|
||||
|
||||
fn criterion_benchmark(c: &mut Criterion) {
|
||||
// To enable this benchmark, set `DELTACHAT_BENCHMARK_DATABASE` to some large database with many
|
||||
// messages, such as your primary account.
|
||||
if let Ok(path) = std::env::var("DELTACHAT_BENCHMARK_DATABASE") {
|
||||
let chats: Vec<_> = async_std::task::block_on(async {
|
||||
let context = Context::new((&path).into(), 100, Events::new())
|
||||
.await
|
||||
.unwrap();
|
||||
let chatlist = Chatlist::try_load(&context, 0, None, None).await.unwrap();
|
||||
let len = chatlist.len();
|
||||
(0..len).map(|i| chatlist.get_chat_id(i).unwrap()).collect()
|
||||
});
|
||||
|
||||
c.bench_function("chat::get_chat_msgs (load messages from 10 chats)", |b| {
|
||||
b.to_async(AsyncStdExecutor)
|
||||
.iter(|| get_chat_msgs_benchmark(black_box(path.as_ref()), black_box(&chats)))
|
||||
});
|
||||
} else {
|
||||
println!("env var not set: DELTACHAT_BENCHMARK_DATABASE");
|
||||
}
|
||||
}
|
||||
|
||||
criterion_group!(benches, criterion_benchmark);
|
||||
criterion_main!(benches);
|
||||
29
benches/get_chatlist.rs
Normal file
29
benches/get_chatlist.rs
Normal file
@@ -0,0 +1,29 @@
|
||||
use criterion::async_executor::AsyncStdExecutor;
|
||||
use criterion::{black_box, criterion_group, criterion_main, Criterion};
|
||||
|
||||
use deltachat::chatlist::Chatlist;
|
||||
use deltachat::context::Context;
|
||||
use deltachat::Events;
|
||||
|
||||
async fn get_chat_list_benchmark(context: &Context) {
|
||||
Chatlist::try_load(context, 0, None, None).await.unwrap();
|
||||
}
|
||||
|
||||
fn criterion_benchmark(c: &mut Criterion) {
|
||||
// To enable this benchmark, set `DELTACHAT_BENCHMARK_DATABASE` to some large database with many
|
||||
// messages, such as your primary account.
|
||||
if let Ok(path) = std::env::var("DELTACHAT_BENCHMARK_DATABASE") {
|
||||
let context = async_std::task::block_on(async {
|
||||
Context::new(path.into(), 100, Events::new()).await.unwrap()
|
||||
});
|
||||
c.bench_function("chatlist:try_load (Get Chatlist)", |b| {
|
||||
b.to_async(AsyncStdExecutor)
|
||||
.iter(|| get_chat_list_benchmark(black_box(&context)))
|
||||
});
|
||||
} else {
|
||||
println!("env var not set: DELTACHAT_BENCHMARK_DATABASE");
|
||||
}
|
||||
}
|
||||
|
||||
criterion_group!(benches, criterion_benchmark);
|
||||
criterion_main!(benches);
|
||||
87
benches/receive_emails.rs
Normal file
87
benches/receive_emails.rs
Normal file
@@ -0,0 +1,87 @@
|
||||
use async_std::{path::PathBuf, task::block_on};
|
||||
use criterion::{
|
||||
async_executor::AsyncStdExecutor, black_box, criterion_group, criterion_main, BatchSize,
|
||||
Criterion,
|
||||
};
|
||||
use deltachat::{
|
||||
config::Config,
|
||||
context::Context,
|
||||
dc_receive_imf::dc_receive_imf,
|
||||
imex::{imex, ImexMode},
|
||||
Events,
|
||||
};
|
||||
use tempfile::tempdir;
|
||||
|
||||
async fn recv_all_emails(context: Context) -> Context {
|
||||
for i in 0..100 {
|
||||
let imf_raw = format!(
|
||||
"Subject: Benchmark
|
||||
Message-ID: Mr.OssSYnOFkhR.{i}@testrun.org
|
||||
Date: Sat, 07 Dec 2019 19:00:27 +0000
|
||||
To: alice@example.com
|
||||
From: sender@testrun.org
|
||||
Chat-Version: 1.0
|
||||
Chat-Disposition-Notification-To: sender@testrun.org
|
||||
Chat-User-Avatar: 0
|
||||
In-Reply-To: Mr.OssSYnOFkhR.{i_dec}@testrun.org
|
||||
MIME-Version: 1.0
|
||||
|
||||
Content-Type: text/plain; charset=utf-8; format=flowed; delsp=no
|
||||
|
||||
Hello {i}",
|
||||
i = i,
|
||||
i_dec = i - 1,
|
||||
);
|
||||
dc_receive_imf(&context, black_box(imf_raw.as_bytes()), false)
|
||||
.await
|
||||
.unwrap();
|
||||
}
|
||||
context
|
||||
}
|
||||
|
||||
async fn create_context() -> Context {
|
||||
let dir = tempdir().unwrap();
|
||||
let dbfile = dir.path().join("db.sqlite");
|
||||
let id = 100;
|
||||
let context = Context::new(dbfile.into(), id, Events::new())
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
let backup: PathBuf = std::env::current_dir()
|
||||
.unwrap()
|
||||
.join("delta-chat-backup.tar")
|
||||
.into();
|
||||
if backup.exists().await {
|
||||
println!("Importing backup");
|
||||
imex(&context, ImexMode::ImportBackup, &backup, None)
|
||||
.await
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
let addr = "alice@example.com";
|
||||
context.set_config(Config::Addr, Some(addr)).await.unwrap();
|
||||
context
|
||||
.set_config(Config::ConfiguredAddr, Some(addr))
|
||||
.await
|
||||
.unwrap();
|
||||
context
|
||||
.set_config(Config::Configured, Some("1"))
|
||||
.await
|
||||
.unwrap();
|
||||
context
|
||||
}
|
||||
|
||||
fn criterion_benchmark(c: &mut Criterion) {
|
||||
let mut group = c.benchmark_group("Receive messages");
|
||||
group.bench_function("Receive 100 simple text msgs", |b| {
|
||||
b.to_async(AsyncStdExecutor).iter_batched(
|
||||
|| block_on(create_context()),
|
||||
|context| recv_all_emails(black_box(context)),
|
||||
BatchSize::LargeInput,
|
||||
);
|
||||
});
|
||||
group.finish();
|
||||
}
|
||||
|
||||
criterion_group!(benches, criterion_benchmark);
|
||||
criterion_main!(benches);
|
||||
@@ -1,12 +1,13 @@
|
||||
use async_std::task::block_on;
|
||||
use criterion::{black_box, criterion_group, criterion_main, Criterion};
|
||||
use deltachat::context::Context;
|
||||
use deltachat::Events;
|
||||
use std::path::Path;
|
||||
|
||||
async fn search_benchmark(path: impl AsRef<Path>) {
|
||||
let dbfile = path.as_ref();
|
||||
let id = 100;
|
||||
let context = Context::new("FakeOS".into(), dbfile.into(), id)
|
||||
let context = Context::new(dbfile.into(), id, Events::new())
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
@@ -22,6 +23,8 @@ fn criterion_benchmark(c: &mut Criterion) {
|
||||
c.bench_function("search hello", |b| {
|
||||
b.iter(|| block_on(async { search_benchmark(black_box(&path)).await }))
|
||||
});
|
||||
} else {
|
||||
println!("env var not set: DELTACHAT_BENCHMARK_DATABASE");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "deltachat_ffi"
|
||||
version = "1.66.0"
|
||||
version = "1.86.0"
|
||||
description = "Deltachat FFI"
|
||||
authors = ["Delta Chat Developers (ML) <delta@codespeak.net>"]
|
||||
edition = "2018"
|
||||
@@ -16,6 +16,7 @@ crate-type = ["cdylib", "staticlib"]
|
||||
|
||||
[dependencies]
|
||||
deltachat = { path = "../", default-features = false }
|
||||
deltachat-jsonrpc = { path = "../deltachat-jsonrpc", optional = true }
|
||||
libc = "0.2"
|
||||
human-panic = "1"
|
||||
num-traits = "0.2"
|
||||
@@ -29,4 +30,5 @@ rand = "0.7"
|
||||
default = ["vendored"]
|
||||
vendored = ["deltachat/vendored"]
|
||||
nightly = ["deltachat/nightly"]
|
||||
jsonrpc = ["deltachat-jsonrpc"]
|
||||
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
# Delta Chat C Interface
|
||||
|
||||
## Installation
|
||||
|
||||
see `Installing libdeltachat system wide` in [../README.md](../README.md)
|
||||
|
||||
## Documentation
|
||||
|
||||
To generate the C Interface documentation,
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,5 +1,5 @@
|
||||
use crate::chat::ChatItem;
|
||||
use crate::constants::{DC_MSG_ID_DAYMARKER, DC_MSG_ID_MARKER1};
|
||||
use crate::constants::DC_MSG_ID_DAYMARKER;
|
||||
use crate::location::Location;
|
||||
use crate::message::MsgId;
|
||||
|
||||
@@ -18,7 +18,6 @@ impl dc_array_t {
|
||||
Self::MsgIds(array) => array[index].to_u32(),
|
||||
Self::Chat(array) => match array[index] {
|
||||
ChatItem::Message { msg_id } => msg_id.to_u32(),
|
||||
ChatItem::Marker1 => DC_MSG_ID_MARKER1,
|
||||
ChatItem::DayMarker { .. } => DC_MSG_ID_DAYMARKER,
|
||||
},
|
||||
Self::Locations(array) => array[index].location_id,
|
||||
@@ -31,7 +30,6 @@ impl dc_array_t {
|
||||
Self::MsgIds(_) => None,
|
||||
Self::Chat(array) => array.get(index).and_then(|item| match item {
|
||||
ChatItem::Message { .. } => None,
|
||||
ChatItem::Marker1 { .. } => None,
|
||||
ChatItem::DayMarker { timestamp } => Some(*timestamp),
|
||||
}),
|
||||
Self::Locations(array) => array.get(index).map(|location| location.timestamp),
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#![deny(clippy::all)]
|
||||
#![deny(unused, clippy::all)]
|
||||
#![allow(
|
||||
non_camel_case_types,
|
||||
non_snake_case,
|
||||
@@ -11,8 +11,6 @@
|
||||
|
||||
#[macro_use]
|
||||
extern crate human_panic;
|
||||
extern crate num_traits;
|
||||
extern crate serde_json;
|
||||
|
||||
use std::collections::BTreeMap;
|
||||
use std::convert::TryFrom;
|
||||
@@ -20,21 +18,25 @@ use std::fmt::Write;
|
||||
use std::ops::Deref;
|
||||
use std::ptr;
|
||||
use std::str::FromStr;
|
||||
use std::sync::Arc;
|
||||
use std::time::{Duration, SystemTime};
|
||||
|
||||
use anyhow::Context as _;
|
||||
use async_std::sync::RwLock;
|
||||
use async_std::task::{block_on, spawn};
|
||||
use deltachat::qr_code_generator::get_securejoin_qr_svg;
|
||||
use num_traits::{FromPrimitive, ToPrimitive};
|
||||
use rand::Rng;
|
||||
|
||||
use deltachat::chat::{ChatId, ChatVisibility, MuteDuration, ProtectionStatus};
|
||||
use deltachat::constants::DC_MSG_ID_LAST_SPECIAL;
|
||||
use deltachat::contact::{Contact, Origin};
|
||||
use deltachat::contact::{Contact, ContactId, Origin};
|
||||
use deltachat::context::Context;
|
||||
use deltachat::ephemeral::Timer as EphemeralTimer;
|
||||
use deltachat::key::DcKey;
|
||||
use deltachat::message::MsgId;
|
||||
use deltachat::stock_str::StockMessage;
|
||||
use deltachat::webxdc::StatusUpdateSerial;
|
||||
use deltachat::*;
|
||||
use deltachat::{accounts::Accounts, log::LogExt};
|
||||
|
||||
@@ -62,7 +64,7 @@ pub type dc_context_t = Context;
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn dc_context_new(
|
||||
os_name: *const libc::c_char,
|
||||
_os_name: *const libc::c_char,
|
||||
dbfile: *const libc::c_char,
|
||||
blobdir: *const libc::c_char,
|
||||
) -> *mut dc_context_t {
|
||||
@@ -73,20 +75,13 @@ pub unsafe extern "C" fn dc_context_new(
|
||||
return ptr::null_mut();
|
||||
}
|
||||
|
||||
let os_name = if os_name.is_null() {
|
||||
String::from("DcFFI")
|
||||
} else {
|
||||
to_string_lossy(os_name)
|
||||
};
|
||||
|
||||
let ctx = if blobdir.is_null() || *blobdir == 0 {
|
||||
use rand::Rng;
|
||||
// generate random ID as this functionality is not yet available on the C-api.
|
||||
let id = rand::thread_rng().gen();
|
||||
block_on(Context::new(
|
||||
os_name,
|
||||
as_path(dbfile).to_path_buf().into(),
|
||||
id,
|
||||
Events::new(),
|
||||
))
|
||||
} else {
|
||||
eprintln!("blobdir can not be defined explicitly anymore");
|
||||
@@ -95,12 +90,64 @@ pub unsafe extern "C" fn dc_context_new(
|
||||
match ctx {
|
||||
Ok(ctx) => Box::into_raw(Box::new(ctx)),
|
||||
Err(err) => {
|
||||
eprintln!("failed to create context: {}", err);
|
||||
eprintln!("failed to create context: {:#}", err);
|
||||
ptr::null_mut()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn dc_context_new_closed(dbfile: *const libc::c_char) -> *mut dc_context_t {
|
||||
setup_panic!();
|
||||
|
||||
if dbfile.is_null() {
|
||||
eprintln!("ignoring careless call to dc_context_new_closed()");
|
||||
return ptr::null_mut();
|
||||
}
|
||||
|
||||
let id = rand::thread_rng().gen();
|
||||
match block_on(Context::new_closed(
|
||||
as_path(dbfile).to_path_buf().into(),
|
||||
id,
|
||||
Events::new(),
|
||||
)) {
|
||||
Ok(context) => Box::into_raw(Box::new(context)),
|
||||
Err(err) => {
|
||||
eprintln!("failed to create context: {:#}", err);
|
||||
ptr::null_mut()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn dc_context_open(
|
||||
context: *mut dc_context_t,
|
||||
passphrase: *const libc::c_char,
|
||||
) -> libc::c_int {
|
||||
if context.is_null() {
|
||||
eprintln!("ignoring careless call to dc_context_open()");
|
||||
return 0;
|
||||
}
|
||||
|
||||
let ctx = &*context;
|
||||
let passphrase = to_string_lossy(passphrase);
|
||||
block_on(ctx.open(passphrase))
|
||||
.log_err(ctx, "dc_context_open() failed")
|
||||
.map(|b| b as libc::c_int)
|
||||
.unwrap_or(0)
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn dc_context_is_open(context: *mut dc_context_t) -> libc::c_int {
|
||||
if context.is_null() {
|
||||
eprintln!("ignoring careless call to dc_context_is_open()");
|
||||
return 0;
|
||||
}
|
||||
|
||||
let ctx = &*context;
|
||||
block_on(ctx.is_open()) as libc::c_int
|
||||
}
|
||||
|
||||
/// Release the context structure.
|
||||
///
|
||||
/// This function releases the memory of the `dc_context_t` structure.
|
||||
@@ -192,7 +239,7 @@ pub unsafe extern "C" fn dc_get_config(
|
||||
.unwrap_or_default()
|
||||
.strdup(),
|
||||
Err(_) => {
|
||||
warn!(ctx, "dc_get_config(): invalid key");
|
||||
warn!(ctx, "dc_get_config(): invalid key '{}'", &key);
|
||||
"".strdup()
|
||||
}
|
||||
}
|
||||
@@ -415,7 +462,37 @@ pub unsafe extern "C" fn dc_event_get_id(event: *mut dc_event_t) -> libc::c_int
|
||||
}
|
||||
|
||||
let event = &*event;
|
||||
event.as_id()
|
||||
match event.typ {
|
||||
EventType::Info(_) => 100,
|
||||
EventType::SmtpConnected(_) => 101,
|
||||
EventType::ImapConnected(_) => 102,
|
||||
EventType::SmtpMessageSent(_) => 103,
|
||||
EventType::ImapMessageDeleted(_) => 104,
|
||||
EventType::ImapMessageMoved(_) => 105,
|
||||
EventType::NewBlobFile(_) => 150,
|
||||
EventType::DeletedBlobFile(_) => 151,
|
||||
EventType::Warning(_) => 300,
|
||||
EventType::Error(_) => 400,
|
||||
EventType::ErrorSelfNotInGroup(_) => 410,
|
||||
EventType::MsgsChanged { .. } => 2000,
|
||||
EventType::IncomingMsg { .. } => 2005,
|
||||
EventType::MsgsNoticed { .. } => 2008,
|
||||
EventType::MsgDelivered { .. } => 2010,
|
||||
EventType::MsgFailed { .. } => 2012,
|
||||
EventType::MsgRead { .. } => 2015,
|
||||
EventType::ChatModified(_) => 2020,
|
||||
EventType::ChatEphemeralTimerModified { .. } => 2021,
|
||||
EventType::ContactsChanged(_) => 2030,
|
||||
EventType::LocationChanged(_) => 2035,
|
||||
EventType::ConfigureProgress { .. } => 2041,
|
||||
EventType::ImexProgress(_) => 2051,
|
||||
EventType::ImexFileWritten(_) => 2052,
|
||||
EventType::SecurejoinInviterProgress { .. } => 2060,
|
||||
EventType::SecurejoinJoinerProgress { .. } => 2061,
|
||||
EventType::ConnectivityChanged => 2100,
|
||||
EventType::SelfavatarChanged => 2110,
|
||||
EventType::WebxdcStatusUpdate { .. } => 2120,
|
||||
}
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
@@ -450,14 +527,17 @@ pub unsafe extern "C" fn dc_event_get_data1_int(event: *mut dc_event_t) -> libc:
|
||||
| EventType::ChatEphemeralTimerModified { chat_id, .. } => chat_id.to_u32() as libc::c_int,
|
||||
EventType::ContactsChanged(id) | EventType::LocationChanged(id) => {
|
||||
let id = id.unwrap_or_default();
|
||||
id as libc::c_int
|
||||
id.to_u32() as libc::c_int
|
||||
}
|
||||
EventType::ConfigureProgress { progress, .. } | EventType::ImexProgress(progress) => {
|
||||
*progress as libc::c_int
|
||||
}
|
||||
EventType::ImexFileWritten(_) => 0,
|
||||
EventType::SecurejoinInviterProgress { contact_id, .. }
|
||||
| EventType::SecurejoinJoinerProgress { contact_id, .. } => *contact_id as libc::c_int,
|
||||
| EventType::SecurejoinJoinerProgress { contact_id, .. } => {
|
||||
contact_id.to_u32() as libc::c_int
|
||||
}
|
||||
EventType::WebxdcStatusUpdate { msg_id, .. } => msg_id.to_u32() as libc::c_int,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -489,8 +569,8 @@ pub unsafe extern "C" fn dc_event_get_data2_int(event: *mut dc_event_t) -> libc:
|
||||
| EventType::ImexFileWritten(_)
|
||||
| EventType::MsgsNoticed(_)
|
||||
| EventType::ConnectivityChanged
|
||||
| EventType::SelfavatarChanged
|
||||
| EventType::ChatModified(_) => 0,
|
||||
| EventType::SelfavatarChanged => 0,
|
||||
EventType::ChatModified(_) => 0,
|
||||
EventType::MsgsChanged { msg_id, .. }
|
||||
| EventType::IncomingMsg { msg_id, .. }
|
||||
| EventType::MsgDelivered { msg_id, .. }
|
||||
@@ -499,6 +579,10 @@ pub unsafe extern "C" fn dc_event_get_data2_int(event: *mut dc_event_t) -> libc:
|
||||
EventType::SecurejoinInviterProgress { progress, .. }
|
||||
| EventType::SecurejoinJoinerProgress { progress, .. } => *progress as libc::c_int,
|
||||
EventType::ChatEphemeralTimerModified { timer, .. } => timer.to_u32() as libc::c_int,
|
||||
EventType::WebxdcStatusUpdate {
|
||||
status_update_serial,
|
||||
..
|
||||
} => status_update_serial.to_u32() as libc::c_int,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -540,6 +624,7 @@ pub unsafe extern "C" fn dc_event_get_data2_str(event: *mut dc_event_t) -> *mut
|
||||
| EventType::SecurejoinJoinerProgress { .. }
|
||||
| EventType::ConnectivityChanged
|
||||
| EventType::SelfavatarChanged
|
||||
| EventType::WebxdcStatusUpdate { .. }
|
||||
| EventType::ChatEphemeralTimerModified { .. } => ptr::null_mut(),
|
||||
EventType::ConfigureProgress { comment, .. } => {
|
||||
if let Some(comment) = comment {
|
||||
@@ -606,7 +691,7 @@ pub unsafe extern "C" fn dc_get_next_event(events: *mut dc_event_emitter_t) -> *
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn dc_stop_io(context: *mut dc_context_t) {
|
||||
if context.is_null() {
|
||||
eprintln!("ignoring careless call to dc_shutdown()");
|
||||
eprintln!("ignoring careless call to dc_stop_io()");
|
||||
return;
|
||||
}
|
||||
let ctx = &*context;
|
||||
@@ -641,8 +726,8 @@ pub unsafe extern "C" fn dc_preconfigure_keypair(
|
||||
let ctx = &*context;
|
||||
block_on(async move {
|
||||
let addr = dc_tools::EmailAddress::new(&to_string_lossy(addr))?;
|
||||
let public = key::SignedPublicKey::from_base64(&to_string_lossy(public_data))?;
|
||||
let secret = key::SignedSecretKey::from_base64(&to_string_lossy(secret_data))?;
|
||||
let public = key::SignedPublicKey::from_asc(&to_string_lossy(public_data))?.0;
|
||||
let secret = key::SignedSecretKey::from_asc(&to_string_lossy(secret_data))?.0;
|
||||
let keypair = key::KeyPair {
|
||||
addr,
|
||||
public,
|
||||
@@ -669,7 +754,11 @@ pub unsafe extern "C" fn dc_get_chatlist(
|
||||
let ctx = &*context;
|
||||
let qs = to_opt_string_lossy(query_str);
|
||||
|
||||
let qi = if query_id == 0 { None } else { Some(query_id) };
|
||||
let qi = if query_id == 0 {
|
||||
None
|
||||
} else {
|
||||
Some(ContactId::new(query_id))
|
||||
};
|
||||
|
||||
block_on(async move {
|
||||
match chatlist::Chatlist::try_load(ctx, flags as usize, qs.as_deref(), qi)
|
||||
@@ -697,7 +786,7 @@ pub unsafe extern "C" fn dc_create_chat_by_contact_id(
|
||||
let ctx = &*context;
|
||||
|
||||
block_on(async move {
|
||||
ChatId::create_for_contact(ctx, contact_id)
|
||||
ChatId::create_for_contact(ctx, ContactId::new(contact_id))
|
||||
.await
|
||||
.log_err(ctx, "Failed to create chat from contact_id")
|
||||
.map(|id| id.to_u32())
|
||||
@@ -717,7 +806,7 @@ pub unsafe extern "C" fn dc_get_chat_id_by_contact_id(
|
||||
let ctx = &*context;
|
||||
|
||||
block_on(async move {
|
||||
ChatId::lookup_by_contact(ctx, contact_id)
|
||||
ChatId::lookup_by_contact(ctx, ContactId::new(contact_id))
|
||||
.await
|
||||
.log_err(ctx, "Failed to get chat for contact_id")
|
||||
.unwrap_or_default() // unwraps the Result
|
||||
@@ -829,6 +918,48 @@ pub unsafe extern "C" fn dc_send_videochat_invitation(
|
||||
})
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn dc_send_webxdc_status_update(
|
||||
context: *mut dc_context_t,
|
||||
msg_id: u32,
|
||||
json: *const libc::c_char,
|
||||
descr: *const libc::c_char,
|
||||
) -> libc::c_int {
|
||||
if context.is_null() {
|
||||
eprintln!("ignoring careless call to dc_send_webxdc_status_update()");
|
||||
return 0;
|
||||
}
|
||||
let ctx = &*context;
|
||||
|
||||
block_on(ctx.send_webxdc_status_update(
|
||||
MsgId::new(msg_id),
|
||||
&to_string_lossy(json),
|
||||
&to_string_lossy(descr),
|
||||
))
|
||||
.log_err(ctx, "Failed to send webxdc update")
|
||||
.is_ok() as libc::c_int
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn dc_get_webxdc_status_updates(
|
||||
context: *mut dc_context_t,
|
||||
msg_id: u32,
|
||||
last_known_serial: u32,
|
||||
) -> *mut libc::c_char {
|
||||
if context.is_null() {
|
||||
eprintln!("ignoring careless call to dc_get_webxdc_status_updates()");
|
||||
return "".strdup();
|
||||
}
|
||||
let ctx = &*context;
|
||||
|
||||
block_on(ctx.get_webxdc_status_updates(
|
||||
MsgId::new(msg_id),
|
||||
StatusUpdateSerial::new(last_known_serial),
|
||||
))
|
||||
.unwrap_or_else(|_| "".to_string())
|
||||
.strdup()
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn dc_set_draft(
|
||||
context: *mut dc_context_t,
|
||||
@@ -930,22 +1061,17 @@ pub unsafe extern "C" fn dc_get_chat_msgs(
|
||||
context: *mut dc_context_t,
|
||||
chat_id: u32,
|
||||
flags: u32,
|
||||
marker1before: u32,
|
||||
_marker1before: u32,
|
||||
) -> *mut dc_array::dc_array_t {
|
||||
if context.is_null() {
|
||||
eprintln!("ignoring careless call to dc_get_chat_msgs()");
|
||||
return ptr::null_mut();
|
||||
}
|
||||
let ctx = &*context;
|
||||
let marker_flag = if marker1before <= DC_MSG_ID_LAST_SPECIAL {
|
||||
None
|
||||
} else {
|
||||
Some(MsgId::new(marker1before))
|
||||
};
|
||||
|
||||
block_on(async move {
|
||||
Box::into_raw(Box::new(
|
||||
chat::get_chat_msgs(ctx, ChatId::new(chat_id), flags, marker_flag)
|
||||
chat::get_chat_msgs(ctx, ChatId::new(chat_id), flags)
|
||||
.await
|
||||
.unwrap_or_log_default(ctx, "failed to get chat msgs")
|
||||
.into(),
|
||||
@@ -1252,7 +1378,10 @@ pub unsafe extern "C" fn dc_get_chat_contacts(
|
||||
let arr = dc_array_t::from(
|
||||
chat::get_chat_contacts(ctx, ChatId::new(chat_id))
|
||||
.await
|
||||
.unwrap_or_log_default(ctx, "Failed get_chat_contacts"),
|
||||
.unwrap_or_log_default(ctx, "Failed get_chat_contacts")
|
||||
.iter()
|
||||
.map(|id| id.to_u32())
|
||||
.collect::<Vec<u32>>(),
|
||||
);
|
||||
Box::into_raw(Box::new(arr))
|
||||
})
|
||||
@@ -1362,7 +1491,7 @@ pub unsafe extern "C" fn dc_is_contact_in_chat(
|
||||
block_on(chat::is_contact_in_chat(
|
||||
ctx,
|
||||
ChatId::new(chat_id),
|
||||
contact_id,
|
||||
ContactId::new(contact_id),
|
||||
))
|
||||
.log_err(ctx, "is_contact_in_chat failed")
|
||||
.unwrap_or_default() as libc::c_int
|
||||
@@ -1383,7 +1512,7 @@ pub unsafe extern "C" fn dc_add_contact_to_chat(
|
||||
block_on(chat::add_contact_to_chat(
|
||||
ctx,
|
||||
ChatId::new(chat_id),
|
||||
contact_id,
|
||||
ContactId::new(contact_id),
|
||||
))
|
||||
.log_err(ctx, "Failed to add contact")
|
||||
.is_ok() as libc::c_int
|
||||
@@ -1404,7 +1533,7 @@ pub unsafe extern "C" fn dc_remove_contact_from_chat(
|
||||
block_on(chat::remove_contact_from_chat(
|
||||
ctx,
|
||||
ChatId::new(chat_id),
|
||||
contact_id,
|
||||
ContactId::new(contact_id),
|
||||
))
|
||||
.log_err(ctx, "Failed to remove contact")
|
||||
.is_ok() as libc::c_int
|
||||
@@ -1651,6 +1780,27 @@ pub unsafe extern "C" fn dc_forward_msgs(
|
||||
})
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn dc_resend_msgs(
|
||||
context: *mut dc_context_t,
|
||||
msg_ids: *const u32,
|
||||
msg_cnt: libc::c_int,
|
||||
) -> libc::c_int {
|
||||
if context.is_null() || msg_ids.is_null() || msg_cnt <= 0 {
|
||||
eprintln!("ignoring careless call to dc_resend_msgs()");
|
||||
return 0;
|
||||
}
|
||||
let ctx = &*context;
|
||||
let msg_ids = convert_and_prune_message_ids(msg_ids, msg_cnt);
|
||||
|
||||
if let Err(err) = block_on(chat::resend_msgs(ctx, &msg_ids)) {
|
||||
error!(ctx, "Resending failed: {}", err);
|
||||
0
|
||||
} else {
|
||||
1
|
||||
}
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn dc_markseen_msgs(
|
||||
context: *mut dc_context_t,
|
||||
@@ -1736,10 +1886,11 @@ pub unsafe extern "C" fn dc_lookup_contact_id_by_addr(
|
||||
let ctx = &*context;
|
||||
|
||||
block_on(async move {
|
||||
Contact::lookup_id_by_addr(ctx, to_string_lossy(addr), Origin::IncomingReplyTo)
|
||||
Contact::lookup_id_by_addr(ctx, &to_string_lossy(addr), Origin::IncomingReplyTo)
|
||||
.await
|
||||
.unwrap_or_log_default(ctx, "failed to lookup id")
|
||||
.unwrap_or(0)
|
||||
.map(|id| id.to_u32())
|
||||
.unwrap_or_default()
|
||||
})
|
||||
}
|
||||
|
||||
@@ -1759,6 +1910,7 @@ pub unsafe extern "C" fn dc_create_contact(
|
||||
block_on(async move {
|
||||
Contact::create(ctx, &name, &to_string_lossy(addr))
|
||||
.await
|
||||
.map(|id| id.to_u32())
|
||||
.unwrap_or(0)
|
||||
})
|
||||
}
|
||||
@@ -1796,8 +1948,10 @@ pub unsafe extern "C" fn dc_get_contacts(
|
||||
let query = to_opt_string_lossy(query);
|
||||
|
||||
block_on(async move {
|
||||
match Contact::get_all(ctx, flags, query).await {
|
||||
Ok(contacts) => Box::into_raw(Box::new(dc_array_t::from(contacts))),
|
||||
match Contact::get_all(ctx, flags, query.as_deref()).await {
|
||||
Ok(contacts) => Box::into_raw(Box::new(dc_array_t::from(
|
||||
contacts.iter().map(|id| id.to_u32()).collect::<Vec<u32>>(),
|
||||
))),
|
||||
Err(_) => ptr::null_mut(),
|
||||
}
|
||||
})
|
||||
@@ -1834,7 +1988,10 @@ pub unsafe extern "C" fn dc_get_blocked_contacts(
|
||||
Contact::get_all_blocked(ctx)
|
||||
.await
|
||||
.log_err(ctx, "Can't get blocked contacts")
|
||||
.unwrap_or_default(),
|
||||
.unwrap_or_default()
|
||||
.iter()
|
||||
.map(|id| id.to_u32())
|
||||
.collect::<Vec<u32>>(),
|
||||
)))
|
||||
})
|
||||
}
|
||||
@@ -1845,7 +2002,8 @@ pub unsafe extern "C" fn dc_block_contact(
|
||||
contact_id: u32,
|
||||
block: libc::c_int,
|
||||
) {
|
||||
if context.is_null() || contact_id <= constants::DC_CONTACT_ID_LAST_SPECIAL as u32 {
|
||||
let contact_id = ContactId::new(contact_id);
|
||||
if context.is_null() || contact_id.is_special() {
|
||||
eprintln!("ignoring careless call to dc_block_contact()");
|
||||
return;
|
||||
}
|
||||
@@ -1875,7 +2033,7 @@ pub unsafe extern "C" fn dc_get_contact_encrinfo(
|
||||
let ctx = &*context;
|
||||
|
||||
block_on(async move {
|
||||
Contact::get_encrinfo(ctx, contact_id)
|
||||
Contact::get_encrinfo(ctx, ContactId::new(contact_id))
|
||||
.await
|
||||
.map(|s| s.strdup())
|
||||
.unwrap_or_else(|e| {
|
||||
@@ -1890,7 +2048,8 @@ pub unsafe extern "C" fn dc_delete_contact(
|
||||
context: *mut dc_context_t,
|
||||
contact_id: u32,
|
||||
) -> libc::c_int {
|
||||
if context.is_null() || contact_id <= constants::DC_CONTACT_ID_LAST_SPECIAL as u32 {
|
||||
let contact_id = ContactId::new(contact_id);
|
||||
if context.is_null() || contact_id.is_special() {
|
||||
eprintln!("ignoring careless call to dc_delete_contact()");
|
||||
return 0;
|
||||
}
|
||||
@@ -1916,7 +2075,7 @@ pub unsafe extern "C" fn dc_get_contact(
|
||||
let ctx = &*context;
|
||||
|
||||
block_on(async move {
|
||||
Contact::get_by_id(ctx, contact_id)
|
||||
Contact::get_by_id(ctx, ContactId::new(contact_id))
|
||||
.await
|
||||
.map(|contact| Box::into_raw(Box::new(ContactWrapper { context, contact })))
|
||||
.unwrap_or_else(|_| ptr::null_mut())
|
||||
@@ -1928,7 +2087,7 @@ pub unsafe extern "C" fn dc_imex(
|
||||
context: *mut dc_context_t,
|
||||
what_raw: libc::c_int,
|
||||
param1: *const libc::c_char,
|
||||
_param2: *const libc::c_char,
|
||||
param2: *const libc::c_char,
|
||||
) {
|
||||
if context.is_null() {
|
||||
eprintln!("ignoring careless call to dc_imex()");
|
||||
@@ -1941,12 +2100,13 @@ pub unsafe extern "C" fn dc_imex(
|
||||
return;
|
||||
}
|
||||
};
|
||||
let passphrase = to_opt_string_lossy(param2);
|
||||
|
||||
let ctx = &*context;
|
||||
|
||||
if let Some(param1) = to_opt_string_lossy(param1) {
|
||||
spawn(async move {
|
||||
imex::imex(ctx, what, param1.as_ref())
|
||||
imex::imex(ctx, what, param1.as_ref(), passphrase)
|
||||
.await
|
||||
.log_err(ctx, "IMEX failed")
|
||||
});
|
||||
@@ -2075,6 +2235,27 @@ pub unsafe extern "C" fn dc_get_securejoin_qr(
|
||||
.strdup()
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn dc_get_securejoin_qr_svg(
|
||||
context: *mut dc_context_t,
|
||||
chat_id: u32,
|
||||
) -> *mut libc::c_char {
|
||||
if context.is_null() {
|
||||
eprintln!("ignoring careless call to generate_verification_qr()");
|
||||
return "".strdup();
|
||||
}
|
||||
let ctx = &*context;
|
||||
let chat_id = if chat_id == 0 {
|
||||
None
|
||||
} else {
|
||||
Some(ChatId::new(chat_id))
|
||||
};
|
||||
|
||||
block_on(get_securejoin_qr_svg(ctx, chat_id))
|
||||
.unwrap_or_else(|_| "".to_string())
|
||||
.strdup()
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn dc_join_securejoin(
|
||||
context: *mut dc_context_t,
|
||||
@@ -2317,7 +2498,7 @@ pub unsafe extern "C" fn dc_array_get_contact_id(
|
||||
return 0;
|
||||
}
|
||||
|
||||
(*array).get_location(index).contact_id
|
||||
(*array).get_location(index).contact_id.to_u32()
|
||||
}
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn dc_array_get_msg_id(
|
||||
@@ -2431,7 +2612,14 @@ pub unsafe extern "C" fn dc_chatlist_get_chat_id(
|
||||
return 0;
|
||||
}
|
||||
let ffi_list = &*chatlist;
|
||||
ffi_list.list.get_chat_id(index as usize).to_u32()
|
||||
let ctx = &*ffi_list.context;
|
||||
match ffi_list.list.get_chat_id(index as usize) {
|
||||
Ok(chat_id) => chat_id.to_u32(),
|
||||
Err(err) => {
|
||||
warn!(ctx, "get_chat_id failed: {}", err);
|
||||
0
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
@@ -2826,7 +3014,7 @@ pub unsafe extern "C" fn dc_msg_get_from_id(msg: *mut dc_msg_t) -> u32 {
|
||||
return 0;
|
||||
}
|
||||
let ffi_msg = &*msg;
|
||||
ffi_msg.message.get_from_id()
|
||||
ffi_msg.message.get_from_id().to_u32()
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
@@ -2948,6 +3136,61 @@ pub unsafe extern "C" fn dc_msg_get_filename(msg: *mut dc_msg_t) -> *mut libc::c
|
||||
ffi_msg.message.get_filename().unwrap_or_default().strdup()
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn dc_msg_get_webxdc_blob(
|
||||
msg: *mut dc_msg_t,
|
||||
filename: *const libc::c_char,
|
||||
ret_bytes: *mut libc::size_t,
|
||||
) -> *mut libc::c_char {
|
||||
if msg.is_null() || filename.is_null() || ret_bytes.is_null() {
|
||||
eprintln!("ignoring careless call to dc_msg_get_webxdc_blob()");
|
||||
return ptr::null_mut();
|
||||
}
|
||||
let ffi_msg = &*msg;
|
||||
let ctx = &*ffi_msg.context;
|
||||
let blob = block_on(async move {
|
||||
ffi_msg
|
||||
.message
|
||||
.get_webxdc_blob(ctx, &to_string_lossy(filename))
|
||||
.await
|
||||
});
|
||||
match blob {
|
||||
Ok(blob) => {
|
||||
*ret_bytes = blob.len();
|
||||
let ptr = libc::malloc(*ret_bytes);
|
||||
libc::memcpy(ptr, blob.as_ptr() as *mut libc::c_void, *ret_bytes);
|
||||
ptr as *mut libc::c_char
|
||||
}
|
||||
Err(err) => {
|
||||
eprintln!("failed read blob from archive: {}", err);
|
||||
ptr::null_mut()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn dc_msg_get_webxdc_info(msg: *mut dc_msg_t) -> *mut libc::c_char {
|
||||
if msg.is_null() {
|
||||
eprintln!("ignoring careless call to dc_msg_get_webxdc_info()");
|
||||
return "".strdup();
|
||||
}
|
||||
let ffi_msg = &*msg;
|
||||
let ctx = &*ffi_msg.context;
|
||||
|
||||
block_on(async move {
|
||||
let info = match ffi_msg.message.get_webxdc_info(ctx).await {
|
||||
Ok(info) => info,
|
||||
Err(err) => {
|
||||
error!(ctx, "dc_msg_get_webxdc_info() failed to get info: {}", err);
|
||||
return "".strdup();
|
||||
}
|
||||
};
|
||||
serde_json::to_string(&info)
|
||||
.unwrap_or_log_default(ctx, "dc_msg_get_webxdc_info() failed to serialise to json")
|
||||
.strdup()
|
||||
})
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn dc_msg_get_filemime(msg: *mut dc_msg_t) -> *mut libc::c_char {
|
||||
if msg.is_null() {
|
||||
@@ -3337,7 +3580,8 @@ pub unsafe extern "C" fn dc_msg_latefiling_mediasize(
|
||||
ffi_msg
|
||||
.message
|
||||
.latefiling_mediasize(ctx, width, height, duration)
|
||||
});
|
||||
})
|
||||
.ok_or_log_msg(ctx, "Cannot set media size");
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
@@ -3360,17 +3604,21 @@ pub unsafe extern "C" fn dc_msg_set_quote(msg: *mut dc_msg_t, quote: *const dc_m
|
||||
return;
|
||||
}
|
||||
let ffi_msg = &mut *msg;
|
||||
let ffi_quote = &*quote;
|
||||
|
||||
if ffi_msg.context != ffi_quote.context {
|
||||
eprintln!("ignoring attempt to quote message from a different context");
|
||||
return;
|
||||
}
|
||||
let quote_msg = if quote.is_null() {
|
||||
None
|
||||
} else {
|
||||
let ffi_quote = &*quote;
|
||||
if ffi_msg.context != ffi_quote.context {
|
||||
eprintln!("ignoring attempt to quote message from a different context");
|
||||
return;
|
||||
}
|
||||
Some(&ffi_quote.message)
|
||||
};
|
||||
|
||||
block_on(async move {
|
||||
ffi_msg
|
||||
.message
|
||||
.set_quote(&*ffi_msg.context, &ffi_quote.message)
|
||||
.set_quote(&*ffi_msg.context, quote_msg)
|
||||
.await
|
||||
.log_err(&*ffi_msg.context, "failed to set quote")
|
||||
.ok();
|
||||
@@ -3413,6 +3661,39 @@ pub unsafe extern "C" fn dc_msg_get_quoted_msg(msg: *const dc_msg_t) -> *mut dc_
|
||||
}
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn dc_msg_get_parent(msg: *const dc_msg_t) -> *mut dc_msg_t {
|
||||
if msg.is_null() {
|
||||
eprintln!("ignoring careless call to dc_msg_get_parent()");
|
||||
return ptr::null_mut();
|
||||
}
|
||||
let ffi_msg: &MessageWrapper = &*msg;
|
||||
let context = &*ffi_msg.context;
|
||||
let res = block_on(async move {
|
||||
ffi_msg
|
||||
.message
|
||||
.parent(context)
|
||||
.await
|
||||
.log_err(context, "failed to get parent message")
|
||||
.unwrap_or(None)
|
||||
});
|
||||
|
||||
match res {
|
||||
Some(message) => Box::into_raw(Box::new(MessageWrapper { context, message })),
|
||||
None => ptr::null_mut(),
|
||||
}
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn dc_msg_force_plaintext(msg: *mut dc_msg_t) {
|
||||
if msg.is_null() {
|
||||
eprintln!("ignoring careless call to dc_msg_force_plaintext()");
|
||||
return;
|
||||
}
|
||||
let ffi_msg = &mut *msg;
|
||||
ffi_msg.message.force_plaintext();
|
||||
}
|
||||
|
||||
// dc_contact_t
|
||||
|
||||
/// FFI struct for [dc_contact_t]
|
||||
@@ -3445,7 +3726,7 @@ pub unsafe extern "C" fn dc_contact_get_id(contact: *mut dc_contact_t) -> u32 {
|
||||
return 0;
|
||||
}
|
||||
let ffi_contact = &*contact;
|
||||
ffi_contact.contact.get_id()
|
||||
ffi_contact.contact.get_id().to_u32()
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
@@ -3722,6 +4003,25 @@ pub unsafe extern "C" fn dc_provider_new_from_email(
|
||||
}
|
||||
let addr = to_string_lossy(addr);
|
||||
|
||||
let ctx = &*context;
|
||||
|
||||
match block_on(provider::get_provider_info(ctx, addr.as_str(), true)) {
|
||||
Some(provider) => provider,
|
||||
None => ptr::null_mut(),
|
||||
}
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn dc_provider_new_from_email_with_dns(
|
||||
context: *const dc_context_t,
|
||||
addr: *const libc::c_char,
|
||||
) -> *const dc_provider_t {
|
||||
if context.is_null() || addr.is_null() {
|
||||
eprintln!("ignoring careless call to dc_provider_new_from_email_with_dns()");
|
||||
return ptr::null();
|
||||
}
|
||||
let addr = to_string_lossy(addr);
|
||||
|
||||
let ctx = &*context;
|
||||
let socks5_enabled = block_on(async move {
|
||||
ctx.get_config_bool(config::Config::Socks5Enabled)
|
||||
@@ -3731,7 +4031,11 @@ pub unsafe extern "C" fn dc_provider_new_from_email(
|
||||
|
||||
match socks5_enabled {
|
||||
Ok(socks5_enabled) => {
|
||||
match block_on(provider::get_provider_info(addr.as_str(), socks5_enabled)) {
|
||||
match block_on(provider::get_provider_info(
|
||||
ctx,
|
||||
addr.as_str(),
|
||||
socks5_enabled,
|
||||
)) {
|
||||
Some(provider) => provider,
|
||||
None => ptr::null_mut(),
|
||||
}
|
||||
@@ -3790,11 +4094,11 @@ pub unsafe extern "C" fn dc_provider_unref(provider: *mut dc_provider_t) {
|
||||
/// Reader-writer lock wrapper for accounts manager to guarantee thread safety when using
|
||||
/// `dc_accounts_t` in multiple threads at once.
|
||||
pub struct AccountsWrapper {
|
||||
inner: RwLock<Accounts>,
|
||||
inner: Arc<RwLock<Accounts>>,
|
||||
}
|
||||
|
||||
impl Deref for AccountsWrapper {
|
||||
type Target = RwLock<Accounts>;
|
||||
type Target = Arc<RwLock<Accounts>>;
|
||||
|
||||
fn deref(&self) -> &Self::Target {
|
||||
&self.inner
|
||||
@@ -3803,7 +4107,7 @@ impl Deref for AccountsWrapper {
|
||||
|
||||
impl AccountsWrapper {
|
||||
fn new(accounts: Accounts) -> Self {
|
||||
let inner = RwLock::new(accounts);
|
||||
let inner = Arc::new(RwLock::new(accounts));
|
||||
Self { inner }
|
||||
}
|
||||
}
|
||||
@@ -3813,7 +4117,7 @@ pub type dc_accounts_t = AccountsWrapper;
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn dc_accounts_new(
|
||||
os_name: *const libc::c_char,
|
||||
_os_name: *const libc::c_char,
|
||||
dbfile: *const libc::c_char,
|
||||
) -> *mut dc_accounts_t {
|
||||
setup_panic!();
|
||||
@@ -3823,13 +4127,7 @@ pub unsafe extern "C" fn dc_accounts_new(
|
||||
return ptr::null_mut();
|
||||
}
|
||||
|
||||
let os_name = if os_name.is_null() {
|
||||
String::from("DcFFI")
|
||||
} else {
|
||||
to_string_lossy(os_name)
|
||||
};
|
||||
|
||||
let accs = block_on(Accounts::new(os_name, as_path(dbfile).to_path_buf().into()));
|
||||
let accs = block_on(Accounts::new(as_path(dbfile).to_path_buf().into()));
|
||||
|
||||
match accs {
|
||||
Ok(accs) => Box::into_raw(Box::new(AccountsWrapper::new(accs))),
|
||||
@@ -3934,6 +4232,30 @@ pub unsafe extern "C" fn dc_accounts_add_account(accounts: *mut dc_accounts_t) -
|
||||
})
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn dc_accounts_add_closed_account(accounts: *mut dc_accounts_t) -> u32 {
|
||||
if accounts.is_null() {
|
||||
eprintln!("ignoring careless call to dc_accounts_add_closed_account()");
|
||||
return 0;
|
||||
}
|
||||
|
||||
let accounts = &mut *accounts;
|
||||
|
||||
block_on(async move {
|
||||
let mut accounts = accounts.write().await;
|
||||
match accounts.add_closed_account().await {
|
||||
Ok(id) => id,
|
||||
Err(err) => {
|
||||
accounts.emit_event(EventType::Error(format!(
|
||||
"Failed to add account: {:#}",
|
||||
err
|
||||
)));
|
||||
0
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn dc_accounts_remove_account(
|
||||
accounts: *mut dc_accounts_t,
|
||||
@@ -4060,7 +4382,7 @@ pub unsafe extern "C" fn dc_accounts_maybe_network_lost(accounts: *mut dc_accoun
|
||||
block_on(async move { accounts.write().await.maybe_network_lost().await });
|
||||
}
|
||||
|
||||
pub type dc_accounts_event_emitter_t = deltachat::accounts::EventEmitter;
|
||||
pub type dc_accounts_event_emitter_t = EventEmitter;
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn dc_accounts_get_event_emitter(
|
||||
@@ -4103,3 +4425,77 @@ pub unsafe extern "C" fn dc_accounts_get_next_event(
|
||||
.map(|ev| Box::into_raw(Box::new(ev)))
|
||||
.unwrap_or_else(ptr::null_mut)
|
||||
}
|
||||
|
||||
#[cfg(feature = "jsonrpc")]
|
||||
mod jsonrpc {
|
||||
use super::*;
|
||||
use deltachat_jsonrpc::api::CommandApi;
|
||||
use deltachat_jsonrpc::yerpc::{MessageHandle, RpcHandle};
|
||||
|
||||
pub struct dc_jsonrpc_instance_t {
|
||||
receiver: async_std::channel::Receiver<deltachat_jsonrpc::yerpc::Message>,
|
||||
handle: MessageHandle<CommandApi>,
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn dc_jsonrpc_init(
|
||||
account_manager: *mut dc_accounts_t,
|
||||
) -> *mut dc_jsonrpc_instance_t {
|
||||
if account_manager.is_null() {
|
||||
eprintln!("ignoring careless call to dc_jsonrpc_init()");
|
||||
return ptr::null_mut();
|
||||
}
|
||||
|
||||
let cmd_api =
|
||||
deltachat_jsonrpc::api::CommandApi::new_from_arc((*account_manager).inner.clone());
|
||||
|
||||
let (request_handle, receiver) = RpcHandle::new();
|
||||
let handle = MessageHandle::new(request_handle, cmd_api);
|
||||
|
||||
let instance = dc_jsonrpc_instance_t { receiver, handle };
|
||||
|
||||
Box::into_raw(Box::new(instance))
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn dc_jsonrpc_unref(jsonrpc_instance: *mut dc_jsonrpc_instance_t) {
|
||||
if jsonrpc_instance.is_null() {
|
||||
eprintln!("ignoring careless call to dc_jsonrpc_unref()");
|
||||
return;
|
||||
}
|
||||
|
||||
Box::from_raw(jsonrpc_instance);
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn dc_jsonrpc_request(
|
||||
jsonrpc_instance: *mut dc_jsonrpc_instance_t,
|
||||
request: *const libc::c_char,
|
||||
) {
|
||||
if jsonrpc_instance.is_null() || request.is_null() {
|
||||
eprintln!("ignoring careless call to dc_jsonrpc_request()");
|
||||
return;
|
||||
}
|
||||
|
||||
let api = &*jsonrpc_instance;
|
||||
let handle = &api.handle;
|
||||
let request = to_string_lossy(request);
|
||||
async_std::task::spawn(async move {
|
||||
handle.handle_message(&request).await;
|
||||
});
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn dc_jsonrpc_next_response(
|
||||
jsonrpc_instance: *mut dc_jsonrpc_instance_t,
|
||||
) -> *mut libc::c_char {
|
||||
if jsonrpc_instance.is_null() {
|
||||
eprintln!("ignoring careless call to dc_jsonrpc_next_response()");
|
||||
return ptr::null_mut();
|
||||
}
|
||||
let api = &*jsonrpc_instance;
|
||||
async_std::task::block_on(api.receiver.recv())
|
||||
.map(|result| serde_json::to_string(&result).unwrap_or_default().strdup())
|
||||
.unwrap_or(ptr::null_mut())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -111,19 +111,19 @@ impl Lot {
|
||||
match self {
|
||||
Self::Summary(_) => Default::default(),
|
||||
Self::Qr(qr) => match qr {
|
||||
Qr::AskVerifyContact { contact_id, .. } => *contact_id,
|
||||
Qr::AskVerifyContact { contact_id, .. } => contact_id.to_u32(),
|
||||
Qr::AskVerifyGroup { .. } => Default::default(),
|
||||
Qr::FprOk { contact_id } => *contact_id,
|
||||
Qr::FprMismatch { contact_id } => contact_id.unwrap_or_default(),
|
||||
Qr::FprOk { contact_id } => contact_id.to_u32(),
|
||||
Qr::FprMismatch { contact_id } => contact_id.unwrap_or_default().to_u32(),
|
||||
Qr::FprWithoutAddr { .. } => Default::default(),
|
||||
Qr::Account { .. } => Default::default(),
|
||||
Qr::WebrtcInstance { .. } => Default::default(),
|
||||
Qr::Addr { contact_id } => *contact_id,
|
||||
Qr::Addr { contact_id } => contact_id.to_u32(),
|
||||
Qr::Url { .. } => Default::default(),
|
||||
Qr::Text { .. } => Default::default(),
|
||||
Qr::WithdrawVerifyContact { contact_id, .. } => *contact_id,
|
||||
Qr::WithdrawVerifyContact { contact_id, .. } => contact_id.to_u32(),
|
||||
Qr::WithdrawVerifyGroup { .. } => Default::default(),
|
||||
Qr::ReviveVerifyContact { contact_id, .. } => *contact_id,
|
||||
Qr::ReviveVerifyContact { contact_id, .. } => contact_id.to_u32(),
|
||||
Qr::ReviveVerifyGroup { .. } => Default::default(),
|
||||
},
|
||||
Self::Error(_) => Default::default(),
|
||||
|
||||
3
deltachat-jsonrpc/.gitignore
vendored
Normal file
3
deltachat-jsonrpc/.gitignore
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
accounts/
|
||||
|
||||
.cargo
|
||||
39
deltachat-jsonrpc/Cargo.toml
Normal file
39
deltachat-jsonrpc/Cargo.toml
Normal file
@@ -0,0 +1,39 @@
|
||||
[package]
|
||||
name = "deltachat-jsonrpc"
|
||||
version = "1.86.0"
|
||||
authors = ["Delta Chat Developers (ML) <delta@codespeak.net>"]
|
||||
edition = "2021"
|
||||
default-run = "webserver"
|
||||
license = "MPL-2.0"
|
||||
|
||||
[[bin]]
|
||||
name = "webserver"
|
||||
path = "src/webserver.rs"
|
||||
required-features = ["webserver"]
|
||||
|
||||
[dependencies]
|
||||
anyhow = "1"
|
||||
async-std = { version = "1", features = ["attributes"] }
|
||||
deltachat = { path = ".." }
|
||||
num-traits = "0.2"
|
||||
serde = { version = "1.0", features = ["derive"] }
|
||||
tempfile = "3.3.0"
|
||||
log = "0.4"
|
||||
async-channel = { version = "1.6.1" }
|
||||
futures = { version = "0.3.19" }
|
||||
serde_json = "1.0.75"
|
||||
yerpc = { git = "https://github.com/Frando/yerpc", features = ["anyhow"] }
|
||||
typescript-type-def = { git = "https://github.com/Frando/rust-typescript-type-def", branch = "yerpc", features = ["json_value"] }
|
||||
# optional, depended on features
|
||||
env_logger = { version = "0.9.0", optional = true }
|
||||
tide = { version = "0.16.0", optional = true }
|
||||
tide-websockets = { version = "0.4.0", optional = true }
|
||||
yerpc-tide = { git = "https://github.com/Frando/yerpc", optional = true }
|
||||
|
||||
|
||||
[features]
|
||||
default = []
|
||||
webserver = ["env_logger", "tide", "tide-websockets", "yerpc-tide"]
|
||||
|
||||
[profile.release]
|
||||
lto = true
|
||||
75
deltachat-jsonrpc/README.MD
Normal file
75
deltachat-jsonrpc/README.MD
Normal file
@@ -0,0 +1,75 @@
|
||||
# deltachat-jsonrpc
|
||||
|
||||
## Build Requirements
|
||||
|
||||
- Linux or Mac, scrips make use of features like `>` pipes and `&&` (maybe the newer versions of powershell support them, but I didn't try that.)
|
||||
- rust (installed via rustup)
|
||||
|
||||
## Start the webserver
|
||||
|
||||
The webserver is an example usage. Goal of it is to be usable both as example and as base for deltachat-kaiOS.
|
||||
|
||||
```sh
|
||||
RUST_LOG=info cargo run --features webserver
|
||||
```
|
||||
|
||||
## Generate Typescript Bindings
|
||||
|
||||
```sh
|
||||
cd typescript
|
||||
npm i
|
||||
npm run build
|
||||
```
|
||||
|
||||
## Run the development example
|
||||
|
||||
Mac
|
||||
|
||||
```sh
|
||||
alias firefox=/Applications/Firefox.app/Contents/MacOS/firefox
|
||||
npm run example:build && firefox --devtools $(pwd)/example/browser-example.html
|
||||
```
|
||||
|
||||
Linux:
|
||||
|
||||
```sh
|
||||
npm run example:run
|
||||
```
|
||||
|
||||
## Compiling server for kaiOS or android:
|
||||
|
||||
```sh
|
||||
cross build --features=webserver --target armv7-linux-androideabi --release
|
||||
```
|
||||
|
||||
## Run the tests
|
||||
|
||||
### Rust tests
|
||||
|
||||
```
|
||||
cargo test --features=webserver
|
||||
```
|
||||
|
||||
### Typescript
|
||||
|
||||
```
|
||||
cd typescript
|
||||
npm run test
|
||||
```
|
||||
|
||||
For the online tests to run you need a test account token for a mailadm instance,
|
||||
you can use docker to spin up a local instance: https://github.com/deltachat/docker-mailadm
|
||||
|
||||
> set the env var `DCC_NEW_TMP_EMAIL` to your mailadm token: example:
|
||||
> `DCC_NEW_TMP_EMAIL=https://testrun.org/new_email?t=1h_195dksa6544`
|
||||
|
||||
If your test fail with server shutdown at the start, then you might have a process from a last run still running probably and you need to kill that process manually to continue.
|
||||
|
||||
#### Test Coverage
|
||||
|
||||
You can test coverage with `npm run coverage`, but you need to have `DCC_NEW_TMP_EMAIL` set, otherwise the result will be useless because some functions can only be tested with the online tests.
|
||||
|
||||
> If you are offline and want to see the coverage results anyway (even though they are NOT correct), you can bypass the error with `COVERAGE_OFFLINE=1 npm run coverage`
|
||||
|
||||
Open `coverage/index.html` for a detailed report.
|
||||
`bindings.ts` is probably the most interesting file for coverage, because it describes the api functions.
|
||||
347
deltachat-jsonrpc/TODO.md
Normal file
347
deltachat-jsonrpc/TODO.md
Normal file
@@ -0,0 +1,347 @@
|
||||
## Core system
|
||||
|
||||
- [X] Base structure of JSON API code
|
||||
- [X] Implement the first methods for testing + the code that should later be generated by the proc macro
|
||||
- [X] Create the proc macro
|
||||
- [X] json api
|
||||
- [X] ts types
|
||||
- [X] arguments (no args, one argument, multiple args)
|
||||
- [X] return type
|
||||
- [X] custom types as type aliases that ts file looks prettier
|
||||
|
||||
|
||||
## Pre - MVP
|
||||
|
||||
- [X] Web socket server
|
||||
- [WIP] Web socket client (ts)
|
||||
- [X] backend connection state changed events
|
||||
- [X] Reconnect on connection loss / connection state
|
||||
- [ ] find a way to type the event emitter callback functions
|
||||
- [X] Events
|
||||
|
||||
## MVP
|
||||
|
||||
- [X] mocha integration test for ts api
|
||||
- [X] basic tests
|
||||
- [X] advanced / "online tests" (mailadm for burner accounts)
|
||||
- [ ] coverage for a majority of the API
|
||||
- [ ] Blobs served
|
||||
- [ ] Blob upload (for attachments, setting profile-picture, importing backup and so on)
|
||||
- [ ] Web push API? At least some kind of notification hook closure this lib can accept.
|
||||
|
||||
## Other Ideas
|
||||
|
||||
- [ ] make sure there can only be one connection at a time to the ws
|
||||
- why? , it could give problems if its commanded from multiple connections
|
||||
- [ ] encrypted connection?
|
||||
- [ ] authenticated connection?
|
||||
- [ ] Look into unit-testing for the proc macros?
|
||||
- [ ] proc macro taking over doc comments to generated typescript file
|
||||
- [X] GH action for tests (rust and typescript)
|
||||
- [X] rust test
|
||||
- [X] rust fmt
|
||||
- [X] rust clippy
|
||||
- [X] tsc check
|
||||
- [X] prettier
|
||||
- [X] mocha
|
||||
- [X] scripts to check&fix prettier formatting
|
||||
|
||||
|
||||
|
||||
## Apis
|
||||
|
||||
replicate desktop api feature set:
|
||||
|
||||
(this feature set is based on desktop version `1.20`, needs to be updated in the future)
|
||||
|
||||
```rs
|
||||
|
||||
|
||||
struct sendMessageParams {
|
||||
text: Option<String>,
|
||||
filename: Option<String>, // TODO we need to think about blobs some more
|
||||
location: Option<(u32,u32)>,
|
||||
quote_message_id: Option<u32>,
|
||||
}
|
||||
|
||||
struct QrCodeResponse = {
|
||||
state: u32 // also enum in reality, for simlicity u32 here
|
||||
id: u32
|
||||
text1: String
|
||||
}
|
||||
|
||||
impl Api {
|
||||
|
||||
// root ---------------------------------------------------------------
|
||||
|
||||
// NEEDS_THE_BLOB_QUESTION_ANSWERED_EVENTUALLY
|
||||
async fn sc_set_profile_picture(&self, new_image: String) -> Result<()> {}
|
||||
|
||||
// NEEDS_THE_BLOB_QUESTION_ANSWERED_EVENTUALLY
|
||||
// 'getProfilePicture' equals to `dc.getContact(C.DC_CONTACT_ID_SELF).getProfileImage()` or `dc.get_config("selfavatar")`
|
||||
|
||||
async fn sc_join_secure_join(&self, qrCode: String) -> Result<u32> {}
|
||||
async fn sc_stop_ongoing_process(&self) -> Result<u32> {}
|
||||
async fn sc_check_qr_code(&self, qrCode: String) -> Result<QrCodeResponse> {}
|
||||
|
||||
// login ----------------------------------------------------
|
||||
|
||||
// INFO: login functions need to call stop&start io where applicable
|
||||
|
||||
// login.newLogin:
|
||||
// do instead in frontend:
|
||||
// 1. call `add_account`
|
||||
// 2. call `select_account`
|
||||
// 3. set credentials via set config
|
||||
// 4. call `sc_configure`
|
||||
|
||||
// login.getLogins - is already implemented: `get_all_accounts`
|
||||
|
||||
// login.loadAccount - Basically `select_account`
|
||||
|
||||
// login.logout -> TODO: unselect account, which isn't implemented in the core yet
|
||||
|
||||
// login.forgetAccount -> `remove_account`
|
||||
|
||||
// login.getLastLoggedInAccount -> `get_selected_account_id`
|
||||
|
||||
// login.updateCredentials -> do instead: set config then call `sc_configure`
|
||||
|
||||
// backup -------------------------------------------------------------
|
||||
|
||||
// INFO: backup functions need to call stop&start io
|
||||
|
||||
// NEEDS_THE_BLOB_QUESTION_ANSWERED_EVENTUALLY
|
||||
async fn sc_backup_export(&self, out_dir: String) -> Result<()> {}
|
||||
// NEEDS_THE_BLOB_QUESTION_ANSWERED_EVENTUALLY
|
||||
async fn sc_backup_import(&self, file: String) -> Result<()> {} // will not return the same as in desktop because this function imports backup to the current context unlike it was in desktop
|
||||
|
||||
// chatList -----------------------------------------------------------
|
||||
|
||||
// chatList.selectChat - will be removed from desktop
|
||||
// chatList.getSelectedChatId - will be removed from desktop
|
||||
// chatList.onChatModified - will be removed from desktop
|
||||
|
||||
async fn sc_chatlist_get_general_fresh_message_counter(&self) -> Result<u32> // this method might be used for a favicon badge counter
|
||||
|
||||
// contacts ------------------------------------------------------------
|
||||
|
||||
async fn sc_contacts_change_nickname(&self, contact_id: u32, new_name: String) -> Result<()>
|
||||
|
||||
|
||||
// contacts.getChatIdByContactId - very similar to sc_contacts_create_chat_by_contact_id
|
||||
// contacts.getDMChatId - very similar to sc_contacts_create_chat_by_contact_id
|
||||
|
||||
async fn sc_contacts_get_encryption_info(&self, contact_id: u32) -> Result<String>
|
||||
|
||||
async fn sc_contacts_lookup_contact_id_by_addr(&self, email: String) -> Result<u32>
|
||||
|
||||
|
||||
}
|
||||
|
||||
```
|
||||
```ts
|
||||
|
||||
class DeltaRemote {
|
||||
// chat ---------------------------------------------------------------
|
||||
call(
|
||||
fnName: 'chat.getChatMedia',
|
||||
chatId: number,
|
||||
msgType1: number,
|
||||
msgType2: number
|
||||
): Promise<MessageType[]>
|
||||
call(fnName: 'chat.getEncryptionInfo', chatId: number): Promise<string>
|
||||
call(fnName: 'chat.getQrCode', chatId?: number): Promise<string>
|
||||
call(fnName: 'chat.leaveGroup', chatId: number): Promise<void>
|
||||
call(fnName: 'chat.setName', chatId: number, name: string): Promise<boolean>
|
||||
call(
|
||||
fnName: 'chat.modifyGroup',
|
||||
chatId: number,
|
||||
name: string,
|
||||
image: string,
|
||||
remove: number[],
|
||||
add: number[]
|
||||
): Promise<boolean>
|
||||
call(
|
||||
fnName: 'chat.addContactToChat',
|
||||
chatId: number,
|
||||
contactId: number
|
||||
): Promise<boolean>
|
||||
call(
|
||||
fnName: 'chat.setProfileImage',
|
||||
chatId: number,
|
||||
newImage: string
|
||||
): Promise<boolean>
|
||||
call(
|
||||
fnName: 'chat.setMuteDuration',
|
||||
chatId: number,
|
||||
duration: MuteDuration
|
||||
): Promise<boolean>
|
||||
call(
|
||||
fnName: 'chat.createGroupChat',
|
||||
verified: boolean,
|
||||
name: string
|
||||
): Promise<number>
|
||||
call(fnName: 'chat.delete', chatId: number): Promise<void>
|
||||
call(
|
||||
fnName: 'chat.setVisibility',
|
||||
chatId: number,
|
||||
visibility:
|
||||
| C.DC_CERTCK_AUTO
|
||||
| C.DC_CERTCK_STRICT
|
||||
| C.DC_CHAT_VISIBILITY_PINNED
|
||||
): Promise<void>
|
||||
call(fnName: 'chat.getChatContacts', chatId: number): Promise<number[]>
|
||||
call(fnName: 'chat.markNoticedChat', chatId: number): Promise<void>
|
||||
call(fnName: 'chat.getChatEphemeralTimer', chatId: number): Promise<number>
|
||||
call(
|
||||
fnName: 'chat.setChatEphemeralTimer',
|
||||
chatId: number,
|
||||
ephemeralTimer: number
|
||||
): Promise<void>
|
||||
call(fnName: 'chat.sendVideoChatInvitation', chatId: number): Promise<number>
|
||||
call(
|
||||
fnName: 'chat.decideOnContactRequest',
|
||||
messageId: number,
|
||||
decision:
|
||||
| C.DC_DECISION_START_CHAT
|
||||
| C.DC_DECISION_NOT_NOW
|
||||
| C.DC_DECISION_BLOCK
|
||||
): Promise<number>
|
||||
// locations ----------------------------------------------------------
|
||||
call(
|
||||
fnName: 'locations.setLocation',
|
||||
latitude: number,
|
||||
longitude: number,
|
||||
accuracy: number
|
||||
): Promise<void>
|
||||
call(
|
||||
fnName: 'locations.getLocations',
|
||||
chatId: number,
|
||||
contactId: number,
|
||||
timestampFrom: number,
|
||||
timestampTo: number
|
||||
): Promise<JsonLocations>
|
||||
|
||||
// NOTHING HERE that is called directly from the frontend, yet
|
||||
// messageList --------------------------------------------------------
|
||||
call(
|
||||
fnName: 'messageList.sendMessage',
|
||||
chatId: number,
|
||||
params: sendMessageParams
|
||||
): Promise<[number, MessageType | null]>
|
||||
call(
|
||||
fnName: 'messageList.sendSticker',
|
||||
chatId: number,
|
||||
stickerPath: string
|
||||
): Promise<void>
|
||||
call(fnName: 'messageList.deleteMessage', id: number): Promise<void>
|
||||
call(fnName: 'messageList.getMessageInfo', msgId: number): Promise<string>
|
||||
call(
|
||||
fnName: 'messageList.getDraft',
|
||||
chatId: number
|
||||
): Promise<MessageType | null>
|
||||
call(
|
||||
fnName: 'messageList.setDraft',
|
||||
chatId: number,
|
||||
{
|
||||
text,
|
||||
file,
|
||||
quotedMessageId,
|
||||
}: { text?: string; file?: string; quotedMessageId?: number }
|
||||
): Promise<void>
|
||||
call(
|
||||
fnName: 'messageList.messageIdToJson',
|
||||
id: number
|
||||
): Promise<{ msg: null } | MessageType>
|
||||
call(
|
||||
fnName: 'messageList.forwardMessage',
|
||||
msgId: number,
|
||||
chatId: number
|
||||
): Promise<void>
|
||||
call(
|
||||
fnName: 'messageList.searchMessages',
|
||||
query: string,
|
||||
chatId?: number
|
||||
): Promise<number[]>
|
||||
call(
|
||||
fnName: 'messageList.msgIds2SearchResultItems',
|
||||
msgIds: number[]
|
||||
): Promise<{ [id: number]: MessageSearchResult }>
|
||||
call(
|
||||
fnName: 'messageList.saveMessageHTML2Disk',
|
||||
messageId: number
|
||||
): Promise<string>
|
||||
// settings -----------------------------------------------------------
|
||||
call(fnName: 'settings.keysImport', directory: string): Promise<void>
|
||||
call(fnName: 'settings.keysExport', directory: string): Promise<void>
|
||||
call(
|
||||
fnName: 'settings.serverFlags',
|
||||
{
|
||||
mail_security,
|
||||
send_security,
|
||||
}: {
|
||||
mail_security?: string
|
||||
send_security?: string
|
||||
}
|
||||
): Promise<number | ''>
|
||||
call(
|
||||
fnName: 'settings.setDesktopSetting',
|
||||
key: keyof DesktopSettings,
|
||||
value: string | number | boolean
|
||||
): Promise<boolean>
|
||||
call(fnName: 'settings.getDesktopSettings'): Promise<DesktopSettings>
|
||||
call(
|
||||
fnName: 'settings.saveBackgroundImage',
|
||||
file: string,
|
||||
isDefaultPicture: boolean
|
||||
): Promise<string>
|
||||
call(
|
||||
fnName: 'settings.estimateAutodeleteCount',
|
||||
fromServer: boolean,
|
||||
seconds: number
|
||||
): Promise<number>
|
||||
// stickers -----------------------------------------------------------
|
||||
call(
|
||||
fnName: 'stickers.getStickers'
|
||||
): Promise<{
|
||||
[key: string]: string[]
|
||||
}> // todo move to extras? because its not directly elated to core
|
||||
// context ------------------------------------------------------------
|
||||
call(fnName: 'context.maybeNetwork'): Promise<void>
|
||||
// burner accounts ------------------------------------------------------------
|
||||
call(
|
||||
fnName: 'burnerAccounts.create',
|
||||
url: string
|
||||
): Promise<{ email: string; password: string }> // think about how to improve that api - probably use core api instead
|
||||
// extras -------------------------------------------------------------
|
||||
call(fnName: 'extras.getLocaleData', locale: string): Promise<LocaleData>
|
||||
call(fnName: 'extras.setLocale', locale: string): Promise<void>
|
||||
call(
|
||||
fnName: 'extras.getActiveTheme'
|
||||
): Promise<{
|
||||
theme: Theme
|
||||
data: string
|
||||
} | null>
|
||||
call(fnName: 'extras.setThemeFilePath', address: string): void
|
||||
call(fnName: 'extras.getAvailableThemes'): Promise<Theme[]>
|
||||
call(fnName: 'extras.setTheme', address: string): Promise<boolean>
|
||||
// catchall: ----------------------------------------------------------
|
||||
call(fnName: string): Promise<any>
|
||||
call(fnName: string, ...args: any[]): Promise<any> {
|
||||
return _callDcMethodAsync(fnName, ...args)
|
||||
}
|
||||
}
|
||||
|
||||
export const DeltaBackend = new DeltaRemote()
|
||||
```
|
||||
|
||||
|
||||
after that, or while doing it adjust api to be more complete
|
||||
|
||||
|
||||
|
||||
|
||||
TODO different test to simulate two devices:
|
||||
|
||||
to test autocrypt_initiate_key_transfer & autocrypt_continue_key_transfer
|
||||
154
deltachat-jsonrpc/src/api/events.rs
Normal file
154
deltachat-jsonrpc/src/api/events.rs
Normal file
@@ -0,0 +1,154 @@
|
||||
use deltachat::{Event, EventType};
|
||||
use serde::Serialize;
|
||||
use serde_json::{json, Value};
|
||||
use typescript_type_def::TypeDef;
|
||||
|
||||
pub fn event_to_json_rpc_notification(event: Event) -> Value {
|
||||
let (field1, field2): (Value, Value) = match &event.typ {
|
||||
// events with a single string in field1
|
||||
EventType::Info(txt)
|
||||
| EventType::SmtpConnected(txt)
|
||||
| EventType::ImapConnected(txt)
|
||||
| EventType::SmtpMessageSent(txt)
|
||||
| EventType::ImapMessageDeleted(txt)
|
||||
| EventType::ImapMessageMoved(txt)
|
||||
| EventType::NewBlobFile(txt)
|
||||
| EventType::DeletedBlobFile(txt)
|
||||
| EventType::Warning(txt)
|
||||
| EventType::Error(txt)
|
||||
| EventType::ErrorSelfNotInGroup(txt) => (json!(txt), Value::Null),
|
||||
EventType::ImexFileWritten(path) => (json!(path.to_str()), Value::Null),
|
||||
// single number
|
||||
EventType::MsgsNoticed(chat_id) | EventType::ChatModified(chat_id) => {
|
||||
(json!(chat_id), Value::Null)
|
||||
}
|
||||
EventType::ImexProgress(progress) => (json!(progress), Value::Null),
|
||||
// both fields contain numbers
|
||||
EventType::MsgsChanged { chat_id, msg_id }
|
||||
| EventType::IncomingMsg { chat_id, msg_id }
|
||||
| EventType::MsgDelivered { chat_id, msg_id }
|
||||
| EventType::MsgFailed { chat_id, msg_id }
|
||||
| EventType::MsgRead { chat_id, msg_id } => (json!(chat_id), json!(msg_id)),
|
||||
EventType::ChatEphemeralTimerModified { chat_id, timer } => (json!(chat_id), json!(timer)),
|
||||
EventType::SecurejoinInviterProgress {
|
||||
contact_id,
|
||||
progress,
|
||||
}
|
||||
| EventType::SecurejoinJoinerProgress {
|
||||
contact_id,
|
||||
progress,
|
||||
} => (json!(contact_id), json!(progress)),
|
||||
// field 1 number or null
|
||||
EventType::ContactsChanged(maybe_number) | EventType::LocationChanged(maybe_number) => (
|
||||
match maybe_number {
|
||||
Some(number) => json!(number),
|
||||
None => Value::Null,
|
||||
},
|
||||
Value::Null,
|
||||
),
|
||||
// number and maybe string
|
||||
EventType::ConfigureProgress { progress, comment } => (
|
||||
json!(progress),
|
||||
match comment {
|
||||
Some(content) => json!(content),
|
||||
None => Value::Null,
|
||||
},
|
||||
),
|
||||
EventType::ConnectivityChanged => (Value::Null, Value::Null),
|
||||
EventType::SelfavatarChanged => (Value::Null, Value::Null),
|
||||
EventType::WebxdcStatusUpdate {
|
||||
msg_id,
|
||||
status_update_serial,
|
||||
} => (json!(msg_id), json!(status_update_serial)),
|
||||
};
|
||||
|
||||
json!({
|
||||
"id": event_type_to_string(event.typ),
|
||||
"contextId": event.id,
|
||||
"field1": field1,
|
||||
"field2": field2
|
||||
})
|
||||
}
|
||||
|
||||
#[derive(Serialize, TypeDef)]
|
||||
pub enum EventTypeName {
|
||||
Info,
|
||||
SmtpConnected,
|
||||
ImapConnected,
|
||||
SmtpMessageSent,
|
||||
ImapMessageDeleted,
|
||||
ImapMessageMoved,
|
||||
NewBlobFile,
|
||||
DeletedBlobFile,
|
||||
Warning,
|
||||
Error,
|
||||
ErrorSelfNotInGroup,
|
||||
MsgsChanged,
|
||||
IncomingMsg,
|
||||
MsgsNoticed,
|
||||
MsgDelivered,
|
||||
MsgFailed,
|
||||
MsgRead,
|
||||
ChatModified,
|
||||
ChatEphemeralTimerModified,
|
||||
ContactsChanged,
|
||||
LocationChanged,
|
||||
ConfigureProgress,
|
||||
ImexProgress,
|
||||
ImexFileWritten,
|
||||
SecurejoinInviterProgress,
|
||||
SecurejoinJoinerProgress,
|
||||
ConnectivityChanged,
|
||||
SelfavatarChanged,
|
||||
WebxdcStatusUpdate,
|
||||
}
|
||||
|
||||
fn event_type_to_string(event: EventType) -> EventTypeName {
|
||||
use EventTypeName::*;
|
||||
match event {
|
||||
EventType::Info(_) => Info,
|
||||
EventType::SmtpConnected(_) => SmtpConnected,
|
||||
EventType::ImapConnected(_) => ImapConnected,
|
||||
EventType::SmtpMessageSent(_) => SmtpMessageSent,
|
||||
EventType::ImapMessageDeleted(_) => ImapMessageDeleted,
|
||||
EventType::ImapMessageMoved(_) => ImapMessageMoved,
|
||||
EventType::NewBlobFile(_) => NewBlobFile,
|
||||
EventType::DeletedBlobFile(_) => DeletedBlobFile,
|
||||
EventType::Warning(_) => Warning,
|
||||
EventType::Error(_) => Error,
|
||||
EventType::ErrorSelfNotInGroup(_) => ErrorSelfNotInGroup,
|
||||
EventType::MsgsChanged { .. } => MsgsChanged,
|
||||
EventType::IncomingMsg { .. } => IncomingMsg,
|
||||
EventType::MsgsNoticed(_) => MsgsNoticed,
|
||||
EventType::MsgDelivered { .. } => MsgDelivered,
|
||||
EventType::MsgFailed { .. } => MsgFailed,
|
||||
EventType::MsgRead { .. } => MsgRead,
|
||||
EventType::ChatModified(_) => ChatModified,
|
||||
EventType::ChatEphemeralTimerModified { .. } => ChatEphemeralTimerModified,
|
||||
EventType::ContactsChanged(_) => ContactsChanged,
|
||||
EventType::LocationChanged(_) => LocationChanged,
|
||||
EventType::ConfigureProgress { .. } => ConfigureProgress,
|
||||
EventType::ImexProgress(_) => ImexProgress,
|
||||
EventType::ImexFileWritten(_) => ImexFileWritten,
|
||||
EventType::SecurejoinInviterProgress { .. } => SecurejoinInviterProgress,
|
||||
EventType::SecurejoinJoinerProgress { .. } => SecurejoinJoinerProgress,
|
||||
EventType::ConnectivityChanged => ConnectivityChanged,
|
||||
EventType::SelfavatarChanged => SelfavatarChanged,
|
||||
EventType::WebxdcStatusUpdate { .. } => WebxdcStatusUpdate,
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
#[test]
|
||||
fn generate_events_ts_types_definition() {
|
||||
let events = {
|
||||
let mut buf = Vec::new();
|
||||
let options = typescript_type_def::DefinitionFileOptions {
|
||||
root_namespace: None,
|
||||
..typescript_type_def::DefinitionFileOptions::default()
|
||||
};
|
||||
typescript_type_def::write_definition_file::<_, EventTypeName>(&mut buf, options).unwrap();
|
||||
String::from_utf8(buf).unwrap()
|
||||
};
|
||||
std::fs::write("typescript/generated/events.ts", events).unwrap();
|
||||
}
|
||||
536
deltachat-jsonrpc/src/api/mod.rs
Normal file
536
deltachat-jsonrpc/src/api/mod.rs
Normal file
@@ -0,0 +1,536 @@
|
||||
use anyhow::{anyhow, bail, Context, Result};
|
||||
use async_std::sync::{Arc, RwLock};
|
||||
use deltachat::{
|
||||
chat::{get_chat_msgs, ChatId},
|
||||
chatlist::Chatlist,
|
||||
config::Config,
|
||||
contact::{may_be_valid_addr, Contact, ContactId},
|
||||
context::get_info,
|
||||
message::{Message, MsgId, Viewtype},
|
||||
provider::get_provider_info,
|
||||
};
|
||||
use std::collections::BTreeMap;
|
||||
use std::{collections::HashMap, str::FromStr};
|
||||
use yerpc::rpc;
|
||||
|
||||
pub use deltachat::accounts::Accounts;
|
||||
|
||||
pub mod events;
|
||||
pub mod types;
|
||||
|
||||
use crate::api::types::chat_list::{get_chat_list_item_by_id, ChatListItemFetchResult};
|
||||
|
||||
use types::account::Account;
|
||||
use types::chat::FullChat;
|
||||
use types::chat_list::ChatListEntry;
|
||||
use types::contact::ContactObject;
|
||||
use types::message::MessageObject;
|
||||
use types::provider_info::ProviderInfo;
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct CommandApi {
|
||||
pub(crate) accounts: Arc<RwLock<Accounts>>,
|
||||
}
|
||||
|
||||
impl CommandApi {
|
||||
pub fn new(accounts: Accounts) -> Self {
|
||||
CommandApi {
|
||||
accounts: Arc::new(RwLock::new(accounts)),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn new_from_arc(accounts: Arc<RwLock<Accounts>>) -> Self {
|
||||
CommandApi { accounts }
|
||||
}
|
||||
|
||||
async fn get_context(&self, id: u32) -> Result<deltachat::context::Context> {
|
||||
let sc = self
|
||||
.accounts
|
||||
.read()
|
||||
.await
|
||||
.get_account(id)
|
||||
.await
|
||||
.ok_or_else(|| anyhow!("account with id {} not found", id))?;
|
||||
Ok(sc)
|
||||
}
|
||||
}
|
||||
|
||||
#[rpc(all_positional, ts_outdir = "typescript/generated")]
|
||||
impl CommandApi {
|
||||
// ---------------------------------------------
|
||||
// Misc top level functions
|
||||
// ---------------------------------------------
|
||||
|
||||
/// Check if an email address is valid.
|
||||
async fn check_email_validity(&self, email: String) -> bool {
|
||||
may_be_valid_addr(&email)
|
||||
}
|
||||
|
||||
/// Get general system info.
|
||||
async fn get_system_info(&self) -> BTreeMap<&'static str, String> {
|
||||
get_info()
|
||||
}
|
||||
|
||||
// ---------------------------------------------
|
||||
// Account Management
|
||||
// ---------------------------------------------
|
||||
|
||||
async fn add_account(&self) -> Result<u32> {
|
||||
self.accounts.write().await.add_account().await
|
||||
}
|
||||
|
||||
async fn remove_account(&self, account_id: u32) -> Result<()> {
|
||||
self.accounts.write().await.remove_account(account_id).await
|
||||
}
|
||||
|
||||
async fn get_all_account_ids(&self) -> Vec<u32> {
|
||||
self.accounts.read().await.get_all().await
|
||||
}
|
||||
|
||||
/// Select account id for internally selected state.
|
||||
/// TODO: Likely this is deprecated as all methods take an account id now.
|
||||
async fn select_account(&self, id: u32) -> Result<()> {
|
||||
self.accounts.write().await.select_account(id).await
|
||||
}
|
||||
|
||||
/// Get the selected account id of the internal state..
|
||||
/// TODO: Likely this is deprecated as all methods take an account id now.
|
||||
async fn get_selected_account_id(&self) -> Option<u32> {
|
||||
self.accounts.read().await.get_selected_account_id().await
|
||||
}
|
||||
|
||||
/// Get a list of all configured accounts.
|
||||
async fn get_all_accounts(&self) -> Result<Vec<Account>> {
|
||||
let mut accounts = Vec::new();
|
||||
for id in self.accounts.read().await.get_all().await {
|
||||
let context_option = self.accounts.read().await.get_account(id).await;
|
||||
if let Some(ctx) = context_option {
|
||||
accounts.push(Account::from_context(&ctx, id).await?)
|
||||
} else {
|
||||
println!("account with id {} doesn't exist anymore", id);
|
||||
}
|
||||
}
|
||||
Ok(accounts)
|
||||
}
|
||||
|
||||
// ---------------------------------------------
|
||||
// Methods that work on individual accounts
|
||||
// ---------------------------------------------
|
||||
|
||||
/// Get top-level info for an account.
|
||||
async fn get_account_info(&self, account_id: u32) -> Result<Account> {
|
||||
let context_option = self.accounts.read().await.get_account(account_id).await;
|
||||
if let Some(ctx) = context_option {
|
||||
Ok(Account::from_context(&ctx, account_id).await?)
|
||||
} else {
|
||||
Err(anyhow!(
|
||||
"account with id {} doesn't exist anymore",
|
||||
account_id
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns provider for the given domain.
|
||||
///
|
||||
/// This function looks up domain in offline database.
|
||||
///
|
||||
/// For compatibility, email address can be passed to this function
|
||||
/// instead of the domain.
|
||||
async fn get_provider_info(
|
||||
&self,
|
||||
account_id: u32,
|
||||
email: String,
|
||||
) -> Result<Option<ProviderInfo>> {
|
||||
let ctx = self.get_context(account_id).await?;
|
||||
|
||||
let socks5_enabled = ctx
|
||||
.get_config_bool(deltachat::config::Config::Socks5Enabled)
|
||||
.await?;
|
||||
|
||||
let provider_info =
|
||||
get_provider_info(&ctx, email.split('@').last().unwrap_or(""), socks5_enabled).await;
|
||||
Ok(ProviderInfo::from_dc_type(provider_info))
|
||||
}
|
||||
|
||||
/// Checks if the context is already configured.
|
||||
async fn is_configured(&self, account_id: u32) -> Result<bool> {
|
||||
let ctx = self.get_context(account_id).await?;
|
||||
ctx.is_configured().await
|
||||
}
|
||||
|
||||
/// Get system info for an account.
|
||||
async fn get_info(&self, account_id: u32) -> Result<BTreeMap<&'static str, String>> {
|
||||
let ctx = self.get_context(account_id).await?;
|
||||
ctx.get_info().await
|
||||
}
|
||||
|
||||
async fn set_config(&self, account_id: u32, key: String, value: Option<String>) -> Result<()> {
|
||||
let ctx = self.get_context(account_id).await?;
|
||||
set_config(&ctx, &key, value.as_deref()).await
|
||||
}
|
||||
|
||||
async fn batch_set_config(
|
||||
&self,
|
||||
account_id: u32,
|
||||
config: HashMap<String, Option<String>>,
|
||||
) -> Result<()> {
|
||||
let ctx = self.get_context(account_id).await?;
|
||||
for (key, value) in config.into_iter() {
|
||||
set_config(&ctx, &key, value.as_deref())
|
||||
.await
|
||||
.with_context(|| format!("Can't set {} to {:?}", key, value))?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn get_config(&self, account_id: u32, key: String) -> Result<Option<String>> {
|
||||
let ctx = self.get_context(account_id).await?;
|
||||
get_config(&ctx, &key).await
|
||||
}
|
||||
|
||||
async fn batch_get_config(
|
||||
&self,
|
||||
account_id: u32,
|
||||
keys: Vec<String>,
|
||||
) -> Result<HashMap<String, Option<String>>> {
|
||||
let ctx = self.get_context(account_id).await?;
|
||||
let mut result: HashMap<String, Option<String>> = HashMap::new();
|
||||
for key in keys {
|
||||
result.insert(key.clone(), get_config(&ctx, &key).await?);
|
||||
}
|
||||
Ok(result)
|
||||
}
|
||||
|
||||
/// Configures this account with the currently set parameters.
|
||||
/// Setup the credential config before calling this.
|
||||
async fn configure(&self, account_id: u32) -> Result<()> {
|
||||
let ctx = self.get_context(account_id).await?;
|
||||
ctx.stop_io().await;
|
||||
ctx.configure().await?;
|
||||
ctx.start_io().await;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Signal an ongoing process to stop.
|
||||
async fn stop_ongoing_process(&self, account_id: u32) -> Result<()> {
|
||||
let ctx = self.get_context(account_id).await?;
|
||||
ctx.stop_ongoing().await;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
// ---------------------------------------------
|
||||
// autocrypt
|
||||
// ---------------------------------------------
|
||||
|
||||
async fn autocrypt_initiate_key_transfer(&self, account_id: u32) -> Result<String> {
|
||||
let ctx = self.get_context(account_id).await?;
|
||||
deltachat::imex::initiate_key_transfer(&ctx).await
|
||||
}
|
||||
|
||||
async fn autocrypt_continue_key_transfer(
|
||||
&self,
|
||||
account_id: u32,
|
||||
message_id: u32,
|
||||
setup_code: String,
|
||||
) -> Result<()> {
|
||||
let ctx = self.get_context(account_id).await?;
|
||||
deltachat::imex::continue_key_transfer(&ctx, MsgId::new(message_id), &setup_code).await
|
||||
}
|
||||
|
||||
// ---------------------------------------------
|
||||
// chat list
|
||||
// ---------------------------------------------
|
||||
|
||||
async fn get_chatlist_entries(
|
||||
&self,
|
||||
account_id: u32,
|
||||
list_flags: Option<u32>,
|
||||
query_string: Option<String>,
|
||||
query_contact_id: Option<u32>,
|
||||
) -> Result<Vec<ChatListEntry>> {
|
||||
let ctx = self.get_context(account_id).await?;
|
||||
let list = Chatlist::try_load(
|
||||
&ctx,
|
||||
list_flags.unwrap_or(0) as usize,
|
||||
query_string.as_deref(),
|
||||
query_contact_id.map(ContactId::new),
|
||||
)
|
||||
.await?;
|
||||
let mut l: Vec<ChatListEntry> = Vec::new();
|
||||
for i in 0..list.len() {
|
||||
l.push(ChatListEntry(
|
||||
list.get_chat_id(i)?.to_u32(),
|
||||
list.get_msg_id(i)?.unwrap_or_default().to_u32(),
|
||||
));
|
||||
}
|
||||
Ok(l)
|
||||
}
|
||||
|
||||
async fn get_chatlist_items_by_entries(
|
||||
&self,
|
||||
account_id: u32,
|
||||
entries: Vec<ChatListEntry>,
|
||||
) -> Result<HashMap<u32, ChatListItemFetchResult>> {
|
||||
// todo custom json deserializer for ChatListEntry?
|
||||
let ctx = self.get_context(account_id).await?;
|
||||
let mut result: HashMap<u32, ChatListItemFetchResult> = HashMap::new();
|
||||
for (_i, entry) in entries.iter().enumerate() {
|
||||
result.insert(
|
||||
entry.0,
|
||||
match get_chat_list_item_by_id(&ctx, entry).await {
|
||||
Ok(res) => res,
|
||||
Err(err) => ChatListItemFetchResult::Error {
|
||||
id: entry.0,
|
||||
error: format!("{:?}", err),
|
||||
},
|
||||
},
|
||||
);
|
||||
}
|
||||
Ok(result)
|
||||
}
|
||||
|
||||
// ---------------------------------------------
|
||||
// chat
|
||||
// ---------------------------------------------
|
||||
|
||||
async fn chatlist_get_full_chat_by_id(
|
||||
&self,
|
||||
account_id: u32,
|
||||
chat_id: u32,
|
||||
) -> Result<FullChat> {
|
||||
let ctx = self.get_context(account_id).await?;
|
||||
FullChat::from_dc_chat_id(&ctx, chat_id).await
|
||||
}
|
||||
|
||||
async fn accept_chat(&self, account_id: u32, chat_id: u32) -> Result<()> {
|
||||
let ctx = self.get_context(account_id).await?;
|
||||
ChatId::new(chat_id).accept(&ctx).await
|
||||
}
|
||||
|
||||
async fn block_chat(&self, account_id: u32, chat_id: u32) -> Result<()> {
|
||||
let ctx = self.get_context(account_id).await?;
|
||||
ChatId::new(chat_id).block(&ctx).await
|
||||
}
|
||||
|
||||
// ---------------------------------------------
|
||||
// message list
|
||||
// ---------------------------------------------
|
||||
|
||||
async fn message_list_get_message_ids(
|
||||
&self,
|
||||
account_id: u32,
|
||||
chat_id: u32,
|
||||
flags: u32,
|
||||
) -> Result<Vec<u32>> {
|
||||
let ctx = self.get_context(account_id).await?;
|
||||
let msg = get_chat_msgs(&ctx, ChatId::new(chat_id), flags).await?;
|
||||
Ok(msg
|
||||
.iter()
|
||||
.filter_map(|chat_item| match chat_item {
|
||||
deltachat::chat::ChatItem::Message { msg_id } => Some(msg_id.to_u32()),
|
||||
_ => None,
|
||||
})
|
||||
.collect())
|
||||
}
|
||||
|
||||
async fn message_get_message(&self, account_id: u32, message_id: u32) -> Result<MessageObject> {
|
||||
let ctx = self.get_context(account_id).await?;
|
||||
MessageObject::from_message_id(&ctx, message_id).await
|
||||
}
|
||||
|
||||
async fn message_get_messages(
|
||||
&self,
|
||||
account_id: u32,
|
||||
message_ids: Vec<u32>,
|
||||
) -> Result<HashMap<u32, MessageObject>> {
|
||||
let ctx = self.get_context(account_id).await?;
|
||||
let mut messages: HashMap<u32, MessageObject> = HashMap::new();
|
||||
for message_id in message_ids {
|
||||
messages.insert(
|
||||
message_id,
|
||||
MessageObject::from_message_id(&ctx, message_id).await?,
|
||||
);
|
||||
}
|
||||
Ok(messages)
|
||||
}
|
||||
|
||||
// ---------------------------------------------
|
||||
// contact
|
||||
// ---------------------------------------------
|
||||
|
||||
/// Get a single contact options by ID.
|
||||
async fn contacts_get_contact(
|
||||
&self,
|
||||
account_id: u32,
|
||||
contact_id: u32,
|
||||
) -> Result<ContactObject> {
|
||||
let ctx = self.get_context(account_id).await?;
|
||||
let contact_id = ContactId::new(contact_id);
|
||||
|
||||
ContactObject::from_dc_contact(
|
||||
&ctx,
|
||||
deltachat::contact::Contact::get_by_id(&ctx, contact_id).await?,
|
||||
)
|
||||
.await
|
||||
}
|
||||
|
||||
/// Add a single contact as a result of an explicit user action.
|
||||
///
|
||||
/// Returns contact id of the created or existing contact
|
||||
async fn contacts_create_contact(
|
||||
&self,
|
||||
account_id: u32,
|
||||
email: String,
|
||||
name: Option<String>,
|
||||
) -> Result<u32> {
|
||||
let ctx = self.get_context(account_id).await?;
|
||||
if !may_be_valid_addr(&email) {
|
||||
bail!(anyhow!(
|
||||
"provided email address is not a valid email address"
|
||||
))
|
||||
}
|
||||
let contact_id = Contact::create(&ctx, &name.unwrap_or_default(), &email).await?;
|
||||
Ok(contact_id.to_u32())
|
||||
}
|
||||
|
||||
/// Returns contact id of the created or existing DM chat with that contact
|
||||
async fn contacts_create_chat_by_contact_id(
|
||||
&self,
|
||||
account_id: u32,
|
||||
contact_id: u32,
|
||||
) -> Result<u32> {
|
||||
let ctx = self.get_context(account_id).await?;
|
||||
let contact = Contact::get_by_id(&ctx, ContactId::new(contact_id)).await?;
|
||||
ChatId::create_for_contact(&ctx, contact.id)
|
||||
.await
|
||||
.map(|id| id.to_u32())
|
||||
}
|
||||
|
||||
async fn contacts_block(&self, account_id: u32, contact_id: u32) -> Result<()> {
|
||||
let ctx = self.get_context(account_id).await?;
|
||||
Contact::block(&ctx, ContactId::new(contact_id)).await
|
||||
}
|
||||
|
||||
async fn contacts_unblock(&self, account_id: u32, contact_id: u32) -> Result<()> {
|
||||
let ctx = self.get_context(account_id).await?;
|
||||
Contact::unblock(&ctx, ContactId::new(contact_id)).await
|
||||
}
|
||||
|
||||
async fn contacts_get_blocked(&self, account_id: u32) -> Result<Vec<ContactObject>> {
|
||||
let ctx = self.get_context(account_id).await?;
|
||||
let blocked_ids = Contact::get_all_blocked(&ctx).await?;
|
||||
let mut contacts: Vec<ContactObject> = Vec::with_capacity(blocked_ids.len());
|
||||
for id in blocked_ids {
|
||||
contacts.push(
|
||||
ContactObject::from_dc_contact(
|
||||
&ctx,
|
||||
deltachat::contact::Contact::get_by_id(&ctx, id).await?,
|
||||
)
|
||||
.await?,
|
||||
);
|
||||
}
|
||||
Ok(contacts)
|
||||
}
|
||||
|
||||
async fn contacts_get_contact_ids(
|
||||
&self,
|
||||
account_id: u32,
|
||||
list_flags: u32,
|
||||
query: Option<String>,
|
||||
) -> Result<Vec<u32>> {
|
||||
let ctx = self.get_context(account_id).await?;
|
||||
let contacts = Contact::get_all(&ctx, list_flags, query.as_deref()).await?;
|
||||
Ok(contacts.into_iter().map(|c| c.to_u32()).collect())
|
||||
}
|
||||
|
||||
/// Get a list of contacts.
|
||||
/// (formerly called getContacts2 in desktop)
|
||||
async fn contacts_get_contacts(
|
||||
&self,
|
||||
account_id: u32,
|
||||
list_flags: u32,
|
||||
query: Option<String>,
|
||||
) -> Result<Vec<ContactObject>> {
|
||||
let ctx = self.get_context(account_id).await?;
|
||||
let contact_ids = Contact::get_all(&ctx, list_flags, query.as_deref()).await?;
|
||||
let mut contacts: Vec<ContactObject> = Vec::with_capacity(contact_ids.len());
|
||||
for id in contact_ids {
|
||||
contacts.push(
|
||||
ContactObject::from_dc_contact(
|
||||
&ctx,
|
||||
deltachat::contact::Contact::get_by_id(&ctx, id).await?,
|
||||
)
|
||||
.await?,
|
||||
);
|
||||
}
|
||||
Ok(contacts)
|
||||
}
|
||||
|
||||
async fn contacts_get_contacts_by_ids(
|
||||
&self,
|
||||
account_id: u32,
|
||||
ids: Vec<u32>,
|
||||
) -> Result<HashMap<u32, ContactObject>> {
|
||||
let ctx = self.get_context(account_id).await?;
|
||||
|
||||
let mut contacts = HashMap::with_capacity(ids.len());
|
||||
for id in ids {
|
||||
contacts.insert(
|
||||
id,
|
||||
ContactObject::from_dc_contact(
|
||||
&ctx,
|
||||
deltachat::contact::Contact::get_by_id(&ctx, ContactId::new(id)).await?,
|
||||
)
|
||||
.await?,
|
||||
);
|
||||
}
|
||||
Ok(contacts)
|
||||
}
|
||||
|
||||
// ---------------------------------------------
|
||||
// misc prototyping functions
|
||||
// that might get removed later again
|
||||
// ---------------------------------------------
|
||||
|
||||
/// Returns the messageid of the sent message
|
||||
async fn misc_send_text_message(
|
||||
&self,
|
||||
account_id: u32,
|
||||
text: String,
|
||||
chat_id: u32,
|
||||
) -> Result<u32> {
|
||||
let ctx = self.get_context(account_id).await?;
|
||||
|
||||
let mut msg = Message::new(Viewtype::Text);
|
||||
msg.set_text(Some(text));
|
||||
|
||||
let message_id = deltachat::chat::send_msg(&ctx, ChatId::new(chat_id), &mut msg).await?;
|
||||
Ok(message_id.to_u32())
|
||||
}
|
||||
}
|
||||
|
||||
// Helper functions (to prevent code duplication)
|
||||
async fn set_config(
|
||||
ctx: &deltachat::context::Context,
|
||||
key: &str,
|
||||
value: Option<&str>,
|
||||
) -> Result<(), anyhow::Error> {
|
||||
if key.starts_with("ui.") {
|
||||
ctx.set_ui_config(key, value).await
|
||||
} else {
|
||||
ctx.set_config(Config::from_str(key).context("unknown key")?, value)
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
||||
async fn get_config(
|
||||
ctx: &deltachat::context::Context,
|
||||
key: &str,
|
||||
) -> Result<Option<String>, anyhow::Error> {
|
||||
if key.starts_with("ui.") {
|
||||
ctx.get_ui_config(key).await
|
||||
} else {
|
||||
ctx.get_config(Config::from_str(key).context("unknown key")?)
|
||||
.await
|
||||
}
|
||||
}
|
||||
46
deltachat-jsonrpc/src/api/types/account.rs
Normal file
46
deltachat-jsonrpc/src/api/types/account.rs
Normal file
@@ -0,0 +1,46 @@
|
||||
use anyhow::Result;
|
||||
use deltachat::config::Config;
|
||||
use deltachat::contact::{Contact, ContactId};
|
||||
use serde::Serialize;
|
||||
use typescript_type_def::TypeDef;
|
||||
|
||||
use super::color_int_to_hex_string;
|
||||
|
||||
#[derive(Serialize, TypeDef)]
|
||||
#[serde(tag = "type")]
|
||||
pub enum Account {
|
||||
//#[serde(rename_all = "camelCase")]
|
||||
Configured {
|
||||
id: u32,
|
||||
display_name: Option<String>,
|
||||
addr: Option<String>,
|
||||
// size: u32,
|
||||
profile_image: Option<String>, // TODO: This needs to be converted to work with blob http server.
|
||||
color: String,
|
||||
},
|
||||
Unconfigured {
|
||||
id: u32,
|
||||
},
|
||||
}
|
||||
|
||||
impl Account {
|
||||
pub async fn from_context(ctx: &deltachat::context::Context, id: u32) -> Result<Self> {
|
||||
if ctx.is_configured().await? {
|
||||
let display_name = ctx.get_config(Config::Displayname).await?;
|
||||
let addr = ctx.get_config(Config::Addr).await?;
|
||||
let profile_image = ctx.get_config(Config::Selfavatar).await?;
|
||||
let color = color_int_to_hex_string(
|
||||
Contact::get_by_id(ctx, ContactId::SELF).await?.get_color(),
|
||||
);
|
||||
Ok(Account::Configured {
|
||||
id,
|
||||
display_name,
|
||||
addr,
|
||||
profile_image,
|
||||
color,
|
||||
})
|
||||
} else {
|
||||
Ok(Account::Unconfigured { id })
|
||||
}
|
||||
}
|
||||
}
|
||||
91
deltachat-jsonrpc/src/api/types/chat.rs
Normal file
91
deltachat-jsonrpc/src/api/types/chat.rs
Normal file
@@ -0,0 +1,91 @@
|
||||
use anyhow::{anyhow, Result};
|
||||
use deltachat::chat::get_chat_contacts;
|
||||
use deltachat::chat::{Chat, ChatId};
|
||||
use deltachat::contact::{Contact, ContactId};
|
||||
use deltachat::context::Context;
|
||||
use num_traits::cast::ToPrimitive;
|
||||
use serde::Serialize;
|
||||
use typescript_type_def::TypeDef;
|
||||
|
||||
use super::color_int_to_hex_string;
|
||||
use super::contact::ContactObject;
|
||||
|
||||
#[derive(Serialize, TypeDef)]
|
||||
pub struct FullChat {
|
||||
id: u32,
|
||||
name: String,
|
||||
is_protected: bool,
|
||||
profile_image: Option<String>, //BLOBS ?
|
||||
archived: bool,
|
||||
// subtitle - will be moved to frontend because it uses translation functions
|
||||
chat_type: u32,
|
||||
is_unpromoted: bool,
|
||||
is_self_talk: bool,
|
||||
contacts: Vec<ContactObject>,
|
||||
contact_ids: Vec<u32>,
|
||||
color: String,
|
||||
fresh_message_counter: usize,
|
||||
// is_group - please check over chat.type in frontend instead
|
||||
is_contact_request: bool,
|
||||
is_device_chat: bool,
|
||||
self_in_group: bool,
|
||||
is_muted: bool,
|
||||
ephemeral_timer: u32, //TODO look if there are more important properties in newer core versions
|
||||
can_send: bool,
|
||||
}
|
||||
|
||||
impl FullChat {
|
||||
pub async fn from_dc_chat_id(context: &Context, chat_id: u32) -> Result<Self> {
|
||||
let rust_chat_id = ChatId::new(chat_id);
|
||||
let chat = Chat::load_from_db(context, rust_chat_id).await?;
|
||||
|
||||
let contact_ids = get_chat_contacts(context, rust_chat_id).await?;
|
||||
|
||||
let mut contacts = Vec::new();
|
||||
|
||||
for contact_id in &contact_ids {
|
||||
contacts.push(
|
||||
ContactObject::from_dc_contact(
|
||||
context,
|
||||
Contact::load_from_db(context, *contact_id).await?,
|
||||
)
|
||||
.await?,
|
||||
)
|
||||
}
|
||||
|
||||
let profile_image = match chat.get_profile_image(context).await? {
|
||||
Some(path_buf) => path_buf.to_str().map(|s| s.to_owned()),
|
||||
None => None,
|
||||
};
|
||||
|
||||
let color = color_int_to_hex_string(chat.get_color(context).await?);
|
||||
let fresh_message_counter = rust_chat_id.get_fresh_msg_cnt(context).await?;
|
||||
let ephemeral_timer = rust_chat_id.get_ephemeral_timer(context).await?.to_u32();
|
||||
|
||||
let can_send = chat.can_send(context).await?;
|
||||
|
||||
Ok(FullChat {
|
||||
id: chat_id,
|
||||
name: chat.name.clone(),
|
||||
is_protected: chat.is_protected(),
|
||||
profile_image, //BLOBS ?
|
||||
archived: chat.get_visibility() == deltachat::chat::ChatVisibility::Archived,
|
||||
chat_type: chat
|
||||
.get_type()
|
||||
.to_u32()
|
||||
.ok_or_else(|| anyhow!("unknown chat type id"))?, // TODO get rid of this unwrap?
|
||||
is_unpromoted: chat.is_unpromoted(),
|
||||
is_self_talk: chat.is_self_talk(),
|
||||
contacts,
|
||||
contact_ids: contact_ids.iter().map(|id| id.to_u32()).collect(),
|
||||
color,
|
||||
fresh_message_counter,
|
||||
is_contact_request: chat.is_contact_request(),
|
||||
is_device_chat: chat.is_device_talk(),
|
||||
self_in_group: contact_ids.contains(&ContactId::SELF),
|
||||
is_muted: chat.is_muted(),
|
||||
ephemeral_timer,
|
||||
can_send,
|
||||
})
|
||||
}
|
||||
}
|
||||
117
deltachat-jsonrpc/src/api/types/chat_list.rs
Normal file
117
deltachat-jsonrpc/src/api/types/chat_list.rs
Normal file
@@ -0,0 +1,117 @@
|
||||
use anyhow::Result;
|
||||
use deltachat::constants::*;
|
||||
use deltachat::contact::ContactId;
|
||||
use deltachat::{
|
||||
chat::{get_chat_contacts, ChatVisibility},
|
||||
chatlist::Chatlist,
|
||||
};
|
||||
use deltachat::{
|
||||
chat::{Chat, ChatId},
|
||||
message::MsgId,
|
||||
};
|
||||
use num_traits::cast::ToPrimitive;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use typescript_type_def::TypeDef;
|
||||
|
||||
use super::color_int_to_hex_string;
|
||||
|
||||
#[derive(Deserialize, Serialize, TypeDef)]
|
||||
pub struct ChatListEntry(pub u32, pub u32);
|
||||
|
||||
#[derive(Serialize, TypeDef)]
|
||||
#[serde(tag = "type")]
|
||||
pub enum ChatListItemFetchResult {
|
||||
#[serde(rename_all = "camelCase")]
|
||||
ChatListItem {
|
||||
id: u32,
|
||||
name: String,
|
||||
avatar_path: Option<String>,
|
||||
color: String,
|
||||
last_updated: Option<i64>,
|
||||
summary_text1: String,
|
||||
summary_text2: String,
|
||||
summary_status: u32,
|
||||
is_protected: bool,
|
||||
is_group: bool,
|
||||
fresh_message_counter: usize,
|
||||
is_self_talk: bool,
|
||||
is_device_talk: bool,
|
||||
is_sending_location: bool,
|
||||
is_self_in_group: bool,
|
||||
is_archived: bool,
|
||||
is_pinned: bool,
|
||||
is_muted: bool,
|
||||
is_contact_request: bool,
|
||||
},
|
||||
ArchiveLink,
|
||||
#[serde(rename_all = "camelCase")]
|
||||
Error {
|
||||
id: u32,
|
||||
error: String,
|
||||
},
|
||||
}
|
||||
|
||||
pub(crate) async fn get_chat_list_item_by_id(
|
||||
ctx: &deltachat::context::Context,
|
||||
entry: &ChatListEntry,
|
||||
) -> Result<ChatListItemFetchResult> {
|
||||
let chat_id = ChatId::new(entry.0);
|
||||
let last_msgid = match entry.1 {
|
||||
0 => None,
|
||||
_ => Some(MsgId::new(entry.1)),
|
||||
};
|
||||
|
||||
if chat_id.is_archived_link() {
|
||||
return Ok(ChatListItemFetchResult::ArchiveLink);
|
||||
}
|
||||
|
||||
let chat = Chat::load_from_db(ctx, chat_id).await?;
|
||||
let summary = Chatlist::get_summary2(ctx, chat_id, last_msgid, Some(&chat)).await?;
|
||||
|
||||
let summary_text1 = summary.prefix.map_or_else(String::new, |s| s.to_string());
|
||||
let summary_text2 = summary.text.to_owned();
|
||||
|
||||
let visibility = chat.get_visibility();
|
||||
|
||||
let avatar_path = chat
|
||||
.get_profile_image(ctx)
|
||||
.await?
|
||||
.map(|path| path.to_str().unwrap_or("invalid/path").to_owned());
|
||||
|
||||
let last_updated = match last_msgid {
|
||||
Some(id) => {
|
||||
let last_message = deltachat::message::Message::load_from_db(ctx, id).await?;
|
||||
Some(last_message.get_timestamp() * 1000)
|
||||
}
|
||||
None => None,
|
||||
};
|
||||
|
||||
let self_in_group = get_chat_contacts(ctx, chat_id)
|
||||
.await?
|
||||
.contains(&ContactId::SELF);
|
||||
|
||||
let fresh_message_counter = chat_id.get_fresh_msg_cnt(ctx).await?;
|
||||
let color = color_int_to_hex_string(chat.get_color(ctx).await?);
|
||||
|
||||
Ok(ChatListItemFetchResult::ChatListItem {
|
||||
id: chat_id.to_u32(),
|
||||
name: chat.get_name().to_owned(),
|
||||
avatar_path,
|
||||
color,
|
||||
last_updated,
|
||||
summary_text1,
|
||||
summary_text2,
|
||||
summary_status: summary.state.to_u32().expect("impossible"), // idea and a function to transform the constant to strings? or return string enum
|
||||
is_protected: chat.is_protected(),
|
||||
is_group: chat.get_type() == Chattype::Group,
|
||||
fresh_message_counter,
|
||||
is_self_talk: chat.is_self_talk(),
|
||||
is_device_talk: chat.is_device_talk(),
|
||||
is_self_in_group: self_in_group,
|
||||
is_sending_location: chat.is_sending_locations(),
|
||||
is_archived: visibility == ChatVisibility::Archived,
|
||||
is_pinned: visibility == ChatVisibility::Pinned,
|
||||
is_muted: chat.is_muted(),
|
||||
is_contact_request: chat.is_contact_request(),
|
||||
})
|
||||
}
|
||||
50
deltachat-jsonrpc/src/api/types/contact.rs
Normal file
50
deltachat-jsonrpc/src/api/types/contact.rs
Normal file
@@ -0,0 +1,50 @@
|
||||
use anyhow::Result;
|
||||
use deltachat::contact::VerifiedStatus;
|
||||
use deltachat::context::Context;
|
||||
use serde::Serialize;
|
||||
use typescript_type_def::TypeDef;
|
||||
|
||||
use super::color_int_to_hex_string;
|
||||
|
||||
#[derive(Serialize, TypeDef)]
|
||||
#[serde(rename = "Contact")]
|
||||
pub struct ContactObject {
|
||||
address: String,
|
||||
color: String,
|
||||
auth_name: String,
|
||||
status: String,
|
||||
display_name: String,
|
||||
id: u32,
|
||||
name: String,
|
||||
profile_image: Option<String>, // BLOBS
|
||||
name_and_addr: String,
|
||||
is_blocked: bool,
|
||||
is_verified: bool,
|
||||
}
|
||||
|
||||
impl ContactObject {
|
||||
pub async fn from_dc_contact(
|
||||
context: &Context,
|
||||
contact: deltachat::contact::Contact,
|
||||
) -> Result<Self> {
|
||||
let profile_image = match contact.get_profile_image(context).await? {
|
||||
Some(path_buf) => path_buf.to_str().map(|s| s.to_owned()),
|
||||
None => None,
|
||||
};
|
||||
let is_verified = contact.is_verified(context).await? == VerifiedStatus::BidirectVerified;
|
||||
|
||||
Ok(ContactObject {
|
||||
address: contact.get_addr().to_owned(),
|
||||
color: color_int_to_hex_string(contact.get_color()),
|
||||
auth_name: contact.get_authname().to_owned(),
|
||||
status: contact.get_status().to_owned(),
|
||||
display_name: contact.get_display_name().to_owned(),
|
||||
id: contact.id.to_u32(),
|
||||
name: contact.get_name().to_owned(),
|
||||
profile_image, //BLOBS
|
||||
name_and_addr: contact.get_name_n_addr(),
|
||||
is_blocked: contact.is_blocked(),
|
||||
is_verified,
|
||||
})
|
||||
}
|
||||
}
|
||||
127
deltachat-jsonrpc/src/api/types/message.rs
Normal file
127
deltachat-jsonrpc/src/api/types/message.rs
Normal file
@@ -0,0 +1,127 @@
|
||||
use anyhow::{anyhow, Result};
|
||||
use deltachat::contact::Contact;
|
||||
use deltachat::context::Context;
|
||||
use deltachat::message::Message;
|
||||
use deltachat::message::MsgId;
|
||||
use num_traits::cast::ToPrimitive;
|
||||
use serde::Serialize;
|
||||
use typescript_type_def::TypeDef;
|
||||
|
||||
use super::contact::ContactObject;
|
||||
|
||||
#[derive(Serialize, TypeDef)]
|
||||
#[serde(rename = "Message")]
|
||||
pub struct MessageObject {
|
||||
id: u32,
|
||||
chat_id: u32,
|
||||
from_id: u32,
|
||||
quoted_text: Option<String>,
|
||||
quoted_message_id: Option<u32>,
|
||||
text: Option<String>,
|
||||
has_location: bool,
|
||||
has_html: bool,
|
||||
view_type: u32,
|
||||
state: u32,
|
||||
|
||||
timestamp: i64,
|
||||
sort_timestamp: i64,
|
||||
received_timestamp: i64,
|
||||
has_deviating_timestamp: bool,
|
||||
|
||||
// summary - use/create another function if you need it
|
||||
subject: String,
|
||||
show_padlock: bool,
|
||||
is_setupmessage: bool,
|
||||
is_info: bool,
|
||||
is_forwarded: bool,
|
||||
|
||||
duration: i32,
|
||||
dimensions_height: i32,
|
||||
dimensions_width: i32,
|
||||
|
||||
videochat_type: Option<u32>,
|
||||
videochat_url: Option<String>,
|
||||
|
||||
override_sender_name: Option<String>,
|
||||
sender: ContactObject,
|
||||
|
||||
setup_code_begin: Option<String>,
|
||||
|
||||
file: Option<String>,
|
||||
file_mime: Option<String>,
|
||||
file_bytes: u64,
|
||||
file_name: Option<String>,
|
||||
}
|
||||
|
||||
impl MessageObject {
|
||||
pub async fn from_message_id(context: &Context, message_id: u32) -> Result<Self> {
|
||||
let msg_id = MsgId::new(message_id);
|
||||
let message = Message::load_from_db(context, msg_id).await?;
|
||||
|
||||
let quoted_message_id = message
|
||||
.quoted_message(context)
|
||||
.await?
|
||||
.map(|m| m.get_id().to_u32());
|
||||
|
||||
let sender_contact = Contact::load_from_db(context, message.get_from_id()).await?;
|
||||
let sender = ContactObject::from_dc_contact(context, sender_contact).await?;
|
||||
let file_bytes = message.get_filebytes(context).await;
|
||||
let override_sender_name = message.get_override_sender_name();
|
||||
|
||||
Ok(MessageObject {
|
||||
id: message_id,
|
||||
chat_id: message.get_chat_id().to_u32(),
|
||||
from_id: message.get_from_id().to_u32(),
|
||||
quoted_text: message.quoted_text(),
|
||||
quoted_message_id,
|
||||
text: message.get_text(),
|
||||
has_location: message.has_location(),
|
||||
has_html: message.has_html(),
|
||||
view_type: message
|
||||
.get_viewtype()
|
||||
.to_u32()
|
||||
.ok_or_else(|| anyhow!("viewtype conversion to number failed"))?,
|
||||
state: message
|
||||
.get_state()
|
||||
.to_u32()
|
||||
.ok_or_else(|| anyhow!("state conversion to number failed"))?,
|
||||
|
||||
timestamp: message.get_timestamp(),
|
||||
sort_timestamp: message.get_sort_timestamp(),
|
||||
received_timestamp: message.get_received_timestamp(),
|
||||
has_deviating_timestamp: message.has_deviating_timestamp(),
|
||||
|
||||
subject: message.get_subject().to_owned(),
|
||||
show_padlock: message.get_showpadlock(),
|
||||
is_setupmessage: message.is_setupmessage(),
|
||||
is_info: message.is_info(),
|
||||
is_forwarded: message.is_forwarded(),
|
||||
|
||||
duration: message.get_duration(),
|
||||
dimensions_height: message.get_height(),
|
||||
dimensions_width: message.get_width(),
|
||||
|
||||
videochat_type: match message.get_videochat_type() {
|
||||
Some(vct) => Some(
|
||||
vct.to_u32()
|
||||
.ok_or_else(|| anyhow!("state conversion to number failed"))?,
|
||||
),
|
||||
None => None,
|
||||
},
|
||||
videochat_url: message.get_videochat_url(),
|
||||
|
||||
override_sender_name,
|
||||
sender,
|
||||
|
||||
setup_code_begin: message.get_setupcodebegin(context).await,
|
||||
|
||||
file: match message.get_file(context) {
|
||||
Some(path_buf) => path_buf.to_str().map(|s| s.to_owned()),
|
||||
None => None,
|
||||
}, //BLOBS
|
||||
file_mime: message.get_filemime(),
|
||||
file_bytes,
|
||||
file_name: message.get_filename(),
|
||||
})
|
||||
}
|
||||
}
|
||||
10
deltachat-jsonrpc/src/api/types/mod.rs
Normal file
10
deltachat-jsonrpc/src/api/types/mod.rs
Normal file
@@ -0,0 +1,10 @@
|
||||
pub mod account;
|
||||
pub mod chat;
|
||||
pub mod chat_list;
|
||||
pub mod contact;
|
||||
pub mod message;
|
||||
pub mod provider_info;
|
||||
|
||||
pub fn color_int_to_hex_string(color: u32) -> String {
|
||||
format!("{:#08x}", color).replace("0x", "#")
|
||||
}
|
||||
21
deltachat-jsonrpc/src/api/types/provider_info.rs
Normal file
21
deltachat-jsonrpc/src/api/types/provider_info.rs
Normal file
@@ -0,0 +1,21 @@
|
||||
use deltachat::provider::Provider;
|
||||
use num_traits::cast::ToPrimitive;
|
||||
use serde::Serialize;
|
||||
use typescript_type_def::TypeDef;
|
||||
|
||||
#[derive(Serialize, TypeDef)]
|
||||
pub struct ProviderInfo {
|
||||
pub before_login_hint: String,
|
||||
pub overview_page: String,
|
||||
pub status: u32, // in reality this is an enum, but for simlicity and because it gets converted into a number anyway, we use an u32 here.
|
||||
}
|
||||
|
||||
impl ProviderInfo {
|
||||
pub fn from_dc_type(provider: Option<&Provider>) -> Option<Self> {
|
||||
provider.map(|p| ProviderInfo {
|
||||
before_login_hint: p.before_login_hint.to_owned(),
|
||||
overview_page: p.overview_page.to_owned(),
|
||||
status: p.status.to_u32().unwrap(),
|
||||
})
|
||||
}
|
||||
}
|
||||
60
deltachat-jsonrpc/src/lib.rs
Normal file
60
deltachat-jsonrpc/src/lib.rs
Normal file
@@ -0,0 +1,60 @@
|
||||
pub mod api;
|
||||
pub use api::events;
|
||||
|
||||
pub use yerpc;
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::api::{Accounts, CommandApi};
|
||||
use async_channel::unbounded;
|
||||
use async_std::task;
|
||||
use futures::StreamExt;
|
||||
use tempfile::TempDir;
|
||||
use yerpc::{MessageHandle, RpcHandle};
|
||||
|
||||
#[async_std::test]
|
||||
async fn basic_json_rpc_functionality() -> anyhow::Result<()> {
|
||||
// println!("{}", "");
|
||||
let tmp_dir = TempDir::new().unwrap().path().into();
|
||||
println!("tmp_dir: {:?}", tmp_dir);
|
||||
|
||||
let accounts = Accounts::new(tmp_dir).await?;
|
||||
let cmd_api = CommandApi::new(accounts);
|
||||
|
||||
let (sender, mut receiver) = unbounded::<String>();
|
||||
|
||||
let (request_handle, mut rx) = RpcHandle::new();
|
||||
let session = cmd_api;
|
||||
let handle = MessageHandle::new(request_handle, session);
|
||||
task::spawn({
|
||||
async move {
|
||||
while let Some(message) = rx.next().await {
|
||||
let message = serde_json::to_string(&message)?;
|
||||
// Abort serialization on error.
|
||||
sender.send(message).await?;
|
||||
}
|
||||
let res: Result<(), anyhow::Error> = Ok(());
|
||||
res
|
||||
}
|
||||
});
|
||||
|
||||
{
|
||||
let request = r#"{"jsonrpc":"2.0","method":"add_account","params":[],"id":1}"#;
|
||||
let response = r#"{"jsonrpc":"2.0","id":1,"result":1}"#;
|
||||
handle.handle_message(request).await;
|
||||
let result = receiver.next().await;
|
||||
println!("{:?}", result);
|
||||
assert_eq!(result, Some(response.to_owned()));
|
||||
}
|
||||
{
|
||||
let request = r#"{"jsonrpc":"2.0","method":"get_all_account_ids","params":[],"id":2}"#;
|
||||
let response = r#"{"jsonrpc":"2.0","id":2,"result":[1]}"#;
|
||||
handle.handle_message(request).await;
|
||||
let result = receiver.next().await;
|
||||
println!("{:?}", result);
|
||||
assert_eq!(result, Some(response.to_owned()));
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
44
deltachat-jsonrpc/src/webserver.rs
Normal file
44
deltachat-jsonrpc/src/webserver.rs
Normal file
@@ -0,0 +1,44 @@
|
||||
use async_std::path::PathBuf;
|
||||
use async_std::task;
|
||||
use tide::Request;
|
||||
use yerpc::RpcHandle;
|
||||
use yerpc_tide::yerpc_handler;
|
||||
|
||||
mod api;
|
||||
use api::events::event_to_json_rpc_notification;
|
||||
use api::{Accounts, CommandApi};
|
||||
|
||||
#[async_std::main]
|
||||
async fn main() -> Result<(), std::io::Error> {
|
||||
env_logger::init();
|
||||
log::info!("Starting");
|
||||
|
||||
let accounts = Accounts::new(PathBuf::from("./accounts")).await.unwrap();
|
||||
let state = CommandApi::new(accounts);
|
||||
|
||||
let mut app = tide::with_state(state.clone());
|
||||
app.at("/ws").get(yerpc_handler(request_handler));
|
||||
|
||||
state.accounts.read().await.start_io().await;
|
||||
app.listen("127.0.0.1:20808").await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
async fn request_handler(
|
||||
request: Request<CommandApi>,
|
||||
rpc: RpcHandle,
|
||||
) -> anyhow::Result<CommandApi> {
|
||||
let state = request.state().clone();
|
||||
task::spawn(event_loop(state.clone(), rpc));
|
||||
Ok(state)
|
||||
}
|
||||
|
||||
async fn event_loop(state: CommandApi, rpc: RpcHandle) -> anyhow::Result<()> {
|
||||
let events = state.accounts.read().await.get_event_emitter().await;
|
||||
while let Some(event) = events.recv().await {
|
||||
// log::debug!("event {:?}", event);
|
||||
let event = event_to_json_rpc_notification(event);
|
||||
rpc.notify("event", Some(event)).await?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
6
deltachat-jsonrpc/typescript/.gitignore
vendored
Normal file
6
deltachat-jsonrpc/typescript/.gitignore
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
node_modules
|
||||
dist
|
||||
test_dist
|
||||
coverage
|
||||
yarn.lock
|
||||
package-lock.json
|
||||
3
deltachat-jsonrpc/typescript/.prettierignore
Normal file
3
deltachat-jsonrpc/typescript/.prettierignore
Normal file
@@ -0,0 +1,3 @@
|
||||
coverage
|
||||
dist
|
||||
generated
|
||||
1
deltachat-jsonrpc/typescript/deltachat.ts
Normal file
1
deltachat-jsonrpc/typescript/deltachat.ts
Normal file
@@ -0,0 +1 @@
|
||||
export * from "./src/lib.js";
|
||||
107
deltachat-jsonrpc/typescript/example.ts
Normal file
107
deltachat-jsonrpc/typescript/example.ts
Normal file
@@ -0,0 +1,107 @@
|
||||
import { RawClient, RPC } from "./src/lib";
|
||||
import { WebsocketTransport, Request } from "yerpc";
|
||||
|
||||
type DeltaEvent = { id: string; contextId: number; field1: any; field2: any };
|
||||
var selectedAccount = 0;
|
||||
window.addEventListener("DOMContentLoaded", (_event) => {
|
||||
(window as any).selectDeltaAccount = (id: string) => {
|
||||
selectedAccount = Number(id);
|
||||
window.dispatchEvent(new Event("account-changed"));
|
||||
};
|
||||
run().catch((err) => console.error("run failed", err));
|
||||
});
|
||||
|
||||
async function run() {
|
||||
const $main = document.getElementById("main")!;
|
||||
const $side = document.getElementById("side")!;
|
||||
const $head = document.getElementById("header")!;
|
||||
|
||||
const transport = new WebsocketTransport("ws://localhost:20808/ws");
|
||||
const client = new RawClient(transport);
|
||||
|
||||
(window as any).client = client;
|
||||
|
||||
transport.on("request", (request: Request) => {
|
||||
const method = request.method;
|
||||
if (method === "event") {
|
||||
const params = request.params! as DeltaEvent;
|
||||
onIncomingEvent(params, params.id);
|
||||
}
|
||||
});
|
||||
|
||||
window.addEventListener("account-changed", async (_event: Event) => {
|
||||
await client.selectAccount(selectedAccount);
|
||||
listChatsForSelectedAccount();
|
||||
});
|
||||
|
||||
await Promise.all([loadAccountsInHeader(), listChatsForSelectedAccount()]);
|
||||
|
||||
async function loadAccountsInHeader() {
|
||||
const accounts = await client.getAllAccounts();
|
||||
for (const account of accounts) {
|
||||
if (account.type === "Configured") {
|
||||
write(
|
||||
$head,
|
||||
`<a href="#" onclick="selectDeltaAccount(${account.id})">
|
||||
${account.addr!}
|
||||
</a> `
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async function listChatsForSelectedAccount() {
|
||||
clear($main);
|
||||
const selectedAccount = await client.getSelectedAccountId();
|
||||
if (!selectedAccount) return write($main, "No account selected");
|
||||
const info = await client.getAccountInfo(selectedAccount);
|
||||
if (info.type !== "Configured") {
|
||||
return write($main, "Account is not configured");
|
||||
}
|
||||
write($main, `<h2>${info.addr!}</h2>`);
|
||||
const chats = await client.getChatlistEntries(
|
||||
selectedAccount,
|
||||
0,
|
||||
null,
|
||||
null
|
||||
);
|
||||
for (const [chatId, _messageId] of chats) {
|
||||
const chat = await client.chatlistGetFullChatById(
|
||||
selectedAccount,
|
||||
chatId
|
||||
);
|
||||
write($main, `<h3>${chat.name}</h3>`);
|
||||
const messageIds = await client.messageListGetMessageIds(
|
||||
selectedAccount,
|
||||
chatId,
|
||||
0
|
||||
);
|
||||
const messages = await client.messageGetMessages(
|
||||
selectedAccount,
|
||||
messageIds
|
||||
);
|
||||
for (const [_messageId, message] of Object.entries(messages)) {
|
||||
write($main, `<p>${message.text}</p>`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function onIncomingEvent(event: DeltaEvent, name: string) {
|
||||
write(
|
||||
$side,
|
||||
`
|
||||
<p class="message">
|
||||
[<strong>${name}</strong> on account ${event.contextId}]<br>
|
||||
<em>f1:</em> ${JSON.stringify(event.field1)}<br>
|
||||
<em>f2:</em> ${JSON.stringify(event.field2)}
|
||||
</p>`
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
function write(el: HTMLElement, html: string) {
|
||||
el.innerHTML += html;
|
||||
}
|
||||
function clear(el: HTMLElement) {
|
||||
el.innerHTML = "";
|
||||
}
|
||||
251
deltachat-jsonrpc/typescript/generated/client.ts
Normal file
251
deltachat-jsonrpc/typescript/generated/client.ts
Normal file
@@ -0,0 +1,251 @@
|
||||
// AUTO-GENERATED by yerpc-derive
|
||||
|
||||
import * as T from "./types.js"
|
||||
import * as RPC from "./jsonrpc.js"
|
||||
|
||||
type RequestMethod = (method: string, params?: RPC.Params) => Promise<unknown>;
|
||||
type NotificationMethod = (method: string, params?: RPC.Params) => void;
|
||||
|
||||
interface Transport {
|
||||
request: RequestMethod,
|
||||
notification: NotificationMethod
|
||||
}
|
||||
|
||||
export class RawClient {
|
||||
constructor(private _transport: Transport) {}
|
||||
|
||||
/**
|
||||
* Check if an email address is valid.
|
||||
*/
|
||||
public checkEmailValidity(email: string): Promise<boolean> {
|
||||
return (this._transport.request('check_email_validity', [email] as RPC.Params)) as Promise<boolean>;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get general system info.
|
||||
*/
|
||||
public getSystemInfo(): Promise<Record<string,string>> {
|
||||
return (this._transport.request('get_system_info', [] as RPC.Params)) as Promise<Record<string,string>>;
|
||||
}
|
||||
|
||||
|
||||
public addAccount(): Promise<T.U32> {
|
||||
return (this._transport.request('add_account', [] as RPC.Params)) as Promise<T.U32>;
|
||||
}
|
||||
|
||||
|
||||
public removeAccount(accountId: T.U32): Promise<null> {
|
||||
return (this._transport.request('remove_account', [accountId] as RPC.Params)) as Promise<null>;
|
||||
}
|
||||
|
||||
|
||||
public getAllAccountIds(): Promise<(T.U32)[]> {
|
||||
return (this._transport.request('get_all_account_ids', [] as RPC.Params)) as Promise<(T.U32)[]>;
|
||||
}
|
||||
|
||||
/**
|
||||
* Select account id for internally selected state.
|
||||
* TODO: Likely this is deprecated as all methods take an account id now.
|
||||
*/
|
||||
public selectAccount(id: T.U32): Promise<null> {
|
||||
return (this._transport.request('select_account', [id] as RPC.Params)) as Promise<null>;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the selected account id of the internal state..
|
||||
* TODO: Likely this is deprecated as all methods take an account id now.
|
||||
*/
|
||||
public getSelectedAccountId(): Promise<(T.U32|null)> {
|
||||
return (this._transport.request('get_selected_account_id', [] as RPC.Params)) as Promise<(T.U32|null)>;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of all configured accounts.
|
||||
*/
|
||||
public getAllAccounts(): Promise<(T.Account)[]> {
|
||||
return (this._transport.request('get_all_accounts', [] as RPC.Params)) as Promise<(T.Account)[]>;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get top-level info for an account.
|
||||
*/
|
||||
public getAccountInfo(accountId: T.U32): Promise<T.Account> {
|
||||
return (this._transport.request('get_account_info', [accountId] as RPC.Params)) as Promise<T.Account>;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns provider for the given domain.
|
||||
*
|
||||
* This function looks up domain in offline database.
|
||||
*
|
||||
* For compatibility, email address can be passed to this function
|
||||
* instead of the domain.
|
||||
*/
|
||||
public getProviderInfo(accountId: T.U32, email: string): Promise<(T.ProviderInfo|null)> {
|
||||
return (this._transport.request('get_provider_info', [accountId, email] as RPC.Params)) as Promise<(T.ProviderInfo|null)>;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the context is already configured.
|
||||
*/
|
||||
public isConfigured(accountId: T.U32): Promise<boolean> {
|
||||
return (this._transport.request('is_configured', [accountId] as RPC.Params)) as Promise<boolean>;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get system info for an account.
|
||||
*/
|
||||
public getInfo(accountId: T.U32): Promise<Record<string,string>> {
|
||||
return (this._transport.request('get_info', [accountId] as RPC.Params)) as Promise<Record<string,string>>;
|
||||
}
|
||||
|
||||
|
||||
public setConfig(accountId: T.U32, key: string, value: (string|null)): Promise<null> {
|
||||
return (this._transport.request('set_config', [accountId, key, value] as RPC.Params)) as Promise<null>;
|
||||
}
|
||||
|
||||
|
||||
public batchSetConfig(accountId: T.U32, config: Record<string,(string|null)>): Promise<null> {
|
||||
return (this._transport.request('batch_set_config', [accountId, config] as RPC.Params)) as Promise<null>;
|
||||
}
|
||||
|
||||
|
||||
public getConfig(accountId: T.U32, key: string): Promise<(string|null)> {
|
||||
return (this._transport.request('get_config', [accountId, key] as RPC.Params)) as Promise<(string|null)>;
|
||||
}
|
||||
|
||||
|
||||
public batchGetConfig(accountId: T.U32, keys: (string)[]): Promise<Record<string,(string|null)>> {
|
||||
return (this._transport.request('batch_get_config', [accountId, keys] as RPC.Params)) as Promise<Record<string,(string|null)>>;
|
||||
}
|
||||
|
||||
/**
|
||||
* Configures this account with the currently set parameters.
|
||||
* Setup the credential config before calling this.
|
||||
*/
|
||||
public configure(accountId: T.U32): Promise<null> {
|
||||
return (this._transport.request('configure', [accountId] as RPC.Params)) as Promise<null>;
|
||||
}
|
||||
|
||||
/**
|
||||
* Signal an ongoing process to stop.
|
||||
*/
|
||||
public stopOngoingProcess(accountId: T.U32): Promise<null> {
|
||||
return (this._transport.request('stop_ongoing_process', [accountId] as RPC.Params)) as Promise<null>;
|
||||
}
|
||||
|
||||
|
||||
public autocryptInitiateKeyTransfer(accountId: T.U32): Promise<string> {
|
||||
return (this._transport.request('autocrypt_initiate_key_transfer', [accountId] as RPC.Params)) as Promise<string>;
|
||||
}
|
||||
|
||||
|
||||
public autocryptContinueKeyTransfer(accountId: T.U32, messageId: T.U32, setupCode: string): Promise<null> {
|
||||
return (this._transport.request('autocrypt_continue_key_transfer', [accountId, messageId, setupCode] as RPC.Params)) as Promise<null>;
|
||||
}
|
||||
|
||||
|
||||
public getChatlistEntries(accountId: T.U32, listFlags: (T.U32|null), queryString: (string|null), queryContactId: (T.U32|null)): Promise<(T.ChatListEntry)[]> {
|
||||
return (this._transport.request('get_chatlist_entries', [accountId, listFlags, queryString, queryContactId] as RPC.Params)) as Promise<(T.ChatListEntry)[]>;
|
||||
}
|
||||
|
||||
|
||||
public getChatlistItemsByEntries(accountId: T.U32, entries: (T.ChatListEntry)[]): Promise<Record<T.U32,T.ChatListItemFetchResult>> {
|
||||
return (this._transport.request('get_chatlist_items_by_entries', [accountId, entries] as RPC.Params)) as Promise<Record<T.U32,T.ChatListItemFetchResult>>;
|
||||
}
|
||||
|
||||
|
||||
public chatlistGetFullChatById(accountId: T.U32, chatId: T.U32): Promise<T.FullChat> {
|
||||
return (this._transport.request('chatlist_get_full_chat_by_id', [accountId, chatId] as RPC.Params)) as Promise<T.FullChat>;
|
||||
}
|
||||
|
||||
|
||||
public acceptChat(accountId: T.U32, chatId: T.U32): Promise<null> {
|
||||
return (this._transport.request('accept_chat', [accountId, chatId] as RPC.Params)) as Promise<null>;
|
||||
}
|
||||
|
||||
|
||||
public blockChat(accountId: T.U32, chatId: T.U32): Promise<null> {
|
||||
return (this._transport.request('block_chat', [accountId, chatId] as RPC.Params)) as Promise<null>;
|
||||
}
|
||||
|
||||
|
||||
public messageListGetMessageIds(accountId: T.U32, chatId: T.U32, flags: T.U32): Promise<(T.U32)[]> {
|
||||
return (this._transport.request('message_list_get_message_ids', [accountId, chatId, flags] as RPC.Params)) as Promise<(T.U32)[]>;
|
||||
}
|
||||
|
||||
|
||||
public messageGetMessage(accountId: T.U32, messageId: T.U32): Promise<T.Message> {
|
||||
return (this._transport.request('message_get_message', [accountId, messageId] as RPC.Params)) as Promise<T.Message>;
|
||||
}
|
||||
|
||||
|
||||
public messageGetMessages(accountId: T.U32, messageIds: (T.U32)[]): Promise<Record<T.U32,T.Message>> {
|
||||
return (this._transport.request('message_get_messages', [accountId, messageIds] as RPC.Params)) as Promise<Record<T.U32,T.Message>>;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a single contact options by ID.
|
||||
*/
|
||||
public contactsGetContact(accountId: T.U32, contactId: T.U32): Promise<T.Contact> {
|
||||
return (this._transport.request('contacts_get_contact', [accountId, contactId] as RPC.Params)) as Promise<T.Contact>;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a single contact as a result of an explicit user action.
|
||||
*
|
||||
* Returns contact id of the created or existing contact
|
||||
*/
|
||||
public contactsCreateContact(accountId: T.U32, email: string, name: (string|null)): Promise<T.U32> {
|
||||
return (this._transport.request('contacts_create_contact', [accountId, email, name] as RPC.Params)) as Promise<T.U32>;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns contact id of the created or existing DM chat with that contact
|
||||
*/
|
||||
public contactsCreateChatByContactId(accountId: T.U32, contactId: T.U32): Promise<T.U32> {
|
||||
return (this._transport.request('contacts_create_chat_by_contact_id', [accountId, contactId] as RPC.Params)) as Promise<T.U32>;
|
||||
}
|
||||
|
||||
|
||||
public contactsBlock(accountId: T.U32, contactId: T.U32): Promise<null> {
|
||||
return (this._transport.request('contacts_block', [accountId, contactId] as RPC.Params)) as Promise<null>;
|
||||
}
|
||||
|
||||
|
||||
public contactsUnblock(accountId: T.U32, contactId: T.U32): Promise<null> {
|
||||
return (this._transport.request('contacts_unblock', [accountId, contactId] as RPC.Params)) as Promise<null>;
|
||||
}
|
||||
|
||||
|
||||
public contactsGetBlocked(accountId: T.U32): Promise<(T.Contact)[]> {
|
||||
return (this._transport.request('contacts_get_blocked', [accountId] as RPC.Params)) as Promise<(T.Contact)[]>;
|
||||
}
|
||||
|
||||
|
||||
public contactsGetContactIds(accountId: T.U32, listFlags: T.U32, query: (string|null)): Promise<(T.U32)[]> {
|
||||
return (this._transport.request('contacts_get_contact_ids', [accountId, listFlags, query] as RPC.Params)) as Promise<(T.U32)[]>;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of contacts.
|
||||
* (formerly called getContacts2 in desktop)
|
||||
*/
|
||||
public contactsGetContacts(accountId: T.U32, listFlags: T.U32, query: (string|null)): Promise<(T.Contact)[]> {
|
||||
return (this._transport.request('contacts_get_contacts', [accountId, listFlags, query] as RPC.Params)) as Promise<(T.Contact)[]>;
|
||||
}
|
||||
|
||||
|
||||
public contactsGetContactsByIds(accountId: T.U32, ids: (T.U32)[]): Promise<Record<T.U32,T.Contact>> {
|
||||
return (this._transport.request('contacts_get_contacts_by_ids', [accountId, ids] as RPC.Params)) as Promise<Record<T.U32,T.Contact>>;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the messageid of the sent message
|
||||
*/
|
||||
public miscSendTextMessage(accountId: T.U32, text: string, chatId: T.U32): Promise<T.U32> {
|
||||
return (this._transport.request('misc_send_text_message', [accountId, text, chatId] as RPC.Params)) as Promise<T.U32>;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
3
deltachat-jsonrpc/typescript/generated/events.ts
Normal file
3
deltachat-jsonrpc/typescript/generated/events.ts
Normal file
@@ -0,0 +1,3 @@
|
||||
// AUTO-GENERATED by typescript-type-def
|
||||
|
||||
export type EventTypeName=("Info"|"SmtpConnected"|"ImapConnected"|"SmtpMessageSent"|"ImapMessageDeleted"|"ImapMessageMoved"|"NewBlobFile"|"DeletedBlobFile"|"Warning"|"Error"|"ErrorSelfNotInGroup"|"MsgsChanged"|"IncomingMsg"|"MsgsNoticed"|"MsgDelivered"|"MsgFailed"|"MsgRead"|"ChatModified"|"ChatEphemeralTimerModified"|"ContactsChanged"|"LocationChanged"|"ConfigureProgress"|"ImexProgress"|"ImexFileWritten"|"SecurejoinInviterProgress"|"SecurejoinJoinerProgress"|"ConnectivityChanged"|"SelfavatarChanged"|"WebxdcStatusUpdate");
|
||||
10
deltachat-jsonrpc/typescript/generated/jsonrpc.ts
Normal file
10
deltachat-jsonrpc/typescript/generated/jsonrpc.ts
Normal file
@@ -0,0 +1,10 @@
|
||||
// AUTO-GENERATED by typescript-type-def
|
||||
|
||||
export type JSONValue=(null|boolean|number|string|(JSONValue)[]|{[key:string]:JSONValue;});
|
||||
export type Params=((JSONValue)[]|Record<string,JSONValue>);
|
||||
export type U32=number;
|
||||
export type Request={"jsonrpc":"2.0";"method":string;"params"?:Params;"id"?:U32;};
|
||||
export type I32=number;
|
||||
export type Error={"code":I32;"message":string;"data"?:JSONValue;};
|
||||
export type Response={"jsonrpc":"2.0";"id":(U32|null);"result"?:JSONValue;"error"?:Error;};
|
||||
export type Message=(Request|Response);
|
||||
15
deltachat-jsonrpc/typescript/generated/types.ts
Normal file
15
deltachat-jsonrpc/typescript/generated/types.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
// AUTO-GENERATED by typescript-type-def
|
||||
|
||||
export type U32=number;
|
||||
export type Account=(({"type":"Configured";}&{"id":U32;"display_name":(string|null);"addr":(string|null);"profile_image":(string|null);"color":string;})|({"type":"Unconfigured";}&{"id":U32;}));
|
||||
export type ProviderInfo={"before_login_hint":string;"overview_page":string;"status":U32;};
|
||||
export type ChatListEntry=[U32,U32];
|
||||
export type I64=number;
|
||||
export type Usize=number;
|
||||
export type ChatListItemFetchResult=(({"type":"ChatListItem";}&{"id":U32;"name":string;"avatarPath":(string|null);"color":string;"lastUpdated":(I64|null);"summaryText1":string;"summaryText2":string;"summaryStatus":U32;"isProtected":boolean;"isGroup":boolean;"freshMessageCounter":Usize;"isSelfTalk":boolean;"isDeviceTalk":boolean;"isSendingLocation":boolean;"isSelfInGroup":boolean;"isArchived":boolean;"isPinned":boolean;"isMuted":boolean;"isContactRequest":boolean;})|{"type":"ArchiveLink";}|({"type":"Error";}&{"id":U32;"error":string;}));
|
||||
export type Contact={"address":string;"color":string;"auth_name":string;"status":string;"display_name":string;"id":U32;"name":string;"profile_image":(string|null);"name_and_addr":string;"is_blocked":boolean;"is_verified":boolean;};
|
||||
export type FullChat={"id":U32;"name":string;"is_protected":boolean;"profile_image":(string|null);"archived":boolean;"chat_type":U32;"is_unpromoted":boolean;"is_self_talk":boolean;"contacts":(Contact)[];"contact_ids":(U32)[];"color":string;"fresh_message_counter":Usize;"is_contact_request":boolean;"is_device_chat":boolean;"self_in_group":boolean;"is_muted":boolean;"ephemeral_timer":U32;"can_send":boolean;};
|
||||
export type I32=number;
|
||||
export type U64=number;
|
||||
export type Message={"id":U32;"chat_id":U32;"from_id":U32;"quoted_text":(string|null);"quoted_message_id":(U32|null);"text":(string|null);"has_location":boolean;"has_html":boolean;"view_type":U32;"state":U32;"timestamp":I64;"sort_timestamp":I64;"received_timestamp":I64;"has_deviating_timestamp":boolean;"subject":string;"show_padlock":boolean;"is_setupmessage":boolean;"is_info":boolean;"is_forwarded":boolean;"duration":I32;"dimensions_height":I32;"dimensions_width":I32;"videochat_type":(U32|null);"videochat_url":(string|null);"override_sender_name":(string|null);"sender":Contact;"setup_code_begin":(string|null);"file":(string|null);"file_mime":(string|null);"file_bytes":U64;"file_name":(string|null);};
|
||||
export type __AllTyps=[string,boolean,Record<string,string>,U32,U32,null,(U32)[],U32,null,(U32|null),(Account)[],U32,Account,U32,string,(ProviderInfo|null),U32,boolean,U32,Record<string,string>,U32,string,(string|null),null,U32,Record<string,(string|null)>,null,U32,string,(string|null),U32,(string)[],Record<string,(string|null)>,U32,null,U32,null,U32,string,U32,U32,string,null,U32,(U32|null),(string|null),(U32|null),(ChatListEntry)[],U32,(ChatListEntry)[],Record<U32,ChatListItemFetchResult>,U32,U32,FullChat,U32,U32,null,U32,U32,null,U32,U32,U32,(U32)[],U32,U32,Message,U32,(U32)[],Record<U32,Message>,U32,U32,Contact,U32,string,(string|null),U32,U32,U32,U32,U32,U32,null,U32,U32,null,U32,(Contact)[],U32,U32,(string|null),(U32)[],U32,U32,(string|null),(Contact)[],U32,(U32)[],Record<U32,Contact>,U32,string,U32,U32];
|
||||
54
deltachat-jsonrpc/typescript/index.html
Normal file
54
deltachat-jsonrpc/typescript/index.html
Normal file
@@ -0,0 +1,54 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<style>
|
||||
body {
|
||||
font-family: monospace;
|
||||
background: black;
|
||||
color: grey;
|
||||
}
|
||||
.grid {
|
||||
display: grid;
|
||||
grid-template-columns: 3fr 1fr;
|
||||
grid-template-areas: "a a" "b c";
|
||||
}
|
||||
.message {
|
||||
color: red;
|
||||
}
|
||||
#header {
|
||||
grid-area: a;
|
||||
color: white;
|
||||
font-size: 1.2rem;
|
||||
}
|
||||
#header a {
|
||||
color: white;
|
||||
font-weight: bold;
|
||||
}
|
||||
#main {
|
||||
grid-area: b;
|
||||
color: green;
|
||||
}
|
||||
#main h2,
|
||||
#main h3 {
|
||||
color: blue;
|
||||
}
|
||||
#side {
|
||||
grid-area: c;
|
||||
color: #777;
|
||||
overflow-y: auto;
|
||||
}
|
||||
</style>
|
||||
<script type="module" src="dist/example.bundle.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<div class="grid">
|
||||
<div id="header"></div>
|
||||
<div id="main"></div>
|
||||
<div id="side"><h2>log</h2></div>
|
||||
</div>
|
||||
<p>
|
||||
Tip: open the dev console and use the client with
|
||||
<code>window.client</code>
|
||||
</p>
|
||||
</body>
|
||||
</html>
|
||||
13
deltachat-jsonrpc/typescript/node-demo.js
Normal file
13
deltachat-jsonrpc/typescript/node-demo.js
Normal file
@@ -0,0 +1,13 @@
|
||||
import { Deltachat } from "./dist/deltachat.js";
|
||||
|
||||
run().catch(console.error);
|
||||
|
||||
async function run() {
|
||||
const delta = new Deltachat();
|
||||
delta.addEventListener("event", (event) => {
|
||||
console.log("event", event.data);
|
||||
});
|
||||
|
||||
const accounts = await delta.rpc.getAllAccounts();
|
||||
console.log("accounts", accounts);
|
||||
}
|
||||
41
deltachat-jsonrpc/typescript/package.json
Normal file
41
deltachat-jsonrpc/typescript/package.json
Normal file
@@ -0,0 +1,41 @@
|
||||
{
|
||||
"name": "@deltachat/jsonrpc-client",
|
||||
"version": "0.1.0",
|
||||
"main": "dist/deltachat.js",
|
||||
"types": "dist/deltachat.d.ts",
|
||||
"type": "module",
|
||||
"author": "Delta Chat Developers (ML) <delta@codespeak.net>",
|
||||
"license": "MPL-2.0",
|
||||
"scripts": {
|
||||
"prettier:check": "prettier --check **.ts",
|
||||
"prettier:fix": "prettier --write **.ts",
|
||||
"build": "npm run generate-bindings && tsc",
|
||||
"bundle": "npm run build && esbuild --bundle dist/deltachat.js --outfile=dist/deltachat.bundle.js",
|
||||
"generate-bindings": "cargo test",
|
||||
"example:build": "tsc && esbuild --bundle dist/example.js --outfile=dist/example.bundle.js",
|
||||
"example:dev": "esbuild example.ts --bundle --outdir=dist --servedir=.",
|
||||
"coverage": "tsc -b test && COVERAGE=1 NODE_OPTIONS=--enable-source-maps c8 --include \"dist/*\" -r text -r html -r json mocha test_dist && node report_api_coverage.mjs",
|
||||
"test": "rm -rf dist && npm run build && npm run coverage && npm run prettier:check"
|
||||
},
|
||||
"dependencies": {
|
||||
"isomorphic-ws": "^4.0.1",
|
||||
"tiny-emitter": "git+https://github.com/Simon-Laux/tiny-emitter.git",
|
||||
"yerpc": "^0.2.3"
|
||||
},
|
||||
"devDependencies": {
|
||||
"prettier": "^2.6.2",
|
||||
"chai-as-promised": "^7.1.1",
|
||||
"@types/chai": "^4.2.21",
|
||||
"@types/chai-as-promised": "^7.1.5",
|
||||
"@types/mocha": "^9.0.0",
|
||||
"@types/node-fetch": "^2.5.7",
|
||||
"@types/ws": "^7.2.4",
|
||||
"c8": "^7.10.0",
|
||||
"chai": "^4.3.4",
|
||||
"esbuild": "^0.14.11",
|
||||
"mocha": "^9.1.1",
|
||||
"node-fetch": "^2.6.1",
|
||||
"typescript": "^4.5.5",
|
||||
"ws": "^8.5.0"
|
||||
}
|
||||
}
|
||||
28
deltachat-jsonrpc/typescript/report_api_coverage.mjs
Normal file
28
deltachat-jsonrpc/typescript/report_api_coverage.mjs
Normal file
@@ -0,0 +1,28 @@
|
||||
import { readFileSync } from "fs";
|
||||
// only checks for the coverge of the api functions in bindings.ts for now
|
||||
const generated_file = "typescript/generated/client.ts";
|
||||
const json = JSON.parse(readFileSync("./coverage/coverage-final.json"));
|
||||
const jsonCoverage =
|
||||
json[Object.keys(json).find((k) => k.includes(generated_file))];
|
||||
const fnMap = Object.keys(jsonCoverage.fnMap).map(
|
||||
(key) => jsonCoverage.fnMap[key]
|
||||
);
|
||||
const htmlCoverage = readFileSync(
|
||||
"./coverage/" + generated_file + ".html",
|
||||
"utf8"
|
||||
);
|
||||
const uncoveredLines = htmlCoverage
|
||||
.split("\n")
|
||||
.filter((line) => line.includes(`"function not covered"`));
|
||||
const uncoveredFunctions = uncoveredLines.map(
|
||||
(line) => />([\w_]+)\(/.exec(line)[1]
|
||||
);
|
||||
console.log(
|
||||
"\nUncovered api functions:\n" +
|
||||
uncoveredFunctions
|
||||
.map((uF) => fnMap.find(({ name }) => name === uF))
|
||||
.map(
|
||||
({ name, line }) => `.${name.padEnd(40)} (${generated_file}:${line})`
|
||||
)
|
||||
.join("\n")
|
||||
);
|
||||
77
deltachat-jsonrpc/typescript/src/client.ts
Normal file
77
deltachat-jsonrpc/typescript/src/client.ts
Normal file
@@ -0,0 +1,77 @@
|
||||
import * as T from "../generated/types.js";
|
||||
import * as RPC from "../generated/jsonrpc.js";
|
||||
import { RawClient } from "../generated/client.js";
|
||||
import { EventTypeName } from "../generated/events.js";
|
||||
import { WebsocketTransport, BaseTransport, Request } from "yerpc";
|
||||
import { TinyEmitter } from "tiny-emitter";
|
||||
|
||||
export type DeltachatEvent = {
|
||||
id: EventTypeName;
|
||||
contextId: number;
|
||||
field1: any;
|
||||
field2: any;
|
||||
};
|
||||
export type Events = Record<
|
||||
EventTypeName | "ALL",
|
||||
(event: DeltachatEvent) => void
|
||||
>;
|
||||
|
||||
export class BaseDeltachat<
|
||||
Transport extends BaseTransport
|
||||
> extends TinyEmitter<Events> {
|
||||
rpc: RawClient;
|
||||
account?: T.Account;
|
||||
constructor(protected transport: Transport) {
|
||||
super();
|
||||
this.rpc = new RawClient(this.transport);
|
||||
this.transport.on("request", (request: Request) => {
|
||||
const method = request.method;
|
||||
if (method === "event") {
|
||||
const event = request.params! as DeltachatEvent;
|
||||
this.emit(event.id, event);
|
||||
this.emit("ALL", event);
|
||||
|
||||
if (this.contextEmitters[event.contextId]) {
|
||||
this.contextEmitters[event.contextId].emit(event.id, event);
|
||||
this.contextEmitters[event.contextId].emit("ALL", event);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
async listAccounts(): Promise<T.Account[]> {
|
||||
return await this.rpc.getAllAccounts();
|
||||
}
|
||||
|
||||
private contextEmitters: TinyEmitter<Events>[] = [];
|
||||
|
||||
getContextEvents(account_id: number) {
|
||||
if (this.contextEmitters[account_id]) {
|
||||
return this.contextEmitters[account_id];
|
||||
} else {
|
||||
this.contextEmitters[account_id] = new TinyEmitter();
|
||||
return this.contextEmitters[account_id];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export type Opts = {
|
||||
url: string;
|
||||
};
|
||||
|
||||
export const DEFAULT_OPTS: Opts = {
|
||||
url: "ws://localhost:20808/ws",
|
||||
};
|
||||
export class Deltachat extends BaseDeltachat<WebsocketTransport> {
|
||||
opts: Opts;
|
||||
close() {
|
||||
this.transport._socket.close();
|
||||
}
|
||||
constructor(opts: Opts | string | undefined) {
|
||||
if (typeof opts === "string") opts = { url: opts };
|
||||
if (opts) opts = { ...DEFAULT_OPTS, ...opts };
|
||||
else opts = { ...DEFAULT_OPTS };
|
||||
super(new WebsocketTransport(opts.url));
|
||||
this.opts = opts;
|
||||
}
|
||||
}
|
||||
6
deltachat-jsonrpc/typescript/src/lib.ts
Normal file
6
deltachat-jsonrpc/typescript/src/lib.ts
Normal file
@@ -0,0 +1,6 @@
|
||||
export * as RPC from "../generated/jsonrpc.js";
|
||||
export * as T from "../generated/types.js";
|
||||
export * from "../generated/events.js";
|
||||
export { RawClient } from "../generated/client.js";
|
||||
export * from "./client.js";
|
||||
export * as yerpc from "yerpc";
|
||||
1
deltachat-jsonrpc/typescript/test/README.md
Normal file
1
deltachat-jsonrpc/typescript/test/README.md
Normal file
@@ -0,0 +1 @@
|
||||
# tests need to be ported to new API
|
||||
158
deltachat-jsonrpc/typescript/test/basic.ts
Normal file
158
deltachat-jsonrpc/typescript/test/basic.ts
Normal file
@@ -0,0 +1,158 @@
|
||||
import { strictEqual } from "assert";
|
||||
import chai, { assert, expect } from "chai";
|
||||
import chaiAsPromised from "chai-as-promised";
|
||||
chai.use(chaiAsPromised);
|
||||
import { Deltachat } from "../dist/deltachat.js";
|
||||
|
||||
import {
|
||||
CMD_API_Server_Handle,
|
||||
CMD_API_SERVER_PORT,
|
||||
startCMD_API_Server,
|
||||
} from "./test_base.js";
|
||||
|
||||
describe("basic tests", () => {
|
||||
let server_handle: CMD_API_Server_Handle;
|
||||
let dc: Deltachat;
|
||||
|
||||
before(async () => {
|
||||
server_handle = await startCMD_API_Server(CMD_API_SERVER_PORT);
|
||||
// make sure server is up by the time we continue
|
||||
await new Promise((res) => setTimeout(res, 100));
|
||||
|
||||
dc = new Deltachat({
|
||||
url: "ws://localhost:" + CMD_API_SERVER_PORT + "/ws",
|
||||
});
|
||||
dc.on("ALL", (event) => {
|
||||
//console.log("event", event);
|
||||
});
|
||||
});
|
||||
|
||||
after(async () => {
|
||||
dc && dc.close();
|
||||
await server_handle.close();
|
||||
});
|
||||
|
||||
it("check email", async () => {
|
||||
const positive_test_cases = [
|
||||
"email@example.com",
|
||||
"36aa165ae3406424e0c61af17700f397cad3fe8ab83d682d0bddf3338a5dd52e@yggmail@yggmail",
|
||||
];
|
||||
const negative_test_cases = ["email@", "example.com", "emai221"];
|
||||
|
||||
expect(
|
||||
await Promise.all(
|
||||
positive_test_cases.map((email) => dc.rpc.checkEmailValidity(email))
|
||||
)
|
||||
).to.not.contain(false);
|
||||
|
||||
expect(
|
||||
await Promise.all(
|
||||
negative_test_cases.map((email) => dc.rpc.checkEmailValidity(email))
|
||||
)
|
||||
).to.not.contain(true);
|
||||
});
|
||||
|
||||
it("system info", async () => {
|
||||
const system_info = await dc.rpc.getSystemInfo();
|
||||
expect(system_info).to.contain.keys([
|
||||
"arch",
|
||||
"num_cpus",
|
||||
"deltachat_core_version",
|
||||
"sqlite_version",
|
||||
]);
|
||||
});
|
||||
|
||||
describe("account managment", () => {
|
||||
it("should create account", async () => {
|
||||
await dc.rpc.addAccount();
|
||||
assert((await dc.rpc.getAllAccountIds()).length === 1);
|
||||
});
|
||||
|
||||
it("should remove the account again", async () => {
|
||||
await dc.rpc.removeAccount((await dc.rpc.getAllAccountIds())[0]);
|
||||
assert((await dc.rpc.getAllAccountIds()).length === 0);
|
||||
});
|
||||
|
||||
it("should create multiple accounts", async () => {
|
||||
await dc.rpc.addAccount();
|
||||
await dc.rpc.addAccount();
|
||||
await dc.rpc.addAccount();
|
||||
await dc.rpc.addAccount();
|
||||
assert((await dc.rpc.getAllAccountIds()).length === 4);
|
||||
});
|
||||
});
|
||||
|
||||
describe("contact managment", function () {
|
||||
let acc: number;
|
||||
before(async () => {
|
||||
acc = await dc.rpc.addAccount();
|
||||
});
|
||||
it("block and unblock contact", async function () {
|
||||
const contactId = await dc.rpc.contactsCreateContact(
|
||||
acc,
|
||||
"example@delta.chat",
|
||||
null
|
||||
);
|
||||
expect((await dc.rpc.contactsGetContact(acc, contactId)).is_blocked).to.be
|
||||
.false;
|
||||
await dc.rpc.contactsBlock(acc, contactId);
|
||||
expect((await dc.rpc.contactsGetContact(acc, contactId)).is_blocked).to.be
|
||||
.true;
|
||||
expect(await dc.rpc.contactsGetBlocked(acc)).to.have.length(1);
|
||||
await dc.rpc.contactsUnblock(acc, contactId);
|
||||
expect((await dc.rpc.contactsGetContact(acc, contactId)).is_blocked).to.be
|
||||
.false;
|
||||
expect(await dc.rpc.contactsGetBlocked(acc)).to.have.length(0);
|
||||
});
|
||||
});
|
||||
|
||||
describe("configuration", function () {
|
||||
let acc: number;
|
||||
before(async () => {
|
||||
acc = await dc.rpc.addAccount();
|
||||
});
|
||||
|
||||
it("set and retrive", async function () {
|
||||
await dc.rpc.setConfig(acc, "addr", "valid@email");
|
||||
assert((await dc.rpc.getConfig(acc, "addr")) == "valid@email");
|
||||
});
|
||||
it("set invalid key should throw", async function () {
|
||||
await expect(dc.rpc.setConfig(acc, "invalid_key", "some value")).to.be
|
||||
.eventually.rejected;
|
||||
});
|
||||
it("get invalid key should throw", async function () {
|
||||
await expect(dc.rpc.getConfig(acc, "invalid_key")).to.be.eventually
|
||||
.rejected;
|
||||
});
|
||||
it("set and retrive ui.*", async function () {
|
||||
await dc.rpc.setConfig(acc, "ui.chat_bg", "color:red");
|
||||
assert((await dc.rpc.getConfig(acc, "ui.chat_bg")) == "color:red");
|
||||
});
|
||||
it("set and retrive (batch)", async function () {
|
||||
const config = { addr: "valid@email", mail_pw: "1234" };
|
||||
await dc.rpc.batchSetConfig(acc, config);
|
||||
const retrieved = await dc.rpc.batchGetConfig(acc, Object.keys(config));
|
||||
expect(retrieved).to.deep.equal(config);
|
||||
});
|
||||
it("set and retrive ui.* (batch)", async function () {
|
||||
const config = {
|
||||
"ui.chat_bg": "color:green",
|
||||
"ui.enter_key_sends": "true",
|
||||
};
|
||||
await dc.rpc.batchSetConfig(acc, config);
|
||||
const retrieved = await dc.rpc.batchGetConfig(acc, Object.keys(config));
|
||||
expect(retrieved).to.deep.equal(config);
|
||||
});
|
||||
it("set and retrive mixed(ui and core) (batch)", async function () {
|
||||
const config = {
|
||||
"ui.chat_bg": "color:yellow",
|
||||
"ui.enter_key_sends": "false",
|
||||
addr: "valid2@email",
|
||||
mail_pw: "123456",
|
||||
};
|
||||
await dc.rpc.batchSetConfig(acc, config);
|
||||
const retrieved = await dc.rpc.batchGetConfig(acc, Object.keys(config));
|
||||
expect(retrieved).to.deep.equal(config);
|
||||
});
|
||||
});
|
||||
});
|
||||
203
deltachat-jsonrpc/typescript/test/online.ts
Normal file
203
deltachat-jsonrpc/typescript/test/online.ts
Normal file
@@ -0,0 +1,203 @@
|
||||
import { assert, expect } from "chai";
|
||||
import { Deltachat, DeltachatEvent, EventTypeName } from "../dist/deltachat.js";
|
||||
import {
|
||||
CMD_API_Server_Handle,
|
||||
CMD_API_SERVER_PORT,
|
||||
createTempUser,
|
||||
startCMD_API_Server,
|
||||
} from "./test_base.js";
|
||||
|
||||
describe("online tests", function () {
|
||||
let server_handle: CMD_API_Server_Handle;
|
||||
let dc: Deltachat;
|
||||
let account: { email: string; password: string };
|
||||
let account2: { email: string; password: string };
|
||||
let acc1: number, acc2: number;
|
||||
|
||||
before(async function () {
|
||||
this.timeout(12000)
|
||||
if (!process.env.DCC_NEW_TMP_EMAIL) {
|
||||
if (process.env.COVERAGE && !process.env.COVERAGE_OFFLINE) {
|
||||
console.error(
|
||||
"CAN NOT RUN COVERAGE correctly: Missing DCC_NEW_TMP_EMAIL environment variable!\n\n",
|
||||
"You can set COVERAGE_OFFLINE=1 to circumvent this check and skip the online tests, but those coverage results will be wrong, because some functions can only be tested in the online test"
|
||||
);
|
||||
process.exit(1);
|
||||
}
|
||||
console.log(
|
||||
"Missing DCC_NEW_TMP_EMAIL environment variable!, skip intergration tests"
|
||||
);
|
||||
this.skip();
|
||||
}
|
||||
server_handle = await startCMD_API_Server(CMD_API_SERVER_PORT);
|
||||
dc = new Deltachat({
|
||||
url: "ws://localhost:" + CMD_API_SERVER_PORT + "/ws",
|
||||
});
|
||||
|
||||
dc.on("ALL", ({ id, contextId }) => {
|
||||
if (id !== "Info") console.log(contextId, id);
|
||||
});
|
||||
|
||||
account = await createTempUser(process.env.DCC_NEW_TMP_EMAIL);
|
||||
if (!account || !account.email || !account.password) {
|
||||
console.log(
|
||||
"We didn't got back an account from the api, skip intergration tests"
|
||||
);
|
||||
this.skip();
|
||||
}
|
||||
|
||||
account2 = await createTempUser(process.env.DCC_NEW_TMP_EMAIL);
|
||||
if (!account2 || !account2.email || !account2.password) {
|
||||
console.log(
|
||||
"We didn't got back an account2 from the api, skip intergration tests"
|
||||
);
|
||||
this.skip();
|
||||
}
|
||||
});
|
||||
|
||||
after(async () => {
|
||||
dc && dc.close();
|
||||
server_handle && (await server_handle.close());
|
||||
});
|
||||
|
||||
let are_configured = false;
|
||||
|
||||
it("configure test accounts", async function () {
|
||||
this.timeout(20000);
|
||||
|
||||
acc1 = await dc.rpc.addAccount();
|
||||
await dc.rpc.setConfig(acc1, "addr", account.email);
|
||||
await dc.rpc.setConfig(acc1, "mail_pw", account.password);
|
||||
let configure_promise = dc.rpc.configure(acc1);
|
||||
|
||||
acc2 = await dc.rpc.addAccount();
|
||||
await dc.rpc.batchSetConfig(acc2, {
|
||||
addr: account2.email,
|
||||
mail_pw: account2.password,
|
||||
});
|
||||
|
||||
await Promise.all([configure_promise, dc.rpc.configure(acc2)]);
|
||||
are_configured = true;
|
||||
});
|
||||
|
||||
it("send and recieve text message", async function () {
|
||||
if (!are_configured) {
|
||||
this.skip();
|
||||
}
|
||||
this.timeout(15000);
|
||||
|
||||
const contactId = await dc.rpc.contactsCreateContact(
|
||||
acc1,
|
||||
account2.email,
|
||||
null
|
||||
);
|
||||
const chatId = await dc.rpc.contactsCreateChatByContactId(acc1, contactId);
|
||||
const eventPromise = Promise.race([
|
||||
waitForEvent(dc, "MsgsChanged", acc2),
|
||||
waitForEvent(dc, "IncomingMsg", acc2),
|
||||
]);
|
||||
|
||||
dc.rpc.miscSendTextMessage(acc1, "Hello", chatId);
|
||||
const { field1: chatIdOnAccountB } = await eventPromise;
|
||||
await dc.rpc.acceptChat(acc2, chatIdOnAccountB);
|
||||
const messageList = await dc.rpc.messageListGetMessageIds(
|
||||
acc2,
|
||||
chatIdOnAccountB,
|
||||
0
|
||||
);
|
||||
|
||||
expect(messageList).have.length(1);
|
||||
const message = await dc.rpc.messageGetMessage(acc2, messageList[0]);
|
||||
expect(message.text).equal("Hello");
|
||||
});
|
||||
|
||||
it("send and recieve text message roundtrip, encrypted on answer onwards", async function () {
|
||||
if (!are_configured) {
|
||||
this.skip();
|
||||
}
|
||||
this.timeout(10000);
|
||||
|
||||
// send message from A to B
|
||||
const contactId = await dc.rpc.contactsCreateContact(
|
||||
acc1,
|
||||
account2.email,
|
||||
null
|
||||
);
|
||||
const chatId = await dc.rpc.contactsCreateChatByContactId(acc1, contactId);
|
||||
const eventPromise = Promise.race([
|
||||
waitForEvent(dc, "MsgsChanged", acc2),
|
||||
waitForEvent(dc, "IncomingMsg", acc2),
|
||||
]);
|
||||
dc.rpc.miscSendTextMessage(acc1, "Hello2", chatId);
|
||||
// wait for message from A
|
||||
console.log("wait for message from A");
|
||||
|
||||
const event = await eventPromise;
|
||||
const { field1: chatIdOnAccountB } = event;
|
||||
|
||||
await dc.rpc.acceptChat(acc2, chatIdOnAccountB);
|
||||
const messageList = await dc.rpc.messageListGetMessageIds(
|
||||
acc2,
|
||||
chatIdOnAccountB,
|
||||
0
|
||||
);
|
||||
const message = await dc.rpc.messageGetMessage(
|
||||
acc2,
|
||||
messageList.reverse()[0]
|
||||
);
|
||||
expect(message.text).equal("Hello2");
|
||||
// Send message back from B to A
|
||||
const eventPromise2 = Promise.race([
|
||||
waitForEvent(dc, "MsgsChanged", acc1),
|
||||
waitForEvent(dc, "IncomingMsg", acc1),
|
||||
]);
|
||||
dc.rpc.miscSendTextMessage(acc2, "super secret message", chatId);
|
||||
// Check if answer arives at A and if it is encrypted
|
||||
await eventPromise2;
|
||||
|
||||
const messageId = (
|
||||
await dc.rpc.messageListGetMessageIds(acc1, chatId, 0)
|
||||
).reverse()[0];
|
||||
const message2 = await dc.rpc.messageGetMessage(acc1, messageId);
|
||||
expect(message2.text).equal("super secret message");
|
||||
expect(message2.show_padlock).equal(true);
|
||||
});
|
||||
|
||||
it("get provider info for example.com", async () => {
|
||||
const acc = await dc.rpc.addAccount();
|
||||
const info = await dc.rpc.getProviderInfo(acc, "example.com");
|
||||
expect(info).to.be.not.null;
|
||||
expect(info?.overview_page).to.equal(
|
||||
"https://providers.delta.chat/example-com"
|
||||
);
|
||||
expect(info?.status).to.equal(3);
|
||||
});
|
||||
|
||||
it("get provider info - domain and email should give same result", async () => {
|
||||
const acc = await dc.rpc.addAccount();
|
||||
const info_domain = await dc.rpc.getProviderInfo(acc, "example.com");
|
||||
const info_email = await dc.rpc.getProviderInfo(acc, "hi@example.com");
|
||||
expect(info_email).to.deep.equal(info_domain);
|
||||
});
|
||||
});
|
||||
|
||||
type event_data = {
|
||||
contextId: number;
|
||||
id: EventTypeName;
|
||||
[key: string]: any;
|
||||
};
|
||||
async function waitForEvent(
|
||||
dc: Deltachat,
|
||||
event: EventTypeName,
|
||||
accountId: number
|
||||
): Promise<event_data> {
|
||||
return new Promise((res, rej) => {
|
||||
const callback = (ev: DeltachatEvent) => {
|
||||
if (ev.contextId == accountId) {
|
||||
dc.off(event, callback);
|
||||
res(ev);
|
||||
}
|
||||
};
|
||||
dc.on(event, callback);
|
||||
});
|
||||
}
|
||||
95
deltachat-jsonrpc/typescript/test/test_base.ts
Normal file
95
deltachat-jsonrpc/typescript/test/test_base.ts
Normal file
@@ -0,0 +1,95 @@
|
||||
import { tmpdir } from "os";
|
||||
import { join } from "path";
|
||||
import { mkdtemp, rm } from "fs/promises";
|
||||
import { existsSync } from "fs";
|
||||
import { spawn, exec } from "child_process";
|
||||
import { unwrapPromise } from "./ts_helpers.js";
|
||||
import fetch from "node-fetch";
|
||||
/* port is not configurable yet */
|
||||
|
||||
|
||||
function getTargetDir(): Promise<string> {
|
||||
return new Promise((res, rej) => {
|
||||
exec(
|
||||
"cargo metadata --no-deps --format-version 1",
|
||||
(error, stdout, stderr) => {
|
||||
if (error) {
|
||||
console.log("error", error);
|
||||
rej(error);
|
||||
} else {
|
||||
try {
|
||||
const json = JSON.parse(stdout);
|
||||
res(json.target_directory);
|
||||
} catch (error) {
|
||||
console.log("json error", error);
|
||||
rej(error);
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
export const CMD_API_SERVER_PORT = 20808;
|
||||
export async function startCMD_API_Server(port: typeof CMD_API_SERVER_PORT) {
|
||||
const tmp_dir = await mkdtemp(join(tmpdir(), "test_prefix"));
|
||||
|
||||
const path_of_server = join(await getTargetDir(), "debug/webserver");
|
||||
console.log(path_of_server);
|
||||
|
||||
if (!existsSync(path_of_server)) {
|
||||
throw new Error(
|
||||
"server executable does not exist, you need to build it first" +
|
||||
"\nserver executable not found at " +
|
||||
path_of_server
|
||||
);
|
||||
}
|
||||
|
||||
const server = spawn(path_of_server, {
|
||||
cwd: tmp_dir,
|
||||
env: {
|
||||
RUST_LOG: "info",
|
||||
},
|
||||
});
|
||||
let should_close = false;
|
||||
|
||||
server.on("exit", () => {
|
||||
if (should_close) {
|
||||
return;
|
||||
}
|
||||
throw new Error("Server quit");
|
||||
});
|
||||
|
||||
server.stderr.pipe(process.stderr);
|
||||
|
||||
//server.stdout.pipe(process.stdout)
|
||||
|
||||
return {
|
||||
close: async () => {
|
||||
should_close = true;
|
||||
if (!server.kill(9)) {
|
||||
console.log("server termination failed");
|
||||
}
|
||||
await rm(tmp_dir, { recursive: true });
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
export type CMD_API_Server_Handle = unwrapPromise<
|
||||
ReturnType<typeof startCMD_API_Server>
|
||||
>;
|
||||
|
||||
export async function createTempUser(url: string) {
|
||||
async function postData(url = "") {
|
||||
// Default options are marked with *
|
||||
const response = await fetch(url, {
|
||||
method: "POST", // *GET, POST, PUT, DELETE, etc.
|
||||
headers: {
|
||||
"cache-control": "no-cache",
|
||||
},
|
||||
});
|
||||
return response.json(); // parses JSON response into native JavaScript objects
|
||||
}
|
||||
|
||||
return await postData(url);
|
||||
}
|
||||
1
deltachat-jsonrpc/typescript/test/ts_helpers.ts
Normal file
1
deltachat-jsonrpc/typescript/test/ts_helpers.ts
Normal file
@@ -0,0 +1 @@
|
||||
export type unwrapPromise<T> = T extends Promise<infer U> ? U : never;
|
||||
17
deltachat-jsonrpc/typescript/test/tsconfig.json
Normal file
17
deltachat-jsonrpc/typescript/test/tsconfig.json
Normal file
@@ -0,0 +1,17 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"rootDir": ".",
|
||||
"outDir": "../test_dist",
|
||||
"target": "ES2020",
|
||||
"module": "es2020",
|
||||
"moduleResolution": "node",
|
||||
"declaration": false,
|
||||
"esModuleInterop": true,
|
||||
"noImplicitAny": true,
|
||||
"isolatedModules": true,
|
||||
"strictNullChecks": true,
|
||||
"strict": true,
|
||||
"sourceMap": true
|
||||
},
|
||||
"compileOnSave": true
|
||||
}
|
||||
20
deltachat-jsonrpc/typescript/tsconfig.json
Normal file
20
deltachat-jsonrpc/typescript/tsconfig.json
Normal file
@@ -0,0 +1,20 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"alwaysStrict": true,
|
||||
"strict": true,
|
||||
"sourceMap": true,
|
||||
"strictNullChecks": true,
|
||||
"rootDir": ".",
|
||||
"outDir": "dist",
|
||||
"lib": ["ES2017", "dom"],
|
||||
"target": "ES2017",
|
||||
"module": "es2015",
|
||||
"declaration": true,
|
||||
"esModuleInterop": true,
|
||||
"moduleResolution": "node",
|
||||
"noImplicitAny": true,
|
||||
"isolatedModules": true
|
||||
},
|
||||
"include": ["*.ts"],
|
||||
"compileOnSave": false
|
||||
}
|
||||
99
draft/aeap-mvp.md
Normal file
99
draft/aeap-mvp.md
Normal file
@@ -0,0 +1,99 @@
|
||||
AEAP MVP
|
||||
========
|
||||
|
||||
Changes to the UIs
|
||||
------------------
|
||||
|
||||
- The secondary self addresses (see below) are shown in the UI, but not editable.
|
||||
|
||||
- When the user changed the email address in the configure screen, show a dialog to the user, either directly explaining things or with a link to the FAQ (see "Other" below)
|
||||
|
||||
Changes in the core
|
||||
-------------------
|
||||
|
||||
- DONE: We have one primary self address and any number of secondary self addresses. `is_self_addr()` checks all of them.
|
||||
|
||||
- DONE: If the user does a reconfigure and changes the email address, the previous address is added as a secondary self address.
|
||||
|
||||
- don't forget to deduplicate secondary self addresses in case the user switches back and forth between addresses).
|
||||
|
||||
- The key stays the same.
|
||||
|
||||
- No changes for 1:1 chats, there simply is a new one. (This works since, contrary to group messages, messages sent to a 1:1 chat are not assigned to the group chat but always to the 1:1 chat with the sender. So it's not a problem that the new messages might be put into the old chat if they are a reply to a message there.)
|
||||
|
||||
- When sending a message: If any of the secondary self addrs is in the chat's member list, remove it locally (because we just transitioned away from it). We add a log message for this (alternatively, a system message in the chat would be more visible).
|
||||
|
||||
- When receiving a message: If the key exists, but belongs to another address (we may want to benchmark this)
|
||||
AND there is a `Chat-Version` header\
|
||||
AND the message timestamp is newer than the contact's `lastseen` (to prevent changing the address back when messages arrive out of order) (this condition is not that important since we will have eventual consistency even without it):
|
||||
|
||||
Replace the contact in _all_ groups, possibly deduplicate the members list, and add a system message to all of these chats.
|
||||
|
||||
- Note that we can't simply compare the keys byte-by-byte, since the UID may have changed, or the sender may have rotated the key and signed the new key with the old one.
|
||||
|
||||
### Notes:
|
||||
|
||||
- We treat protected and non-protected chats the same
|
||||
- We leave the aeap transition statement away since it seems not to be needed, makes things harder on the sending side, wastes some network traffic, and is worse for privacy (since more pepole know what old addresses you had).
|
||||
- As soon as we encrypt read receipts, sending a read receipt will be enough to tell a lot of people that you transitioned
|
||||
- AEAP will make the problem of inconsistent group state worse, both because it doesn't work if the message is unencrypted (even if the design allowed it, it would be problematic security-wise) and because some chat partners may have gotten the transition and some not. We should do something against this at some point in the future, like asking the user whether they want to add/remove the members to restore consistent group state.
|
||||
|
||||
#### Downsides of this design:
|
||||
- Inconsistent group state: Suppose Alice does an AEAP transition and sends a 1:1 message to Bob, so Bob rewrites Alice's contact. Alice, Bob and Charlie are together in a group. Before Alice writes to this group, Bob and Charlie will have different membership lists, and Bob will send messages to Alice's new address, while Charlie will send them to her old address.
|
||||
|
||||
#### Upsides:
|
||||
- With this approach, it's easy to switch to a model where the info about the transition is encoded in the PGP key. Since the key is gossiped, the information about the transition will spread virally.
|
||||
- Faster transation: If you send a message to e.g. "Delta Chat Dev", all members of the "sub-group" "delta android" will know of your transition.
|
||||
|
||||
### Alternatives and old discussions/plans:
|
||||
|
||||
- Change the contact instead of rewriting the group member lists. This seems to call for more trouble since we will end up with multiple contacts having the same email address.
|
||||
|
||||
- If needed, we could add a header a) indicating that the sender did an address transition or b) listing all the secondary (old) addresses. For now, there is no big enough benefit to warrant introducing another header and its processing on the receiver side (including all the neccessary checks and handling of error cases). Instead, we only check for the `Chat-Version` header to prevent accidental transitions when an MUA user sends a message from another email address with the same key.
|
||||
|
||||
- The condition for a transition temporarily was:
|
||||
|
||||
> When receiving a message: If we are going to assign a message to a chat, but the sender is not a member of this chat\
|
||||
> AND the signing key is the same as the direct (non-gossiped) key of one of the chat members\
|
||||
> AND ...
|
||||
|
||||
However, this would mean that in 1:1 messages can't trigger a transition, since we don't assign private messages to the parent chat, but always to the 1:1 chat with the sender.
|
||||
|
||||
<details>
|
||||
<summary>Some previous state of the discussion, which temporarily lived in an issue description</summary>
|
||||
Summarizing the discussions from https://github.com/deltachat/deltachat-core-rust/pull/2896, mostly quoting @hpk42:
|
||||
|
||||
1. (DONE) At the time of configure we push the current primary to become a secondary.
|
||||
|
||||
2. When a message is sent out to a chat, and the message is encrypted, and we have secondary addresses, then we
|
||||
a) add a protected "AEAP-Replacement" header that contains all secondary addresses
|
||||
b) if any of the secondary addresses is in the chat's member list, we remove it and leave a system message that we did so
|
||||
3. When an encrypted message with a replacement header is received, replace the e-mail address of all secondary contacts (if they exist) with the new primary and drop a sysmessage in all chats the secondary is member off. This might (in edge cases) result in chats that have two or more contacts with the same e-mail address. We might ignore this for a first release and just log a warning. Let's maybe not get hung up on this case before everything else works.
|
||||
|
||||
Notes:
|
||||
- for now we will send out aeap replacement headers forever, there is no termination condition other than lack of secondary addresses. I think that's fine for now. Later on we might introduce options to remove secondary addresses but i wouldn't do this for a first release/PR.
|
||||
- the design is resilient against changing e-mail providers from A to B to C and then back to A, with partially updated chats and diverging views from recipients/contacts on this transition. In the end, you will have a primary and some secondaries, and when you start sending out messages everybody will eventually synchronize when they receive the current state of primaries/secondaries.
|
||||
- of course on incoming message for need to check for each stated secondary address in the replacement header that it uses the same signature as the signature we verified as valid with the incoming message **--> Also we have to somehow make sure that the signing key was not just gossiped from some random other person in some group.**
|
||||
- there are no extra flags/columns in the database needed (i hope)
|
||||
|
||||
#### Downsides of the chosen approach:
|
||||
- Inconsistent group state: Suppose Alice does an AEAP transition and sends a 1:1 message to Bob, so Bob rewrites Alice's contact. Alice, Bob and Charlie are together in a group. Before Alice writes to this group, Bob and Charlie will have different membership lists, and Bob will send messages to Alice's new address, while Charlie will send them to her old address.
|
||||
- There will be multiple contacts with the same address in the database. We will have to do something against this at some point.
|
||||
|
||||
The most obvious alternative would be to create a new contact with the new address and replace the old contact in the groups.
|
||||
|
||||
#### Upsides:
|
||||
- With this approach, it's easier to switch to a model where the info about the transition is encoded in the PGP key. Since the key is gossiped, the information about the transition will spread virally.
|
||||
- (Also, less important: Slightly faster transation: If you send a message to e.g. "Delta Chat Dev", all members of the "sub-group" "delta android" will know of your transition.)
|
||||
- It's easier to implement (if too many problems turn up, we can still switch to another approach and didn't wast that much development time.)
|
||||
|
||||
[full messages](https://github.com/deltachat/deltachat-core-rust/pull/2896#discussion_r852002161)
|
||||
|
||||
_end of the previous state of the discussion_
|
||||
|
||||
</details>
|
||||
|
||||
Other
|
||||
-----
|
||||
|
||||
- The user is responsible that messages to the old address arrive at the new address, for example by configuring the old provider to forward all emails to the new one.
|
||||
213
draft/webxdc-dev-reference.md
Normal file
213
draft/webxdc-dev-reference.md
Normal file
@@ -0,0 +1,213 @@
|
||||
# Webxdc Developer Reference
|
||||
|
||||
This document gives a quick overview about the Webxdc specification,
|
||||
It is meant for both, developing Webxdc apps
|
||||
and developing Webxdc implementations.
|
||||
|
||||
The [Webxdc guidebook](https://deltachat.github.io/webxdc_docs/) shows more detailed information
|
||||
when developing Webxdc apps.
|
||||
|
||||
|
||||
## Webxdc File Format
|
||||
|
||||
- a **Webxdc** is a **ZIP-file** with the extension `.xdc`
|
||||
- the ZIP-file must use the default compression methods as of RFC 1950,
|
||||
this is "Deflate" or "Store"
|
||||
- the ZIP-file must contain at least the file `index.html`
|
||||
- if the Webxdc is started, `index.html` is opened in a restricted webview
|
||||
that allow accessing resources only from the ZIP-file
|
||||
|
||||
|
||||
## Webxdc API
|
||||
|
||||
There are some additional APIs available once `webxdc.js` is included
|
||||
(the file will be provided by the concrete implementations,
|
||||
no need to add `webxdc.js` to your ZIP-file):
|
||||
|
||||
```html
|
||||
<script src="webxdc.js"></script>
|
||||
```
|
||||
|
||||
### sendUpdate()
|
||||
|
||||
```js
|
||||
window.webxdc.sendUpdate(update, descr);
|
||||
```
|
||||
|
||||
A Webxdc is usually shared in a chat and run independently on each peer.
|
||||
To get a shared state, the peers use `sendUpdate()` to send updates to each other.
|
||||
|
||||
- `update`: an object with the following properties:
|
||||
- `update.payload`: any javascript primitive, array or object.
|
||||
- `update.info`: optional, short, informational message that will be added to the chat,
|
||||
eg. "Alice voted" or "Bob scored 123 in MyGame".
|
||||
usually only one line of text is shown
|
||||
and if there are series of info messages, older ones may be dropped.
|
||||
use this option sparingly to not spam the chat.
|
||||
- `update.document`: optional, name of the document in edit,
|
||||
must not be used eg. in games where the Webxdc does not create documents
|
||||
- `update.summary`: optional, short text, shown beside Webxdc icon;
|
||||
it is recommended to use some aggregated value, eg. "8 votes", "Highscore: 123"
|
||||
|
||||
- `descr`: short, human-readable description what this update is about.
|
||||
this is shown eg. as a fallback text in an email program.
|
||||
|
||||
All peers, including the sending one,
|
||||
will receive the update by the callback given to `setUpdateListener()`.
|
||||
|
||||
There are situations where the user cannot send messages to a chat,
|
||||
eg. if the webxdc instance comes as a contact request or if the user has left a group.
|
||||
In these cases, you can still call `sendUpdate()`,
|
||||
however, the update won't be sent to other peers
|
||||
and you won't get the update by `setUpdateListener()`.
|
||||
|
||||
|
||||
### setUpdateListener()
|
||||
|
||||
```js
|
||||
let promise = window.webxdc.setUpdateListener((update) => {}, serial);
|
||||
```
|
||||
|
||||
With `setUpdateListener()` you define a callback that receives the updates
|
||||
sent by `sendUpdate()`. The callback is called for updates sent by you or other peers.
|
||||
The `serial` specifies the last serial that you know about (defaults to 0).
|
||||
The returned promise resolves when the listener has processed all the update messages known at the time when `setUpdateListener` was called.
|
||||
|
||||
Each `update` which is passed to the callback comes with the following properties:
|
||||
|
||||
- `update.payload`: equals the payload given to `sendUpdate()`
|
||||
|
||||
- `update.serial`: the serial number of this update.
|
||||
Serials are larger `0` and newer serials have higher numbers.
|
||||
There may be gaps in the serials
|
||||
and it is not guaranteed that the next serial is exactly incremented by one.
|
||||
|
||||
- `update.max_serial`: the maximum serial currently known.
|
||||
If `max_serial` equals `serial` this update is the last update (until new network messages arrive).
|
||||
|
||||
- `update.info`: optional, short, informational message (see `sendUpdate()`)
|
||||
|
||||
- `update.document`: optional, document name as set by the sender, (see `sendUpdate()`),
|
||||
implementations show the document name eg. beside the app icon or in the title bar
|
||||
|
||||
- `update.summary`: optional, short text, shown beside icon (see `sendUpdate()`)
|
||||
|
||||
|
||||
### selfAddr
|
||||
|
||||
```js
|
||||
window.webxdc.selfAddr
|
||||
```
|
||||
|
||||
Property with the peer's own address.
|
||||
This is esp. useful if you want to differ between different peers -
|
||||
just send the address along with the payload,
|
||||
and, if needed, compare the payload addresses against selfAddr() later on.
|
||||
|
||||
|
||||
### selfName
|
||||
|
||||
```js
|
||||
window.webxdc.selfName
|
||||
```
|
||||
|
||||
Property with the peer's own name.
|
||||
This is name chosen by the user in their settings,
|
||||
if there is nothing set, that defaults to the peer's address.
|
||||
|
||||
|
||||
## manifest.toml
|
||||
|
||||
If the ZIP-file contains a `manifest.toml` in its root directory,
|
||||
some basic information are read and used from there.
|
||||
|
||||
the `manifest.toml` has the following format
|
||||
|
||||
```toml
|
||||
name = "My Name"
|
||||
source_code_url = "https://example.org/orga/repo"
|
||||
```
|
||||
|
||||
- `name` - The name of the Webxdc.
|
||||
If no name is set or if there is no manifest, the filename is used as the Webxdc name.
|
||||
|
||||
- `source_code_url` - Optional URL where the source code of the Webxdc and maybe other information can be found.
|
||||
UI may make the url accessible via a "Help" menu in the Webxdc window.
|
||||
|
||||
|
||||
## Webxdc Icon
|
||||
|
||||
If the ZIP-root contains an `icon.png` or `icon.jpg`,
|
||||
these files are used as the icon for the Webxdc.
|
||||
The icon should be a square at reasonable width/height;
|
||||
round corners etc. will be added by the implementations as needed.
|
||||
If no icon is set, a default icon will be used.
|
||||
|
||||
|
||||
## Other APIs and Tags Usage Hints
|
||||
|
||||
- `localStorage`, `sessionStorage`, `indexedDB` are okay to be used
|
||||
- `visibilitychange`-events are okay to be used
|
||||
- `window.navigator.language` is okay to be used, on desktop it is the system language
|
||||
- `<a href="localfile.html">` and other internal links are okay to be used
|
||||
- `<a href="mailto:addr@example.org?body=...">`- mailto links are okay to be used
|
||||
- `<meta name="viewport" ...>` usage is okay to be used
|
||||
and useful esp. different webviews have different defaults
|
||||
|
||||
|
||||
### Discouraged Things
|
||||
|
||||
- `document.cookie` is known not to work on desktop and iOS
|
||||
use `localStorage` instead
|
||||
- `unload`-, `beforeunload`- and `pagehide`-events are known not to work on iOS and are flaky on other systems
|
||||
(also partly discouraged by [mozilla](https://developer.mozilla.org/en-US/docs/Web/API/Window/unload_event))
|
||||
use `visibilitychange` instead
|
||||
- `<title>` and `document.title` is ignored by Webxdc;
|
||||
use the `name` property from `manifest.toml` instead
|
||||
- newest js features may not work on all webviews,
|
||||
you may want to transpile your code down to an older js version
|
||||
eg. with <https://babeljs.io>
|
||||
- `<a href="https://example.org/foo">` and other external links are blocked by definition;
|
||||
instead, embed content or use `mailto:` link to offer a way for contact
|
||||
- `<input type="file">` is discouraged currently; this may change in future
|
||||
|
||||
|
||||
## Webxdc Examples
|
||||
|
||||
The following example shows an input field and every input is show on all peers.
|
||||
|
||||
```html
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8"/>
|
||||
<script src="webxdc.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<input id="input" type="text"/>
|
||||
<a href="" onclick="sendMsg(); return false;">Send</a>
|
||||
<p id="output"></p>
|
||||
<script>
|
||||
|
||||
function sendMsg() {
|
||||
msg = document.getElementById("input").value;
|
||||
window.webxdc.sendUpdate({payload: msg}, 'Someone typed "'+msg+'".');
|
||||
}
|
||||
|
||||
function receiveUpdate(update) {
|
||||
document.getElementById('output').innerHTML += update.payload + "<br>";
|
||||
}
|
||||
|
||||
window.webxdc.setUpdateListener(receiveUpdate, 0);
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
```
|
||||
|
||||
More examples at [github.com/webxdc](https://github.com/webxdc) and
|
||||
[topic #webxdc](https://github.com/topics/webxdc)
|
||||
|
||||
[github.com/webxdc/hello](https://github.com/webxdc/hello)
|
||||
offers an **Webxdc Tool** that can be used in many browsers without any installation needed.
|
||||
You can also use that repository as a template for your own Webxdc -
|
||||
just clone and start adapting things to your need.
|
||||
@@ -17,11 +17,10 @@ use deltachat::download::DownloadState;
|
||||
use deltachat::imex::*;
|
||||
use deltachat::location;
|
||||
use deltachat::log::LogExt;
|
||||
use deltachat::message::{self, Message, MessageState, MsgId};
|
||||
use deltachat::message::{self, Message, MessageState, MsgId, Viewtype};
|
||||
use deltachat::peerstate::*;
|
||||
use deltachat::qr::*;
|
||||
use deltachat::sql;
|
||||
use deltachat::EventType;
|
||||
use deltachat::{config, provider};
|
||||
use std::fs;
|
||||
use std::time::{Duration, SystemTime};
|
||||
@@ -84,6 +83,7 @@ async fn reset_tables(context: &Context, bits: i32) {
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
context.sql().config_cache().write().await.clear();
|
||||
context
|
||||
.sql()
|
||||
.execute("DELETE FROM leftgrps;", paramsv![])
|
||||
@@ -92,16 +92,13 @@ async fn reset_tables(context: &Context, bits: i32) {
|
||||
println!("(8) Rest but server config reset.");
|
||||
}
|
||||
|
||||
context.emit_event(EventType::MsgsChanged {
|
||||
chat_id: ChatId::new(0),
|
||||
msg_id: MsgId::new(0),
|
||||
});
|
||||
context.emit_msgs_changed_without_ids();
|
||||
}
|
||||
|
||||
async fn poke_eml_file(context: &Context, filename: impl AsRef<Path>) -> Result<()> {
|
||||
let data = dc_read_file(context, filename).await?;
|
||||
|
||||
if let Err(err) = dc_receive_imf(context, &data, "import", 0, false).await {
|
||||
if let Err(err) = dc_receive_imf(context, &data, false).await {
|
||||
println!("dc_receive_imf errored: {:?}", err);
|
||||
}
|
||||
Ok(())
|
||||
@@ -163,10 +160,7 @@ async fn poke_spec(context: &Context, spec: Option<&str>) -> bool {
|
||||
}
|
||||
println!("Import: {} items read from \"{}\".", read_cnt, &real_spec);
|
||||
if read_cnt > 0 {
|
||||
context.emit_event(EventType::MsgsChanged {
|
||||
chat_id: ChatId::new(0),
|
||||
msg_id: MsgId::new(0),
|
||||
});
|
||||
context.emit_msgs_changed_without_ids();
|
||||
}
|
||||
true
|
||||
}
|
||||
@@ -209,7 +203,7 @@ async fn log_msg(context: &Context, prefix: impl AsRef<str>, msg: &Message) {
|
||||
contact_id,
|
||||
msgtext.unwrap_or_default(),
|
||||
if msg.has_html() { "[HAS-HTML]️" } else { "" },
|
||||
if msg.get_from_id() == 1 {
|
||||
if msg.get_from_id() == ContactId::SELF {
|
||||
""
|
||||
} else if msg.get_state() == MessageState::InSeen {
|
||||
"[SEEN]"
|
||||
@@ -267,9 +261,8 @@ async fn log_msglist(context: &Context, msglist: &[MsgId]) -> Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn log_contactlist(context: &Context, contacts: &[u32]) -> Result<()> {
|
||||
async fn log_contactlist(context: &Context, contacts: &[ContactId]) -> Result<()> {
|
||||
for contact_id in contacts {
|
||||
let line;
|
||||
let mut line2 = "".to_string();
|
||||
let contact = Contact::get_by_id(context, *contact_id).await?;
|
||||
let name = contact.get_display_name();
|
||||
@@ -284,24 +277,20 @@ async fn log_contactlist(context: &Context, contacts: &[u32]) -> Result<()> {
|
||||
} else {
|
||||
""
|
||||
};
|
||||
line = format!(
|
||||
let line = format!(
|
||||
"{}{} <{}>",
|
||||
if !name.is_empty() {
|
||||
&name
|
||||
name
|
||||
} else {
|
||||
"<name unset>"
|
||||
},
|
||||
verified_str,
|
||||
if !addr.is_empty() {
|
||||
&addr
|
||||
} else {
|
||||
"addr unset"
|
||||
}
|
||||
if !addr.is_empty() { addr } else { "addr unset" }
|
||||
);
|
||||
let peerstate = Peerstate::from_addr(context, &addr)
|
||||
let peerstate = Peerstate::from_addr(context, addr)
|
||||
.await
|
||||
.expect("peerstate error");
|
||||
if peerstate.is_some() && *contact_id != 1 {
|
||||
if peerstate.is_some() && *contact_id != ContactId::SELF {
|
||||
line2 = format!(
|
||||
", prefer-encrypt={}",
|
||||
peerstate.as_ref().unwrap().prefer_encrypt
|
||||
@@ -387,6 +376,7 @@ pub async fn cmdline(context: Context, line: &str, chat_id: &mut ChatId) -> Resu
|
||||
sendfile <file> [<text>]\n\
|
||||
sendhtml <file for html-part> [<text for plain-part>]\n\
|
||||
sendsyncmsg\n\
|
||||
sendupdate <msg-id> <json status update>\n\
|
||||
videochat\n\
|
||||
draft [<text>]\n\
|
||||
devicemsg <text>\n\
|
||||
@@ -409,6 +399,7 @@ pub async fn cmdline(context: Context, line: &str, chat_id: &mut ChatId) -> Resu
|
||||
html <msg-id>\n\
|
||||
listfresh\n\
|
||||
forward <msg-id> <chat-id>\n\
|
||||
resend <msg-id>\n\
|
||||
markseen <msg-id>\n\
|
||||
delmsg <msg-id>\n\
|
||||
===========================Contact commands==\n\
|
||||
@@ -423,12 +414,12 @@ pub async fn cmdline(context: Context, line: &str, chat_id: &mut ChatId) -> Resu
|
||||
listblocked\n\
|
||||
======================================Misc.==\n\
|
||||
getqr [<chat-id>]\n\
|
||||
getqrsvg [<chat-id>]\n\
|
||||
getbadqr\n\
|
||||
checkqr <qr-content>\n\
|
||||
joinqr <qr-content>\n\
|
||||
setqr <qr-content>\n\
|
||||
providerinfo <addr>\n\
|
||||
event <event-id to test>\n\
|
||||
fileinfo <file>\n\
|
||||
estimatedeletion <seconds>\n\
|
||||
clear -- clear screen\n\
|
||||
@@ -470,20 +461,32 @@ pub async fn cmdline(context: Context, line: &str, chat_id: &mut ChatId) -> Resu
|
||||
}
|
||||
"export-backup" => {
|
||||
let dir = dirs::home_dir().unwrap_or_default();
|
||||
imex(&context, ImexMode::ExportBackup, dir.as_ref()).await?;
|
||||
imex(
|
||||
&context,
|
||||
ImexMode::ExportBackup,
|
||||
dir.as_ref(),
|
||||
Some(arg2.to_string()),
|
||||
)
|
||||
.await?;
|
||||
println!("Exported to {}.", dir.to_string_lossy());
|
||||
}
|
||||
"import-backup" => {
|
||||
ensure!(!arg1.is_empty(), "Argument <backup-file> missing.");
|
||||
imex(&context, ImexMode::ImportBackup, arg1.as_ref()).await?;
|
||||
imex(
|
||||
&context,
|
||||
ImexMode::ImportBackup,
|
||||
arg1.as_ref(),
|
||||
Some(arg2.to_string()),
|
||||
)
|
||||
.await?;
|
||||
}
|
||||
"export-keys" => {
|
||||
let dir = dirs::home_dir().unwrap_or_default();
|
||||
imex(&context, ImexMode::ExportSelfKeys, dir.as_ref()).await?;
|
||||
imex(&context, ImexMode::ExportSelfKeys, dir.as_ref(), None).await?;
|
||||
println!("Exported to {}.", dir.to_string_lossy());
|
||||
}
|
||||
"import-keys" => {
|
||||
imex(&context, ImexMode::ImportSelfKeys, arg1.as_ref()).await?;
|
||||
imex(&context, ImexMode::ImportSelfKeys, arg1.as_ref(), None).await?;
|
||||
}
|
||||
"export-setup" => {
|
||||
let setup_code = create_setup_code(&context);
|
||||
@@ -562,7 +565,7 @@ pub async fn cmdline(context: Context, line: &str, chat_id: &mut ChatId) -> Resu
|
||||
);
|
||||
|
||||
for i in (0..cnt).rev() {
|
||||
let chat = Chat::load_from_db(&context, chatlist.get_chat_id(i)).await?;
|
||||
let chat = Chat::load_from_db(&context, chatlist.get_chat_id(i)?).await?;
|
||||
println!(
|
||||
"{}#{}: {} [{} fresh] {}{}{}{}",
|
||||
chat_prefix(&chat),
|
||||
@@ -636,14 +639,13 @@ pub async fn cmdline(context: Context, line: &str, chat_id: &mut ChatId) -> Resu
|
||||
|
||||
let time_start = std::time::SystemTime::now();
|
||||
let msglist =
|
||||
chat::get_chat_msgs(&context, sel_chat.get_id(), DC_GCM_ADDDAYMARKER, None).await?;
|
||||
chat::get_chat_msgs(&context, sel_chat.get_id(), DC_GCM_ADDDAYMARKER).await?;
|
||||
let time_needed = time_start.elapsed().unwrap_or_default();
|
||||
|
||||
let msglist: Vec<MsgId> = msglist
|
||||
.into_iter()
|
||||
.map(|x| match x {
|
||||
ChatItem::Message { msg_id } => msg_id,
|
||||
ChatItem::Marker1 => MsgId::new(DC_MSG_ID_MARKER1),
|
||||
ChatItem::DayMarker { .. } => MsgId::new(DC_MSG_ID_DAYMARKER),
|
||||
})
|
||||
.collect();
|
||||
@@ -705,7 +707,7 @@ pub async fn cmdline(context: Context, line: &str, chat_id: &mut ChatId) -> Resu
|
||||
}
|
||||
"createchat" => {
|
||||
ensure!(!arg1.is_empty(), "Argument <contact-id> missing.");
|
||||
let contact_id: u32 = arg1.parse()?;
|
||||
let contact_id = ContactId::new(arg1.parse()?);
|
||||
let chat_id = ChatId::create_for_contact(&context, contact_id).await?;
|
||||
|
||||
println!("Single#{} created successfully.", chat_id,);
|
||||
@@ -733,7 +735,7 @@ pub async fn cmdline(context: Context, line: &str, chat_id: &mut ChatId) -> Resu
|
||||
ensure!(sel_chat.is_some(), "No chat selected");
|
||||
ensure!(!arg1.is_empty(), "Argument <contact-id> missing.");
|
||||
|
||||
let contact_id_0: u32 = arg1.parse()?;
|
||||
let contact_id_0 = ContactId::new(arg1.parse()?);
|
||||
chat::add_contact_to_chat(&context, sel_chat.as_ref().unwrap().get_id(), contact_id_0)
|
||||
.await?;
|
||||
println!("Contact added to chat.");
|
||||
@@ -741,7 +743,7 @@ pub async fn cmdline(context: Context, line: &str, chat_id: &mut ChatId) -> Resu
|
||||
"removemember" => {
|
||||
ensure!(sel_chat.is_some(), "No chat selected.");
|
||||
ensure!(!arg1.is_empty(), "Argument <contact-id> missing.");
|
||||
let contact_id_1: u32 = arg1.parse()?;
|
||||
let contact_id_1 = ContactId::new(arg1.parse()?);
|
||||
chat::remove_contact_from_chat(
|
||||
&context,
|
||||
sel_chat.as_ref().unwrap().get_id(),
|
||||
@@ -754,7 +756,12 @@ pub async fn cmdline(context: Context, line: &str, chat_id: &mut ChatId) -> Resu
|
||||
"groupname" => {
|
||||
ensure!(sel_chat.is_some(), "No chat selected.");
|
||||
ensure!(!arg1.is_empty(), "Argument <name> missing.");
|
||||
chat::set_chat_name(&context, sel_chat.as_ref().unwrap().get_id(), arg1).await?;
|
||||
chat::set_chat_name(
|
||||
&context,
|
||||
sel_chat.as_ref().unwrap().get_id(),
|
||||
format!("{} {}", arg1, arg2).trim(),
|
||||
)
|
||||
.await?;
|
||||
|
||||
println!("Chat name set");
|
||||
}
|
||||
@@ -901,6 +908,16 @@ pub async fn cmdline(context: Context, line: &str, chat_id: &mut ChatId) -> Resu
|
||||
Some(msg_id) => println!("sync message sent as {}.", msg_id),
|
||||
None => println!("sync message not needed."),
|
||||
},
|
||||
"sendupdate" => {
|
||||
ensure!(
|
||||
!arg1.is_empty() && !arg2.is_empty(),
|
||||
"Arguments <msg-id> <json status update> expected"
|
||||
);
|
||||
let msg_id = MsgId::new(arg1.parse()?);
|
||||
context
|
||||
.send_webxdc_status_update(msg_id, arg2, "this is a webxdc status update")
|
||||
.await?;
|
||||
}
|
||||
"videochat" => {
|
||||
ensure!(sel_chat.is_some(), "No chat selected.");
|
||||
chat::send_videochat_invitation(&context, sel_chat.as_ref().unwrap().get_id()).await?;
|
||||
@@ -908,13 +925,24 @@ pub async fn cmdline(context: Context, line: &str, chat_id: &mut ChatId) -> Resu
|
||||
"listmsgs" => {
|
||||
ensure!(!arg1.is_empty(), "Argument <query> missing.");
|
||||
|
||||
let query = format!("{} {}", arg1, arg2).trim().to_string();
|
||||
let chat = sel_chat.as_ref().map(|sel_chat| sel_chat.get_id());
|
||||
let time_start = std::time::SystemTime::now();
|
||||
let msglist = context.search_msgs(chat, arg1).await?;
|
||||
let msglist = context.search_msgs(chat, &query).await?;
|
||||
let time_needed = time_start.elapsed().unwrap_or_default();
|
||||
|
||||
log_msglist(&context, &msglist).await?;
|
||||
println!("{} messages.", msglist.len());
|
||||
println!(
|
||||
"{}{} messages for {}search of \"{}\"",
|
||||
msglist.len(),
|
||||
if msglist.len() == 1000 { "+" } else { "" },
|
||||
if chat.is_none() {
|
||||
"global "
|
||||
} else {
|
||||
"in-chat-"
|
||||
},
|
||||
query,
|
||||
);
|
||||
println!("{:?} to create this list", time_needed);
|
||||
}
|
||||
"draft" => {
|
||||
@@ -1071,6 +1099,13 @@ pub async fn cmdline(context: Context, line: &str, chat_id: &mut ChatId) -> Resu
|
||||
msg_ids[0] = MsgId::new(arg1.parse()?);
|
||||
chat::forward_msgs(&context, &msg_ids, chat_id).await?;
|
||||
}
|
||||
"resend" => {
|
||||
ensure!(!arg1.is_empty(), "Arguments <msg-id> expected");
|
||||
|
||||
let mut msg_ids = [MsgId::new(0); 1];
|
||||
msg_ids[0] = MsgId::new(arg1.parse()?);
|
||||
chat::resend_msgs(&context, &msg_ids).await?;
|
||||
}
|
||||
"markseen" => {
|
||||
ensure!(!arg1.is_empty(), "Argument <msg-id> missing.");
|
||||
let mut msg_ids = vec![MsgId::new(0)];
|
||||
@@ -1110,7 +1145,7 @@ pub async fn cmdline(context: Context, line: &str, chat_id: &mut ChatId) -> Resu
|
||||
"contactinfo" => {
|
||||
ensure!(!arg1.is_empty(), "Argument <contact-id> missing.");
|
||||
|
||||
let contact_id: u32 = arg1.parse()?;
|
||||
let contact_id = ContactId::new(arg1.parse()?);
|
||||
let contact = Contact::get_by_id(&context, contact_id).await?;
|
||||
let name_n_addr = contact.get_name_n_addr();
|
||||
|
||||
@@ -1136,7 +1171,7 @@ pub async fn cmdline(context: Context, line: &str, chat_id: &mut ChatId) -> Resu
|
||||
if 0 != i {
|
||||
res += ", ";
|
||||
}
|
||||
let chat = Chat::load_from_db(&context, chatlist.get_chat_id(i)).await?;
|
||||
let chat = Chat::load_from_db(&context, chatlist.get_chat_id(i)?).await?;
|
||||
res += &format!("{}#{}", chat_prefix(&chat), chat.get_id());
|
||||
}
|
||||
}
|
||||
@@ -1145,16 +1180,16 @@ pub async fn cmdline(context: Context, line: &str, chat_id: &mut ChatId) -> Resu
|
||||
}
|
||||
"delcontact" => {
|
||||
ensure!(!arg1.is_empty(), "Argument <contact-id> missing.");
|
||||
Contact::delete(&context, arg1.parse()?).await?;
|
||||
Contact::delete(&context, ContactId::new(arg1.parse()?)).await?;
|
||||
}
|
||||
"block" => {
|
||||
ensure!(!arg1.is_empty(), "Argument <contact-id> missing.");
|
||||
let contact_id = arg1.parse()?;
|
||||
let contact_id = ContactId::new(arg1.parse()?);
|
||||
Contact::block(&context, contact_id).await?;
|
||||
}
|
||||
"unblock" => {
|
||||
ensure!(!arg1.is_empty(), "Argument <contact-id> missing.");
|
||||
let contact_id = arg1.parse()?;
|
||||
let contact_id = ContactId::new(arg1.parse()?);
|
||||
Contact::unblock(&context, contact_id).await?;
|
||||
}
|
||||
"listblocked" => {
|
||||
@@ -1179,7 +1214,7 @@ pub async fn cmdline(context: Context, line: &str, chat_id: &mut ChatId) -> Resu
|
||||
let socks5_enabled = context
|
||||
.get_config_bool(config::Config::Socks5Enabled)
|
||||
.await?;
|
||||
match provider::get_provider_info(arg1, socks5_enabled).await {
|
||||
match provider::get_provider_info(&context, arg1, socks5_enabled).await {
|
||||
Some(info) => {
|
||||
println!("Information for provider belonging to {}:", arg1);
|
||||
println!("status: {}", info.status as u32);
|
||||
@@ -1195,17 +1230,6 @@ pub async fn cmdline(context: Context, line: &str, chat_id: &mut ChatId) -> Resu
|
||||
}
|
||||
}
|
||||
}
|
||||
// TODO: implement this again, unclear how to match this through though, without writing a parser.
|
||||
// "event" => {
|
||||
// ensure!(!arg1.is_empty(), "Argument <id> missing.");
|
||||
// let event = arg1.parse()?;
|
||||
// let event = EventType::from_u32(event).ok_or(format_err!("EventType::from_u32({})", event))?;
|
||||
// let r = context.emit_event(event, 0 as libc::uintptr_t, 0 as libc::uintptr_t);
|
||||
// println!(
|
||||
// "Sending event {:?}({}), received value {}.",
|
||||
// event, event as usize, r,
|
||||
// );
|
||||
// }
|
||||
"fileinfo" => {
|
||||
ensure!(!arg1.is_empty(), "Argument <file> missing.");
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ use deltachat::config;
|
||||
use deltachat::context::*;
|
||||
use deltachat::oauth2::*;
|
||||
use deltachat::securejoin::*;
|
||||
use deltachat::EventType;
|
||||
use deltachat::{EventType, Events};
|
||||
use log::{error, info, warn};
|
||||
use rustyline::completion::{Completer, FilenameCompleter, Pair};
|
||||
use rustyline::config::OutputStreamType;
|
||||
@@ -33,6 +33,8 @@ use rustyline::{
|
||||
|
||||
mod cmdline;
|
||||
use self::cmdline::*;
|
||||
use deltachat::qr_code_generator::get_securejoin_qr_svg;
|
||||
use std::fs;
|
||||
|
||||
/// Event Handler
|
||||
fn receive_event(event: EventType) {
|
||||
@@ -167,7 +169,7 @@ const DB_COMMANDS: [&str; 10] = [
|
||||
"housekeeping",
|
||||
];
|
||||
|
||||
const CHAT_COMMANDS: [&str; 35] = [
|
||||
const CHAT_COMMANDS: [&str; 36] = [
|
||||
"listchats",
|
||||
"listarchived",
|
||||
"chat",
|
||||
@@ -189,6 +191,7 @@ const CHAT_COMMANDS: [&str; 35] = [
|
||||
"sendfile",
|
||||
"sendhtml",
|
||||
"sendsyncmsg",
|
||||
"sendupdate",
|
||||
"videochat",
|
||||
"draft",
|
||||
"listmedia",
|
||||
@@ -204,11 +207,12 @@ const CHAT_COMMANDS: [&str; 35] = [
|
||||
"accept",
|
||||
"blockchat",
|
||||
];
|
||||
const MESSAGE_COMMANDS: [&str; 7] = [
|
||||
const MESSAGE_COMMANDS: [&str; 8] = [
|
||||
"listmsgs",
|
||||
"msginfo",
|
||||
"listfresh",
|
||||
"forward",
|
||||
"resend",
|
||||
"markseen",
|
||||
"delmsg",
|
||||
"download",
|
||||
@@ -226,10 +230,10 @@ const CONTACT_COMMANDS: [&str; 9] = [
|
||||
];
|
||||
const MISC_COMMANDS: [&str; 11] = [
|
||||
"getqr",
|
||||
"getqrsvg",
|
||||
"getbadqr",
|
||||
"checkqr",
|
||||
"joinqr",
|
||||
"event",
|
||||
"fileinfo",
|
||||
"clear",
|
||||
"exit",
|
||||
@@ -294,7 +298,7 @@ async fn start(args: Vec<String>) -> Result<(), Error> {
|
||||
println!("Error: Bad arguments, expected [db-name].");
|
||||
bail!("No db-name specified");
|
||||
}
|
||||
let context = Context::new("CLI".into(), Path::new(&args[1]).to_path_buf(), 0).await?;
|
||||
let context = Context::new(Path::new(&args[1]).to_path_buf(), 0, Events::new()).await?;
|
||||
|
||||
let events = context.get_event_emitter();
|
||||
async_std::task::spawn(async move {
|
||||
@@ -412,7 +416,7 @@ async fn handle_cmd(
|
||||
}
|
||||
"getqr" | "getbadqr" => {
|
||||
ctx.start_io().await;
|
||||
let group = arg1.parse::<u32>().ok().map(|id| ChatId::new(id));
|
||||
let group = arg1.parse::<u32>().ok().map(ChatId::new);
|
||||
let mut qr = dc_get_securejoin_qr(&ctx, group).await?;
|
||||
if !qr.is_empty() {
|
||||
if arg0 == "getbadqr" && qr.len() > 40 {
|
||||
@@ -427,6 +431,20 @@ async fn handle_cmd(
|
||||
io::stderr().write_all(&output.stderr).unwrap();
|
||||
}
|
||||
}
|
||||
"getqrsvg" => {
|
||||
ctx.start_io().await;
|
||||
let group = arg1.parse::<u32>().ok().map(ChatId::new);
|
||||
let file = dirs::home_dir().unwrap_or_default().join("qr.svg");
|
||||
match get_securejoin_qr_svg(&ctx, group).await {
|
||||
Ok(svg) => {
|
||||
fs::write(&file, svg)?;
|
||||
println!("QR code svg written to: {:#?}", file);
|
||||
}
|
||||
Err(err) => {
|
||||
bail!("Failed to get QR code svg: {}", err);
|
||||
}
|
||||
}
|
||||
}
|
||||
"joinqr" => {
|
||||
ctx.start_io().await;
|
||||
if !arg0.is_empty() {
|
||||
|
||||
@@ -6,7 +6,7 @@ use deltachat::config;
|
||||
use deltachat::contact::*;
|
||||
use deltachat::context::*;
|
||||
use deltachat::message::Message;
|
||||
use deltachat::EventType;
|
||||
use deltachat::{EventType, Events};
|
||||
|
||||
fn cb(event: EventType) {
|
||||
match event {
|
||||
@@ -36,7 +36,7 @@ async fn main() {
|
||||
let dir = tempdir().unwrap();
|
||||
let dbfile = dir.path().join("db.sqlite");
|
||||
log::info!("creating database {:?}", dbfile);
|
||||
let ctx = Context::new("FakeOs".into(), dbfile.into(), 0)
|
||||
let ctx = Context::new(dbfile.into(), 0, Events::new())
|
||||
.await
|
||||
.expect("Failed to create context");
|
||||
let info = ctx.get_info().await;
|
||||
|
||||
6
node/.prettierrc.yml
Normal file
6
node/.prettierrc.yml
Normal file
@@ -0,0 +1,6 @@
|
||||
# .prettierrc
|
||||
trailingComma: es5
|
||||
tabWidth: 2
|
||||
semi: false
|
||||
singleQuote: true
|
||||
jsxSingleQuote: true
|
||||
21
node/CONTRIBUTORS.md
Normal file
21
node/CONTRIBUTORS.md
Normal file
@@ -0,0 +1,21 @@
|
||||
# Contributors
|
||||
|
||||
| Name | GitHub |
|
||||
| :-------------------- | :----------------------------------------------- |
|
||||
| **Lars-Magnus Skog** | |
|
||||
| **jikstra** | |
|
||||
| **Simon Laux** | [**@Simon-Laux**](https://github.com/Simon-Laux) |
|
||||
| **Jikstra** | [**@Jikstra**](https://github.com/Jikstra) |
|
||||
| **Nico de Haen** | |
|
||||
| **B. Petersen** | |
|
||||
| **Karissa McKelvey** | [**@karissa**](https://github.com/karissa) |
|
||||
| **developer** | |
|
||||
| **Alexander Krotov** | |
|
||||
| **Floris Bruynooghe** | |
|
||||
| **lefherz** | |
|
||||
| **Pablo** | [**@pabzm**](https://github.com/pabzm) |
|
||||
| **pabzm** | |
|
||||
| **holger krekel** | |
|
||||
| **Robert Schütz** | |
|
||||
| **bb** | |
|
||||
| **Charles Paul** | |
|
||||
674
node/LICENSE
Normal file
674
node/LICENSE
Normal file
@@ -0,0 +1,674 @@
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 3, 29 June 2007
|
||||
|
||||
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The GNU General Public License is a free, copyleft license for
|
||||
software and other kinds of works.
|
||||
|
||||
The licenses for most software and other practical works are designed
|
||||
to take away your freedom to share and change the works. By contrast,
|
||||
the GNU General Public License is intended to guarantee your freedom to
|
||||
share and change all versions of a program--to make sure it remains free
|
||||
software for all its users. We, the Free Software Foundation, use the
|
||||
GNU General Public License for most of our software; it applies also to
|
||||
any other work released this way by its authors. You can apply it to
|
||||
your programs, too.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not
|
||||
price. Our General Public Licenses are designed to make sure that you
|
||||
have the freedom to distribute copies of free software (and charge for
|
||||
them if you wish), that you receive source code or can get it if you
|
||||
want it, that you can change the software or use pieces of it in new
|
||||
free programs, and that you know you can do these things.
|
||||
|
||||
To protect your rights, we need to prevent others from denying you
|
||||
these rights or asking you to surrender the rights. Therefore, you have
|
||||
certain responsibilities if you distribute copies of the software, or if
|
||||
you modify it: responsibilities to respect the freedom of others.
|
||||
|
||||
For example, if you distribute copies of such a program, whether
|
||||
gratis or for a fee, you must pass on to the recipients the same
|
||||
freedoms that you received. You must make sure that they, too, receive
|
||||
or can get the source code. And you must show them these terms so they
|
||||
know their rights.
|
||||
|
||||
Developers that use the GNU GPL protect your rights with two steps:
|
||||
(1) assert copyright on the software, and (2) offer you this License
|
||||
giving you legal permission to copy, distribute and/or modify it.
|
||||
|
||||
For the developers' and authors' protection, the GPL clearly explains
|
||||
that there is no warranty for this free software. For both users' and
|
||||
authors' sake, the GPL requires that modified versions be marked as
|
||||
changed, so that their problems will not be attributed erroneously to
|
||||
authors of previous versions.
|
||||
|
||||
Some devices are designed to deny users access to install or run
|
||||
modified versions of the software inside them, although the manufacturer
|
||||
can do so. This is fundamentally incompatible with the aim of
|
||||
protecting users' freedom to change the software. The systematic
|
||||
pattern of such abuse occurs in the area of products for individuals to
|
||||
use, which is precisely where it is most unacceptable. Therefore, we
|
||||
have designed this version of the GPL to prohibit the practice for those
|
||||
products. If such problems arise substantially in other domains, we
|
||||
stand ready to extend this provision to those domains in future versions
|
||||
of the GPL, as needed to protect the freedom of users.
|
||||
|
||||
Finally, every program is threatened constantly by software patents.
|
||||
States should not allow patents to restrict development and use of
|
||||
software on general-purpose computers, but in those that do, we wish to
|
||||
avoid the special danger that patents applied to a free program could
|
||||
make it effectively proprietary. To prevent this, the GPL assures that
|
||||
patents cannot be used to render the program non-free.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
TERMS AND CONDITIONS
|
||||
|
||||
0. Definitions.
|
||||
|
||||
"This License" refers to version 3 of the GNU General Public License.
|
||||
|
||||
"Copyright" also means copyright-like laws that apply to other kinds of
|
||||
works, such as semiconductor masks.
|
||||
|
||||
"The Program" refers to any copyrightable work licensed under this
|
||||
License. Each licensee is addressed as "you". "Licensees" and
|
||||
"recipients" may be individuals or organizations.
|
||||
|
||||
To "modify" a work means to copy from or adapt all or part of the work
|
||||
in a fashion requiring copyright permission, other than the making of an
|
||||
exact copy. The resulting work is called a "modified version" of the
|
||||
earlier work or a work "based on" the earlier work.
|
||||
|
||||
A "covered work" means either the unmodified Program or a work based
|
||||
on the Program.
|
||||
|
||||
To "propagate" a work means to do anything with it that, without
|
||||
permission, would make you directly or secondarily liable for
|
||||
infringement under applicable copyright law, except executing it on a
|
||||
computer or modifying a private copy. Propagation includes copying,
|
||||
distribution (with or without modification), making available to the
|
||||
public, and in some countries other activities as well.
|
||||
|
||||
To "convey" a work means any kind of propagation that enables other
|
||||
parties to make or receive copies. Mere interaction with a user through
|
||||
a computer network, with no transfer of a copy, is not conveying.
|
||||
|
||||
An interactive user interface displays "Appropriate Legal Notices"
|
||||
to the extent that it includes a convenient and prominently visible
|
||||
feature that (1) displays an appropriate copyright notice, and (2)
|
||||
tells the user that there is no warranty for the work (except to the
|
||||
extent that warranties are provided), that licensees may convey the
|
||||
work under this License, and how to view a copy of this License. If
|
||||
the interface presents a list of user commands or options, such as a
|
||||
menu, a prominent item in the list meets this criterion.
|
||||
|
||||
1. Source Code.
|
||||
|
||||
The "source code" for a work means the preferred form of the work
|
||||
for making modifications to it. "Object code" means any non-source
|
||||
form of a work.
|
||||
|
||||
A "Standard Interface" means an interface that either is an official
|
||||
standard defined by a recognized standards body, or, in the case of
|
||||
interfaces specified for a particular programming language, one that
|
||||
is widely used among developers working in that language.
|
||||
|
||||
The "System Libraries" of an executable work include anything, other
|
||||
than the work as a whole, that (a) is included in the normal form of
|
||||
packaging a Major Component, but which is not part of that Major
|
||||
Component, and (b) serves only to enable use of the work with that
|
||||
Major Component, or to implement a Standard Interface for which an
|
||||
implementation is available to the public in source code form. A
|
||||
"Major Component", in this context, means a major essential component
|
||||
(kernel, window system, and so on) of the specific operating system
|
||||
(if any) on which the executable work runs, or a compiler used to
|
||||
produce the work, or an object code interpreter used to run it.
|
||||
|
||||
The "Corresponding Source" for a work in object code form means all
|
||||
the source code needed to generate, install, and (for an executable
|
||||
work) run the object code and to modify the work, including scripts to
|
||||
control those activities. However, it does not include the work's
|
||||
System Libraries, or general-purpose tools or generally available free
|
||||
programs which are used unmodified in performing those activities but
|
||||
which are not part of the work. For example, Corresponding Source
|
||||
includes interface definition files associated with source files for
|
||||
the work, and the source code for shared libraries and dynamically
|
||||
linked subprograms that the work is specifically designed to require,
|
||||
such as by intimate data communication or control flow between those
|
||||
subprograms and other parts of the work.
|
||||
|
||||
The Corresponding Source need not include anything that users
|
||||
can regenerate automatically from other parts of the Corresponding
|
||||
Source.
|
||||
|
||||
The Corresponding Source for a work in source code form is that
|
||||
same work.
|
||||
|
||||
2. Basic Permissions.
|
||||
|
||||
All rights granted under this License are granted for the term of
|
||||
copyright on the Program, and are irrevocable provided the stated
|
||||
conditions are met. This License explicitly affirms your unlimited
|
||||
permission to run the unmodified Program. The output from running a
|
||||
covered work is covered by this License only if the output, given its
|
||||
content, constitutes a covered work. This License acknowledges your
|
||||
rights of fair use or other equivalent, as provided by copyright law.
|
||||
|
||||
You may make, run and propagate covered works that you do not
|
||||
convey, without conditions so long as your license otherwise remains
|
||||
in force. You may convey covered works to others for the sole purpose
|
||||
of having them make modifications exclusively for you, or provide you
|
||||
with facilities for running those works, provided that you comply with
|
||||
the terms of this License in conveying all material for which you do
|
||||
not control copyright. Those thus making or running the covered works
|
||||
for you must do so exclusively on your behalf, under your direction
|
||||
and control, on terms that prohibit them from making any copies of
|
||||
your copyrighted material outside their relationship with you.
|
||||
|
||||
Conveying under any other circumstances is permitted solely under
|
||||
the conditions stated below. Sublicensing is not allowed; section 10
|
||||
makes it unnecessary.
|
||||
|
||||
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
||||
|
||||
No covered work shall be deemed part of an effective technological
|
||||
measure under any applicable law fulfilling obligations under article
|
||||
11 of the WIPO copyright treaty adopted on 20 December 1996, or
|
||||
similar laws prohibiting or restricting circumvention of such
|
||||
measures.
|
||||
|
||||
When you convey a covered work, you waive any legal power to forbid
|
||||
circumvention of technological measures to the extent such circumvention
|
||||
is effected by exercising rights under this License with respect to
|
||||
the covered work, and you disclaim any intention to limit operation or
|
||||
modification of the work as a means of enforcing, against the work's
|
||||
users, your or third parties' legal rights to forbid circumvention of
|
||||
technological measures.
|
||||
|
||||
4. Conveying Verbatim Copies.
|
||||
|
||||
You may convey verbatim copies of the Program's source code as you
|
||||
receive it, in any medium, provided that you conspicuously and
|
||||
appropriately publish on each copy an appropriate copyright notice;
|
||||
keep intact all notices stating that this License and any
|
||||
non-permissive terms added in accord with section 7 apply to the code;
|
||||
keep intact all notices of the absence of any warranty; and give all
|
||||
recipients a copy of this License along with the Program.
|
||||
|
||||
You may charge any price or no price for each copy that you convey,
|
||||
and you may offer support or warranty protection for a fee.
|
||||
|
||||
5. Conveying Modified Source Versions.
|
||||
|
||||
You may convey a work based on the Program, or the modifications to
|
||||
produce it from the Program, in the form of source code under the
|
||||
terms of section 4, provided that you also meet all of these conditions:
|
||||
|
||||
a) The work must carry prominent notices stating that you modified
|
||||
it, and giving a relevant date.
|
||||
|
||||
b) The work must carry prominent notices stating that it is
|
||||
released under this License and any conditions added under section
|
||||
7. This requirement modifies the requirement in section 4 to
|
||||
"keep intact all notices".
|
||||
|
||||
c) You must license the entire work, as a whole, under this
|
||||
License to anyone who comes into possession of a copy. This
|
||||
License will therefore apply, along with any applicable section 7
|
||||
additional terms, to the whole of the work, and all its parts,
|
||||
regardless of how they are packaged. This License gives no
|
||||
permission to license the work in any other way, but it does not
|
||||
invalidate such permission if you have separately received it.
|
||||
|
||||
d) If the work has interactive user interfaces, each must display
|
||||
Appropriate Legal Notices; however, if the Program has interactive
|
||||
interfaces that do not display Appropriate Legal Notices, your
|
||||
work need not make them do so.
|
||||
|
||||
A compilation of a covered work with other separate and independent
|
||||
works, which are not by their nature extensions of the covered work,
|
||||
and which are not combined with it such as to form a larger program,
|
||||
in or on a volume of a storage or distribution medium, is called an
|
||||
"aggregate" if the compilation and its resulting copyright are not
|
||||
used to limit the access or legal rights of the compilation's users
|
||||
beyond what the individual works permit. Inclusion of a covered work
|
||||
in an aggregate does not cause this License to apply to the other
|
||||
parts of the aggregate.
|
||||
|
||||
6. Conveying Non-Source Forms.
|
||||
|
||||
You may convey a covered work in object code form under the terms
|
||||
of sections 4 and 5, provided that you also convey the
|
||||
machine-readable Corresponding Source under the terms of this License,
|
||||
in one of these ways:
|
||||
|
||||
a) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by the
|
||||
Corresponding Source fixed on a durable physical medium
|
||||
customarily used for software interchange.
|
||||
|
||||
b) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by a
|
||||
written offer, valid for at least three years and valid for as
|
||||
long as you offer spare parts or customer support for that product
|
||||
model, to give anyone who possesses the object code either (1) a
|
||||
copy of the Corresponding Source for all the software in the
|
||||
product that is covered by this License, on a durable physical
|
||||
medium customarily used for software interchange, for a price no
|
||||
more than your reasonable cost of physically performing this
|
||||
conveying of source, or (2) access to copy the
|
||||
Corresponding Source from a network server at no charge.
|
||||
|
||||
c) Convey individual copies of the object code with a copy of the
|
||||
written offer to provide the Corresponding Source. This
|
||||
alternative is allowed only occasionally and noncommercially, and
|
||||
only if you received the object code with such an offer, in accord
|
||||
with subsection 6b.
|
||||
|
||||
d) Convey the object code by offering access from a designated
|
||||
place (gratis or for a charge), and offer equivalent access to the
|
||||
Corresponding Source in the same way through the same place at no
|
||||
further charge. You need not require recipients to copy the
|
||||
Corresponding Source along with the object code. If the place to
|
||||
copy the object code is a network server, the Corresponding Source
|
||||
may be on a different server (operated by you or a third party)
|
||||
that supports equivalent copying facilities, provided you maintain
|
||||
clear directions next to the object code saying where to find the
|
||||
Corresponding Source. Regardless of what server hosts the
|
||||
Corresponding Source, you remain obligated to ensure that it is
|
||||
available for as long as needed to satisfy these requirements.
|
||||
|
||||
e) Convey the object code using peer-to-peer transmission, provided
|
||||
you inform other peers where the object code and Corresponding
|
||||
Source of the work are being offered to the general public at no
|
||||
charge under subsection 6d.
|
||||
|
||||
A separable portion of the object code, whose source code is excluded
|
||||
from the Corresponding Source as a System Library, need not be
|
||||
included in conveying the object code work.
|
||||
|
||||
A "User Product" is either (1) a "consumer product", which means any
|
||||
tangible personal property which is normally used for personal, family,
|
||||
or household purposes, or (2) anything designed or sold for incorporation
|
||||
into a dwelling. In determining whether a product is a consumer product,
|
||||
doubtful cases shall be resolved in favor of coverage. For a particular
|
||||
product received by a particular user, "normally used" refers to a
|
||||
typical or common use of that class of product, regardless of the status
|
||||
of the particular user or of the way in which the particular user
|
||||
actually uses, or expects or is expected to use, the product. A product
|
||||
is a consumer product regardless of whether the product has substantial
|
||||
commercial, industrial or non-consumer uses, unless such uses represent
|
||||
the only significant mode of use of the product.
|
||||
|
||||
"Installation Information" for a User Product means any methods,
|
||||
procedures, authorization keys, or other information required to install
|
||||
and execute modified versions of a covered work in that User Product from
|
||||
a modified version of its Corresponding Source. The information must
|
||||
suffice to ensure that the continued functioning of the modified object
|
||||
code is in no case prevented or interfered with solely because
|
||||
modification has been made.
|
||||
|
||||
If you convey an object code work under this section in, or with, or
|
||||
specifically for use in, a User Product, and the conveying occurs as
|
||||
part of a transaction in which the right of possession and use of the
|
||||
User Product is transferred to the recipient in perpetuity or for a
|
||||
fixed term (regardless of how the transaction is characterized), the
|
||||
Corresponding Source conveyed under this section must be accompanied
|
||||
by the Installation Information. But this requirement does not apply
|
||||
if neither you nor any third party retains the ability to install
|
||||
modified object code on the User Product (for example, the work has
|
||||
been installed in ROM).
|
||||
|
||||
The requirement to provide Installation Information does not include a
|
||||
requirement to continue to provide support service, warranty, or updates
|
||||
for a work that has been modified or installed by the recipient, or for
|
||||
the User Product in which it has been modified or installed. Access to a
|
||||
network may be denied when the modification itself materially and
|
||||
adversely affects the operation of the network or violates the rules and
|
||||
protocols for communication across the network.
|
||||
|
||||
Corresponding Source conveyed, and Installation Information provided,
|
||||
in accord with this section must be in a format that is publicly
|
||||
documented (and with an implementation available to the public in
|
||||
source code form), and must require no special password or key for
|
||||
unpacking, reading or copying.
|
||||
|
||||
7. Additional Terms.
|
||||
|
||||
"Additional permissions" are terms that supplement the terms of this
|
||||
License by making exceptions from one or more of its conditions.
|
||||
Additional permissions that are applicable to the entire Program shall
|
||||
be treated as though they were included in this License, to the extent
|
||||
that they are valid under applicable law. If additional permissions
|
||||
apply only to part of the Program, that part may be used separately
|
||||
under those permissions, but the entire Program remains governed by
|
||||
this License without regard to the additional permissions.
|
||||
|
||||
When you convey a copy of a covered work, you may at your option
|
||||
remove any additional permissions from that copy, or from any part of
|
||||
it. (Additional permissions may be written to require their own
|
||||
removal in certain cases when you modify the work.) You may place
|
||||
additional permissions on material, added by you to a covered work,
|
||||
for which you have or can give appropriate copyright permission.
|
||||
|
||||
Notwithstanding any other provision of this License, for material you
|
||||
add to a covered work, you may (if authorized by the copyright holders of
|
||||
that material) supplement the terms of this License with terms:
|
||||
|
||||
a) Disclaiming warranty or limiting liability differently from the
|
||||
terms of sections 15 and 16 of this License; or
|
||||
|
||||
b) Requiring preservation of specified reasonable legal notices or
|
||||
author attributions in that material or in the Appropriate Legal
|
||||
Notices displayed by works containing it; or
|
||||
|
||||
c) Prohibiting misrepresentation of the origin of that material, or
|
||||
requiring that modified versions of such material be marked in
|
||||
reasonable ways as different from the original version; or
|
||||
|
||||
d) Limiting the use for publicity purposes of names of licensors or
|
||||
authors of the material; or
|
||||
|
||||
e) Declining to grant rights under trademark law for use of some
|
||||
trade names, trademarks, or service marks; or
|
||||
|
||||
f) Requiring indemnification of licensors and authors of that
|
||||
material by anyone who conveys the material (or modified versions of
|
||||
it) with contractual assumptions of liability to the recipient, for
|
||||
any liability that these contractual assumptions directly impose on
|
||||
those licensors and authors.
|
||||
|
||||
All other non-permissive additional terms are considered "further
|
||||
restrictions" within the meaning of section 10. If the Program as you
|
||||
received it, or any part of it, contains a notice stating that it is
|
||||
governed by this License along with a term that is a further
|
||||
restriction, you may remove that term. If a license document contains
|
||||
a further restriction but permits relicensing or conveying under this
|
||||
License, you may add to a covered work material governed by the terms
|
||||
of that license document, provided that the further restriction does
|
||||
not survive such relicensing or conveying.
|
||||
|
||||
If you add terms to a covered work in accord with this section, you
|
||||
must place, in the relevant source files, a statement of the
|
||||
additional terms that apply to those files, or a notice indicating
|
||||
where to find the applicable terms.
|
||||
|
||||
Additional terms, permissive or non-permissive, may be stated in the
|
||||
form of a separately written license, or stated as exceptions;
|
||||
the above requirements apply either way.
|
||||
|
||||
8. Termination.
|
||||
|
||||
You may not propagate or modify a covered work except as expressly
|
||||
provided under this License. Any attempt otherwise to propagate or
|
||||
modify it is void, and will automatically terminate your rights under
|
||||
this License (including any patent licenses granted under the third
|
||||
paragraph of section 11).
|
||||
|
||||
However, if you cease all violation of this License, then your
|
||||
license from a particular copyright holder is reinstated (a)
|
||||
provisionally, unless and until the copyright holder explicitly and
|
||||
finally terminates your license, and (b) permanently, if the copyright
|
||||
holder fails to notify you of the violation by some reasonable means
|
||||
prior to 60 days after the cessation.
|
||||
|
||||
Moreover, your license from a particular copyright holder is
|
||||
reinstated permanently if the copyright holder notifies you of the
|
||||
violation by some reasonable means, this is the first time you have
|
||||
received notice of violation of this License (for any work) from that
|
||||
copyright holder, and you cure the violation prior to 30 days after
|
||||
your receipt of the notice.
|
||||
|
||||
Termination of your rights under this section does not terminate the
|
||||
licenses of parties who have received copies or rights from you under
|
||||
this License. If your rights have been terminated and not permanently
|
||||
reinstated, you do not qualify to receive new licenses for the same
|
||||
material under section 10.
|
||||
|
||||
9. Acceptance Not Required for Having Copies.
|
||||
|
||||
You are not required to accept this License in order to receive or
|
||||
run a copy of the Program. Ancillary propagation of a covered work
|
||||
occurring solely as a consequence of using peer-to-peer transmission
|
||||
to receive a copy likewise does not require acceptance. However,
|
||||
nothing other than this License grants you permission to propagate or
|
||||
modify any covered work. These actions infringe copyright if you do
|
||||
not accept this License. Therefore, by modifying or propagating a
|
||||
covered work, you indicate your acceptance of this License to do so.
|
||||
|
||||
10. Automatic Licensing of Downstream Recipients.
|
||||
|
||||
Each time you convey a covered work, the recipient automatically
|
||||
receives a license from the original licensors, to run, modify and
|
||||
propagate that work, subject to this License. You are not responsible
|
||||
for enforcing compliance by third parties with this License.
|
||||
|
||||
An "entity transaction" is a transaction transferring control of an
|
||||
organization, or substantially all assets of one, or subdividing an
|
||||
organization, or merging organizations. If propagation of a covered
|
||||
work results from an entity transaction, each party to that
|
||||
transaction who receives a copy of the work also receives whatever
|
||||
licenses to the work the party's predecessor in interest had or could
|
||||
give under the previous paragraph, plus a right to possession of the
|
||||
Corresponding Source of the work from the predecessor in interest, if
|
||||
the predecessor has it or can get it with reasonable efforts.
|
||||
|
||||
You may not impose any further restrictions on the exercise of the
|
||||
rights granted or affirmed under this License. For example, you may
|
||||
not impose a license fee, royalty, or other charge for exercise of
|
||||
rights granted under this License, and you may not initiate litigation
|
||||
(including a cross-claim or counterclaim in a lawsuit) alleging that
|
||||
any patent claim is infringed by making, using, selling, offering for
|
||||
sale, or importing the Program or any portion of it.
|
||||
|
||||
11. Patents.
|
||||
|
||||
A "contributor" is a copyright holder who authorizes use under this
|
||||
License of the Program or a work on which the Program is based. The
|
||||
work thus licensed is called the contributor's "contributor version".
|
||||
|
||||
A contributor's "essential patent claims" are all patent claims
|
||||
owned or controlled by the contributor, whether already acquired or
|
||||
hereafter acquired, that would be infringed by some manner, permitted
|
||||
by this License, of making, using, or selling its contributor version,
|
||||
but do not include claims that would be infringed only as a
|
||||
consequence of further modification of the contributor version. For
|
||||
purposes of this definition, "control" includes the right to grant
|
||||
patent sublicenses in a manner consistent with the requirements of
|
||||
this License.
|
||||
|
||||
Each contributor grants you a non-exclusive, worldwide, royalty-free
|
||||
patent license under the contributor's essential patent claims, to
|
||||
make, use, sell, offer for sale, import and otherwise run, modify and
|
||||
propagate the contents of its contributor version.
|
||||
|
||||
In the following three paragraphs, a "patent license" is any express
|
||||
agreement or commitment, however denominated, not to enforce a patent
|
||||
(such as an express permission to practice a patent or covenant not to
|
||||
sue for patent infringement). To "grant" such a patent license to a
|
||||
party means to make such an agreement or commitment not to enforce a
|
||||
patent against the party.
|
||||
|
||||
If you convey a covered work, knowingly relying on a patent license,
|
||||
and the Corresponding Source of the work is not available for anyone
|
||||
to copy, free of charge and under the terms of this License, through a
|
||||
publicly available network server or other readily accessible means,
|
||||
then you must either (1) cause the Corresponding Source to be so
|
||||
available, or (2) arrange to deprive yourself of the benefit of the
|
||||
patent license for this particular work, or (3) arrange, in a manner
|
||||
consistent with the requirements of this License, to extend the patent
|
||||
license to downstream recipients. "Knowingly relying" means you have
|
||||
actual knowledge that, but for the patent license, your conveying the
|
||||
covered work in a country, or your recipient's use of the covered work
|
||||
in a country, would infringe one or more identifiable patents in that
|
||||
country that you have reason to believe are valid.
|
||||
|
||||
If, pursuant to or in connection with a single transaction or
|
||||
arrangement, you convey, or propagate by procuring conveyance of, a
|
||||
covered work, and grant a patent license to some of the parties
|
||||
receiving the covered work authorizing them to use, propagate, modify
|
||||
or convey a specific copy of the covered work, then the patent license
|
||||
you grant is automatically extended to all recipients of the covered
|
||||
work and works based on it.
|
||||
|
||||
A patent license is "discriminatory" if it does not include within
|
||||
the scope of its coverage, prohibits the exercise of, or is
|
||||
conditioned on the non-exercise of one or more of the rights that are
|
||||
specifically granted under this License. You may not convey a covered
|
||||
work if you are a party to an arrangement with a third party that is
|
||||
in the business of distributing software, under which you make payment
|
||||
to the third party based on the extent of your activity of conveying
|
||||
the work, and under which the third party grants, to any of the
|
||||
parties who would receive the covered work from you, a discriminatory
|
||||
patent license (a) in connection with copies of the covered work
|
||||
conveyed by you (or copies made from those copies), or (b) primarily
|
||||
for and in connection with specific products or compilations that
|
||||
contain the covered work, unless you entered into that arrangement,
|
||||
or that patent license was granted, prior to 28 March 2007.
|
||||
|
||||
Nothing in this License shall be construed as excluding or limiting
|
||||
any implied license or other defenses to infringement that may
|
||||
otherwise be available to you under applicable patent law.
|
||||
|
||||
12. No Surrender of Others' Freedom.
|
||||
|
||||
If conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot convey a
|
||||
covered work so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you may
|
||||
not convey it at all. For example, if you agree to terms that obligate you
|
||||
to collect a royalty for further conveying from those to whom you convey
|
||||
the Program, the only way you could satisfy both those terms and this
|
||||
License would be to refrain entirely from conveying the Program.
|
||||
|
||||
13. Use with the GNU Affero General Public License.
|
||||
|
||||
Notwithstanding any other provision of this License, you have
|
||||
permission to link or combine any covered work with a work licensed
|
||||
under version 3 of the GNU Affero General Public License into a single
|
||||
combined work, and to convey the resulting work. The terms of this
|
||||
License will continue to apply to the part which is the covered work,
|
||||
but the special requirements of the GNU Affero General Public License,
|
||||
section 13, concerning interaction through a network will apply to the
|
||||
combination as such.
|
||||
|
||||
14. Revised Versions of this License.
|
||||
|
||||
The Free Software Foundation may publish revised and/or new versions of
|
||||
the GNU General Public License from time to time. Such new versions will
|
||||
be similar in spirit to the present version, but may differ in detail to
|
||||
address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the
|
||||
Program specifies that a certain numbered version of the GNU General
|
||||
Public License "or any later version" applies to it, you have the
|
||||
option of following the terms and conditions either of that numbered
|
||||
version or of any later version published by the Free Software
|
||||
Foundation. If the Program does not specify a version number of the
|
||||
GNU General Public License, you may choose any version ever published
|
||||
by the Free Software Foundation.
|
||||
|
||||
If the Program specifies that a proxy can decide which future
|
||||
versions of the GNU General Public License can be used, that proxy's
|
||||
public statement of acceptance of a version permanently authorizes you
|
||||
to choose that version for the Program.
|
||||
|
||||
Later license versions may give you additional or different
|
||||
permissions. However, no additional obligations are imposed on any
|
||||
author or copyright holder as a result of your choosing to follow a
|
||||
later version.
|
||||
|
||||
15. Disclaimer of Warranty.
|
||||
|
||||
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
|
||||
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
|
||||
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
|
||||
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
|
||||
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
|
||||
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
|
||||
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||
|
||||
16. Limitation of Liability.
|
||||
|
||||
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
|
||||
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
|
||||
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
|
||||
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
|
||||
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
|
||||
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
|
||||
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
|
||||
SUCH DAMAGES.
|
||||
|
||||
17. Interpretation of Sections 15 and 16.
|
||||
|
||||
If the disclaimer of warranty and limitation of liability provided
|
||||
above cannot be given local legal effect according to their terms,
|
||||
reviewing courts shall apply local law that most closely approximates
|
||||
an absolute waiver of all civil liability in connection with the
|
||||
Program, unless a warranty or assumption of liability accompanies a
|
||||
copy of the Program in return for a fee.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Programs
|
||||
|
||||
If you develop a new program, and you want it to be of the greatest
|
||||
possible use to the public, the best way to achieve this is to make it
|
||||
free software which everyone can redistribute and change under these terms.
|
||||
|
||||
To do so, attach the following notices to the program. It is safest
|
||||
to attach them to the start of each source file to most effectively
|
||||
state the exclusion of warranty; and each file should have at least
|
||||
the "copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
<one line to give the program's name and a brief idea of what it does.>
|
||||
Copyright (C) <year> <name of author>
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If the program does terminal interaction, make it output a short
|
||||
notice like this when it starts in an interactive mode:
|
||||
|
||||
<program> Copyright (C) <year> <name of author>
|
||||
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||
This is free software, and you are welcome to redistribute it
|
||||
under certain conditions; type `show c' for details.
|
||||
|
||||
The hypothetical commands `show w' and `show c' should show the appropriate
|
||||
parts of the General Public License. Of course, your program's commands
|
||||
might be different; for a GUI interface, you would use an "about box".
|
||||
|
||||
You should also get your employer (if you work as a programmer) or school,
|
||||
if any, to sign a "copyright disclaimer" for the program, if necessary.
|
||||
For more information on this, and how to apply and follow the GNU GPL, see
|
||||
<http://www.gnu.org/licenses/>.
|
||||
|
||||
The GNU General Public License does not permit incorporating your program
|
||||
into proprietary programs. If your program is a subroutine library, you
|
||||
may consider it more useful to permit linking proprietary applications with
|
||||
the library. If this is what you want to do, use the GNU Lesser General
|
||||
Public License instead of this License. But first, please read
|
||||
<http://www.gnu.org/philosophy/why-not-lgpl.html>.
|
||||
260
node/README.md
Normal file
260
node/README.md
Normal file
@@ -0,0 +1,260 @@
|
||||
# deltachat-node
|
||||
|
||||
> node.js bindings for [`deltachat-core-rust`](..)
|
||||
|
||||
[](https://www.npmjs.com/package/deltachat-node)
|
||||

|
||||
[](https://prettier.io)
|
||||
|
||||
`deltachat-node` primarily aims to offer two things:
|
||||
|
||||
- A high level JavaScript api with syntactic sugar
|
||||
- A low level c binding api around [`deltachat-core-rust`](..)
|
||||
|
||||
This code used to live at [`deltachat-node`](https://github.com/deltachat/deltachat-node)
|
||||
|
||||
## Table of Contents
|
||||
|
||||
<details><summary>Click to expand</summary>
|
||||
|
||||
- [Install](#install)
|
||||
- [Dependencies](#dependencies)
|
||||
- [Build from source](#build-from-source)
|
||||
- [Usage](#usage)
|
||||
- [Developing](#developing)
|
||||
- [License](#license)
|
||||
|
||||
</details>
|
||||
|
||||
## Install
|
||||
|
||||
By default the installation will build try to use the bundled prebuilds in the
|
||||
npm package. If this fails it falls back to compile `../deltachat-core-rust` from
|
||||
this repository, using `scripts/rebuild-core.js`.
|
||||
|
||||
To install from npm use:
|
||||
|
||||
```
|
||||
npm install deltachat-node
|
||||
```
|
||||
|
||||
## Dependencies
|
||||
|
||||
- Nodejs >= `v16.0.0`
|
||||
- rustup (optional if you can't use the prebuilds)
|
||||
|
||||
> On Windows, you may need to also install **Perl** to be able to compile deltachat-core.
|
||||
|
||||
## Build from source
|
||||
|
||||
If you want to build from source, make sure that you have `rustup` installed.
|
||||
You can either use `npm install deltachat-node --build-from-source` to force
|
||||
building from source or clone this repository and follow this steps:
|
||||
|
||||
1. `git clone https://github.com/deltachat/deltachat-core-rust.git`
|
||||
2. `cd deltachat-core-rust`
|
||||
3. `npm i`
|
||||
4. `npm run build`
|
||||
|
||||
> Our `package.json` file is located in the root directory of this repository,
|
||||
> not inside this folder. (We need this in order to include the rust source
|
||||
> code in the npm package.)
|
||||
|
||||
### Use a git branch in deltachat-desktop
|
||||
|
||||
You can directly install a core branch, but make sure:
|
||||
- that you have typescript in your project dependencies, as it is likely required
|
||||
- you know that there are **no prebuilds** and so core is built during installation which is why it takes so long
|
||||
|
||||
```
|
||||
npm install https://github.com/deltachat/deltachat-core-rust.git#branch
|
||||
```
|
||||
|
||||
If you want prebuilds for a branch that has a core pr, you might find an npm tar.gz package for that branch at <https://download.delta.chat/node/preview/>.
|
||||
The github ci also posts a link to it in the checks for each pr.
|
||||
|
||||
### Use build-from-source in deltachat-desktop
|
||||
|
||||
If you want to use the manually built node bindings in the desktop client (for
|
||||
example), you can follow these instructions:
|
||||
|
||||
First clone the
|
||||
[deltachat-desktop](https://github.com/deltachat/deltachat-desktop) repository,
|
||||
e.g. with `git clone https://github.com/deltachat/deltachat-desktop`.
|
||||
|
||||
Then you need to make sure that this directory is referenced correctly in
|
||||
deltachat-desktop's package.json. You need to change
|
||||
`deltachat-desktop/package.json` like this:
|
||||
|
||||
```
|
||||
diff --git i/package.json w/package.json
|
||||
index 45893894..5154512c 100644
|
||||
--- i/package.json
|
||||
+++ w/package.json
|
||||
@@ -83,7 +83,7 @@
|
||||
"application-config": "^1.0.1",
|
||||
"classnames": "^2.3.1",
|
||||
"debounce": "^1.2.0",
|
||||
- "deltachat-node": "1.79.3",
|
||||
+ "deltachat-node": "file:../deltachat-core-rust/",
|
||||
"emoji-js-clean": "^4.0.0",
|
||||
"emoji-mart": "^3.0.1",
|
||||
"emoji-regex": "^9.2.2",
|
||||
```
|
||||
|
||||
Then, in the `deltachat-desktop` repository, run:
|
||||
|
||||
1. `npm i`
|
||||
2. `npm run build`
|
||||
3. And `npm run start` to start the newly built client.
|
||||
|
||||
### Workaround to build for x86_64 on Apple's M1
|
||||
|
||||
deltachat doesn't support universal (fat) binaries (that contain builds for both cpu architectures) yet, until it does you can use the following workaround to get x86_64 builds:
|
||||
|
||||
```
|
||||
$ fnm install 17 --arch x64
|
||||
$ fnm use 17
|
||||
$ node -p process.arch
|
||||
# result should be x64
|
||||
$ cd deltachat-core-rust && rustup target add x86_64-apple-darwin && cd -
|
||||
$ git apply patches/m1_build_use_x86_64.patch
|
||||
$ CARGO_BUILD_TARGET=x86_64-apple-darwin npm run build
|
||||
$ npm run test
|
||||
```
|
||||
|
||||
(when using [fnm](https://github.com/Schniz/fnm) instead of nvm, you can select the architecture)
|
||||
If your node and electron are already build for arm64 you can also try bulding for arm:
|
||||
|
||||
```
|
||||
$ fnm install 16 --arch arm64
|
||||
$ fnm use 16
|
||||
$ node -p process.arch
|
||||
# result should be arm64
|
||||
$ npm_config_arch=arm64 npm run build
|
||||
$ npm run test
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
```js
|
||||
const { Context } = require('deltachat-node')
|
||||
|
||||
const opts = {
|
||||
addr: '[email]',
|
||||
mail_pw: '[password]',
|
||||
}
|
||||
|
||||
const contact = '[email]'
|
||||
|
||||
async function main() {
|
||||
const dc = Context.open('./')
|
||||
dc.on('ALL', console.log.bind(null, 'core |'))
|
||||
|
||||
try {
|
||||
await dc.configure(opts)
|
||||
} catch (err) {
|
||||
console.error('Failed to configure because of: ', err)
|
||||
dc.unref()
|
||||
return
|
||||
}
|
||||
|
||||
dc.startIO()
|
||||
console.log('fully configured')
|
||||
|
||||
const contactId = dc.createContact('Test', contact)
|
||||
const chatId = dc.createChatByContactId(contactId)
|
||||
dc.sendMessage(chatId, 'Hi!')
|
||||
|
||||
console.log('sent message')
|
||||
|
||||
dc.once('DC_EVENT_SMTP_MESSAGE_SENT', async () => {
|
||||
console.log('Message sent, shutting down...')
|
||||
dc.stopIO()
|
||||
console.log('stopped io')
|
||||
dc.unref()
|
||||
})
|
||||
}
|
||||
|
||||
main()
|
||||
```
|
||||
this example can also be found in the examples folder [examples/send_message.js](./examples/send_message.js)
|
||||
|
||||
### Generating Docs
|
||||
|
||||
We are curently migrating to automaticaly generated documentation.
|
||||
You can find the old documentation at [old_docs](./old_docs).
|
||||
|
||||
to generate the documentation, run:
|
||||
|
||||
```
|
||||
npx typedoc
|
||||
```
|
||||
|
||||
The resulting documentation can be found in the `docs/` folder.
|
||||
An online version can be found under [js.delta.chat](https://js.delta.chat).
|
||||
|
||||
## Developing
|
||||
|
||||
### Tests and Coverage
|
||||
|
||||
Running `npm test` ends with showing a code coverage report, which is produced by [`nyc`](https://github.com/istanbuljs/nyc#readme).
|
||||
|
||||

|
||||
|
||||
The coverage report from `nyc` in the console is rather limited. To get a more detailed coverage report you can run `npm run coverage-html-report`. This will produce a html report from the `nyc` data and display it in a browser on your local machine.
|
||||
|
||||
To run the integration tests you need to set the `DCC_NEW_TMP_EMAIL` environment variables. E.g.:
|
||||
|
||||
```
|
||||
$ export DCC_NEW_TMP_EMAIL=https://testrun.org/new_email?t=[token]
|
||||
$ npm run test
|
||||
```
|
||||
|
||||
### Scripts
|
||||
|
||||
We have the following scripts for building, testing and coverage:
|
||||
|
||||
- `npm run coverage` Creates a coverage report and passes it to `coveralls`. Only done by `Travis`.
|
||||
- `npm run coverage-html-report` Generates a html report from the coverage data and opens it in a browser on the local machine.
|
||||
- `npm run generate-constants` Generates `constants.js` and `events.js` based on the `deltachat-core-rust/deltachat-ffi/deltachat.h` header file.
|
||||
- `npm install` After dependencies are installed, runs `node-gyp-build` to see if the native code needs to be rebuilt.
|
||||
- `npm run build` Rebuilds all code.
|
||||
- `npm run build:core` Rebuilds code in `deltachat-core-rust`.
|
||||
- `npm run build:bindings` Rebuilds the bindings and links with `deltachat-core-rust`.
|
||||
- `ǹpm run clean` Removes all built code
|
||||
- `npm run prebuildify` Builds prebuilt binary to `prebuilds/$PLATFORM-$ARCH`. Copies `deltachat.dll` from `deltachat-core-rust` for windows.
|
||||
- `npm run download-prebuilds` Downloads all prebuilt binaries from github before `npm publish`.
|
||||
- `npm test` Runs `standard` and then the tests in `test/index.js`.
|
||||
- `npm run test-integration` Runs the integration tests.
|
||||
- `npm run hallmark` Runs `hallmark` on all markdown files.
|
||||
|
||||
### Releases
|
||||
|
||||
The following steps are needed to make a release:
|
||||
|
||||
1. Wait until `pack-module` github action is completed
|
||||
2. Run `npm publish https://download.delta.chat/node/deltachat-node-v1.x.x.tar.gz` to publish it to npm. You probably need write rights to npm.
|
||||
|
||||
## License
|
||||
|
||||
Licensed under `GPL-3.0-or-later`, see [LICENSE](./LICENSE) file for details.
|
||||
|
||||
> Copyright © 2018 `DeltaChat` contributors.
|
||||
>
|
||||
> This program is free software: you can redistribute it and/or modify
|
||||
> it under the terms of the GNU General Public License as published by
|
||||
> the Free Software Foundation, either version 3 of the License, or
|
||||
> (at your option) any later version.
|
||||
>
|
||||
> This program is distributed in the hope that it will be useful,
|
||||
> but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
> MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
> GNU General Public License for more details.
|
||||
>
|
||||
> You should have received a copy of the GNU General Public License
|
||||
> along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
[appveyor-shield]: https://ci.appveyor.com/api/projects/status/t0narp672wpbl6pd?svg=true
|
||||
|
||||
[appveyor]: https://ci.appveyor.com/project/ralphtheninja/deltachat-node-d4bf8
|
||||
78
node/binding.gyp
Normal file
78
node/binding.gyp
Normal file
@@ -0,0 +1,78 @@
|
||||
{
|
||||
# documentation about the format of this file can be found under https://gyp.gsrc.io/docs/InputFormatReference.md
|
||||
# Variables can be specified when calling node-gyp as so:
|
||||
# node-gyp configure -- -Dvarname=value
|
||||
"variables": {
|
||||
# Whether to use a system-wide installation of deltachat-core
|
||||
# using pkg-config. Set to either "true" or "false".
|
||||
"USE_SYSTEM_LIBDELTACHAT%": "<!(echo $USE_SYSTEM_LIBDELTACHAT)",
|
||||
},
|
||||
"targets": [
|
||||
{
|
||||
"target_name": "deltachat",
|
||||
"sources": ["./src/module.c"],
|
||||
"include_dirs": ["<!(node -e \"require('napi-macros')\")"],
|
||||
"conditions": [
|
||||
[
|
||||
"OS == 'win'",
|
||||
{
|
||||
"include_dirs": ["../deltachat-ffi"],
|
||||
"libraries": [
|
||||
"../../target/release/deltachat.dll.lib",
|
||||
],
|
||||
"conditions": [
|
||||
[
|
||||
"USE_SYSTEM_LIBDELTACHAT == 'true'",
|
||||
{
|
||||
"cflags": ["<!(pkg-config --cflags deltachat)"],
|
||||
"libraries": ["<!(pkg-config --libs deltachat)"],
|
||||
},
|
||||
],
|
||||
],
|
||||
},
|
||||
],
|
||||
[
|
||||
"OS == 'linux' or OS == 'mac'",
|
||||
{
|
||||
"libraries": ["-lpthread"],
|
||||
"cflags": ["-std=gnu99"],
|
||||
"conditions": [
|
||||
[
|
||||
"USE_SYSTEM_LIBDELTACHAT != 'true'",
|
||||
{
|
||||
"include_dirs": ["../deltachat-ffi"],
|
||||
"ldflags": ["-Wl,-Bsymbolic"], # Prevent sqlite3 from electron from overriding sqlcipher
|
||||
"libraries": [
|
||||
"../../target/release/libdeltachat.a",
|
||||
"-ldl",
|
||||
],
|
||||
"conditions": [],
|
||||
},
|
||||
{
|
||||
# USE_SYSTEM_LIBDELTACHAT == 'true'
|
||||
"cflags": ["<!(pkg-config --cflags deltachat)"],
|
||||
"libraries": ["<!(pkg-config --libs deltachat)"],
|
||||
},
|
||||
],
|
||||
[
|
||||
"OS == 'mac'",
|
||||
{
|
||||
"libraries": [
|
||||
"-framework CoreFoundation",
|
||||
"-framework CoreServices",
|
||||
"-framework Security",
|
||||
"-lresolv",
|
||||
],
|
||||
},
|
||||
{
|
||||
# OS == 'linux'
|
||||
"libraries": ["-lm", "-lrt"],
|
||||
},
|
||||
],
|
||||
],
|
||||
},
|
||||
],
|
||||
],
|
||||
},
|
||||
],
|
||||
}
|
||||
1
node/binding.js
Normal file
1
node/binding.js
Normal file
@@ -0,0 +1 @@
|
||||
module.exports = require('node-gyp-build')(__dirname)
|
||||
226
node/constants.js
Normal file
226
node/constants.js
Normal file
@@ -0,0 +1,226 @@
|
||||
// Generated!
|
||||
|
||||
module.exports = {
|
||||
DC_CERTCK_ACCEPT_INVALID_CERTIFICATES: 3,
|
||||
DC_CERTCK_AUTO: 0,
|
||||
DC_CERTCK_STRICT: 1,
|
||||
DC_CHAT_ID_ALLDONE_HINT: 7,
|
||||
DC_CHAT_ID_ARCHIVED_LINK: 6,
|
||||
DC_CHAT_ID_LAST_SPECIAL: 9,
|
||||
DC_CHAT_ID_TRASH: 3,
|
||||
DC_CHAT_TYPE_BROADCAST: 160,
|
||||
DC_CHAT_TYPE_GROUP: 120,
|
||||
DC_CHAT_TYPE_MAILINGLIST: 140,
|
||||
DC_CHAT_TYPE_SINGLE: 100,
|
||||
DC_CHAT_TYPE_UNDEFINED: 0,
|
||||
DC_CHAT_VISIBILITY_ARCHIVED: 1,
|
||||
DC_CHAT_VISIBILITY_NORMAL: 0,
|
||||
DC_CHAT_VISIBILITY_PINNED: 2,
|
||||
DC_CONNECTIVITY_CONNECTED: 4000,
|
||||
DC_CONNECTIVITY_CONNECTING: 2000,
|
||||
DC_CONNECTIVITY_NOT_CONNECTED: 1000,
|
||||
DC_CONNECTIVITY_WORKING: 3000,
|
||||
DC_CONTACT_ID_DEVICE: 5,
|
||||
DC_CONTACT_ID_INFO: 2,
|
||||
DC_CONTACT_ID_LAST_SPECIAL: 9,
|
||||
DC_CONTACT_ID_SELF: 1,
|
||||
DC_DOWNLOAD_AVAILABLE: 10,
|
||||
DC_DOWNLOAD_DONE: 0,
|
||||
DC_DOWNLOAD_FAILURE: 20,
|
||||
DC_DOWNLOAD_IN_PROGRESS: 1000,
|
||||
DC_EVENT_CHAT_EPHEMERAL_TIMER_MODIFIED: 2021,
|
||||
DC_EVENT_CHAT_MODIFIED: 2020,
|
||||
DC_EVENT_CONFIGURE_PROGRESS: 2041,
|
||||
DC_EVENT_CONNECTIVITY_CHANGED: 2100,
|
||||
DC_EVENT_CONTACTS_CHANGED: 2030,
|
||||
DC_EVENT_DELETED_BLOB_FILE: 151,
|
||||
DC_EVENT_ERROR: 400,
|
||||
DC_EVENT_ERROR_SELF_NOT_IN_GROUP: 410,
|
||||
DC_EVENT_IMAP_CONNECTED: 102,
|
||||
DC_EVENT_IMAP_MESSAGE_DELETED: 104,
|
||||
DC_EVENT_IMAP_MESSAGE_MOVED: 105,
|
||||
DC_EVENT_IMEX_FILE_WRITTEN: 2052,
|
||||
DC_EVENT_IMEX_PROGRESS: 2051,
|
||||
DC_EVENT_INCOMING_MSG: 2005,
|
||||
DC_EVENT_INFO: 100,
|
||||
DC_EVENT_LOCATION_CHANGED: 2035,
|
||||
DC_EVENT_MSGS_CHANGED: 2000,
|
||||
DC_EVENT_MSGS_NOTICED: 2008,
|
||||
DC_EVENT_MSG_DELIVERED: 2010,
|
||||
DC_EVENT_MSG_FAILED: 2012,
|
||||
DC_EVENT_MSG_READ: 2015,
|
||||
DC_EVENT_NEW_BLOB_FILE: 150,
|
||||
DC_EVENT_SECUREJOIN_INVITER_PROGRESS: 2060,
|
||||
DC_EVENT_SECUREJOIN_JOINER_PROGRESS: 2061,
|
||||
DC_EVENT_SELFAVATAR_CHANGED: 2110,
|
||||
DC_EVENT_SMTP_CONNECTED: 101,
|
||||
DC_EVENT_SMTP_MESSAGE_SENT: 103,
|
||||
DC_EVENT_WARNING: 300,
|
||||
DC_EVENT_WEBXDC_STATUS_UPDATE: 2120,
|
||||
DC_GCL_ADD_ALLDONE_HINT: 4,
|
||||
DC_GCL_ADD_SELF: 2,
|
||||
DC_GCL_ARCHIVED_ONLY: 1,
|
||||
DC_GCL_FOR_FORWARDING: 8,
|
||||
DC_GCL_NO_SPECIALS: 2,
|
||||
DC_GCL_VERIFIED_ONLY: 1,
|
||||
DC_GCM_ADDDAYMARKER: 1,
|
||||
DC_GCM_INFO_ONLY: 2,
|
||||
DC_IMEX_EXPORT_BACKUP: 11,
|
||||
DC_IMEX_EXPORT_SELF_KEYS: 1,
|
||||
DC_IMEX_IMPORT_BACKUP: 12,
|
||||
DC_IMEX_IMPORT_SELF_KEYS: 2,
|
||||
DC_INFO_PROTECTION_DISABLED: 12,
|
||||
DC_INFO_PROTECTION_ENABLED: 11,
|
||||
DC_KEY_GEN_DEFAULT: 0,
|
||||
DC_KEY_GEN_ED25519: 2,
|
||||
DC_KEY_GEN_RSA2048: 1,
|
||||
DC_LP_AUTH_NORMAL: 4,
|
||||
DC_LP_AUTH_OAUTH2: 2,
|
||||
DC_MEDIA_QUALITY_BALANCED: 0,
|
||||
DC_MEDIA_QUALITY_WORSE: 1,
|
||||
DC_MSG_AUDIO: 40,
|
||||
DC_MSG_FILE: 60,
|
||||
DC_MSG_GIF: 21,
|
||||
DC_MSG_ID_DAYMARKER: 9,
|
||||
DC_MSG_ID_LAST_SPECIAL: 9,
|
||||
DC_MSG_ID_MARKER1: 1,
|
||||
DC_MSG_IMAGE: 20,
|
||||
DC_MSG_STICKER: 23,
|
||||
DC_MSG_TEXT: 10,
|
||||
DC_MSG_VIDEO: 50,
|
||||
DC_MSG_VIDEOCHAT_INVITATION: 70,
|
||||
DC_MSG_VOICE: 41,
|
||||
DC_MSG_WEBXDC: 80,
|
||||
DC_PROVIDER_STATUS_BROKEN: 3,
|
||||
DC_PROVIDER_STATUS_OK: 1,
|
||||
DC_PROVIDER_STATUS_PREPARATION: 2,
|
||||
DC_QR_ACCOUNT: 250,
|
||||
DC_QR_ADDR: 320,
|
||||
DC_QR_ASK_VERIFYCONTACT: 200,
|
||||
DC_QR_ASK_VERIFYGROUP: 202,
|
||||
DC_QR_ERROR: 400,
|
||||
DC_QR_FPR_MISMATCH: 220,
|
||||
DC_QR_FPR_OK: 210,
|
||||
DC_QR_FPR_WITHOUT_ADDR: 230,
|
||||
DC_QR_REVIVE_VERIFYCONTACT: 510,
|
||||
DC_QR_REVIVE_VERIFYGROUP: 512,
|
||||
DC_QR_TEXT: 330,
|
||||
DC_QR_URL: 332,
|
||||
DC_QR_WEBRTC_INSTANCE: 260,
|
||||
DC_QR_WITHDRAW_VERIFYCONTACT: 500,
|
||||
DC_QR_WITHDRAW_VERIFYGROUP: 502,
|
||||
DC_SHOW_EMAILS_ACCEPTED_CONTACTS: 1,
|
||||
DC_SHOW_EMAILS_ALL: 2,
|
||||
DC_SHOW_EMAILS_OFF: 0,
|
||||
DC_SOCKET_AUTO: 0,
|
||||
DC_SOCKET_PLAIN: 3,
|
||||
DC_SOCKET_SSL: 1,
|
||||
DC_SOCKET_STARTTLS: 2,
|
||||
DC_STATE_IN_FRESH: 10,
|
||||
DC_STATE_IN_NOTICED: 13,
|
||||
DC_STATE_IN_SEEN: 16,
|
||||
DC_STATE_OUT_DELIVERED: 26,
|
||||
DC_STATE_OUT_DRAFT: 19,
|
||||
DC_STATE_OUT_FAILED: 24,
|
||||
DC_STATE_OUT_MDN_RCVD: 28,
|
||||
DC_STATE_OUT_PENDING: 20,
|
||||
DC_STATE_OUT_PREPARING: 18,
|
||||
DC_STATE_UNDEFINED: 0,
|
||||
DC_STR_AC_SETUP_MSG_BODY: 43,
|
||||
DC_STR_AC_SETUP_MSG_SUBJECT: 42,
|
||||
DC_STR_ARCHIVEDCHATS: 40,
|
||||
DC_STR_AUDIO: 11,
|
||||
DC_STR_BAD_TIME_MSG_BODY: 85,
|
||||
DC_STR_BROADCAST_LIST: 115,
|
||||
DC_STR_CANNOT_LOGIN: 60,
|
||||
DC_STR_CANTDECRYPT_MSG_BODY: 29,
|
||||
DC_STR_CONFIGURATION_FAILED: 84,
|
||||
DC_STR_CONNECTED: 107,
|
||||
DC_STR_CONNTECTING: 108,
|
||||
DC_STR_CONTACT_NOT_VERIFIED: 36,
|
||||
DC_STR_CONTACT_SETUP_CHANGED: 37,
|
||||
DC_STR_CONTACT_VERIFIED: 35,
|
||||
DC_STR_DEVICE_MESSAGES: 68,
|
||||
DC_STR_DEVICE_MESSAGES_HINT: 70,
|
||||
DC_STR_DOWNLOAD_AVAILABILITY: 100,
|
||||
DC_STR_DRAFT: 3,
|
||||
DC_STR_E2E_AVAILABLE: 25,
|
||||
DC_STR_E2E_PREFERRED: 34,
|
||||
DC_STR_ENCRYPTEDMSG: 24,
|
||||
DC_STR_ENCR_NONE: 28,
|
||||
DC_STR_ENCR_TRANSP: 27,
|
||||
DC_STR_EPHEMERAL_DAY: 79,
|
||||
DC_STR_EPHEMERAL_DAYS: 95,
|
||||
DC_STR_EPHEMERAL_DISABLED: 75,
|
||||
DC_STR_EPHEMERAL_FOUR_WEEKS: 81,
|
||||
DC_STR_EPHEMERAL_HOUR: 78,
|
||||
DC_STR_EPHEMERAL_HOURS: 94,
|
||||
DC_STR_EPHEMERAL_MINUTE: 77,
|
||||
DC_STR_EPHEMERAL_MINUTES: 93,
|
||||
DC_STR_EPHEMERAL_SECONDS: 76,
|
||||
DC_STR_EPHEMERAL_WEEK: 80,
|
||||
DC_STR_EPHEMERAL_WEEKS: 96,
|
||||
DC_STR_ERROR: 112,
|
||||
DC_STR_ERROR_NO_NETWORK: 87,
|
||||
DC_STR_FAILED_SENDING_TO: 74,
|
||||
DC_STR_FILE: 12,
|
||||
DC_STR_FINGERPRINTS: 30,
|
||||
DC_STR_FORWARDED: 97,
|
||||
DC_STR_GIF: 23,
|
||||
DC_STR_IMAGE: 9,
|
||||
DC_STR_INCOMING_MESSAGES: 103,
|
||||
DC_STR_LAST_MSG_SENT_SUCCESSFULLY: 111,
|
||||
DC_STR_LOCATION: 66,
|
||||
DC_STR_MESSAGES: 114,
|
||||
DC_STR_MSGACTIONBYME: 63,
|
||||
DC_STR_MSGACTIONBYUSER: 62,
|
||||
DC_STR_MSGADDMEMBER: 17,
|
||||
DC_STR_MSGDELMEMBER: 18,
|
||||
DC_STR_MSGGROUPLEFT: 19,
|
||||
DC_STR_MSGGRPIMGCHANGED: 16,
|
||||
DC_STR_MSGGRPIMGDELETED: 33,
|
||||
DC_STR_MSGGRPNAME: 15,
|
||||
DC_STR_MSGLOCATIONDISABLED: 65,
|
||||
DC_STR_MSGLOCATIONENABLED: 64,
|
||||
DC_STR_NOMESSAGES: 1,
|
||||
DC_STR_NOT_CONNECTED: 121,
|
||||
DC_STR_NOT_SUPPORTED_BY_PROVIDER: 113,
|
||||
DC_STR_ONE_MOMENT: 106,
|
||||
DC_STR_OUTGOING_MESSAGES: 104,
|
||||
DC_STR_PARTIAL_DOWNLOAD_MSG_BODY: 99,
|
||||
DC_STR_PART_OF_TOTAL_USED: 116,
|
||||
DC_STR_PROTECTION_DISABLED: 89,
|
||||
DC_STR_PROTECTION_ENABLED: 88,
|
||||
DC_STR_QUOTA_EXCEEDING_MSG_BODY: 98,
|
||||
DC_STR_READRCPT: 31,
|
||||
DC_STR_READRCPT_MAILBODY: 32,
|
||||
DC_STR_REPLY_NOUN: 90,
|
||||
DC_STR_SAVED_MESSAGES: 69,
|
||||
DC_STR_SECURE_JOIN_GROUP_QR_DESC: 120,
|
||||
DC_STR_SECURE_JOIN_REPLIES: 118,
|
||||
DC_STR_SECURE_JOIN_STARTED: 117,
|
||||
DC_STR_SELF: 2,
|
||||
DC_STR_SELF_DELETED_MSG_BODY: 91,
|
||||
DC_STR_SENDING: 110,
|
||||
DC_STR_SERVER_TURNED_OFF: 92,
|
||||
DC_STR_SETUP_CONTACT_QR_DESC: 119,
|
||||
DC_STR_STICKER: 67,
|
||||
DC_STR_STORAGE_ON_DOMAIN: 105,
|
||||
DC_STR_SUBJECT_FOR_NEW_CONTACT: 73,
|
||||
DC_STR_SYNC_MSG_BODY: 102,
|
||||
DC_STR_SYNC_MSG_SUBJECT: 101,
|
||||
DC_STR_UNKNOWN_SENDER_FOR_CHAT: 72,
|
||||
DC_STR_UPDATE_REMINDER_MSG_BODY: 86,
|
||||
DC_STR_UPDATING: 109,
|
||||
DC_STR_VIDEO: 10,
|
||||
DC_STR_VIDEOCHAT_INVITATION: 82,
|
||||
DC_STR_VIDEOCHAT_INVITE_MSG_BODY: 83,
|
||||
DC_STR_VOICEMESSAGE: 7,
|
||||
DC_STR_WELCOME_MESSAGE: 71,
|
||||
DC_TEXT1_DRAFT: 1,
|
||||
DC_TEXT1_SELF: 3,
|
||||
DC_TEXT1_USERNAME: 2,
|
||||
DC_VIDEOCHATTYPE_BASICWEBRTC: 1,
|
||||
DC_VIDEOCHATTYPE_JITSI: 2,
|
||||
DC_VIDEOCHATTYPE_UNKNOWN: 0
|
||||
}
|
||||
34
node/events.js
Normal file
34
node/events.js
Normal file
@@ -0,0 +1,34 @@
|
||||
/* eslint-disable quotes */
|
||||
// Generated!
|
||||
|
||||
module.exports = {
|
||||
100: 'DC_EVENT_INFO',
|
||||
101: 'DC_EVENT_SMTP_CONNECTED',
|
||||
102: 'DC_EVENT_IMAP_CONNECTED',
|
||||
103: 'DC_EVENT_SMTP_MESSAGE_SENT',
|
||||
104: 'DC_EVENT_IMAP_MESSAGE_DELETED',
|
||||
105: 'DC_EVENT_IMAP_MESSAGE_MOVED',
|
||||
150: 'DC_EVENT_NEW_BLOB_FILE',
|
||||
151: 'DC_EVENT_DELETED_BLOB_FILE',
|
||||
300: 'DC_EVENT_WARNING',
|
||||
400: 'DC_EVENT_ERROR',
|
||||
410: 'DC_EVENT_ERROR_SELF_NOT_IN_GROUP',
|
||||
2000: 'DC_EVENT_MSGS_CHANGED',
|
||||
2005: 'DC_EVENT_INCOMING_MSG',
|
||||
2008: 'DC_EVENT_MSGS_NOTICED',
|
||||
2010: 'DC_EVENT_MSG_DELIVERED',
|
||||
2012: 'DC_EVENT_MSG_FAILED',
|
||||
2015: 'DC_EVENT_MSG_READ',
|
||||
2020: 'DC_EVENT_CHAT_MODIFIED',
|
||||
2021: 'DC_EVENT_CHAT_EPHEMERAL_TIMER_MODIFIED',
|
||||
2030: 'DC_EVENT_CONTACTS_CHANGED',
|
||||
2035: 'DC_EVENT_LOCATION_CHANGED',
|
||||
2041: 'DC_EVENT_CONFIGURE_PROGRESS',
|
||||
2051: 'DC_EVENT_IMEX_PROGRESS',
|
||||
2052: 'DC_EVENT_IMEX_FILE_WRITTEN',
|
||||
2060: 'DC_EVENT_SECUREJOIN_INVITER_PROGRESS',
|
||||
2061: 'DC_EVENT_SECUREJOIN_JOINER_PROGRESS',
|
||||
2100: 'DC_EVENT_CONNECTIVITY_CHANGED',
|
||||
2110: 'DC_EVENT_SELFAVATAR_CHANGED',
|
||||
2120: 'DC_EVENT_WEBXDC_STATUS_UPDATE'
|
||||
}
|
||||
40
node/examples/send_message.js
Normal file
40
node/examples/send_message.js
Normal file
@@ -0,0 +1,40 @@
|
||||
//@ts-check
|
||||
const { Context } = require('../dist')
|
||||
|
||||
const opts = {
|
||||
addr: '[email]',
|
||||
mail_pw: '[password]',
|
||||
}
|
||||
|
||||
const contact = '[email]'
|
||||
|
||||
async function main() {
|
||||
const dc = Context.open('./')
|
||||
dc.on('ALL', console.log.bind(null, 'core |'))
|
||||
|
||||
try {
|
||||
await dc.configure(opts)
|
||||
} catch (err) {
|
||||
console.error('Failed to configure because of: ', err)
|
||||
dc.unref()
|
||||
return
|
||||
}
|
||||
|
||||
dc.startIO()
|
||||
console.log('fully configured')
|
||||
|
||||
const contactId = dc.createContact('Test', contact)
|
||||
const chatId = dc.createChatByContactId(contactId)
|
||||
dc.sendMessage(chatId, 'Hi!')
|
||||
|
||||
console.log('sent message')
|
||||
|
||||
dc.once('DC_EVENT_SMTP_MESSAGE_SENT', async () => {
|
||||
console.log('Message sent, shutting down...')
|
||||
dc.stopIO()
|
||||
console.log('stopped io')
|
||||
dc.unref()
|
||||
})
|
||||
}
|
||||
|
||||
main()
|
||||
BIN
node/images/tests.png
Normal file
BIN
node/images/tests.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 26 KiB |
9
node/lib/binding.ts
Normal file
9
node/lib/binding.ts
Normal file
@@ -0,0 +1,9 @@
|
||||
import { join } from 'path'
|
||||
|
||||
/**
|
||||
* bindings are not typed yet.
|
||||
* if the availible function names are required they can be found inside of `../src/module.c`
|
||||
*/
|
||||
export const bindings: any = require('node-gyp-build')(join(__dirname, '../'))
|
||||
|
||||
export default bindings
|
||||
106
node/lib/chat.ts
Normal file
106
node/lib/chat.ts
Normal file
@@ -0,0 +1,106 @@
|
||||
/* eslint-disable camelcase */
|
||||
|
||||
import binding from './binding'
|
||||
import rawDebug from 'debug'
|
||||
const debug = rawDebug('deltachat:node:chat')
|
||||
import { C } from './constants'
|
||||
import { integerToHexColor } from './util'
|
||||
import { ChatJSON } from './types'
|
||||
|
||||
interface NativeChat {}
|
||||
/**
|
||||
* Wrapper around dc_chat_t*
|
||||
*/
|
||||
|
||||
export class Chat {
|
||||
constructor(public dc_chat: NativeChat) {
|
||||
debug('Chat constructor')
|
||||
if (dc_chat === null) {
|
||||
throw new Error('native chat can not be null')
|
||||
}
|
||||
}
|
||||
|
||||
getVisibility():
|
||||
| C.DC_CHAT_VISIBILITY_NORMAL
|
||||
| C.DC_CHAT_VISIBILITY_ARCHIVED
|
||||
| C.DC_CHAT_VISIBILITY_PINNED {
|
||||
return binding.dcn_chat_get_visibility(this.dc_chat)
|
||||
}
|
||||
|
||||
get color(): string {
|
||||
return integerToHexColor(binding.dcn_chat_get_color(this.dc_chat))
|
||||
}
|
||||
|
||||
getId(): number {
|
||||
return binding.dcn_chat_get_id(this.dc_chat)
|
||||
}
|
||||
|
||||
getName(): string {
|
||||
return binding.dcn_chat_get_name(this.dc_chat)
|
||||
}
|
||||
|
||||
getProfileImage(): string {
|
||||
return binding.dcn_chat_get_profile_image(this.dc_chat)
|
||||
}
|
||||
|
||||
getType(): number {
|
||||
return binding.dcn_chat_get_type(this.dc_chat)
|
||||
}
|
||||
|
||||
isSelfTalk(): boolean {
|
||||
return Boolean(binding.dcn_chat_is_self_talk(this.dc_chat))
|
||||
}
|
||||
|
||||
isContactRequest(): boolean {
|
||||
return Boolean(binding.dcn_chat_is_contact_request(this.dc_chat))
|
||||
}
|
||||
|
||||
isUnpromoted(): boolean {
|
||||
return Boolean(binding.dcn_chat_is_unpromoted(this.dc_chat))
|
||||
}
|
||||
|
||||
isProtected(): boolean {
|
||||
return Boolean(binding.dcn_chat_is_protected(this.dc_chat))
|
||||
}
|
||||
|
||||
get canSend(): boolean {
|
||||
return Boolean(binding.dcn_chat_can_send(this.dc_chat))
|
||||
}
|
||||
|
||||
isDeviceTalk(): boolean {
|
||||
return Boolean(binding.dcn_chat_is_device_talk(this.dc_chat))
|
||||
}
|
||||
|
||||
isSingle(): boolean {
|
||||
return this.getType() === C.DC_CHAT_TYPE_SINGLE
|
||||
}
|
||||
|
||||
isGroup(): boolean {
|
||||
return this.getType() === C.DC_CHAT_TYPE_GROUP
|
||||
}
|
||||
|
||||
isMuted(): boolean {
|
||||
return Boolean(binding.dcn_chat_is_muted(this.dc_chat))
|
||||
}
|
||||
|
||||
toJson(): ChatJSON {
|
||||
debug('toJson')
|
||||
const visibility = this.getVisibility()
|
||||
return {
|
||||
archived: visibility === C.DC_CHAT_VISIBILITY_ARCHIVED,
|
||||
pinned: visibility === C.DC_CHAT_VISIBILITY_PINNED,
|
||||
color: this.color,
|
||||
id: this.getId(),
|
||||
name: this.getName(),
|
||||
profileImage: this.getProfileImage(),
|
||||
type: this.getType(),
|
||||
isSelfTalk: this.isSelfTalk(),
|
||||
isUnpromoted: this.isUnpromoted(),
|
||||
isProtected: this.isProtected(),
|
||||
canSend: this.canSend,
|
||||
isDeviceTalk: this.isDeviceTalk(),
|
||||
isContactRequest: this.isContactRequest(),
|
||||
muted: this.isMuted(),
|
||||
}
|
||||
}
|
||||
}
|
||||
42
node/lib/chatlist.ts
Normal file
42
node/lib/chatlist.ts
Normal file
@@ -0,0 +1,42 @@
|
||||
/* eslint-disable camelcase */
|
||||
|
||||
import binding from './binding'
|
||||
import { Lot } from './lot'
|
||||
import { Chat } from './chat'
|
||||
const debug = require('debug')('deltachat:node:chatlist')
|
||||
|
||||
interface NativeChatList {}
|
||||
/**
|
||||
* Wrapper around dc_chatlist_t*
|
||||
*/
|
||||
export class ChatList {
|
||||
constructor(private dc_chatlist: NativeChatList) {
|
||||
debug('ChatList constructor')
|
||||
if (dc_chatlist === null) {
|
||||
throw new Error('native chat list can not be null')
|
||||
}
|
||||
}
|
||||
|
||||
getChatId(index: number): number {
|
||||
debug(`getChatId ${index}`)
|
||||
return binding.dcn_chatlist_get_chat_id(this.dc_chatlist, index)
|
||||
}
|
||||
|
||||
getCount(): number {
|
||||
debug('getCount')
|
||||
return binding.dcn_chatlist_get_cnt(this.dc_chatlist)
|
||||
}
|
||||
|
||||
getMessageId(index: number): number {
|
||||
debug(`getMessageId ${index}`)
|
||||
return binding.dcn_chatlist_get_msg_id(this.dc_chatlist, index)
|
||||
}
|
||||
|
||||
getSummary(index: number, chat?: Chat): Lot {
|
||||
debug(`getSummary ${index}`)
|
||||
const dc_chat = (chat && chat.dc_chat) || null
|
||||
return new Lot(
|
||||
binding.dcn_chatlist_get_summary(this.dc_chatlist, index, dc_chat)
|
||||
)
|
||||
}
|
||||
}
|
||||
260
node/lib/constants.ts
Normal file
260
node/lib/constants.ts
Normal file
@@ -0,0 +1,260 @@
|
||||
// Generated!
|
||||
|
||||
export enum C {
|
||||
DC_CERTCK_ACCEPT_INVALID_CERTIFICATES = 3,
|
||||
DC_CERTCK_AUTO = 0,
|
||||
DC_CERTCK_STRICT = 1,
|
||||
DC_CHAT_ID_ALLDONE_HINT = 7,
|
||||
DC_CHAT_ID_ARCHIVED_LINK = 6,
|
||||
DC_CHAT_ID_LAST_SPECIAL = 9,
|
||||
DC_CHAT_ID_TRASH = 3,
|
||||
DC_CHAT_TYPE_BROADCAST = 160,
|
||||
DC_CHAT_TYPE_GROUP = 120,
|
||||
DC_CHAT_TYPE_MAILINGLIST = 140,
|
||||
DC_CHAT_TYPE_SINGLE = 100,
|
||||
DC_CHAT_TYPE_UNDEFINED = 0,
|
||||
DC_CHAT_VISIBILITY_ARCHIVED = 1,
|
||||
DC_CHAT_VISIBILITY_NORMAL = 0,
|
||||
DC_CHAT_VISIBILITY_PINNED = 2,
|
||||
DC_CONNECTIVITY_CONNECTED = 4000,
|
||||
DC_CONNECTIVITY_CONNECTING = 2000,
|
||||
DC_CONNECTIVITY_NOT_CONNECTED = 1000,
|
||||
DC_CONNECTIVITY_WORKING = 3000,
|
||||
DC_CONTACT_ID_DEVICE = 5,
|
||||
DC_CONTACT_ID_INFO = 2,
|
||||
DC_CONTACT_ID_LAST_SPECIAL = 9,
|
||||
DC_CONTACT_ID_SELF = 1,
|
||||
DC_DOWNLOAD_AVAILABLE = 10,
|
||||
DC_DOWNLOAD_DONE = 0,
|
||||
DC_DOWNLOAD_FAILURE = 20,
|
||||
DC_DOWNLOAD_IN_PROGRESS = 1000,
|
||||
DC_EVENT_CHAT_EPHEMERAL_TIMER_MODIFIED = 2021,
|
||||
DC_EVENT_CHAT_MODIFIED = 2020,
|
||||
DC_EVENT_CONFIGURE_PROGRESS = 2041,
|
||||
DC_EVENT_CONNECTIVITY_CHANGED = 2100,
|
||||
DC_EVENT_CONTACTS_CHANGED = 2030,
|
||||
DC_EVENT_DELETED_BLOB_FILE = 151,
|
||||
DC_EVENT_ERROR = 400,
|
||||
DC_EVENT_ERROR_SELF_NOT_IN_GROUP = 410,
|
||||
DC_EVENT_IMAP_CONNECTED = 102,
|
||||
DC_EVENT_IMAP_MESSAGE_DELETED = 104,
|
||||
DC_EVENT_IMAP_MESSAGE_MOVED = 105,
|
||||
DC_EVENT_IMEX_FILE_WRITTEN = 2052,
|
||||
DC_EVENT_IMEX_PROGRESS = 2051,
|
||||
DC_EVENT_INCOMING_MSG = 2005,
|
||||
DC_EVENT_INFO = 100,
|
||||
DC_EVENT_LOCATION_CHANGED = 2035,
|
||||
DC_EVENT_MSGS_CHANGED = 2000,
|
||||
DC_EVENT_MSGS_NOTICED = 2008,
|
||||
DC_EVENT_MSG_DELIVERED = 2010,
|
||||
DC_EVENT_MSG_FAILED = 2012,
|
||||
DC_EVENT_MSG_READ = 2015,
|
||||
DC_EVENT_NEW_BLOB_FILE = 150,
|
||||
DC_EVENT_SECUREJOIN_INVITER_PROGRESS = 2060,
|
||||
DC_EVENT_SECUREJOIN_JOINER_PROGRESS = 2061,
|
||||
DC_EVENT_SELFAVATAR_CHANGED = 2110,
|
||||
DC_EVENT_SMTP_CONNECTED = 101,
|
||||
DC_EVENT_SMTP_MESSAGE_SENT = 103,
|
||||
DC_EVENT_WARNING = 300,
|
||||
DC_EVENT_WEBXDC_STATUS_UPDATE = 2120,
|
||||
DC_GCL_ADD_ALLDONE_HINT = 4,
|
||||
DC_GCL_ADD_SELF = 2,
|
||||
DC_GCL_ARCHIVED_ONLY = 1,
|
||||
DC_GCL_FOR_FORWARDING = 8,
|
||||
DC_GCL_NO_SPECIALS = 2,
|
||||
DC_GCL_VERIFIED_ONLY = 1,
|
||||
DC_GCM_ADDDAYMARKER = 1,
|
||||
DC_GCM_INFO_ONLY = 2,
|
||||
DC_IMEX_EXPORT_BACKUP = 11,
|
||||
DC_IMEX_EXPORT_SELF_KEYS = 1,
|
||||
DC_IMEX_IMPORT_BACKUP = 12,
|
||||
DC_IMEX_IMPORT_SELF_KEYS = 2,
|
||||
DC_INFO_PROTECTION_DISABLED = 12,
|
||||
DC_INFO_PROTECTION_ENABLED = 11,
|
||||
DC_KEY_GEN_DEFAULT = 0,
|
||||
DC_KEY_GEN_ED25519 = 2,
|
||||
DC_KEY_GEN_RSA2048 = 1,
|
||||
DC_LP_AUTH_NORMAL = 4,
|
||||
DC_LP_AUTH_OAUTH2 = 2,
|
||||
DC_MEDIA_QUALITY_BALANCED = 0,
|
||||
DC_MEDIA_QUALITY_WORSE = 1,
|
||||
DC_MSG_AUDIO = 40,
|
||||
DC_MSG_FILE = 60,
|
||||
DC_MSG_GIF = 21,
|
||||
DC_MSG_ID_DAYMARKER = 9,
|
||||
DC_MSG_ID_LAST_SPECIAL = 9,
|
||||
DC_MSG_ID_MARKER1 = 1,
|
||||
DC_MSG_IMAGE = 20,
|
||||
DC_MSG_STICKER = 23,
|
||||
DC_MSG_TEXT = 10,
|
||||
DC_MSG_VIDEO = 50,
|
||||
DC_MSG_VIDEOCHAT_INVITATION = 70,
|
||||
DC_MSG_VOICE = 41,
|
||||
DC_MSG_WEBXDC = 80,
|
||||
DC_PROVIDER_STATUS_BROKEN = 3,
|
||||
DC_PROVIDER_STATUS_OK = 1,
|
||||
DC_PROVIDER_STATUS_PREPARATION = 2,
|
||||
DC_QR_ACCOUNT = 250,
|
||||
DC_QR_ADDR = 320,
|
||||
DC_QR_ASK_VERIFYCONTACT = 200,
|
||||
DC_QR_ASK_VERIFYGROUP = 202,
|
||||
DC_QR_ERROR = 400,
|
||||
DC_QR_FPR_MISMATCH = 220,
|
||||
DC_QR_FPR_OK = 210,
|
||||
DC_QR_FPR_WITHOUT_ADDR = 230,
|
||||
DC_QR_REVIVE_VERIFYCONTACT = 510,
|
||||
DC_QR_REVIVE_VERIFYGROUP = 512,
|
||||
DC_QR_TEXT = 330,
|
||||
DC_QR_URL = 332,
|
||||
DC_QR_WEBRTC_INSTANCE = 260,
|
||||
DC_QR_WITHDRAW_VERIFYCONTACT = 500,
|
||||
DC_QR_WITHDRAW_VERIFYGROUP = 502,
|
||||
DC_SHOW_EMAILS_ACCEPTED_CONTACTS = 1,
|
||||
DC_SHOW_EMAILS_ALL = 2,
|
||||
DC_SHOW_EMAILS_OFF = 0,
|
||||
DC_SOCKET_AUTO = 0,
|
||||
DC_SOCKET_PLAIN = 3,
|
||||
DC_SOCKET_SSL = 1,
|
||||
DC_SOCKET_STARTTLS = 2,
|
||||
DC_STATE_IN_FRESH = 10,
|
||||
DC_STATE_IN_NOTICED = 13,
|
||||
DC_STATE_IN_SEEN = 16,
|
||||
DC_STATE_OUT_DELIVERED = 26,
|
||||
DC_STATE_OUT_DRAFT = 19,
|
||||
DC_STATE_OUT_FAILED = 24,
|
||||
DC_STATE_OUT_MDN_RCVD = 28,
|
||||
DC_STATE_OUT_PENDING = 20,
|
||||
DC_STATE_OUT_PREPARING = 18,
|
||||
DC_STATE_UNDEFINED = 0,
|
||||
DC_STR_AC_SETUP_MSG_BODY = 43,
|
||||
DC_STR_AC_SETUP_MSG_SUBJECT = 42,
|
||||
DC_STR_ARCHIVEDCHATS = 40,
|
||||
DC_STR_AUDIO = 11,
|
||||
DC_STR_BAD_TIME_MSG_BODY = 85,
|
||||
DC_STR_BROADCAST_LIST = 115,
|
||||
DC_STR_CANNOT_LOGIN = 60,
|
||||
DC_STR_CANTDECRYPT_MSG_BODY = 29,
|
||||
DC_STR_CONFIGURATION_FAILED = 84,
|
||||
DC_STR_CONNECTED = 107,
|
||||
DC_STR_CONNTECTING = 108,
|
||||
DC_STR_CONTACT_NOT_VERIFIED = 36,
|
||||
DC_STR_CONTACT_SETUP_CHANGED = 37,
|
||||
DC_STR_CONTACT_VERIFIED = 35,
|
||||
DC_STR_DEVICE_MESSAGES = 68,
|
||||
DC_STR_DEVICE_MESSAGES_HINT = 70,
|
||||
DC_STR_DOWNLOAD_AVAILABILITY = 100,
|
||||
DC_STR_DRAFT = 3,
|
||||
DC_STR_E2E_AVAILABLE = 25,
|
||||
DC_STR_E2E_PREFERRED = 34,
|
||||
DC_STR_ENCRYPTEDMSG = 24,
|
||||
DC_STR_ENCR_NONE = 28,
|
||||
DC_STR_ENCR_TRANSP = 27,
|
||||
DC_STR_EPHEMERAL_DAY = 79,
|
||||
DC_STR_EPHEMERAL_DAYS = 95,
|
||||
DC_STR_EPHEMERAL_DISABLED = 75,
|
||||
DC_STR_EPHEMERAL_FOUR_WEEKS = 81,
|
||||
DC_STR_EPHEMERAL_HOUR = 78,
|
||||
DC_STR_EPHEMERAL_HOURS = 94,
|
||||
DC_STR_EPHEMERAL_MINUTE = 77,
|
||||
DC_STR_EPHEMERAL_MINUTES = 93,
|
||||
DC_STR_EPHEMERAL_SECONDS = 76,
|
||||
DC_STR_EPHEMERAL_WEEK = 80,
|
||||
DC_STR_EPHEMERAL_WEEKS = 96,
|
||||
DC_STR_ERROR = 112,
|
||||
DC_STR_ERROR_NO_NETWORK = 87,
|
||||
DC_STR_FAILED_SENDING_TO = 74,
|
||||
DC_STR_FILE = 12,
|
||||
DC_STR_FINGERPRINTS = 30,
|
||||
DC_STR_FORWARDED = 97,
|
||||
DC_STR_GIF = 23,
|
||||
DC_STR_IMAGE = 9,
|
||||
DC_STR_INCOMING_MESSAGES = 103,
|
||||
DC_STR_LAST_MSG_SENT_SUCCESSFULLY = 111,
|
||||
DC_STR_LOCATION = 66,
|
||||
DC_STR_MESSAGES = 114,
|
||||
DC_STR_MSGACTIONBYME = 63,
|
||||
DC_STR_MSGACTIONBYUSER = 62,
|
||||
DC_STR_MSGADDMEMBER = 17,
|
||||
DC_STR_MSGDELMEMBER = 18,
|
||||
DC_STR_MSGGROUPLEFT = 19,
|
||||
DC_STR_MSGGRPIMGCHANGED = 16,
|
||||
DC_STR_MSGGRPIMGDELETED = 33,
|
||||
DC_STR_MSGGRPNAME = 15,
|
||||
DC_STR_MSGLOCATIONDISABLED = 65,
|
||||
DC_STR_MSGLOCATIONENABLED = 64,
|
||||
DC_STR_NOMESSAGES = 1,
|
||||
DC_STR_NOT_CONNECTED = 121,
|
||||
DC_STR_NOT_SUPPORTED_BY_PROVIDER = 113,
|
||||
DC_STR_ONE_MOMENT = 106,
|
||||
DC_STR_OUTGOING_MESSAGES = 104,
|
||||
DC_STR_PARTIAL_DOWNLOAD_MSG_BODY = 99,
|
||||
DC_STR_PART_OF_TOTAL_USED = 116,
|
||||
DC_STR_PROTECTION_DISABLED = 89,
|
||||
DC_STR_PROTECTION_ENABLED = 88,
|
||||
DC_STR_QUOTA_EXCEEDING_MSG_BODY = 98,
|
||||
DC_STR_READRCPT = 31,
|
||||
DC_STR_READRCPT_MAILBODY = 32,
|
||||
DC_STR_REPLY_NOUN = 90,
|
||||
DC_STR_SAVED_MESSAGES = 69,
|
||||
DC_STR_SECURE_JOIN_GROUP_QR_DESC = 120,
|
||||
DC_STR_SECURE_JOIN_REPLIES = 118,
|
||||
DC_STR_SECURE_JOIN_STARTED = 117,
|
||||
DC_STR_SELF = 2,
|
||||
DC_STR_SELF_DELETED_MSG_BODY = 91,
|
||||
DC_STR_SENDING = 110,
|
||||
DC_STR_SERVER_TURNED_OFF = 92,
|
||||
DC_STR_SETUP_CONTACT_QR_DESC = 119,
|
||||
DC_STR_STICKER = 67,
|
||||
DC_STR_STORAGE_ON_DOMAIN = 105,
|
||||
DC_STR_SUBJECT_FOR_NEW_CONTACT = 73,
|
||||
DC_STR_SYNC_MSG_BODY = 102,
|
||||
DC_STR_SYNC_MSG_SUBJECT = 101,
|
||||
DC_STR_UNKNOWN_SENDER_FOR_CHAT = 72,
|
||||
DC_STR_UPDATE_REMINDER_MSG_BODY = 86,
|
||||
DC_STR_UPDATING = 109,
|
||||
DC_STR_VIDEO = 10,
|
||||
DC_STR_VIDEOCHAT_INVITATION = 82,
|
||||
DC_STR_VIDEOCHAT_INVITE_MSG_BODY = 83,
|
||||
DC_STR_VOICEMESSAGE = 7,
|
||||
DC_STR_WELCOME_MESSAGE = 71,
|
||||
DC_TEXT1_DRAFT = 1,
|
||||
DC_TEXT1_SELF = 3,
|
||||
DC_TEXT1_USERNAME = 2,
|
||||
DC_VIDEOCHATTYPE_BASICWEBRTC = 1,
|
||||
DC_VIDEOCHATTYPE_JITSI = 2,
|
||||
DC_VIDEOCHATTYPE_UNKNOWN = 0,
|
||||
}
|
||||
|
||||
// Generated!
|
||||
|
||||
export const EventId2EventName: { [key: number]: string } = {
|
||||
100: 'DC_EVENT_INFO',
|
||||
101: 'DC_EVENT_SMTP_CONNECTED',
|
||||
102: 'DC_EVENT_IMAP_CONNECTED',
|
||||
103: 'DC_EVENT_SMTP_MESSAGE_SENT',
|
||||
104: 'DC_EVENT_IMAP_MESSAGE_DELETED',
|
||||
105: 'DC_EVENT_IMAP_MESSAGE_MOVED',
|
||||
150: 'DC_EVENT_NEW_BLOB_FILE',
|
||||
151: 'DC_EVENT_DELETED_BLOB_FILE',
|
||||
300: 'DC_EVENT_WARNING',
|
||||
400: 'DC_EVENT_ERROR',
|
||||
410: 'DC_EVENT_ERROR_SELF_NOT_IN_GROUP',
|
||||
2000: 'DC_EVENT_MSGS_CHANGED',
|
||||
2005: 'DC_EVENT_INCOMING_MSG',
|
||||
2008: 'DC_EVENT_MSGS_NOTICED',
|
||||
2010: 'DC_EVENT_MSG_DELIVERED',
|
||||
2012: 'DC_EVENT_MSG_FAILED',
|
||||
2015: 'DC_EVENT_MSG_READ',
|
||||
2020: 'DC_EVENT_CHAT_MODIFIED',
|
||||
2021: 'DC_EVENT_CHAT_EPHEMERAL_TIMER_MODIFIED',
|
||||
2030: 'DC_EVENT_CONTACTS_CHANGED',
|
||||
2035: 'DC_EVENT_LOCATION_CHANGED',
|
||||
2041: 'DC_EVENT_CONFIGURE_PROGRESS',
|
||||
2051: 'DC_EVENT_IMEX_PROGRESS',
|
||||
2052: 'DC_EVENT_IMEX_FILE_WRITTEN',
|
||||
2060: 'DC_EVENT_SECUREJOIN_INVITER_PROGRESS',
|
||||
2061: 'DC_EVENT_SECUREJOIN_JOINER_PROGRESS',
|
||||
2100: 'DC_EVENT_CONNECTIVITY_CHANGED',
|
||||
2110: 'DC_EVENT_SELFAVATAR_CHANGED',
|
||||
2120: 'DC_EVENT_WEBXDC_STATUS_UPDATE',
|
||||
}
|
||||
94
node/lib/contact.ts
Normal file
94
node/lib/contact.ts
Normal file
@@ -0,0 +1,94 @@
|
||||
import { integerToHexColor } from './util'
|
||||
|
||||
/* eslint-disable camelcase */
|
||||
|
||||
import binding from './binding'
|
||||
const debug = require('debug')('deltachat:node:contact')
|
||||
|
||||
interface NativeContact {}
|
||||
/**
|
||||
* Wrapper around dc_contact_t*
|
||||
*/
|
||||
export class Contact {
|
||||
constructor(public dc_contact: NativeContact) {
|
||||
debug('Contact constructor')
|
||||
if (dc_contact === null) {
|
||||
throw new Error('native contact can not be null')
|
||||
}
|
||||
}
|
||||
|
||||
toJson() {
|
||||
debug('toJson')
|
||||
return {
|
||||
address: this.getAddress(),
|
||||
color: this.color,
|
||||
authName: this.authName,
|
||||
status: this.status,
|
||||
displayName: this.getDisplayName(),
|
||||
id: this.getId(),
|
||||
lastSeen: this.lastSeen,
|
||||
name: this.getName(),
|
||||
profileImage: this.getProfileImage(),
|
||||
nameAndAddr: this.getNameAndAddress(),
|
||||
isBlocked: this.isBlocked(),
|
||||
isVerified: this.isVerified(),
|
||||
}
|
||||
}
|
||||
|
||||
getAddress(): string {
|
||||
return binding.dcn_contact_get_addr(this.dc_contact)
|
||||
}
|
||||
|
||||
/** Get original contact name.
|
||||
* This is the name of the contact as defined by the contact themself.
|
||||
* If the contact themself does not define such a name,
|
||||
* an empty string is returned. */
|
||||
get authName(): string {
|
||||
return binding.dcn_contact_get_auth_name(this.dc_contact)
|
||||
}
|
||||
|
||||
get color(): string {
|
||||
return integerToHexColor(binding.dcn_contact_get_color(this.dc_contact))
|
||||
}
|
||||
|
||||
/**
|
||||
* contact's status
|
||||
*
|
||||
* Status is the last signature received in a message from this contact.
|
||||
*/
|
||||
get status(): string {
|
||||
return binding.dcn_contact_get_status(this.dc_contact)
|
||||
}
|
||||
|
||||
getDisplayName(): string {
|
||||
return binding.dcn_contact_get_display_name(this.dc_contact)
|
||||
}
|
||||
|
||||
getId(): number {
|
||||
return binding.dcn_contact_get_id(this.dc_contact)
|
||||
}
|
||||
|
||||
get lastSeen(): number {
|
||||
return binding.dcn_contact_get_last_seen(this.dc_contact)
|
||||
}
|
||||
|
||||
getName(): string {
|
||||
return binding.dcn_contact_get_name(this.dc_contact)
|
||||
}
|
||||
|
||||
getNameAndAddress(): string {
|
||||
return binding.dcn_contact_get_name_n_addr(this.dc_contact)
|
||||
}
|
||||
|
||||
getProfileImage(): string {
|
||||
return binding.dcn_contact_get_profile_image(this.dc_contact)
|
||||
}
|
||||
|
||||
isBlocked() {
|
||||
return Boolean(binding.dcn_contact_is_blocked(this.dc_contact))
|
||||
}
|
||||
|
||||
isVerified() {
|
||||
return Boolean(binding.dcn_contact_is_verified(this.dc_contact))
|
||||
}
|
||||
}
|
||||
955
node/lib/context.ts
Normal file
955
node/lib/context.ts
Normal file
@@ -0,0 +1,955 @@
|
||||
/* eslint-disable camelcase */
|
||||
|
||||
import binding from './binding'
|
||||
import { C, EventId2EventName } from './constants'
|
||||
import { Chat } from './chat'
|
||||
import { ChatList } from './chatlist'
|
||||
import { Contact } from './contact'
|
||||
import { Message } from './message'
|
||||
import { Lot } from './lot'
|
||||
import { Locations } from './locations'
|
||||
import rawDebug from 'debug'
|
||||
import { AccountManager } from './deltachat'
|
||||
import { join } from 'path'
|
||||
import { EventEmitter } from 'stream'
|
||||
const debug = rawDebug('deltachat:node:index')
|
||||
|
||||
const noop = function () {}
|
||||
interface NativeContext {}
|
||||
|
||||
/**
|
||||
* Wrapper around dcn_context_t*
|
||||
*
|
||||
* only acts as event emitter when created in standalone mode (without account manager)
|
||||
* with `Context.open`
|
||||
*/
|
||||
export class Context extends EventEmitter {
|
||||
constructor(
|
||||
readonly manager: AccountManager | null,
|
||||
private inner_dcn_context: NativeContext,
|
||||
readonly account_id: number | null
|
||||
) {
|
||||
super()
|
||||
debug('DeltaChat constructor')
|
||||
if (inner_dcn_context === null) {
|
||||
throw new Error('inner_dcn_context can not be null')
|
||||
}
|
||||
}
|
||||
|
||||
/** Opens a stanalone context (without an account manager)
|
||||
* automatically starts the event handler */
|
||||
static open(cwd: string): Context {
|
||||
const dbFile = join(cwd, 'db.sqlite')
|
||||
const context = new Context(null, binding.dcn_context_new(dbFile), null)
|
||||
debug('Opened context')
|
||||
function handleCoreEvent(
|
||||
eventId: number,
|
||||
data1: number,
|
||||
data2: number | string
|
||||
) {
|
||||
const eventString = EventId2EventName[eventId]
|
||||
debug(eventString, data1, data2)
|
||||
if (!context.emit) {
|
||||
console.log('Received an event but EventEmitter is already destroyed.')
|
||||
console.log(eventString, data1, data2)
|
||||
return
|
||||
}
|
||||
context.emit(eventString, data1, data2)
|
||||
context.emit('ALL', eventString, data1, data2)
|
||||
}
|
||||
binding.dcn_start_event_handler(
|
||||
context.dcn_context,
|
||||
handleCoreEvent.bind(this)
|
||||
)
|
||||
debug('Started event handler')
|
||||
return context
|
||||
}
|
||||
|
||||
get dcn_context() {
|
||||
return this.inner_dcn_context
|
||||
}
|
||||
|
||||
get is_open() {
|
||||
return Boolean(binding.dcn_context_is_open())
|
||||
}
|
||||
|
||||
open(passphrase?: string) {
|
||||
return Boolean(
|
||||
binding.dcn_context_open(this.dcn_context, passphrase ? passphrase : '')
|
||||
)
|
||||
}
|
||||
|
||||
unref() {
|
||||
binding.dcn_context_unref(this.dcn_context)
|
||||
;(this.inner_dcn_context as any) = null
|
||||
}
|
||||
|
||||
acceptChat(chatId: number) {
|
||||
binding.dcn_accept_chat(this.dcn_context, chatId)
|
||||
}
|
||||
|
||||
blockChat(chatId: number) {
|
||||
binding.dcn_block_chat(this.dcn_context, chatId)
|
||||
}
|
||||
|
||||
addAddressBook(addressBook: string) {
|
||||
debug(`addAddressBook ${addressBook}`)
|
||||
return binding.dcn_add_address_book(this.dcn_context, addressBook)
|
||||
}
|
||||
|
||||
addContactToChat(chatId: number, contactId: number) {
|
||||
debug(`addContactToChat ${chatId} ${contactId}`)
|
||||
return Boolean(
|
||||
binding.dcn_add_contact_to_chat(
|
||||
this.dcn_context,
|
||||
Number(chatId),
|
||||
Number(contactId)
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
addDeviceMessage(label: string, msg: Message | string) {
|
||||
debug(`addDeviceMessage ${label} ${msg}`)
|
||||
if (!msg) {
|
||||
throw new Error('invalid msg parameter')
|
||||
}
|
||||
if (typeof label !== 'string') {
|
||||
throw new Error('invalid label parameter, must be a string')
|
||||
}
|
||||
if (typeof msg === 'string') {
|
||||
const msgObj = this.messageNew()
|
||||
msgObj.setText(msg)
|
||||
msg = msgObj
|
||||
}
|
||||
if (!msg.dc_msg) {
|
||||
throw new Error('invalid msg object')
|
||||
}
|
||||
return binding.dcn_add_device_msg(this.dcn_context, label, msg.dc_msg)
|
||||
}
|
||||
|
||||
setChatVisibility(
|
||||
chatId: number,
|
||||
visibility:
|
||||
| C.DC_CHAT_VISIBILITY_NORMAL
|
||||
| C.DC_CHAT_VISIBILITY_ARCHIVED
|
||||
| C.DC_CHAT_VISIBILITY_PINNED
|
||||
) {
|
||||
debug(`setChatVisibility ${chatId} ${visibility}`)
|
||||
binding.dcn_set_chat_visibility(
|
||||
this.dcn_context,
|
||||
Number(chatId),
|
||||
visibility
|
||||
)
|
||||
}
|
||||
|
||||
blockContact(contactId: number, block: boolean) {
|
||||
debug(`blockContact ${contactId} ${block}`)
|
||||
binding.dcn_block_contact(
|
||||
this.dcn_context,
|
||||
Number(contactId),
|
||||
block ? 1 : 0
|
||||
)
|
||||
}
|
||||
|
||||
checkQrCode(qrCode: string) {
|
||||
debug(`checkQrCode ${qrCode}`)
|
||||
const dc_lot = binding.dcn_check_qr(this.dcn_context, qrCode)
|
||||
let result = dc_lot ? new Lot(dc_lot) : null
|
||||
if (result) {
|
||||
return { id: result.getId(), ...result.toJson() }
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
configure(opts: any): Promise<void> {
|
||||
return new Promise((resolve, reject) => {
|
||||
debug('configure')
|
||||
|
||||
const onSuccess = () => {
|
||||
removeListeners()
|
||||
resolve()
|
||||
}
|
||||
const onFail = (error: string) => {
|
||||
removeListeners()
|
||||
reject(new Error(error))
|
||||
}
|
||||
|
||||
let onConfigure: (...args: any[]) => void
|
||||
if (this.account_id === null) {
|
||||
onConfigure = (data1: number, data2: string) => {
|
||||
if (data1 === 0) return onFail(data2)
|
||||
else if (data1 === 1000) return onSuccess()
|
||||
}
|
||||
} else {
|
||||
onConfigure = (accountId: number, data1: number, data2: string) => {
|
||||
if (this.account_id !== accountId) {
|
||||
return
|
||||
}
|
||||
if (data1 === 0) return onFail(data2)
|
||||
else if (data1 === 1000) return onSuccess()
|
||||
}
|
||||
}
|
||||
|
||||
const removeListeners = () => {
|
||||
;(this.manager || this).removeListener(
|
||||
'DC_EVENT_CONFIGURE_PROGRESS',
|
||||
onConfigure
|
||||
)
|
||||
}
|
||||
|
||||
const registerListeners = () => {
|
||||
;(this.manager || this).on('DC_EVENT_CONFIGURE_PROGRESS', onConfigure)
|
||||
}
|
||||
|
||||
registerListeners()
|
||||
|
||||
if (!opts) opts = {}
|
||||
Object.keys(opts).forEach((key) => {
|
||||
const value = opts[key]
|
||||
this.setConfig(key, value)
|
||||
})
|
||||
|
||||
binding.dcn_configure(this.dcn_context)
|
||||
})
|
||||
}
|
||||
|
||||
continueKeyTransfer(messageId: number, setupCode: string) {
|
||||
debug(`continueKeyTransfer ${messageId}`)
|
||||
return new Promise((resolve, reject) => {
|
||||
binding.dcn_continue_key_transfer(
|
||||
this.dcn_context,
|
||||
Number(messageId),
|
||||
setupCode,
|
||||
(result: number) => resolve(result === 1)
|
||||
)
|
||||
})
|
||||
}
|
||||
/** @returns chatId */
|
||||
createBroadcastList(): number {
|
||||
debug(`createBroadcastList`)
|
||||
return binding.dcn_create_broadcast_list(this.dcn_context)
|
||||
}
|
||||
|
||||
/** @returns chatId */
|
||||
createChatByContactId(contactId: number): number {
|
||||
debug(`createChatByContactId ${contactId}`)
|
||||
return binding.dcn_create_chat_by_contact_id(
|
||||
this.dcn_context,
|
||||
Number(contactId)
|
||||
)
|
||||
}
|
||||
|
||||
/** @returns contactId */
|
||||
createContact(name: string, addr: string): number {
|
||||
debug(`createContact ${name} ${addr}`)
|
||||
return binding.dcn_create_contact(this.dcn_context, name, addr)
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param chatName The name of the chat that should be created
|
||||
* @param is_protected Whether the chat should be protected at creation time
|
||||
* @returns chatId
|
||||
*/
|
||||
createGroupChat(chatName: string, is_protected: boolean = false): number {
|
||||
debug(`createGroupChat ${chatName} [protected:${is_protected}]`)
|
||||
return binding.dcn_create_group_chat(
|
||||
this.dcn_context,
|
||||
is_protected ? 1 : 0,
|
||||
chatName
|
||||
)
|
||||
}
|
||||
|
||||
deleteChat(chatId: number) {
|
||||
debug(`deleteChat ${chatId}`)
|
||||
binding.dcn_delete_chat(this.dcn_context, Number(chatId))
|
||||
}
|
||||
|
||||
deleteContact(contactId: number) {
|
||||
debug(`deleteContact ${contactId}`)
|
||||
return Boolean(
|
||||
binding.dcn_delete_contact(this.dcn_context, Number(contactId))
|
||||
)
|
||||
}
|
||||
|
||||
deleteMessages(messageIds: number[]) {
|
||||
if (!Array.isArray(messageIds)) {
|
||||
messageIds = [messageIds]
|
||||
}
|
||||
messageIds = messageIds.map((id) => Number(id))
|
||||
debug('deleteMessages', messageIds)
|
||||
binding.dcn_delete_msgs(this.dcn_context, messageIds)
|
||||
}
|
||||
|
||||
forwardMessages(messageIds: number[], chatId: number) {
|
||||
if (!Array.isArray(messageIds)) {
|
||||
messageIds = [messageIds]
|
||||
}
|
||||
messageIds = messageIds.map((id) => Number(id))
|
||||
debug('forwardMessages', messageIds)
|
||||
binding.dcn_forward_msgs(this.dcn_context, messageIds, chatId)
|
||||
}
|
||||
|
||||
getBlobdir(): string {
|
||||
debug('getBlobdir')
|
||||
return binding.dcn_get_blobdir(this.dcn_context)
|
||||
}
|
||||
|
||||
getBlockedCount(): number {
|
||||
debug('getBlockedCount')
|
||||
return binding.dcn_get_blocked_cnt(this.dcn_context)
|
||||
}
|
||||
|
||||
getBlockedContacts(): number[] {
|
||||
debug('getBlockedContacts')
|
||||
return binding.dcn_get_blocked_contacts(this.dcn_context)
|
||||
}
|
||||
|
||||
getChat(chatId: number) {
|
||||
debug(`getChat ${chatId}`)
|
||||
const dc_chat = binding.dcn_get_chat(this.dcn_context, Number(chatId))
|
||||
return dc_chat ? new Chat(dc_chat) : null
|
||||
}
|
||||
|
||||
getChatContacts(chatId: number): number[] {
|
||||
debug(`getChatContacts ${chatId}`)
|
||||
return binding.dcn_get_chat_contacts(this.dcn_context, Number(chatId))
|
||||
}
|
||||
|
||||
getChatIdByContactId(contactId: number): number {
|
||||
debug(`getChatIdByContactId ${contactId}`)
|
||||
return binding.dcn_get_chat_id_by_contact_id(
|
||||
this.dcn_context,
|
||||
Number(contactId)
|
||||
)
|
||||
}
|
||||
|
||||
getChatMedia(
|
||||
chatId: number,
|
||||
msgType1: number,
|
||||
msgType2: number,
|
||||
msgType3: number
|
||||
): number[] {
|
||||
debug(`getChatMedia ${chatId}`)
|
||||
return binding.dcn_get_chat_media(
|
||||
this.dcn_context,
|
||||
Number(chatId),
|
||||
msgType1,
|
||||
msgType2 || 0,
|
||||
msgType3 || 0
|
||||
)
|
||||
}
|
||||
|
||||
getMimeHeaders(messageId: number): string {
|
||||
debug(`getMimeHeaders ${messageId}`)
|
||||
return binding.dcn_get_mime_headers(this.dcn_context, Number(messageId))
|
||||
}
|
||||
|
||||
getChatlistItemSummary(chatId: number, messageId: number) {
|
||||
debug(`getChatlistItemSummary ${chatId} ${messageId}`)
|
||||
return new Lot(
|
||||
binding.dcn_chatlist_get_summary2(this.dcn_context, chatId, messageId)
|
||||
)
|
||||
}
|
||||
|
||||
getChatMessages(chatId: number, flags: number, marker1before: number) {
|
||||
debug(`getChatMessages ${chatId} ${flags} ${marker1before}`)
|
||||
return binding.dcn_get_chat_msgs(
|
||||
this.dcn_context,
|
||||
Number(chatId),
|
||||
flags,
|
||||
marker1before
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Get encryption info for a chat.
|
||||
* Get a multi-line encryption info, containing encryption preferences of all members.
|
||||
* Can be used to find out why messages sent to group are not encrypted.
|
||||
*
|
||||
* @param chatId ID of the chat to get the encryption info for.
|
||||
* @return Multi-line text, must be released using dc_str_unref() after usage.
|
||||
*/
|
||||
getChatEncrytionInfo(chatId: number): string {
|
||||
return binding.dcn_get_chat_encrinfo(this.dcn_context, chatId)
|
||||
}
|
||||
|
||||
getChats(listFlags: number, queryStr: string, queryContactId: number) {
|
||||
debug('getChats')
|
||||
const result = []
|
||||
const list = this.getChatList(listFlags, queryStr, queryContactId)
|
||||
const count = list.getCount()
|
||||
for (let i = 0; i < count; i++) {
|
||||
result.push(list.getChatId(i))
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
getChatList(listFlags: number, queryStr: string, queryContactId: number) {
|
||||
listFlags = listFlags || 0
|
||||
queryStr = queryStr || ''
|
||||
queryContactId = queryContactId || 0
|
||||
debug(`getChatList ${listFlags} ${queryStr} ${queryContactId}`)
|
||||
return new ChatList(
|
||||
binding.dcn_get_chatlist(
|
||||
this.dcn_context,
|
||||
listFlags,
|
||||
queryStr,
|
||||
Number(queryContactId)
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
getConfig(key: string): string {
|
||||
debug(`getConfig ${key}`)
|
||||
return binding.dcn_get_config(this.dcn_context, key)
|
||||
}
|
||||
|
||||
getContact(contactId: number) {
|
||||
debug(`getContact ${contactId}`)
|
||||
const dc_contact = binding.dcn_get_contact(
|
||||
this.dcn_context,
|
||||
Number(contactId)
|
||||
)
|
||||
return dc_contact ? new Contact(dc_contact) : null
|
||||
}
|
||||
|
||||
getContactEncryptionInfo(contactId: number) {
|
||||
debug(`getContactEncryptionInfo ${contactId}`)
|
||||
return binding.dcn_get_contact_encrinfo(this.dcn_context, Number(contactId))
|
||||
}
|
||||
|
||||
getContacts(listFlags: number, query: string) {
|
||||
listFlags = listFlags || 0
|
||||
query = query || ''
|
||||
debug(`getContacts ${listFlags} ${query}`)
|
||||
return binding.dcn_get_contacts(this.dcn_context, listFlags, query)
|
||||
}
|
||||
|
||||
wasDeviceMessageEverAdded(label: string) {
|
||||
debug(`wasDeviceMessageEverAdded ${label}`)
|
||||
const added = binding.dcn_was_device_msg_ever_added(this.dcn_context, label)
|
||||
return added === 1
|
||||
}
|
||||
|
||||
getDraft(chatId: number) {
|
||||
debug(`getDraft ${chatId}`)
|
||||
const dc_msg = binding.dcn_get_draft(this.dcn_context, Number(chatId))
|
||||
return dc_msg ? new Message(dc_msg) : null
|
||||
}
|
||||
|
||||
getFreshMessageCount(chatId: number): number {
|
||||
debug(`getFreshMessageCount ${chatId}`)
|
||||
return binding.dcn_get_fresh_msg_cnt(this.dcn_context, Number(chatId))
|
||||
}
|
||||
|
||||
getFreshMessages() {
|
||||
debug('getFreshMessages')
|
||||
return binding.dcn_get_fresh_msgs(this.dcn_context)
|
||||
}
|
||||
|
||||
getInfo() {
|
||||
debug('getInfo')
|
||||
const info = binding.dcn_get_info(this.dcn_context)
|
||||
return AccountManager.parseGetInfo(info)
|
||||
}
|
||||
|
||||
getMessage(messageId: number) {
|
||||
debug(`getMessage ${messageId}`)
|
||||
const dc_msg = binding.dcn_get_msg(this.dcn_context, Number(messageId))
|
||||
return dc_msg ? new Message(dc_msg) : null
|
||||
}
|
||||
|
||||
getMessageCount(chatId: number): number {
|
||||
debug(`getMessageCount ${chatId}`)
|
||||
return binding.dcn_get_msg_cnt(this.dcn_context, Number(chatId))
|
||||
}
|
||||
|
||||
getMessageInfo(messageId: number): string {
|
||||
debug(`getMessageInfo ${messageId}`)
|
||||
return binding.dcn_get_msg_info(this.dcn_context, Number(messageId))
|
||||
}
|
||||
|
||||
getMessageHTML(messageId: number): string {
|
||||
debug(`getMessageHTML ${messageId}`)
|
||||
return binding.dcn_get_msg_html(this.dcn_context, Number(messageId))
|
||||
}
|
||||
|
||||
getNextMediaMessage(
|
||||
messageId: number,
|
||||
msgType1: number,
|
||||
msgType2: number,
|
||||
msgType3: number
|
||||
) {
|
||||
debug(
|
||||
`getNextMediaMessage ${messageId} ${msgType1} ${msgType2} ${msgType3}`
|
||||
)
|
||||
return this._getNextMedia(messageId, 1, msgType1, msgType2, msgType3)
|
||||
}
|
||||
|
||||
getPreviousMediaMessage(
|
||||
messageId: number,
|
||||
msgType1: number,
|
||||
msgType2: number,
|
||||
msgType3: number
|
||||
) {
|
||||
debug(
|
||||
`getPreviousMediaMessage ${messageId} ${msgType1} ${msgType2} ${msgType3}`
|
||||
)
|
||||
return this._getNextMedia(messageId, -1, msgType1, msgType2, msgType3)
|
||||
}
|
||||
|
||||
_getNextMedia(
|
||||
messageId: number,
|
||||
dir: number,
|
||||
msgType1: number,
|
||||
msgType2: number,
|
||||
msgType3: number
|
||||
): number {
|
||||
return binding.dcn_get_next_media(
|
||||
this.dcn_context,
|
||||
Number(messageId),
|
||||
dir,
|
||||
msgType1 || 0,
|
||||
msgType2 || 0,
|
||||
msgType3 || 0
|
||||
)
|
||||
}
|
||||
|
||||
getSecurejoinQrCode(chatId: number): string {
|
||||
debug(`getSecurejoinQrCode ${chatId}`)
|
||||
return binding.dcn_get_securejoin_qr(this.dcn_context, Number(chatId))
|
||||
}
|
||||
|
||||
getSecurejoinQrCodeSVG(chatId: number): string {
|
||||
debug(`getSecurejoinQrCodeSVG ${chatId}`)
|
||||
return binding.dcn_get_securejoin_qr_svg(this.dcn_context, chatId)
|
||||
}
|
||||
|
||||
startIO(): void {
|
||||
debug(`startIO`)
|
||||
binding.dcn_start_io(this.dcn_context)
|
||||
}
|
||||
|
||||
stopIO(): void {
|
||||
debug(`stopIO`)
|
||||
binding.dcn_stop_io(this.dcn_context)
|
||||
}
|
||||
|
||||
stopOngoingProcess(): void {
|
||||
debug(`stopOngoingProcess`)
|
||||
binding.dcn_stop_ongoing_process(this.dcn_context)
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @deprectated please use `AccountManager.getSystemInfo()` instead
|
||||
*/
|
||||
static getSystemInfo() {
|
||||
return AccountManager.getSystemInfo()
|
||||
}
|
||||
|
||||
getConnectivity(): number {
|
||||
return binding.dcn_get_connectivity(this.dcn_context)
|
||||
}
|
||||
|
||||
getConnectivityHTML(): String {
|
||||
return binding.dcn_get_connectivity_html(this.dcn_context)
|
||||
}
|
||||
|
||||
importExport(what: number, param1: string, param2 = '') {
|
||||
debug(`importExport ${what} ${param1} ${param2}`)
|
||||
binding.dcn_imex(this.dcn_context, what, param1, param2)
|
||||
}
|
||||
|
||||
importExportHasBackup(dir: string) {
|
||||
debug(`importExportHasBackup ${dir}`)
|
||||
return binding.dcn_imex_has_backup(this.dcn_context, dir)
|
||||
}
|
||||
|
||||
initiateKeyTransfer(): Promise<string> {
|
||||
return new Promise((resolve, reject) => {
|
||||
debug('initiateKeyTransfer2')
|
||||
binding.dcn_initiate_key_transfer(this.dcn_context, resolve)
|
||||
})
|
||||
}
|
||||
|
||||
isConfigured() {
|
||||
debug('isConfigured')
|
||||
return Boolean(binding.dcn_is_configured(this.dcn_context))
|
||||
}
|
||||
|
||||
isContactInChat(chatId: number, contactId: number) {
|
||||
debug(`isContactInChat ${chatId} ${contactId}`)
|
||||
return Boolean(
|
||||
binding.dcn_is_contact_in_chat(
|
||||
this.dcn_context,
|
||||
Number(chatId),
|
||||
Number(contactId)
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @returns resulting chat id or 0 on error
|
||||
*/
|
||||
joinSecurejoin(qrCode: string): number {
|
||||
debug(`joinSecurejoin ${qrCode}`)
|
||||
return binding.dcn_join_securejoin(this.dcn_context, qrCode)
|
||||
}
|
||||
|
||||
lookupContactIdByAddr(addr: string): number {
|
||||
debug(`lookupContactIdByAddr ${addr}`)
|
||||
return binding.dcn_lookup_contact_id_by_addr(this.dcn_context, addr)
|
||||
}
|
||||
|
||||
markNoticedChat(chatId: number) {
|
||||
debug(`markNoticedChat ${chatId}`)
|
||||
binding.dcn_marknoticed_chat(this.dcn_context, Number(chatId))
|
||||
}
|
||||
|
||||
markSeenMessages(messageIds: number[]) {
|
||||
if (!Array.isArray(messageIds)) {
|
||||
messageIds = [messageIds]
|
||||
}
|
||||
messageIds = messageIds.map((id) => Number(id))
|
||||
debug('markSeenMessages', messageIds)
|
||||
binding.dcn_markseen_msgs(this.dcn_context, messageIds)
|
||||
}
|
||||
|
||||
maybeNetwork() {
|
||||
debug('maybeNetwork')
|
||||
binding.dcn_maybe_network(this.dcn_context)
|
||||
}
|
||||
|
||||
messageNew(viewType = C.DC_MSG_TEXT) {
|
||||
debug(`messageNew ${viewType}`)
|
||||
return new Message(binding.dcn_msg_new(this.dcn_context, viewType))
|
||||
}
|
||||
|
||||
removeContactFromChat(chatId: number, contactId: number) {
|
||||
debug(`removeContactFromChat ${chatId} ${contactId}`)
|
||||
return Boolean(
|
||||
binding.dcn_remove_contact_from_chat(
|
||||
this.dcn_context,
|
||||
Number(chatId),
|
||||
Number(contactId)
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param chatId ID of the chat to search messages in. Set this to 0 for a global search.
|
||||
* @param query The query to search for.
|
||||
*/
|
||||
searchMessages(chatId: number, query: string): number[] {
|
||||
debug(`searchMessages ${chatId} ${query}`)
|
||||
return binding.dcn_search_msgs(this.dcn_context, Number(chatId), query)
|
||||
}
|
||||
|
||||
sendMessage(chatId: number, msg: string | Message) {
|
||||
debug(`sendMessage ${chatId}`)
|
||||
if (!msg) {
|
||||
throw new Error('invalid msg parameter')
|
||||
}
|
||||
if (typeof msg === 'string') {
|
||||
const msgObj = this.messageNew()
|
||||
msgObj.setText(msg)
|
||||
msg = msgObj
|
||||
}
|
||||
if (!msg.dc_msg) {
|
||||
throw new Error('invalid msg object')
|
||||
}
|
||||
return binding.dcn_send_msg(this.dcn_context, Number(chatId), msg.dc_msg)
|
||||
}
|
||||
|
||||
downloadFullMessage(messageId: number) {
|
||||
binding.dcn_download_full_msg(this.dcn_context, messageId)
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @returns {Promise<number>} Promise that resolves into the resulting message id
|
||||
*/
|
||||
sendVideochatInvitation(chatId: number): Promise<number> {
|
||||
debug(`sendVideochatInvitation ${chatId}`)
|
||||
return new Promise((resolve, reject) => {
|
||||
binding.dcn_send_videochat_invitation(
|
||||
this.dcn_context,
|
||||
chatId,
|
||||
(result: number) => {
|
||||
if (result !== 0) {
|
||||
resolve(result)
|
||||
} else {
|
||||
reject(
|
||||
'Videochatinvitation failed to send, see error events for detailed info'
|
||||
)
|
||||
}
|
||||
}
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
setChatName(chatId: number, name: string) {
|
||||
debug(`setChatName ${chatId} ${name}`)
|
||||
return Boolean(
|
||||
binding.dcn_set_chat_name(this.dcn_context, Number(chatId), name)
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param chatId
|
||||
* @param protect
|
||||
* @returns success boolean
|
||||
*/
|
||||
setChatProtection(chatId: number, protect: boolean) {
|
||||
debug(`setChatProtection ${chatId} ${protect}`)
|
||||
return Boolean(
|
||||
binding.dcn_set_chat_protection(
|
||||
this.dcn_context,
|
||||
Number(chatId),
|
||||
protect ? 1 : 0
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
getChatEphemeralTimer(chatId: number): number {
|
||||
debug(`getChatEphemeralTimer ${chatId}`)
|
||||
return binding.dcn_get_chat_ephemeral_timer(
|
||||
this.dcn_context,
|
||||
Number(chatId)
|
||||
)
|
||||
}
|
||||
|
||||
setChatEphemeralTimer(chatId: number, timer: number) {
|
||||
debug(`setChatEphemeralTimer ${chatId} ${timer}`)
|
||||
return Boolean(
|
||||
binding.dcn_set_chat_ephemeral_timer(
|
||||
this.dcn_context,
|
||||
Number(chatId),
|
||||
Number(timer)
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
setChatProfileImage(chatId: number, image: string) {
|
||||
debug(`setChatProfileImage ${chatId} ${image}`)
|
||||
return Boolean(
|
||||
binding.dcn_set_chat_profile_image(
|
||||
this.dcn_context,
|
||||
Number(chatId),
|
||||
image || ''
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
setConfig(key: string, value: string | boolean | number): number {
|
||||
debug(`setConfig (string) ${key} ${value}`)
|
||||
if (value === null) {
|
||||
return binding.dcn_set_config_null(this.dcn_context, key)
|
||||
} else {
|
||||
if (typeof value === 'boolean') {
|
||||
value = value === true ? '1' : '0'
|
||||
} else if (typeof value === 'number') {
|
||||
value = String(value)
|
||||
}
|
||||
return binding.dcn_set_config(this.dcn_context, key, value)
|
||||
}
|
||||
}
|
||||
|
||||
setConfigFromQr(qrcodeContent: string): boolean {
|
||||
return Boolean(
|
||||
binding.dcn_set_config_from_qr(this.dcn_context, qrcodeContent)
|
||||
)
|
||||
}
|
||||
|
||||
estimateDeletionCount(fromServer: boolean, seconds: number): number {
|
||||
debug(`estimateDeletionCount fromServer: ${fromServer} seconds: ${seconds}`)
|
||||
return binding.dcn_estimate_deletion_cnt(
|
||||
this.dcn_context,
|
||||
fromServer === true ? 1 : 0,
|
||||
seconds
|
||||
)
|
||||
}
|
||||
|
||||
setStockTranslation(stockId: number, stockMsg: string) {
|
||||
debug(`setStockTranslation ${stockId} ${stockMsg}`)
|
||||
return Boolean(
|
||||
binding.dcn_set_stock_translation(
|
||||
this.dcn_context,
|
||||
Number(stockId),
|
||||
stockMsg
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
setDraft(chatId: number, msg: Message | null) {
|
||||
debug(`setDraft ${chatId}`)
|
||||
binding.dcn_set_draft(
|
||||
this.dcn_context,
|
||||
Number(chatId),
|
||||
msg ? msg.dc_msg : null
|
||||
)
|
||||
}
|
||||
|
||||
setLocation(latitude: number, longitude: number, accuracy: number) {
|
||||
debug(`setLocation ${latitude}`)
|
||||
binding.dcn_set_location(
|
||||
this.dcn_context,
|
||||
Number(latitude),
|
||||
Number(longitude),
|
||||
Number(accuracy)
|
||||
)
|
||||
}
|
||||
|
||||
/*
|
||||
* @param chatId Chat-id to get location information for.
|
||||
* 0 to get locations independently of the chat.
|
||||
* @param contactId Contact id to get location information for.
|
||||
* If also a chat-id is given, this should be a member of the given chat.
|
||||
* 0 to get locations independently of the contact.
|
||||
* @param timestampFrom Start of timespan to return.
|
||||
* Must be given in number of seconds since 00:00 hours, Jan 1, 1970 UTC.
|
||||
* 0 for "start from the beginning".
|
||||
* @param timestampTo End of timespan to return.
|
||||
* Must be given in number of seconds since 00:00 hours, Jan 1, 1970 UTC.
|
||||
* 0 for "all up to now".
|
||||
* @return Array of locations, NULL is never returned.
|
||||
* The array is sorted decending;
|
||||
* the first entry in the array is the location with the newest timestamp.
|
||||
*
|
||||
* Examples:
|
||||
* // get locations from the last hour for a global map
|
||||
* getLocations(0, 0, time(NULL)-60*60, 0);
|
||||
*
|
||||
* // get locations from a contact for a global map
|
||||
* getLocations(0, contact_id, 0, 0);
|
||||
*
|
||||
* // get all locations known for a given chat
|
||||
* getLocations(chat_id, 0, 0, 0);
|
||||
*
|
||||
* // get locations from a single contact for a given chat
|
||||
* getLocations(chat_id, contact_id, 0, 0);
|
||||
*/
|
||||
|
||||
getLocations(
|
||||
chatId: number,
|
||||
contactId: number,
|
||||
timestampFrom = 0,
|
||||
timestampTo = 0
|
||||
) {
|
||||
const locations = new Locations(
|
||||
binding.dcn_get_locations(
|
||||
this.dcn_context,
|
||||
Number(chatId),
|
||||
Number(contactId),
|
||||
timestampFrom,
|
||||
timestampTo
|
||||
)
|
||||
)
|
||||
return locations.toJson()
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param duration The duration (0 for no mute, -1 for forever mute, everything else is is the relative mute duration from now in seconds)
|
||||
*/
|
||||
setChatMuteDuration(chatId: number, duration: number) {
|
||||
return Boolean(
|
||||
binding.dcn_set_chat_mute_duration(this.dcn_context, chatId, duration)
|
||||
)
|
||||
}
|
||||
|
||||
/** get information about the provider */
|
||||
getProviderFromEmail(email: string) {
|
||||
debug('DeltaChat.getProviderFromEmail')
|
||||
const provider = binding.dcn_provider_new_from_email(
|
||||
this.dcn_context,
|
||||
email
|
||||
)
|
||||
if (!provider) {
|
||||
return undefined
|
||||
}
|
||||
return {
|
||||
before_login_hint: binding.dcn_provider_get_before_login_hint(provider),
|
||||
overview_page: binding.dcn_provider_get_overview_page(provider),
|
||||
status: binding.dcn_provider_get_status(provider),
|
||||
}
|
||||
}
|
||||
|
||||
sendWebxdcStatusUpdate<T>(
|
||||
msgId: number,
|
||||
json: WebxdcSendingStatusUpdate<T>,
|
||||
descr: string
|
||||
) {
|
||||
return Boolean(
|
||||
binding.dcn_send_webxdc_status_update(
|
||||
this.dcn_context,
|
||||
msgId,
|
||||
JSON.stringify(json),
|
||||
descr
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
getWebxdcStatusUpdates<T>(
|
||||
msgId: number,
|
||||
serial = 0
|
||||
): WebxdcReceivedStatusUpdate<T>[] {
|
||||
return JSON.parse(
|
||||
binding.dcn_get_webxdc_status_updates(this.dcn_context, msgId, serial)
|
||||
)
|
||||
}
|
||||
|
||||
/** the string contains the binary data, it is an "u8 string", maybe we will use a more efficient type in the future. */
|
||||
getWebxdcBlob(message: Message, filename: string): Buffer | null {
|
||||
return binding.dcn_msg_get_webxdc_blob(message.dc_msg, filename)
|
||||
}
|
||||
}
|
||||
|
||||
export type WebxdcInfo = {
|
||||
name: string
|
||||
icon: string
|
||||
summary: string
|
||||
/**
|
||||
* if set by the webxdc, name of the document in edit
|
||||
*/
|
||||
document?: string
|
||||
}
|
||||
|
||||
type WebxdcSendingStatusUpdate<T> = {
|
||||
/** the payload, deserialized json:
|
||||
* any javascript primitive, array or object. */
|
||||
payload: T
|
||||
/** optional, short, informational message that will be added to the chat,
|
||||
* eg. "Alice voted" or "Bob scored 123 in MyGame";
|
||||
* usually only one line of text is shown,
|
||||
* use this option sparingly to not spam the chat. */
|
||||
info?: string
|
||||
/** optional, short text, shown beside app icon;
|
||||
* it is recommended to use some aggregated value,
|
||||
* eg. "8 votes", "Highscore: 123" */
|
||||
summary?: string
|
||||
/**
|
||||
* optional, name of the document in edit,
|
||||
* must not be used eg. in games where the Webxdc does not create documents
|
||||
*/
|
||||
document?: string
|
||||
}
|
||||
|
||||
type WebxdcReceivedStatusUpdate<T> = {
|
||||
/** the payload, deserialized json */
|
||||
payload: T
|
||||
/** the serial number of this update. Serials are larger `0` and newer serials have higher numbers. */
|
||||
serial: number
|
||||
/** the maximum serial currently known.
|
||||
* If `max_serial` equals `serial` this update is the last update (until new network messages arrive). */
|
||||
max_serial: number
|
||||
/** optional, short, informational message. */
|
||||
info?: string
|
||||
/** optional, short text, shown beside app icon. If there are no updates, an empty JSON-array is returned. */
|
||||
summary?: string
|
||||
}
|
||||
231
node/lib/deltachat.ts
Normal file
231
node/lib/deltachat.ts
Normal file
@@ -0,0 +1,231 @@
|
||||
/* eslint-disable camelcase */
|
||||
|
||||
import binding from './binding'
|
||||
import { EventId2EventName } from './constants'
|
||||
import { EventEmitter } from 'events'
|
||||
import { existsSync } from 'fs'
|
||||
import rawDebug from 'debug'
|
||||
import { tmpdir } from 'os'
|
||||
import { join } from 'path'
|
||||
import { Context } from './context'
|
||||
const debug = rawDebug('deltachat:node:index')
|
||||
|
||||
const noop = function () {}
|
||||
interface NativeAccount {}
|
||||
|
||||
/**
|
||||
* Wrapper around dcn_account_t*
|
||||
*/
|
||||
export class AccountManager extends EventEmitter {
|
||||
dcn_accounts: NativeAccount
|
||||
accountDir: string
|
||||
jsonRpcStarted = false
|
||||
|
||||
constructor(cwd: string, os = 'deltachat-node') {
|
||||
super()
|
||||
debug('DeltaChat constructor')
|
||||
|
||||
this.accountDir = cwd
|
||||
this.dcn_accounts = binding.dcn_accounts_new(os, this.accountDir)
|
||||
}
|
||||
|
||||
getAllAccountIds() {
|
||||
return binding.dcn_accounts_get_all(this.dcn_accounts)
|
||||
}
|
||||
|
||||
selectAccount(account_id: number) {
|
||||
return binding.dcn_accounts_select_account(this.dcn_accounts, account_id)
|
||||
}
|
||||
|
||||
selectedAccount(): number {
|
||||
return binding.dcn_accounts_get_selected_account(this.dcn_accounts)
|
||||
}
|
||||
|
||||
addAccount(): number {
|
||||
return binding.dcn_accounts_add_account(this.dcn_accounts)
|
||||
}
|
||||
|
||||
addClosedAccount(): number {
|
||||
return binding.dcn_accounts_add_closed_account(this.dcn_accounts)
|
||||
}
|
||||
|
||||
removeAccount(account_id: number) {
|
||||
return binding.dcn_accounts_remove_account(this.dcn_accounts, account_id)
|
||||
}
|
||||
|
||||
accountContext(account_id: number) {
|
||||
const native_context = binding.dcn_accounts_get_account(
|
||||
this.dcn_accounts,
|
||||
account_id
|
||||
)
|
||||
if (native_context === null) {
|
||||
throw new Error(
|
||||
`could not get context with id ${account_id}, does it even exist? please check your ids`
|
||||
)
|
||||
}
|
||||
return new Context(this, native_context, account_id)
|
||||
}
|
||||
|
||||
migrateAccount(dbfile: string): number {
|
||||
return binding.dcn_accounts_migrate_account(this.dcn_accounts, dbfile)
|
||||
}
|
||||
|
||||
close() {
|
||||
this.stopIO()
|
||||
debug('unrefing context')
|
||||
binding.dcn_accounts_unref(this.dcn_accounts)
|
||||
debug('Unref end')
|
||||
}
|
||||
|
||||
emit(
|
||||
event: string | symbol,
|
||||
account_id: number,
|
||||
data1: any,
|
||||
data2: any
|
||||
): boolean {
|
||||
super.emit('ALL', event, account_id, data1, data2)
|
||||
return super.emit(event, account_id, data1, data2)
|
||||
}
|
||||
|
||||
handleCoreEvent(
|
||||
eventId: number,
|
||||
accountId: number,
|
||||
data1: number,
|
||||
data2: number | string
|
||||
) {
|
||||
const eventString = EventId2EventName[eventId]
|
||||
debug('event', eventString, accountId, data1, data2)
|
||||
debug(eventString, data1, data2)
|
||||
if (!this.emit) {
|
||||
console.log('Received an event but EventEmitter is already destroyed.')
|
||||
console.log(eventString, data1, data2)
|
||||
return
|
||||
}
|
||||
this.emit(eventString, accountId, data1, data2)
|
||||
}
|
||||
|
||||
startEvents() {
|
||||
if (this.dcn_accounts === null) {
|
||||
throw new Error('dcn_account is null')
|
||||
}
|
||||
binding.dcn_accounts_start_event_handler(
|
||||
this.dcn_accounts,
|
||||
this.handleCoreEvent.bind(this)
|
||||
)
|
||||
debug('Started event handler')
|
||||
}
|
||||
|
||||
startJSONRPCHandler(callback: ((response: string) => void) | null) {
|
||||
if (this.dcn_accounts === null) {
|
||||
throw new Error('dcn_account is null')
|
||||
}
|
||||
if (!callback) {
|
||||
throw new Error('no callback set')
|
||||
}
|
||||
if (this.jsonRpcStarted) {
|
||||
throw new Error('jsonrpc was started already')
|
||||
}
|
||||
|
||||
binding.dcn_accounts_start_jsonrpc(this.dcn_accounts, callback.bind(this))
|
||||
debug('Started jsonrpc handler')
|
||||
this.jsonRpcStarted = true
|
||||
}
|
||||
|
||||
jsonRPCRequest(message: string) {
|
||||
if (!this.jsonRpcStarted) {
|
||||
throw new Error(
|
||||
'jsonrpc is not active, start it with startJSONRPCHandler first'
|
||||
)
|
||||
}
|
||||
binding.dcn_json_rpc_request(this.dcn_accounts, message)
|
||||
}
|
||||
|
||||
startIO() {
|
||||
binding.dcn_accounts_start_io(this.dcn_accounts)
|
||||
}
|
||||
|
||||
stopIO() {
|
||||
binding.dcn_accounts_stop_io(this.dcn_accounts)
|
||||
}
|
||||
|
||||
static maybeValidAddr(addr: string) {
|
||||
debug('DeltaChat.maybeValidAddr')
|
||||
if (addr === null) return false
|
||||
return Boolean(binding.dcn_maybe_valid_addr(addr))
|
||||
}
|
||||
|
||||
static parseGetInfo(info: string) {
|
||||
debug('static _getInfo')
|
||||
const result: { [key: string]: string } = {}
|
||||
|
||||
const regex = /^(\w+)=(.*)$/i
|
||||
info
|
||||
.split('\n')
|
||||
.filter(Boolean)
|
||||
.forEach((line) => {
|
||||
const match = regex.exec(line)
|
||||
if (match) {
|
||||
result[match[1]] = match[2]
|
||||
}
|
||||
})
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
static newTemporary() {
|
||||
let directory = null
|
||||
while (true) {
|
||||
const randomString = Math.random().toString(36).substr(2, 5)
|
||||
directory = join(tmpdir(), 'deltachat-' + randomString)
|
||||
if (!existsSync(directory)) break
|
||||
}
|
||||
const dc = new AccountManager(directory)
|
||||
const accountId = dc.addAccount()
|
||||
const context = dc.accountContext(accountId)
|
||||
return { dc, context, accountId, directory }
|
||||
}
|
||||
|
||||
static getSystemInfo() {
|
||||
debug('DeltaChat.getSystemInfo')
|
||||
const { dc, context } = AccountManager.newTemporary()
|
||||
const info = AccountManager.parseGetInfo(
|
||||
binding.dcn_get_info(context.dcn_context)
|
||||
)
|
||||
const {
|
||||
deltachat_core_version,
|
||||
sqlite_version,
|
||||
sqlite_thread_safe,
|
||||
libetpan_version,
|
||||
openssl_version,
|
||||
compile_date,
|
||||
arch,
|
||||
} = info
|
||||
const result = {
|
||||
deltachat_core_version,
|
||||
sqlite_version,
|
||||
sqlite_thread_safe,
|
||||
libetpan_version,
|
||||
openssl_version,
|
||||
compile_date,
|
||||
arch,
|
||||
}
|
||||
context.unref()
|
||||
dc.close()
|
||||
return result
|
||||
}
|
||||
|
||||
/** get information about the provider
|
||||
*
|
||||
* This function creates a temporary context to be standalone,
|
||||
* if posible use `Context.getProviderFromEmail` instead. (otherwise potential proxy settings are not used)
|
||||
* @deprecated
|
||||
*/
|
||||
static getProviderFromEmail(email: string) {
|
||||
debug('DeltaChat.getProviderFromEmail')
|
||||
const { dc, context } = AccountManager.newTemporary()
|
||||
const provider = context.getProviderFromEmail(email)
|
||||
context.unref()
|
||||
dc.close()
|
||||
return provider
|
||||
}
|
||||
}
|
||||
20
node/lib/index.ts
Normal file
20
node/lib/index.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
import { AccountManager } from './deltachat'
|
||||
|
||||
export default AccountManager
|
||||
|
||||
export { Context } from './context'
|
||||
export { Chat } from './chat'
|
||||
export { ChatList } from './chatlist'
|
||||
export { C } from './constants'
|
||||
export { Contact } from './contact'
|
||||
export { AccountManager as DeltaChat }
|
||||
export { Locations } from './locations'
|
||||
export { Lot } from './lot'
|
||||
export {
|
||||
Message,
|
||||
MessageState,
|
||||
MessageViewType,
|
||||
MessageDownloadState,
|
||||
} from './message'
|
||||
|
||||
export * from './types'
|
||||
82
node/lib/locations.ts
Normal file
82
node/lib/locations.ts
Normal file
@@ -0,0 +1,82 @@
|
||||
/* eslint-disable camelcase */
|
||||
|
||||
const binding = require('../binding')
|
||||
const debug = require('debug')('deltachat:node:locations')
|
||||
|
||||
interface NativeLocations {}
|
||||
/**
|
||||
* Wrapper around dc_location_t*
|
||||
*/
|
||||
export class Locations {
|
||||
constructor(public dc_locations: NativeLocations) {
|
||||
debug('Locations constructor')
|
||||
if (dc_locations === null) {
|
||||
throw new Error('dc_locations can not be null')
|
||||
}
|
||||
}
|
||||
|
||||
locationToJson(index: number) {
|
||||
debug('locationToJson')
|
||||
return {
|
||||
accuracy: this.getAccuracy(index),
|
||||
latitude: this.getLatitude(index),
|
||||
longitude: this.getLongitude(index),
|
||||
timestamp: this.getTimestamp(index),
|
||||
contactId: this.getContactId(index),
|
||||
msgId: this.getMsgId(index),
|
||||
chatId: this.getChatId(index),
|
||||
isIndependent: this.isIndependent(index),
|
||||
marker: this.getMarker(index),
|
||||
}
|
||||
}
|
||||
|
||||
toJson(): ReturnType<Locations['locationToJson']>[] {
|
||||
debug('toJson')
|
||||
const locations = []
|
||||
const count = this.getCount()
|
||||
for (let index = 0; index < count; index++) {
|
||||
locations.push(this.locationToJson(index))
|
||||
}
|
||||
return locations
|
||||
}
|
||||
|
||||
getCount(): number {
|
||||
return binding.dcn_array_get_cnt(this.dc_locations)
|
||||
}
|
||||
|
||||
getAccuracy(index: number): number {
|
||||
return binding.dcn_array_get_accuracy(this.dc_locations, index)
|
||||
}
|
||||
|
||||
getLatitude(index: number): number {
|
||||
return binding.dcn_array_get_latitude(this.dc_locations, index)
|
||||
}
|
||||
|
||||
getLongitude(index: number): number {
|
||||
return binding.dcn_array_get_longitude(this.dc_locations, index)
|
||||
}
|
||||
|
||||
getTimestamp(index: number): number {
|
||||
return binding.dcn_array_get_timestamp(this.dc_locations, index)
|
||||
}
|
||||
|
||||
getMsgId(index: number): number {
|
||||
return binding.dcn_array_get_msg_id(this.dc_locations, index)
|
||||
}
|
||||
|
||||
getContactId(index: number): number {
|
||||
return binding.dcn_array_get_contact_id(this.dc_locations, index)
|
||||
}
|
||||
|
||||
getChatId(index: number): number {
|
||||
return binding.dcn_array_get_chat_id(this.dc_locations, index)
|
||||
}
|
||||
|
||||
isIndependent(index: number): boolean {
|
||||
return binding.dcn_array_is_independent(this.dc_locations, index)
|
||||
}
|
||||
|
||||
getMarker(index: number): string {
|
||||
return binding.dcn_array_get_marker(this.dc_locations, index)
|
||||
}
|
||||
}
|
||||
52
node/lib/lot.ts
Normal file
52
node/lib/lot.ts
Normal file
@@ -0,0 +1,52 @@
|
||||
/* eslint-disable camelcase */
|
||||
|
||||
const binding = require('../binding')
|
||||
const debug = require('debug')('deltachat:node:lot')
|
||||
|
||||
interface NativeLot {}
|
||||
/**
|
||||
* Wrapper around dc_lot_t*
|
||||
*/
|
||||
export class Lot {
|
||||
constructor(public dc_lot: NativeLot) {
|
||||
debug('Lot constructor')
|
||||
if (dc_lot === null) {
|
||||
throw new Error('dc_lot can not be null')
|
||||
}
|
||||
}
|
||||
|
||||
toJson() {
|
||||
debug('toJson')
|
||||
return {
|
||||
state: this.getState(),
|
||||
text1: this.getText1(),
|
||||
text1Meaning: this.getText1Meaning(),
|
||||
text2: this.getText2(),
|
||||
timestamp: this.getTimestamp(),
|
||||
}
|
||||
}
|
||||
|
||||
getId(): number {
|
||||
return binding.dcn_lot_get_id(this.dc_lot)
|
||||
}
|
||||
|
||||
getState(): number {
|
||||
return binding.dcn_lot_get_state(this.dc_lot)
|
||||
}
|
||||
|
||||
getText1(): string {
|
||||
return binding.dcn_lot_get_text1(this.dc_lot)
|
||||
}
|
||||
|
||||
getText1Meaning(): string {
|
||||
return binding.dcn_lot_get_text1_meaning(this.dc_lot)
|
||||
}
|
||||
|
||||
getText2(): string {
|
||||
return binding.dcn_lot_get_text2(this.dc_lot)
|
||||
}
|
||||
|
||||
getTimestamp(): number {
|
||||
return binding.dcn_lot_get_timestamp(this.dc_lot)
|
||||
}
|
||||
}
|
||||
370
node/lib/message.ts
Normal file
370
node/lib/message.ts
Normal file
@@ -0,0 +1,370 @@
|
||||
/* eslint-disable camelcase */
|
||||
|
||||
import binding from './binding'
|
||||
import { C } from './constants'
|
||||
import { Lot } from './lot'
|
||||
import { Chat } from './chat'
|
||||
import { WebxdcInfo } from './context'
|
||||
const debug = require('debug')('deltachat:node:message')
|
||||
|
||||
export enum MessageDownloadState {
|
||||
Available = C.DC_DOWNLOAD_AVAILABLE,
|
||||
Done = C.DC_DOWNLOAD_DONE,
|
||||
Failure = C.DC_DOWNLOAD_FAILURE,
|
||||
InProgress = C.DC_DOWNLOAD_IN_PROGRESS,
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper class for message states so you can do e.g.
|
||||
*
|
||||
* if (msg.getState().isPending()) { .. }
|
||||
*
|
||||
*/
|
||||
export class MessageState {
|
||||
constructor(public state: number) {
|
||||
debug(`MessageState constructor ${state}`)
|
||||
}
|
||||
|
||||
isUndefined() {
|
||||
return this.state === C.DC_STATE_UNDEFINED
|
||||
}
|
||||
|
||||
isFresh() {
|
||||
return this.state === C.DC_STATE_IN_FRESH
|
||||
}
|
||||
|
||||
isNoticed() {
|
||||
return this.state === C.DC_STATE_IN_NOTICED
|
||||
}
|
||||
|
||||
isSeen() {
|
||||
return this.state === C.DC_STATE_IN_SEEN
|
||||
}
|
||||
|
||||
isPending() {
|
||||
return this.state === C.DC_STATE_OUT_PENDING
|
||||
}
|
||||
|
||||
isFailed() {
|
||||
return this.state === C.DC_STATE_OUT_FAILED
|
||||
}
|
||||
|
||||
isDelivered() {
|
||||
return this.state === C.DC_STATE_OUT_DELIVERED
|
||||
}
|
||||
|
||||
isReceived() {
|
||||
return this.state === C.DC_STATE_OUT_MDN_RCVD
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper class for message types so you can do e.g.
|
||||
*
|
||||
* if (msg.getViewType().isVideo()) { .. }
|
||||
*
|
||||
*/
|
||||
export class MessageViewType {
|
||||
constructor(public viewType: number) {
|
||||
debug(`MessageViewType constructor ${viewType}`)
|
||||
}
|
||||
|
||||
isText() {
|
||||
return this.viewType === C.DC_MSG_TEXT
|
||||
}
|
||||
|
||||
isImage() {
|
||||
return this.viewType === C.DC_MSG_IMAGE || this.viewType === C.DC_MSG_GIF
|
||||
}
|
||||
|
||||
isGif() {
|
||||
return this.viewType === C.DC_MSG_GIF
|
||||
}
|
||||
|
||||
isAudio() {
|
||||
return this.viewType === C.DC_MSG_AUDIO || this.viewType === C.DC_MSG_VOICE
|
||||
}
|
||||
|
||||
isVoice() {
|
||||
return this.viewType === C.DC_MSG_VOICE
|
||||
}
|
||||
|
||||
isVideo() {
|
||||
return this.viewType === C.DC_MSG_VIDEO
|
||||
}
|
||||
|
||||
isFile() {
|
||||
return this.viewType === C.DC_MSG_FILE
|
||||
}
|
||||
|
||||
isVideochatInvitation() {
|
||||
return this.viewType === C.DC_MSG_VIDEOCHAT_INVITATION
|
||||
}
|
||||
}
|
||||
|
||||
interface NativeMessage {}
|
||||
/**
|
||||
* Wrapper around dc_msg_t*
|
||||
*/
|
||||
export class Message {
|
||||
constructor(public dc_msg: NativeMessage) {
|
||||
debug('Message constructor')
|
||||
if (dc_msg === null) {
|
||||
throw new Error('dc_msg can not be null')
|
||||
}
|
||||
}
|
||||
|
||||
toJson() {
|
||||
debug('toJson')
|
||||
const quotedMessage = this.getQuotedMessage()
|
||||
const viewType = binding.dcn_msg_get_viewtype(this.dc_msg)
|
||||
return {
|
||||
chatId: this.getChatId(),
|
||||
webxdcInfo: viewType == C.DC_MSG_WEBXDC ? this.webxdcInfo : null,
|
||||
downloadState: this.downloadState,
|
||||
duration: this.getDuration(),
|
||||
file: this.getFile(),
|
||||
fromId: this.getFromId(),
|
||||
id: this.getId(),
|
||||
quotedText: this.getQuotedText(),
|
||||
quotedMessageId: quotedMessage ? quotedMessage.getId() : null,
|
||||
receivedTimestamp: this.getReceivedTimestamp(),
|
||||
sortTimestamp: this.getSortTimestamp(),
|
||||
text: this.getText(),
|
||||
timestamp: this.getTimestamp(),
|
||||
hasLocation: this.hasLocation(),
|
||||
hasHTML: this.hasHTML,
|
||||
viewType,
|
||||
state: binding.dcn_msg_get_state(this.dc_msg),
|
||||
hasDeviatingTimestamp: this.hasDeviatingTimestamp(),
|
||||
showPadlock: this.getShowpadlock(),
|
||||
summary: this.getSummary().toJson(),
|
||||
subject: this.subject,
|
||||
isSetupmessage: this.isSetupmessage(),
|
||||
isInfo: this.isInfo(),
|
||||
isForwarded: this.isForwarded(),
|
||||
dimensions: {
|
||||
height: this.getHeight(),
|
||||
width: this.getWidth(),
|
||||
},
|
||||
videochatType: this.getVideochatType(),
|
||||
videochatUrl: this.getVideochatUrl(),
|
||||
overrideSenderName: this.overrideSenderName,
|
||||
parentId: this.parent?.getId(),
|
||||
}
|
||||
}
|
||||
|
||||
getChatId(): number {
|
||||
return binding.dcn_msg_get_chat_id(this.dc_msg)
|
||||
}
|
||||
|
||||
get webxdcInfo(): WebxdcInfo | null {
|
||||
let info = binding.dcn_msg_get_webxdc_info(this.dc_msg)
|
||||
return info
|
||||
? JSON.parse(binding.dcn_msg_get_webxdc_info(this.dc_msg))
|
||||
: null
|
||||
}
|
||||
|
||||
get downloadState(): MessageDownloadState {
|
||||
return binding.dcn_msg_get_download_state(this.dc_msg)
|
||||
}
|
||||
|
||||
get parent(): Message | null {
|
||||
let msg = binding.dcn_msg_get_parent(this.dc_msg)
|
||||
return msg ? new Message(msg) : null
|
||||
}
|
||||
|
||||
getDuration(): number {
|
||||
return binding.dcn_msg_get_duration(this.dc_msg)
|
||||
}
|
||||
|
||||
getFile(): string {
|
||||
return binding.dcn_msg_get_file(this.dc_msg)
|
||||
}
|
||||
|
||||
getFilebytes(): number {
|
||||
return binding.dcn_msg_get_filebytes(this.dc_msg)
|
||||
}
|
||||
|
||||
getFilemime(): string {
|
||||
return binding.dcn_msg_get_filemime(this.dc_msg)
|
||||
}
|
||||
|
||||
getFilename(): string {
|
||||
return binding.dcn_msg_get_filename(this.dc_msg)
|
||||
}
|
||||
|
||||
getFromId(): number {
|
||||
return binding.dcn_msg_get_from_id(this.dc_msg)
|
||||
}
|
||||
|
||||
getHeight(): number {
|
||||
return binding.dcn_msg_get_height(this.dc_msg)
|
||||
}
|
||||
|
||||
getId(): number {
|
||||
return binding.dcn_msg_get_id(this.dc_msg)
|
||||
}
|
||||
|
||||
getQuotedText(): string {
|
||||
return binding.dcn_msg_get_quoted_text(this.dc_msg)
|
||||
}
|
||||
|
||||
getQuotedMessage(): Message | null {
|
||||
const dc_msg = binding.dcn_msg_get_quoted_msg(this.dc_msg)
|
||||
return dc_msg ? new Message(dc_msg) : null
|
||||
}
|
||||
|
||||
getReceivedTimestamp(): number {
|
||||
return binding.dcn_msg_get_received_timestamp(this.dc_msg)
|
||||
}
|
||||
|
||||
getSetupcodebegin() {
|
||||
return binding.dcn_msg_get_setupcodebegin(this.dc_msg)
|
||||
}
|
||||
|
||||
getShowpadlock() {
|
||||
return Boolean(binding.dcn_msg_get_showpadlock(this.dc_msg))
|
||||
}
|
||||
|
||||
getSortTimestamp(): number {
|
||||
return binding.dcn_msg_get_sort_timestamp(this.dc_msg)
|
||||
}
|
||||
|
||||
getState() {
|
||||
return new MessageState(binding.dcn_msg_get_state(this.dc_msg))
|
||||
}
|
||||
|
||||
getSummary(chat?: Chat) {
|
||||
const dc_chat = (chat && chat.dc_chat) || null
|
||||
return new Lot(binding.dcn_msg_get_summary(this.dc_msg, dc_chat))
|
||||
}
|
||||
|
||||
get subject(): string {
|
||||
return binding.dcn_msg_get_subject(this.dc_msg)
|
||||
}
|
||||
|
||||
getSummarytext(approxCharacters: number): string {
|
||||
approxCharacters = approxCharacters || 0
|
||||
return binding.dcn_msg_get_summarytext(this.dc_msg, approxCharacters)
|
||||
}
|
||||
|
||||
getText(): string {
|
||||
return binding.dcn_msg_get_text(this.dc_msg)
|
||||
}
|
||||
|
||||
getTimestamp(): number {
|
||||
return binding.dcn_msg_get_timestamp(this.dc_msg)
|
||||
}
|
||||
|
||||
getViewType() {
|
||||
return new MessageViewType(binding.dcn_msg_get_viewtype(this.dc_msg))
|
||||
}
|
||||
|
||||
getVideochatType(): number {
|
||||
return binding.dcn_msg_get_videochat_type(this.dc_msg)
|
||||
}
|
||||
|
||||
getVideochatUrl(): string {
|
||||
return binding.dcn_msg_get_videochat_url(this.dc_msg)
|
||||
}
|
||||
|
||||
getWidth(): number {
|
||||
return binding.dcn_msg_get_width(this.dc_msg)
|
||||
}
|
||||
|
||||
get overrideSenderName(): string {
|
||||
return binding.dcn_msg_get_override_sender_name(this.dc_msg)
|
||||
}
|
||||
|
||||
hasDeviatingTimestamp() {
|
||||
return binding.dcn_msg_has_deviating_timestamp(this.dc_msg)
|
||||
}
|
||||
|
||||
hasLocation() {
|
||||
return Boolean(binding.dcn_msg_has_location(this.dc_msg))
|
||||
}
|
||||
|
||||
get hasHTML() {
|
||||
return Boolean(binding.dcn_msg_has_html(this.dc_msg))
|
||||
}
|
||||
|
||||
isDeadDrop() {
|
||||
// TODO: Fix
|
||||
//return this.getChatId() === C.DC_CHAT_ID_DEADDROP
|
||||
return false
|
||||
}
|
||||
|
||||
isForwarded() {
|
||||
return Boolean(binding.dcn_msg_is_forwarded(this.dc_msg))
|
||||
}
|
||||
|
||||
isIncreation() {
|
||||
return Boolean(binding.dcn_msg_is_increation(this.dc_msg))
|
||||
}
|
||||
|
||||
isInfo() {
|
||||
return Boolean(binding.dcn_msg_is_info(this.dc_msg))
|
||||
}
|
||||
|
||||
isSent() {
|
||||
return Boolean(binding.dcn_msg_is_sent(this.dc_msg))
|
||||
}
|
||||
|
||||
isSetupmessage() {
|
||||
return Boolean(binding.dcn_msg_is_setupmessage(this.dc_msg))
|
||||
}
|
||||
|
||||
latefilingMediasize(width: number, height: number, duration: number) {
|
||||
binding.dcn_msg_latefiling_mediasize(this.dc_msg, width, height, duration)
|
||||
}
|
||||
|
||||
setDimension(width: number, height: number) {
|
||||
binding.dcn_msg_set_dimension(this.dc_msg, width, height)
|
||||
return this
|
||||
}
|
||||
|
||||
setDuration(duration: number) {
|
||||
binding.dcn_msg_set_duration(this.dc_msg, duration)
|
||||
return this
|
||||
}
|
||||
|
||||
setFile(file: string, mime?: string) {
|
||||
if (typeof file !== 'string') throw new Error('Missing filename')
|
||||
binding.dcn_msg_set_file(this.dc_msg, file, mime || '')
|
||||
return this
|
||||
}
|
||||
|
||||
setLocation(longitude: number, latitude: number) {
|
||||
binding.dcn_msg_set_location(this.dc_msg, longitude, latitude)
|
||||
return this
|
||||
}
|
||||
|
||||
setQuote(quotedMessage: Message | null) {
|
||||
binding.dcn_msg_set_quote(this.dc_msg, quotedMessage?.dc_msg)
|
||||
return this
|
||||
}
|
||||
|
||||
setText(text: string) {
|
||||
binding.dcn_msg_set_text(this.dc_msg, text)
|
||||
return this
|
||||
}
|
||||
|
||||
setHTML(html: string) {
|
||||
binding.dcn_msg_set_html(this.dc_msg, html)
|
||||
return this
|
||||
}
|
||||
|
||||
setOverrideSenderName(senderName: string) {
|
||||
binding.dcn_msg_set_override_sender_name(this.dc_msg, senderName)
|
||||
return this
|
||||
}
|
||||
|
||||
/** Force the message to be sent in plain text.
|
||||
*
|
||||
* This API is for bots, there is no need to expose it in the UI.
|
||||
*/
|
||||
forcePlaintext() {
|
||||
binding.dcn_msg_force_plaintext(this.dc_msg)
|
||||
}
|
||||
}
|
||||
24
node/lib/types.ts
Normal file
24
node/lib/types.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
import { C } from './constants'
|
||||
|
||||
export type ChatTypes =
|
||||
| C.DC_CHAT_TYPE_GROUP
|
||||
| C.DC_CHAT_TYPE_MAILINGLIST
|
||||
| C.DC_CHAT_TYPE_SINGLE
|
||||
| C.DC_CHAT_TYPE_UNDEFINED
|
||||
|
||||
export interface ChatJSON {
|
||||
archived: boolean
|
||||
pinned: boolean
|
||||
color: string
|
||||
id: number
|
||||
name: string
|
||||
profileImage: string
|
||||
type: number
|
||||
isSelfTalk: boolean
|
||||
isUnpromoted: boolean
|
||||
isProtected: boolean
|
||||
canSend: boolean
|
||||
isDeviceTalk: boolean
|
||||
isContactRequest: boolean
|
||||
muted: boolean
|
||||
}
|
||||
6
node/lib/util.ts
Normal file
6
node/lib/util.ts
Normal file
@@ -0,0 +1,6 @@
|
||||
/**
|
||||
* @param integerColor expects a 24bit rgb integer (left to right: 8bits red, 8bits green, 8bits blue)
|
||||
*/
|
||||
export function integerToHexColor(integerColor: number) {
|
||||
return '#' + (integerColor + 16777216).toString(16).substring(1)
|
||||
}
|
||||
13
node/patches/m1_build_use_x86_64.patch
Normal file
13
node/patches/m1_build_use_x86_64.patch
Normal file
@@ -0,0 +1,13 @@
|
||||
diff --git i/node/binding.gyp w/node/binding.gyp
|
||||
index b0d92eae..c5e504fa 100644
|
||||
--- i/node/binding.gyp
|
||||
+++ w/node/binding.gyp
|
||||
@@ -43,7 +43,7 @@
|
||||
"include_dirs": ["../deltachat-ffi"],
|
||||
"ldflags": ["-Wl,-Bsymbolic"], # Prevent sqlite3 from electron from overriding sqlcipher
|
||||
"libraries": [
|
||||
- "../../target/release/libdeltachat.a",
|
||||
+ "../../target/x86_64-apple-darwin/release/libdeltachat.a",
|
||||
"-ldl",
|
||||
],
|
||||
"conditions": [],
|
||||
26
node/scripts/common.js
Normal file
26
node/scripts/common.js
Normal file
@@ -0,0 +1,26 @@
|
||||
const spawnSync = require('child_process').spawnSync
|
||||
|
||||
const verbose = isVerbose()
|
||||
|
||||
function spawn (cmd, args, opts) {
|
||||
log(`>> spawn: ${cmd} ${args.join(' ')}`)
|
||||
const result = spawnSync(cmd, args, opts)
|
||||
if (result.status === null) {
|
||||
console.error(`Could not find ${cmd}`)
|
||||
process.exit(1)
|
||||
} else if (result.status !== 0) {
|
||||
console.error(`${cmd} failed with code ${result.status}`)
|
||||
process.exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
function log (...args) {
|
||||
if (verbose) console.log(...args)
|
||||
}
|
||||
|
||||
function isVerbose () {
|
||||
const loglevel = process.env.npm_config_loglevel
|
||||
return loglevel === 'verbose' || process.env.CI === 'true'
|
||||
}
|
||||
|
||||
module.exports = { spawn, log, isVerbose, verbose }
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user