@bitsocial/bitsocial-react-hooks 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (269) hide show
  1. package/LICENSE +674 -0
  2. package/README.md +1365 -0
  3. package/dist/hooks/accounts/accounts.d.ts +64 -0
  4. package/dist/hooks/accounts/accounts.d.ts.map +1 -0
  5. package/dist/hooks/accounts/accounts.js +706 -0
  6. package/dist/hooks/accounts/accounts.js.map +1 -0
  7. package/dist/hooks/accounts/index.d.ts +2 -0
  8. package/dist/hooks/accounts/index.d.ts.map +1 -0
  9. package/dist/hooks/accounts/index.js +2 -0
  10. package/dist/hooks/accounts/index.js.map +1 -0
  11. package/dist/hooks/accounts/utils.d.ts +6 -0
  12. package/dist/hooks/accounts/utils.d.ts.map +1 -0
  13. package/dist/hooks/accounts/utils.js +226 -0
  14. package/dist/hooks/accounts/utils.js.map +1 -0
  15. package/dist/hooks/actions/actions.d.ts +19 -0
  16. package/dist/hooks/actions/actions.d.ts.map +1 -0
  17. package/dist/hooks/actions/actions.js +552 -0
  18. package/dist/hooks/actions/actions.js.map +1 -0
  19. package/dist/hooks/actions/index.d.ts +2 -0
  20. package/dist/hooks/actions/index.d.ts.map +1 -0
  21. package/dist/hooks/actions/index.js +2 -0
  22. package/dist/hooks/actions/index.js.map +1 -0
  23. package/dist/hooks/authors/author-avatars.d.ts +28 -0
  24. package/dist/hooks/authors/author-avatars.d.ts.map +1 -0
  25. package/dist/hooks/authors/author-avatars.js +191 -0
  26. package/dist/hooks/authors/author-avatars.js.map +1 -0
  27. package/dist/hooks/authors/authors.d.ts +37 -0
  28. package/dist/hooks/authors/authors.d.ts.map +1 -0
  29. package/dist/hooks/authors/authors.js +509 -0
  30. package/dist/hooks/authors/authors.js.map +1 -0
  31. package/dist/hooks/authors/index.d.ts +2 -0
  32. package/dist/hooks/authors/index.d.ts.map +1 -0
  33. package/dist/hooks/authors/index.js +2 -0
  34. package/dist/hooks/authors/index.js.map +1 -0
  35. package/dist/hooks/authors/utils.d.ts +4 -0
  36. package/dist/hooks/authors/utils.d.ts.map +1 -0
  37. package/dist/hooks/authors/utils.js +21 -0
  38. package/dist/hooks/authors/utils.js.map +1 -0
  39. package/dist/hooks/comments.d.ts +17 -0
  40. package/dist/hooks/comments.d.ts.map +1 -0
  41. package/dist/hooks/comments.js +351 -0
  42. package/dist/hooks/comments.js.map +1 -0
  43. package/dist/hooks/communities.d.ts +31 -0
  44. package/dist/hooks/communities.d.ts.map +1 -0
  45. package/dist/hooks/communities.js +389 -0
  46. package/dist/hooks/communities.js.map +1 -0
  47. package/dist/hooks/feeds/feeds.d.ts +18 -0
  48. package/dist/hooks/feeds/feeds.d.ts.map +1 -0
  49. package/dist/hooks/feeds/feeds.js +315 -0
  50. package/dist/hooks/feeds/feeds.js.map +1 -0
  51. package/dist/hooks/feeds/index.d.ts +2 -0
  52. package/dist/hooks/feeds/index.d.ts.map +1 -0
  53. package/dist/hooks/feeds/index.js +2 -0
  54. package/dist/hooks/feeds/index.js.map +1 -0
  55. package/dist/hooks/pkc-rpc.d.ts +7 -0
  56. package/dist/hooks/pkc-rpc.d.ts.map +1 -0
  57. package/dist/hooks/pkc-rpc.js +88 -0
  58. package/dist/hooks/pkc-rpc.js.map +1 -0
  59. package/dist/hooks/replies.d.ts +5 -0
  60. package/dist/hooks/replies.d.ts.map +1 -0
  61. package/dist/hooks/replies.js +155 -0
  62. package/dist/hooks/replies.js.map +1 -0
  63. package/dist/hooks/states.d.ts +15 -0
  64. package/dist/hooks/states.d.ts.map +1 -0
  65. package/dist/hooks/states.js +213 -0
  66. package/dist/hooks/states.js.map +1 -0
  67. package/dist/hooks/utils/use-interval.d.ts +3 -0
  68. package/dist/hooks/utils/use-interval.d.ts.map +1 -0
  69. package/dist/hooks/utils/use-interval.js +36 -0
  70. package/dist/hooks/utils/use-interval.js.map +1 -0
  71. package/dist/hooks/utils/use-previous.d.ts +1 -0
  72. package/dist/hooks/utils/use-previous.js +10 -0
  73. package/dist/index.d.ts +82 -0
  74. package/dist/index.d.ts.map +1 -0
  75. package/dist/index.js +128 -0
  76. package/dist/index.js.map +1 -0
  77. package/dist/lib/chain/chain.d.ts +36 -0
  78. package/dist/lib/chain/chain.d.ts.map +1 -0
  79. package/dist/lib/chain/chain.js +195 -0
  80. package/dist/lib/chain/chain.js.map +1 -0
  81. package/dist/lib/chain/index.d.ts +4 -0
  82. package/dist/lib/chain/index.d.ts.map +1 -0
  83. package/dist/lib/chain/index.js +4 -0
  84. package/dist/lib/chain/index.js.map +1 -0
  85. package/dist/lib/community-address.d.ts +6 -0
  86. package/dist/lib/community-address.d.ts.map +1 -0
  87. package/dist/lib/community-address.js +26 -0
  88. package/dist/lib/community-address.js.map +1 -0
  89. package/dist/lib/community-ref.d.ts +23 -0
  90. package/dist/lib/community-ref.d.ts.map +1 -0
  91. package/dist/lib/community-ref.js +113 -0
  92. package/dist/lib/community-ref.js.map +1 -0
  93. package/dist/lib/debug-utils.d.ts +9 -0
  94. package/dist/lib/debug-utils.d.ts.map +1 -0
  95. package/dist/lib/debug-utils.js +21 -0
  96. package/dist/lib/debug-utils.js.map +1 -0
  97. package/dist/lib/feed-sort-type.d.ts +2 -0
  98. package/dist/lib/feed-sort-type.d.ts.map +1 -0
  99. package/dist/lib/feed-sort-type.js +22 -0
  100. package/dist/lib/feed-sort-type.js.map +1 -0
  101. package/dist/lib/localforage-lru/index.d.ts +3 -0
  102. package/dist/lib/localforage-lru/index.d.ts.map +1 -0
  103. package/dist/lib/localforage-lru/index.js +46 -0
  104. package/dist/lib/localforage-lru/index.js.map +1 -0
  105. package/dist/lib/localforage-lru/localforage-lru.d.ts +6 -0
  106. package/dist/lib/localforage-lru/localforage-lru.d.ts.map +1 -0
  107. package/dist/lib/localforage-lru/localforage-lru.js +182 -0
  108. package/dist/lib/localforage-lru/localforage-lru.js.map +1 -0
  109. package/dist/lib/pkc-compat.d.ts +25 -0
  110. package/dist/lib/pkc-compat.d.ts.map +1 -0
  111. package/dist/lib/pkc-compat.js +131 -0
  112. package/dist/lib/pkc-compat.js.map +1 -0
  113. package/dist/lib/pkc-js/fixtures/markdown-example.d.ts +3 -0
  114. package/dist/lib/pkc-js/fixtures/markdown-example.d.ts.map +1 -0
  115. package/dist/lib/pkc-js/fixtures/markdown-example.js +280 -0
  116. package/dist/lib/pkc-js/fixtures/markdown-example.js.map +1 -0
  117. package/dist/lib/pkc-js/index.d.ts +11 -0
  118. package/dist/lib/pkc-js/index.d.ts.map +1 -0
  119. package/dist/lib/pkc-js/index.js +85 -0
  120. package/dist/lib/pkc-js/index.js.map +1 -0
  121. package/dist/lib/pkc-js/pkc-js-mock-content.d.ts +3 -0
  122. package/dist/lib/pkc-js/pkc-js-mock-content.d.ts.map +1 -0
  123. package/dist/lib/pkc-js/pkc-js-mock-content.js +1235 -0
  124. package/dist/lib/pkc-js/pkc-js-mock-content.js.map +1 -0
  125. package/dist/lib/pkc-js/pkc-js-mock.d.ts +137 -0
  126. package/dist/lib/pkc-js/pkc-js-mock.d.ts.map +1 -0
  127. package/dist/lib/pkc-js/pkc-js-mock.js +644 -0
  128. package/dist/lib/pkc-js/pkc-js-mock.js.map +1 -0
  129. package/dist/lib/polyfill.d.ts +3 -0
  130. package/dist/lib/polyfill.d.ts.map +1 -0
  131. package/dist/lib/polyfill.js +14 -0
  132. package/dist/lib/polyfill.js.map +1 -0
  133. package/dist/lib/protocol-compat.d.ts +14 -0
  134. package/dist/lib/protocol-compat.d.ts.map +1 -0
  135. package/dist/lib/protocol-compat.js +67 -0
  136. package/dist/lib/protocol-compat.js.map +1 -0
  137. package/dist/lib/test-utils.d.ts +29 -0
  138. package/dist/lib/test-utils.d.ts.map +1 -0
  139. package/dist/lib/test-utils.js +184 -0
  140. package/dist/lib/test-utils.js.map +1 -0
  141. package/dist/lib/utils/comment-moderation.d.ts +4 -0
  142. package/dist/lib/utils/comment-moderation.d.ts.map +1 -0
  143. package/dist/lib/utils/comment-moderation.js +56 -0
  144. package/dist/lib/utils/comment-moderation.js.map +1 -0
  145. package/dist/lib/utils/index.d.ts +4 -0
  146. package/dist/lib/utils/index.d.ts.map +1 -0
  147. package/dist/lib/utils/index.js +4 -0
  148. package/dist/lib/utils/index.js.map +1 -0
  149. package/dist/lib/utils/utils.d.ts +23 -0
  150. package/dist/lib/utils/utils.d.ts.map +1 -0
  151. package/dist/lib/utils/utils.js +375 -0
  152. package/dist/lib/utils/utils.js.map +1 -0
  153. package/dist/lib/validator.d.ts +30 -0
  154. package/dist/lib/validator.d.ts.map +1 -0
  155. package/dist/lib/validator.js +307 -0
  156. package/dist/lib/validator.js.map +1 -0
  157. package/dist/stores/accounts/account-generator.d.ts +51 -0
  158. package/dist/stores/accounts/account-generator.d.ts.map +1 -0
  159. package/dist/stores/accounts/account-generator.js +160 -0
  160. package/dist/stores/accounts/account-generator.js.map +1 -0
  161. package/dist/stores/accounts/accounts-actions-internal.d.ts +8 -0
  162. package/dist/stores/accounts/accounts-actions-internal.d.ts.map +1 -0
  163. package/dist/stores/accounts/accounts-actions-internal.js +403 -0
  164. package/dist/stores/accounts/accounts-actions-internal.js.map +1 -0
  165. package/dist/stores/accounts/accounts-actions.d.ts +46 -0
  166. package/dist/stores/accounts/accounts-actions.d.ts.map +1 -0
  167. package/dist/stores/accounts/accounts-actions.js +1341 -0
  168. package/dist/stores/accounts/accounts-actions.js.map +1 -0
  169. package/dist/stores/accounts/accounts-database.d.ts +34 -0
  170. package/dist/stores/accounts/accounts-database.d.ts.map +1 -0
  171. package/dist/stores/accounts/accounts-database.js +685 -0
  172. package/dist/stores/accounts/accounts-database.js.map +1 -0
  173. package/dist/stores/accounts/accounts-store.d.ts +32 -0
  174. package/dist/stores/accounts/accounts-store.d.ts.map +1 -0
  175. package/dist/stores/accounts/accounts-store.js +169 -0
  176. package/dist/stores/accounts/accounts-store.js.map +1 -0
  177. package/dist/stores/accounts/index.d.ts +4 -0
  178. package/dist/stores/accounts/index.d.ts.map +1 -0
  179. package/dist/stores/accounts/index.js +4 -0
  180. package/dist/stores/accounts/index.js.map +1 -0
  181. package/dist/stores/accounts/utils.d.ts +49 -0
  182. package/dist/stores/accounts/utils.d.ts.map +1 -0
  183. package/dist/stores/accounts/utils.js +419 -0
  184. package/dist/stores/accounts/utils.js.map +1 -0
  185. package/dist/stores/authors-comments/authors-comments-store.d.ts +37 -0
  186. package/dist/stores/authors-comments/authors-comments-store.d.ts.map +1 -0
  187. package/dist/stores/authors-comments/authors-comments-store.js +338 -0
  188. package/dist/stores/authors-comments/authors-comments-store.js.map +1 -0
  189. package/dist/stores/authors-comments/index.d.ts +4 -0
  190. package/dist/stores/authors-comments/index.d.ts.map +1 -0
  191. package/dist/stores/authors-comments/index.js +4 -0
  192. package/dist/stores/authors-comments/index.js.map +1 -0
  193. package/dist/stores/authors-comments/utils.d.ts +14 -0
  194. package/dist/stores/authors-comments/utils.d.ts.map +1 -0
  195. package/dist/stores/authors-comments/utils.js +81 -0
  196. package/dist/stores/authors-comments/utils.js.map +1 -0
  197. package/dist/stores/comments/comments-store.d.ts +19 -0
  198. package/dist/stores/comments/comments-store.d.ts.map +1 -0
  199. package/dist/stores/comments/comments-store.js +385 -0
  200. package/dist/stores/comments/comments-store.js.map +1 -0
  201. package/dist/stores/comments/index.d.ts +4 -0
  202. package/dist/stores/comments/index.d.ts.map +1 -0
  203. package/dist/stores/comments/index.js +4 -0
  204. package/dist/stores/comments/index.js.map +1 -0
  205. package/dist/stores/communities/communities-store.d.ts +17 -0
  206. package/dist/stores/communities/communities-store.d.ts.map +1 -0
  207. package/dist/stores/communities/communities-store.js +304 -0
  208. package/dist/stores/communities/communities-store.js.map +1 -0
  209. package/dist/stores/communities/index.d.ts +4 -0
  210. package/dist/stores/communities/index.d.ts.map +1 -0
  211. package/dist/stores/communities/index.js +4 -0
  212. package/dist/stores/communities/index.js.map +1 -0
  213. package/dist/stores/communities-pages/communities-pages-store.d.ts +23 -0
  214. package/dist/stores/communities-pages/communities-pages-store.d.ts.map +1 -0
  215. package/dist/stores/communities-pages/communities-pages-store.js +316 -0
  216. package/dist/stores/communities-pages/communities-pages-store.js.map +1 -0
  217. package/dist/stores/communities-pages/index.d.ts +4 -0
  218. package/dist/stores/communities-pages/index.d.ts.map +1 -0
  219. package/dist/stores/communities-pages/index.js +4 -0
  220. package/dist/stores/communities-pages/index.js.map +1 -0
  221. package/dist/stores/feeds/feed-sorter.d.ts +5 -0
  222. package/dist/stores/feeds/feed-sorter.d.ts.map +1 -0
  223. package/dist/stores/feeds/feed-sorter.js +135 -0
  224. package/dist/stores/feeds/feed-sorter.js.map +1 -0
  225. package/dist/stores/feeds/feeds-store.d.ts +25 -0
  226. package/dist/stores/feeds/feeds-store.d.ts.map +1 -0
  227. package/dist/stores/feeds/feeds-store.js +459 -0
  228. package/dist/stores/feeds/feeds-store.js.map +1 -0
  229. package/dist/stores/feeds/index.d.ts +4 -0
  230. package/dist/stores/feeds/index.d.ts.map +1 -0
  231. package/dist/stores/feeds/index.js +4 -0
  232. package/dist/stores/feeds/index.js.map +1 -0
  233. package/dist/stores/feeds/utils.d.ts +43 -0
  234. package/dist/stores/feeds/utils.d.ts.map +1 -0
  235. package/dist/stores/feeds/utils.js +736 -0
  236. package/dist/stores/feeds/utils.js.map +1 -0
  237. package/dist/stores/replies/index.d.ts +4 -0
  238. package/dist/stores/replies/index.d.ts.map +1 -0
  239. package/dist/stores/replies/index.js +4 -0
  240. package/dist/stores/replies/index.js.map +1 -0
  241. package/dist/stores/replies/replies-comments-store.d.ts +8 -0
  242. package/dist/stores/replies/replies-comments-store.d.ts.map +1 -0
  243. package/dist/stores/replies/replies-comments-store.js +23 -0
  244. package/dist/stores/replies/replies-comments-store.js.map +1 -0
  245. package/dist/stores/replies/replies-store.d.ts +29 -0
  246. package/dist/stores/replies/replies-store.d.ts.map +1 -0
  247. package/dist/stores/replies/replies-store.js +413 -0
  248. package/dist/stores/replies/replies-store.js.map +1 -0
  249. package/dist/stores/replies/utils.d.ts +25 -0
  250. package/dist/stores/replies/utils.d.ts.map +1 -0
  251. package/dist/stores/replies/utils.js +549 -0
  252. package/dist/stores/replies/utils.js.map +1 -0
  253. package/dist/stores/replies-pages/index.d.ts +4 -0
  254. package/dist/stores/replies-pages/index.d.ts.map +1 -0
  255. package/dist/stores/replies-pages/index.js +4 -0
  256. package/dist/stores/replies-pages/index.js.map +1 -0
  257. package/dist/stores/replies-pages/replies-pages-store.d.ts +20 -0
  258. package/dist/stores/replies-pages/replies-pages-store.d.ts.map +1 -0
  259. package/dist/stores/replies-pages/replies-pages-store.js +270 -0
  260. package/dist/stores/replies-pages/replies-pages-store.js.map +1 -0
  261. package/dist/stores/replies-pages/utils.d.ts +3 -0
  262. package/dist/stores/replies-pages/utils.d.ts.map +1 -0
  263. package/dist/stores/replies-pages/utils.js +43 -0
  264. package/dist/stores/replies-pages/utils.js.map +1 -0
  265. package/dist/types.d.ts +638 -0
  266. package/dist/types.d.ts.map +1 -0
  267. package/dist/types.js +3 -0
  268. package/dist/types.js.map +1 -0
  269. package/package.json +160 -0
@@ -0,0 +1,304 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ import assert from "assert";
11
+ import localForageLru from "../../lib/localforage-lru/index.js";
12
+ const communitiesDatabase = localForageLru.createInstance({
13
+ name: "bitsocialReactHooks-communities",
14
+ size: 500,
15
+ });
16
+ import Logger from "@pkcprotocol/pkc-logger";
17
+ const log = Logger("bitsocial-react-hooks:communities:stores");
18
+ import utils from "../../lib/utils/index.js";
19
+ import createStore from "zustand";
20
+ import accountsStore from "../accounts/index.js";
21
+ import communitiesPagesStore from "../communities-pages/index.js";
22
+ import { getCommunityLookupOptions, getCommunityRefKey } from "../../lib/community-ref.js";
23
+ import { createPkcCommunity, getPkcCommunity, getPkcCommunityAddresses, getPkcCreateCommunity, getPkcGetCommunity, } from "../../lib/pkc-compat.js";
24
+ let pkcGetCommunityPending = {};
25
+ const createCommunityWithLookupFallback = (pkc, communityLookupOptions, communityKey) => __awaiter(void 0, void 0, void 0, function* () {
26
+ const supportsAddressLookup = "address" in communityLookupOptions;
27
+ const community = yield createPkcCommunity(pkc, communityLookupOptions);
28
+ if ((community === null || community === void 0 ? void 0 : community.address) || supportsAddressLookup) {
29
+ return community;
30
+ }
31
+ throw Error(`communitiesStore.addCommunityToStore failed getting community '${communityKey}'`);
32
+ });
33
+ // reset all event listeners in between tests
34
+ const listeners = [];
35
+ const communitiesStore = createStore((setState, getState) => ({
36
+ communities: {},
37
+ errors: {},
38
+ addCommunityToStore(communityAddressOrRef, account) {
39
+ return __awaiter(this, void 0, void 0, function* () {
40
+ const communityLookupOptions = getCommunityLookupOptions(communityAddressOrRef);
41
+ const communityKey = typeof communityAddressOrRef === "string"
42
+ ? communityAddressOrRef
43
+ : getCommunityRefKey(communityAddressOrRef);
44
+ assert(communityKey !== "" && typeof communityKey === "string", `communitiesStore.addCommunityToStore invalid communityAddress argument '${communityAddressOrRef}'`);
45
+ assert(typeof getPkcCreateCommunity(account === null || account === void 0 ? void 0 : account.pkc) === "function", `communitiesStore.addCommunityToStore invalid account argument '${account}'`);
46
+ // community is in store already, do nothing
47
+ const { communities } = getState();
48
+ let community = communities[communityKey];
49
+ const pendingKey = communityKey + account.id;
50
+ if (community || pkcGetCommunityPending[pendingKey]) {
51
+ return;
52
+ }
53
+ // start trying to get community
54
+ pkcGetCommunityPending[pendingKey] = true;
55
+ let errorGettingCommunity;
56
+ try {
57
+ // try to find community in owner communities
58
+ if (getPkcCommunityAddresses(account.pkc).includes(communityKey)) {
59
+ try {
60
+ community = yield createCommunityWithLookupFallback(account.pkc, communityLookupOptions, communityKey);
61
+ }
62
+ catch (e) {
63
+ errorGettingCommunity = e;
64
+ }
65
+ }
66
+ // try to find community in database
67
+ let fetchedAt;
68
+ if (!community) {
69
+ const communityData = yield communitiesDatabase.getItem(communityKey);
70
+ if (communityData) {
71
+ fetchedAt = communityData.fetchedAt;
72
+ delete communityData.fetchedAt; // not part of pkc-js schema
73
+ try {
74
+ community = yield createPkcCommunity(account.pkc, communityData);
75
+ }
76
+ catch (e) {
77
+ fetchedAt = undefined;
78
+ // need to log this always or it could silently fail in production and cache never be used
79
+ console.error("failed pkc.createCommunity(cachedCommunity)", {
80
+ cachedCommunity: communityData,
81
+ error: e,
82
+ });
83
+ }
84
+ }
85
+ if (community) {
86
+ // add page comments to communitiesPagesStore so they can be used in useComment
87
+ communitiesPagesStore.getState().addCommunityPageCommentsToStore(community);
88
+ }
89
+ }
90
+ // community not in database, try to fetch from pkc-js
91
+ if (!community) {
92
+ try {
93
+ community = yield createCommunityWithLookupFallback(account.pkc, communityLookupOptions, communityKey);
94
+ }
95
+ catch (e) {
96
+ errorGettingCommunity = e;
97
+ }
98
+ }
99
+ // failure getting community
100
+ if (!community) {
101
+ if (errorGettingCommunity) {
102
+ setState((state) => {
103
+ let communityErrors = state.errors[communityKey] || [];
104
+ communityErrors = [...communityErrors, errorGettingCommunity];
105
+ return Object.assign(Object.assign({}, state), { errors: Object.assign(Object.assign({}, state.errors), { [communityKey]: communityErrors }) });
106
+ });
107
+ }
108
+ throw (errorGettingCommunity ||
109
+ Error(`communitiesStore.addCommunityToStore failed getting community '${communityKey}'`));
110
+ }
111
+ // success getting community
112
+ const firstCommunityState = utils.clone(Object.assign(Object.assign({}, community), { fetchedAt }));
113
+ yield communitiesDatabase.setItem(communityKey, firstCommunityState);
114
+ log("communitiesStore.addCommunityToStore", {
115
+ communityAddressOrRef,
116
+ communityKey,
117
+ community,
118
+ account,
119
+ });
120
+ setState((state) => ({
121
+ communities: Object.assign(Object.assign({}, state.communities), { [communityKey]: firstCommunityState }),
122
+ }));
123
+ // the community has published new posts
124
+ community.on("update", (updatedCommunity) => __awaiter(this, void 0, void 0, function* () {
125
+ updatedCommunity = utils.clone(updatedCommunity);
126
+ // add fetchedAt to be able to expire the cache
127
+ // NOTE: fetchedAt is undefined on owner communities because never stale
128
+ updatedCommunity.fetchedAt = Math.floor(Date.now() / 1000);
129
+ yield communitiesDatabase.setItem(communityKey, updatedCommunity);
130
+ log("communitiesStore community update", {
131
+ communityAddressOrRef,
132
+ communityKey,
133
+ updatedCommunity,
134
+ account,
135
+ });
136
+ setState((state) => ({
137
+ communities: Object.assign(Object.assign({}, state.communities), { [communityKey]: updatedCommunity }),
138
+ }));
139
+ // if a community has a role with an account's address add it to the account.communities
140
+ accountsStore
141
+ .getState()
142
+ .accountsActionsInternal.addCommunityRoleToAccountsCommunities(updatedCommunity);
143
+ // add page comments to communitiesPagesStore so they can be used in useComment
144
+ communitiesPagesStore.getState().addCommunityPageCommentsToStore(updatedCommunity);
145
+ }));
146
+ community.on("updatingstatechange", (updatingState) => {
147
+ setState((state) => ({
148
+ communities: Object.assign(Object.assign({}, state.communities), { [communityKey]: Object.assign(Object.assign({}, state.communities[communityKey]), { updatingState }) }),
149
+ }));
150
+ });
151
+ community.on("error", (error) => {
152
+ setState((state) => {
153
+ let communityErrors = state.errors[communityKey] || [];
154
+ communityErrors = [...communityErrors, error];
155
+ return Object.assign(Object.assign({}, state), { errors: Object.assign(Object.assign({}, state.errors), { [communityKey]: communityErrors }) });
156
+ });
157
+ });
158
+ // set clients on community so the frontend can display it, dont persist in db because a reload cancels updating
159
+ utils.clientsOnStateChange(community === null || community === void 0 ? void 0 : community.clients, (clientState, clientType, clientUrl, chainTicker) => {
160
+ setState((state) => {
161
+ var _a;
162
+ // make sure not undefined, sometimes happens in e2e tests
163
+ if (!state.communities[communityKey]) {
164
+ return {};
165
+ }
166
+ const clients = Object.assign({}, (_a = state.communities[communityKey]) === null || _a === void 0 ? void 0 : _a.clients);
167
+ const client = { state: clientState };
168
+ if (chainTicker) {
169
+ const chainProviders = Object.assign(Object.assign({}, clients[clientType][chainTicker]), { [clientUrl]: client });
170
+ clients[clientType] = Object.assign(Object.assign({}, clients[clientType]), { [chainTicker]: chainProviders });
171
+ }
172
+ else {
173
+ clients[clientType] = Object.assign(Object.assign({}, clients[clientType]), { [clientUrl]: client });
174
+ }
175
+ return {
176
+ communities: Object.assign(Object.assign({}, state.communities), { [communityKey]: Object.assign(Object.assign({}, state.communities[communityKey]), { clients }) }),
177
+ };
178
+ });
179
+ });
180
+ listeners.push(community);
181
+ community
182
+ .update()
183
+ .catch((error) => log.trace("community.update error", { community, error }));
184
+ }
185
+ finally {
186
+ pkcGetCommunityPending[pendingKey] = false;
187
+ }
188
+ });
189
+ },
190
+ refreshCommunity(communityAddressOrRef, account) {
191
+ return __awaiter(this, void 0, void 0, function* () {
192
+ const communityLookupOptions = getCommunityLookupOptions(communityAddressOrRef);
193
+ const communityKey = typeof communityAddressOrRef === "string"
194
+ ? communityAddressOrRef
195
+ : getCommunityRefKey(communityAddressOrRef);
196
+ assert(communityKey !== "" && typeof communityKey === "string", `communitiesStore.refreshCommunity invalid communityAddress argument '${communityAddressOrRef}'`);
197
+ assert(typeof getPkcGetCommunity(account === null || account === void 0 ? void 0 : account.pkc) === "function", `communitiesStore.refreshCommunity invalid account argument '${account}'`);
198
+ const refreshedCommunity = utils.clone(yield getPkcCommunity(account.pkc, communityLookupOptions));
199
+ refreshedCommunity.fetchedAt = Math.floor(Date.now() / 1000);
200
+ yield communitiesDatabase.setItem(communityKey, refreshedCommunity);
201
+ log("communitiesStore.refreshCommunity", {
202
+ communityAddressOrRef,
203
+ communityKey,
204
+ refreshedCommunity,
205
+ account,
206
+ });
207
+ setState((state) => ({
208
+ communities: Object.assign(Object.assign({}, state.communities), { [communityKey]: refreshedCommunity }),
209
+ }));
210
+ communitiesPagesStore.getState().addCommunityPageCommentsToStore(refreshedCommunity);
211
+ return refreshedCommunity;
212
+ });
213
+ },
214
+ // user is the owner of the community and can edit it locally
215
+ editCommunity(communityAddress, communityEditOptions, account) {
216
+ return __awaiter(this, void 0, void 0, function* () {
217
+ assert(communityAddress !== "" && typeof communityAddress === "string", `communitiesStore.editCommunity invalid communityAddress argument '${communityAddress}'`);
218
+ assert(communityEditOptions && typeof communityEditOptions === "object", `communitiesStore.editCommunity invalid communityEditOptions argument '${communityEditOptions}'`);
219
+ assert(typeof getPkcCreateCommunity(account === null || account === void 0 ? void 0 : account.pkc) === "function", `communitiesStore.editCommunity invalid account argument '${account}'`);
220
+ // if not added to store first, community.update() is never called
221
+ yield getState().addCommunityToStore(communityAddress, account);
222
+ // `communityAddress` is different from `communityEditOptions.address` when editing the community address
223
+ const community = yield createPkcCommunity(account.pkc, {
224
+ address: communityAddress,
225
+ });
226
+ // could fix some test issues
227
+ community.on("error", console.log);
228
+ yield community.edit(communityEditOptions);
229
+ const updatedCommunity = utils.clone(community);
230
+ // edit db of both old and new community address to not break the UI
231
+ yield communitiesDatabase.setItem(communityAddress, updatedCommunity);
232
+ yield communitiesDatabase.setItem(community.address, updatedCommunity);
233
+ log("communitiesStore.editCommunity", {
234
+ communityAddress,
235
+ communityEditOptions,
236
+ community,
237
+ account,
238
+ });
239
+ setState((state) => ({
240
+ communities: Object.assign(Object.assign({}, state.communities), {
241
+ // edit react state of both old and new community address to not break the UI
242
+ [communityAddress]: updatedCommunity, [community.address]: updatedCommunity }),
243
+ }));
244
+ });
245
+ },
246
+ // internal action called by accountsActions.createCommunity
247
+ createCommunity(createCommunityOptions, account) {
248
+ return __awaiter(this, void 0, void 0, function* () {
249
+ assert(!createCommunityOptions || typeof createCommunityOptions === "object", `communitiesStore.createCommunity invalid createCommunityOptions argument '${createCommunityOptions}'`);
250
+ if (!(createCommunityOptions === null || createCommunityOptions === void 0 ? void 0 : createCommunityOptions.signer)) {
251
+ assert(!(createCommunityOptions === null || createCommunityOptions === void 0 ? void 0 : createCommunityOptions.address), `communitiesStore.createCommunity createCommunityOptions.address '${createCommunityOptions === null || createCommunityOptions === void 0 ? void 0 : createCommunityOptions.address}' must be undefined to create a community`);
252
+ }
253
+ assert(typeof getPkcCreateCommunity(account === null || account === void 0 ? void 0 : account.pkc) === "function", `communitiesStore.createCommunity invalid account argument '${account}'`);
254
+ const community = yield createPkcCommunity(account.pkc, createCommunityOptions);
255
+ // could fix some test issues
256
+ community.on("error", console.log);
257
+ // if not added to store first, community.update() is never called
258
+ yield getState().addCommunityToStore(community.address, account);
259
+ yield communitiesDatabase.setItem(community.address, utils.clone(community));
260
+ log("communitiesStore.createCommunity", { createCommunityOptions, community, account });
261
+ setState((state) => ({
262
+ communities: Object.assign(Object.assign({}, state.communities), { [community.address]: utils.clone(community) }),
263
+ }));
264
+ return community;
265
+ });
266
+ },
267
+ // internal action called by accountsActions.deleteCommunity
268
+ deleteCommunity(communityAddress, account) {
269
+ return __awaiter(this, void 0, void 0, function* () {
270
+ assert(communityAddress && typeof communityAddress === "string", `communitiesStore.deleteCommunity invalid communityAddress argument '${communityAddress}'`);
271
+ assert(typeof getPkcCreateCommunity(account === null || account === void 0 ? void 0 : account.pkc) === "function", `communitiesStore.deleteCommunity invalid account argument '${account}'`);
272
+ const community = yield createPkcCommunity(account.pkc, {
273
+ address: communityAddress,
274
+ });
275
+ // could fix some test issues
276
+ community.on("error", console.log);
277
+ yield community.delete();
278
+ yield communitiesDatabase.removeItem(communityAddress);
279
+ log("communitiesStore.deleteCommunity", { communityAddress, community, account });
280
+ setState((state) => ({
281
+ communities: Object.assign(Object.assign({}, state.communities), { [communityAddress]: undefined }),
282
+ }));
283
+ });
284
+ },
285
+ }));
286
+ // reset store in between tests
287
+ const originalState = communitiesStore.getState();
288
+ // async function because some stores have async init
289
+ export const resetCommunitiesStore = () => __awaiter(void 0, void 0, void 0, function* () {
290
+ pkcGetCommunityPending = {};
291
+ // remove all event listeners
292
+ listeners.forEach((listener) => listener.removeAllListeners());
293
+ // destroy all component subscriptions to the store
294
+ communitiesStore.destroy();
295
+ // restore original state
296
+ communitiesStore.setState(originalState);
297
+ });
298
+ // reset database and store in between tests
299
+ export const resetCommunitiesDatabaseAndStore = () => __awaiter(void 0, void 0, void 0, function* () {
300
+ yield localForageLru.createInstance({ name: "bitsocialReactHooks-communities" }).clear();
301
+ yield resetCommunitiesStore();
302
+ });
303
+ export default communitiesStore;
304
+ //# sourceMappingURL=communities-store.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"communities-store.js","sourceRoot":"","sources":["../../../src/stores/communities/communities-store.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,MAAM,MAAM,QAAQ,CAAC;AAC5B,OAAO,cAAc,MAAM,2BAA2B,CAAC;AACvD,MAAM,mBAAmB,GAAG,cAAc,CAAC,cAAc,CAAC;IACxD,IAAI,EAAE,iCAAiC;IACvC,IAAI,EAAE,GAAG;CACV,CAAC,CAAC;AACH,OAAO,MAAM,MAAM,yBAAyB,CAAC;AAC7C,MAAM,GAAG,GAAG,MAAM,CAAC,0CAA0C,CAAC,CAAC;AAQ/D,OAAO,KAAK,MAAM,iBAAiB,CAAC;AACpC,OAAO,WAAW,MAAM,SAAS,CAAC;AAClC,OAAO,aAAa,MAAM,aAAa,CAAC;AACxC,OAAO,qBAAqB,MAAM,sBAAsB,CAAC;AACzD,OAAO,EAAE,yBAAyB,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AACxF,OAAO,EACL,kBAAkB,EAClB,eAAe,EACf,wBAAwB,EACxB,qBAAqB,EACrB,kBAAkB,GACnB,MAAM,sBAAsB,CAAC;AAE9B,IAAI,sBAAsB,GAA+B,EAAE,CAAC;AAE5D,MAAM,iCAAiC,GAAG,CACxC,GAAQ,EACR,sBAA+E,EAC/E,YAAoB,EACpB,EAAE;IACF,MAAM,qBAAqB,GAAG,SAAS,IAAI,sBAAsB,CAAC;IAClE,MAAM,SAAS,GAAG,MAAM,kBAAkB,CAAC,GAAG,EAAE,sBAAsB,CAAC,CAAC;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,SAAS,EAAE,OAAO,EAAE,CAAC,CAAC;YAClF,QAAQ,CAAC,CAAC,KAAU,EAAE,EAAE,CAAC,CAAC;gBACxB,WAAW,kCAAO,KAAK,CAAC,WAAW,KAAE,CAAC,gBAAgB,CAAC,EAAE,SAAS,GAAE;aACrE,CAAC,CAAC,CAAC;QACN,CAAC;KAAA;CACF,CAAC,CACH,CAAC;AAEF,+BAA+B;AAC/B,MAAM,aAAa,GAAG,gBAAgB,CAAC,QAAQ,EAAE,CAAC;AAClD,qDAAqD;AACrD,MAAM,CAAC,MAAM,qBAAqB,GAAG,GAAS,EAAE;IAC9C,sBAAsB,GAAG,EAAE,CAAC;IAC5B,6BAA6B;IAC7B,SAAS,CAAC,OAAO,CAAC,CAAC,QAAa,EAAE,EAAE,CAAC,QAAQ,CAAC,kBAAkB,EAAE,CAAC,CAAC;IACpE,mDAAmD;IACnD,gBAAgB,CAAC,OAAO,EAAE,CAAC;IAC3B,yBAAyB;IACzB,gBAAgB,CAAC,QAAQ,CAAC,aAAa,CAAC,CAAC;AAC3C,CAAC,CAAA,CAAC;AAEF,4CAA4C;AAC5C,MAAM,CAAC,MAAM,gCAAgC,GAAG,GAAS,EAAE;IACzD,MAAM,cAAc,CAAC,cAAc,CAAC,EAAE,IAAI,EAAE,iCAAiC,EAAE,CAAC,CAAC,KAAK,EAAE,CAAC;IACzF,MAAM,qBAAqB,EAAE,CAAC;AAChC,CAAC,CAAA,CAAC;AAEF,eAAe,gBAAgB,CAAC","sourcesContent":["import assert from \"assert\";\nimport localForageLru from \"../../lib/localforage-lru\";\nconst communitiesDatabase = localForageLru.createInstance({\n name: \"bitsocialReactHooks-communities\",\n size: 500,\n});\nimport Logger from \"@pkcprotocol/pkc-logger\";\nconst log = Logger(\"bitsocial-react-hooks:communities:stores\");\nimport {\n Community,\n Communities,\n Account,\n CommunityIdentifier,\n CreateCommunityOptions,\n} from \"../../types\";\nimport utils from \"../../lib/utils\";\nimport createStore from \"zustand\";\nimport accountsStore from \"../accounts\";\nimport communitiesPagesStore from \"../communities-pages\";\nimport { getCommunityLookupOptions, getCommunityRefKey } from \"../../lib/community-ref\";\nimport {\n createPkcCommunity,\n getPkcCommunity,\n getPkcCommunityAddresses,\n getPkcCreateCommunity,\n getPkcGetCommunity,\n} from \"../../lib/pkc-compat\";\n\nlet pkcGetCommunityPending: { [key: string]: boolean } = {};\n\nconst createCommunityWithLookupFallback = async (\n pkc: any,\n communityLookupOptions: { address?: string; name?: string; publicKey?: string },\n communityKey: string,\n) => {\n const supportsAddressLookup = \"address\" in communityLookupOptions;\n const community = await createPkcCommunity(pkc, communityLookupOptions);\n if (community?.address || supportsAddressLookup) {\n return community;\n }\n throw Error(`communitiesStore.addCommunityToStore failed getting community '${communityKey}'`);\n};\n\n// reset all event listeners in between tests\nconst listeners: any = [];\n\nexport type CommunitiesState = {\n communities: Communities;\n errors: { [communityAddress: string]: Error[] };\n addCommunityToStore: Function;\n refreshCommunity: Function;\n editCommunity: Function;\n createCommunity: Function;\n deleteCommunity: Function;\n};\n\nconst communitiesStore = createStore<CommunitiesState>(\n (setState: Function, getState: Function) => ({\n communities: {},\n errors: {},\n\n async addCommunityToStore(\n communityAddressOrRef: string | CommunityIdentifier,\n account: Account,\n ) {\n const communityLookupOptions = getCommunityLookupOptions(communityAddressOrRef);\n const communityKey =\n typeof communityAddressOrRef === \"string\"\n ? communityAddressOrRef\n : getCommunityRefKey(communityAddressOrRef);\n assert(\n communityKey !== \"\" && typeof communityKey === \"string\",\n `communitiesStore.addCommunityToStore invalid communityAddress argument '${communityAddressOrRef}'`,\n );\n assert(\n typeof getPkcCreateCommunity(account?.pkc) === \"function\",\n `communitiesStore.addCommunityToStore invalid account argument '${account}'`,\n );\n\n // community is in store already, do nothing\n const { communities } = getState();\n let community: Community | undefined = communities[communityKey];\n const pendingKey = communityKey + account.id;\n if (community || pkcGetCommunityPending[pendingKey]) {\n return;\n }\n\n // start trying to get community\n pkcGetCommunityPending[pendingKey] = true;\n let errorGettingCommunity: any;\n try {\n // try to find community in owner communities\n if (getPkcCommunityAddresses(account.pkc).includes(communityKey)) {\n try {\n community = await createCommunityWithLookupFallback(\n account.pkc,\n communityLookupOptions,\n communityKey,\n );\n } catch (e) {\n errorGettingCommunity = e;\n }\n }\n\n // try to find community in database\n let fetchedAt: number | undefined;\n if (!community) {\n const communityData: any = await communitiesDatabase.getItem(communityKey);\n if (communityData) {\n fetchedAt = communityData.fetchedAt;\n delete communityData.fetchedAt; // not part of pkc-js schema\n try {\n community = await createPkcCommunity(account.pkc, communityData);\n } catch (e) {\n fetchedAt = undefined;\n // need to log this always or it could silently fail in production and cache never be used\n console.error(\"failed pkc.createCommunity(cachedCommunity)\", {\n cachedCommunity: communityData,\n error: e,\n });\n }\n }\n if (community) {\n // add page comments to communitiesPagesStore so they can be used in useComment\n communitiesPagesStore.getState().addCommunityPageCommentsToStore(community);\n }\n }\n\n // community not in database, try to fetch from pkc-js\n if (!community) {\n try {\n community = await createCommunityWithLookupFallback(\n account.pkc,\n communityLookupOptions,\n communityKey,\n );\n } catch (e) {\n errorGettingCommunity = e;\n }\n }\n\n // failure getting community\n if (!community) {\n if (errorGettingCommunity) {\n setState((state: CommunitiesState) => {\n let communityErrors = state.errors[communityKey] || [];\n communityErrors = [...communityErrors, errorGettingCommunity];\n return { ...state, errors: { ...state.errors, [communityKey]: communityErrors } };\n });\n }\n\n throw (\n errorGettingCommunity ||\n Error(`communitiesStore.addCommunityToStore failed getting community '${communityKey}'`)\n );\n }\n\n // success getting community\n const firstCommunityState = utils.clone({ ...community, fetchedAt });\n await communitiesDatabase.setItem(communityKey, firstCommunityState);\n log(\"communitiesStore.addCommunityToStore\", {\n communityAddressOrRef,\n communityKey,\n community,\n account,\n });\n setState((state: any) => ({\n communities: { ...state.communities, [communityKey]: firstCommunityState },\n }));\n\n // the community has published new posts\n community.on(\"update\", async (updatedCommunity: Community) => {\n updatedCommunity = utils.clone(updatedCommunity);\n\n // add fetchedAt to be able to expire the cache\n // NOTE: fetchedAt is undefined on owner communities because never stale\n updatedCommunity.fetchedAt = Math.floor(Date.now() / 1000);\n\n await communitiesDatabase.setItem(communityKey, updatedCommunity);\n log(\"communitiesStore community update\", {\n communityAddressOrRef,\n communityKey,\n updatedCommunity,\n account,\n });\n setState((state: any) => ({\n communities: { ...state.communities, [communityKey]: updatedCommunity },\n }));\n\n // if a community has a role with an account's address add it to the account.communities\n accountsStore\n .getState()\n .accountsActionsInternal.addCommunityRoleToAccountsCommunities(updatedCommunity);\n\n // add page comments to communitiesPagesStore so they can be used in useComment\n communitiesPagesStore.getState().addCommunityPageCommentsToStore(updatedCommunity);\n });\n\n community.on(\"updatingstatechange\", (updatingState: string) => {\n setState((state: CommunitiesState) => ({\n communities: {\n ...state.communities,\n [communityKey]: { ...state.communities[communityKey], updatingState },\n },\n }));\n });\n\n community.on(\"error\", (error: Error) => {\n setState((state: CommunitiesState) => {\n let communityErrors = state.errors[communityKey] || [];\n communityErrors = [...communityErrors, error];\n return { ...state, errors: { ...state.errors, [communityKey]: communityErrors } };\n });\n });\n\n // set clients on community so the frontend can display it, dont persist in db because a reload cancels updating\n utils.clientsOnStateChange(\n community?.clients,\n (clientState: string, clientType: string, clientUrl: string, chainTicker?: string) => {\n setState((state: CommunitiesState) => {\n // make sure not undefined, sometimes happens in e2e tests\n if (!state.communities[communityKey]) {\n return {};\n }\n const clients = { ...state.communities[communityKey]?.clients };\n const client = { state: clientState };\n if (chainTicker) {\n const chainProviders = { ...clients[clientType][chainTicker], [clientUrl]: client };\n clients[clientType] = { ...clients[clientType], [chainTicker]: chainProviders };\n } else {\n clients[clientType] = { ...clients[clientType], [clientUrl]: client };\n }\n return {\n communities: {\n ...state.communities,\n [communityKey]: { ...state.communities[communityKey], clients },\n },\n };\n });\n },\n );\n\n listeners.push(community);\n community\n .update()\n .catch((error: unknown) => log.trace(\"community.update error\", { community, error }));\n } finally {\n pkcGetCommunityPending[pendingKey] = false;\n }\n },\n\n async refreshCommunity(communityAddressOrRef: string | CommunityIdentifier, account: Account) {\n const communityLookupOptions = getCommunityLookupOptions(communityAddressOrRef);\n const communityKey =\n typeof communityAddressOrRef === \"string\"\n ? communityAddressOrRef\n : getCommunityRefKey(communityAddressOrRef);\n assert(\n communityKey !== \"\" && typeof communityKey === \"string\",\n `communitiesStore.refreshCommunity invalid communityAddress argument '${communityAddressOrRef}'`,\n );\n assert(\n typeof getPkcGetCommunity(account?.pkc) === \"function\",\n `communitiesStore.refreshCommunity invalid account argument '${account}'`,\n );\n\n const refreshedCommunity = utils.clone(\n await getPkcCommunity(account.pkc, communityLookupOptions),\n );\n refreshedCommunity.fetchedAt = Math.floor(Date.now() / 1000);\n\n await communitiesDatabase.setItem(communityKey, refreshedCommunity);\n log(\"communitiesStore.refreshCommunity\", {\n communityAddressOrRef,\n communityKey,\n refreshedCommunity,\n account,\n });\n setState((state: any) => ({\n communities: { ...state.communities, [communityKey]: refreshedCommunity },\n }));\n\n communitiesPagesStore.getState().addCommunityPageCommentsToStore(refreshedCommunity);\n\n return refreshedCommunity;\n },\n\n // user is the owner of the community and can edit it locally\n async editCommunity(communityAddress: string, communityEditOptions: any, account: Account) {\n assert(\n communityAddress !== \"\" && typeof communityAddress === \"string\",\n `communitiesStore.editCommunity invalid communityAddress argument '${communityAddress}'`,\n );\n assert(\n communityEditOptions && typeof communityEditOptions === \"object\",\n `communitiesStore.editCommunity invalid communityEditOptions argument '${communityEditOptions}'`,\n );\n assert(\n typeof getPkcCreateCommunity(account?.pkc) === \"function\",\n `communitiesStore.editCommunity invalid account argument '${account}'`,\n );\n\n // if not added to store first, community.update() is never called\n await getState().addCommunityToStore(communityAddress, account);\n\n // `communityAddress` is different from `communityEditOptions.address` when editing the community address\n const community = await createPkcCommunity(account.pkc, {\n address: communityAddress,\n });\n\n // could fix some test issues\n community.on(\"error\", console.log);\n\n await community.edit(communityEditOptions);\n\n const updatedCommunity = utils.clone(community);\n // edit db of both old and new community address to not break the UI\n await communitiesDatabase.setItem(communityAddress, updatedCommunity);\n await communitiesDatabase.setItem(community.address, updatedCommunity);\n log(\"communitiesStore.editCommunity\", {\n communityAddress,\n communityEditOptions,\n community,\n account,\n });\n setState((state: any) => ({\n communities: {\n ...state.communities,\n // edit react state of both old and new community address to not break the UI\n [communityAddress]: updatedCommunity,\n [community.address]: updatedCommunity,\n },\n }));\n },\n\n // internal action called by accountsActions.createCommunity\n async createCommunity(createCommunityOptions: CreateCommunityOptions, account: Account) {\n assert(\n !createCommunityOptions || typeof createCommunityOptions === \"object\",\n `communitiesStore.createCommunity invalid createCommunityOptions argument '${createCommunityOptions}'`,\n );\n if (!createCommunityOptions?.signer) {\n assert(\n !createCommunityOptions?.address,\n `communitiesStore.createCommunity createCommunityOptions.address '${createCommunityOptions?.address}' must be undefined to create a community`,\n );\n }\n assert(\n typeof getPkcCreateCommunity(account?.pkc) === \"function\",\n `communitiesStore.createCommunity invalid account argument '${account}'`,\n );\n\n const community = await createPkcCommunity(account.pkc, createCommunityOptions);\n\n // could fix some test issues\n community.on(\"error\", console.log);\n\n // if not added to store first, community.update() is never called\n await getState().addCommunityToStore(community.address, account);\n\n await communitiesDatabase.setItem(community.address, utils.clone(community));\n log(\"communitiesStore.createCommunity\", { createCommunityOptions, community, account });\n setState((state: any) => ({\n communities: { ...state.communities, [community.address]: utils.clone(community) },\n }));\n return community;\n },\n\n // internal action called by accountsActions.deleteCommunity\n async deleteCommunity(communityAddress: string, account: Account) {\n assert(\n communityAddress && typeof communityAddress === \"string\",\n `communitiesStore.deleteCommunity invalid communityAddress argument '${communityAddress}'`,\n );\n assert(\n typeof getPkcCreateCommunity(account?.pkc) === \"function\",\n `communitiesStore.deleteCommunity invalid account argument '${account}'`,\n );\n\n const community = await createPkcCommunity(account.pkc, {\n address: communityAddress,\n });\n\n // could fix some test issues\n community.on(\"error\", console.log);\n\n await community.delete();\n await communitiesDatabase.removeItem(communityAddress);\n log(\"communitiesStore.deleteCommunity\", { communityAddress, community, account });\n setState((state: any) => ({\n communities: { ...state.communities, [communityAddress]: undefined },\n }));\n },\n }),\n);\n\n// reset store in between tests\nconst originalState = communitiesStore.getState();\n// async function because some stores have async init\nexport const resetCommunitiesStore = async () => {\n pkcGetCommunityPending = {};\n // remove all event listeners\n listeners.forEach((listener: any) => listener.removeAllListeners());\n // destroy all component subscriptions to the store\n communitiesStore.destroy();\n // restore original state\n communitiesStore.setState(originalState);\n};\n\n// reset database and store in between tests\nexport const resetCommunitiesDatabaseAndStore = async () => {\n await localForageLru.createInstance({ name: \"bitsocialReactHooks-communities\" }).clear();\n await resetCommunitiesStore();\n};\n\nexport default communitiesStore;\n"]}
@@ -0,0 +1,4 @@
1
+ import communitiesStore from "./communities-store.js";
2
+ export * from "./communities-store.js";
3
+ export default communitiesStore;
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/stores/communities/index.ts"],"names":[],"mappings":"AAAA,OAAO,gBAAgB,MAAM,qBAAqB,CAAC;AACnD,cAAc,qBAAqB,CAAC;AACpC,eAAe,gBAAgB,CAAC"}
@@ -0,0 +1,4 @@
1
+ import communitiesStore from "./communities-store.js";
2
+ export * from "./communities-store.js";
3
+ export default communitiesStore;
4
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/stores/communities/index.ts"],"names":[],"mappings":"AAAA,OAAO,gBAAgB,MAAM,qBAAqB,CAAC;AACnD,cAAc,qBAAqB,CAAC;AACpC,eAAe,gBAAgB,CAAC","sourcesContent":["import communitiesStore from \"./communities-store\";\nexport * from \"./communities-store\";\nexport default communitiesStore;\n"]}
@@ -0,0 +1,23 @@
1
+ import Logger from "@pkcprotocol/pkc-logger";
2
+ export declare const log: Logger;
3
+ import { Community, CommunityPage, CommunitiesPages, Comment, Comments } from "../../types.js";
4
+ /** Freshness for comparison: max(updatedAt, timestamp, 0). Used to decide add vs replace per CID. Exported for coverage. */
5
+ export declare const getCommentFreshness: (comment: Comment | undefined) => number;
6
+ type CommunitiesPagesState = {
7
+ communitiesPages: CommunitiesPages;
8
+ comments: Comments;
9
+ addNextCommunityPageToStore: Function;
10
+ invalidateCommunityPages: Function;
11
+ addCommunityPageCommentsToStore: Function;
12
+ };
13
+ declare const communitiesPagesStore: import("zustand").UseBoundStore<import("zustand").StoreApi<CommunitiesPagesState>>;
14
+ /**
15
+ * Util function to get all pages in the store for a
16
+ * specific community+sortType using `CommunityPage.nextCid`
17
+ */
18
+ export declare const getCommunityPages: (community: Community, sortType: string, communitiesPages: CommunitiesPages, pageType: string, accountId?: string) => CommunityPage[];
19
+ export declare const getCommunityFirstPageCid: (community: Community, sortType: string, pageType?: string) => any;
20
+ export declare const resetCommunitiesPagesStore: () => Promise<void>;
21
+ export declare const resetCommunitiesPagesDatabaseAndStore: () => Promise<void>;
22
+ export default communitiesPagesStore;
23
+ //# sourceMappingURL=communities-pages-store.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"communities-pages-store.d.ts","sourceRoot":"","sources":["../../../src/stores/communities-pages/communities-pages-store.ts"],"names":[],"mappings":"AACA,OAAO,MAAM,MAAM,yBAAyB,CAAC;AAE7C,eAAO,MAAM,GAAG,QAA+C,CAAC;AAChE,OAAO,EACL,SAAS,EACT,aAAa,EACb,gBAAgB,EAEhB,OAAO,EACP,QAAQ,EACT,MAAM,aAAa,CAAC;AA4BrB,4HAA4H;AAC5H,eAAO,MAAM,mBAAmB,GAAI,SAAS,OAAO,GAAG,SAAS,KAAG,MACJ,CAAC;AAKhE,KAAK,qBAAqB,GAAG;IAC3B,gBAAgB,EAAE,gBAAgB,CAAC;IACnC,QAAQ,EAAE,QAAQ,CAAC;IACnB,2BAA2B,EAAE,QAAQ,CAAC;IACtC,wBAAwB,EAAE,QAAQ,CAAC;IACnC,+BAA+B,EAAE,QAAQ,CAAC;CAC3C,CAAC;AAEF,QAAA,MAAM,qBAAqB,oFAgP1B,CAAC;AAsEF;;;GAGG;AACH,eAAO,MAAM,iBAAiB,GAC5B,WAAW,SAAS,EACpB,UAAU,MAAM,EAChB,kBAAkB,gBAAgB,EAClC,UAAU,MAAM,EAChB,YAAY,MAAM,oBA6BnB,CAAC;AAEF,eAAO,MAAM,wBAAwB,GACnC,WAAW,SAAS,EACpB,UAAU,MAAM,EAChB,iBAAkB,QAkBnB,CAAC;AAKF,eAAO,MAAM,0BAA0B,qBAYtC,CAAC;AAGF,eAAO,MAAM,qCAAqC,qBAGjD,CAAC;AAEF,eAAe,qBAAqB,CAAC"}