@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,419 @@
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 Logger from "@pkcprotocol/pkc-logger";
12
+ const log = Logger("bitsocial-react-hooks:accounts:stores");
13
+ import commentsStore from "../comments/index.js";
14
+ import repliesPagesStore from "../replies-pages/index.js";
15
+ import communitiesPagesStore from "../communities-pages/index.js";
16
+ import PkcJs from "../../lib/pkc-js/index.js";
17
+ const getAuthorAddressRolesFromCommunities = (authorAddress, communities) => {
18
+ var _a, _b;
19
+ const roles = {};
20
+ for (const communityAddress in communities) {
21
+ const role = (_b = (_a = communities[communityAddress]) === null || _a === void 0 ? void 0 : _a.roles) === null || _b === void 0 ? void 0 : _b[authorAddress];
22
+ if (role) {
23
+ roles[communityAddress] = role;
24
+ }
25
+ }
26
+ return roles;
27
+ };
28
+ export const getAccountCommunities = (account, communities) => {
29
+ var _a, _b, _c;
30
+ assert(((_a = account === null || account === void 0 ? void 0 : account.author) === null || _a === void 0 ? void 0 : _a.address) && typeof ((_b = account === null || account === void 0 ? void 0 : account.author) === null || _b === void 0 ? void 0 : _b.address) === "string", `accountsStore utils getAccountCommunities invalid account.author.address '${(_c = account === null || account === void 0 ? void 0 : account.author) === null || _c === void 0 ? void 0 : _c.address}'`);
31
+ assert(communities && typeof communities === "object", `accountsStore utils getAccountCommunities invalid communities '${communities}'`);
32
+ const roles = getAuthorAddressRolesFromCommunities(account.author.address, communities);
33
+ const accountCommunities = Object.assign({}, account.communities);
34
+ for (const communityAddress in roles) {
35
+ accountCommunities[communityAddress] = Object.assign({}, accountCommunities[communityAddress]);
36
+ accountCommunities[communityAddress].role = roles[communityAddress];
37
+ }
38
+ return accountCommunities;
39
+ };
40
+ export const getCommentCidsToAccountsComments = (accountsComments) => {
41
+ const commentCidsToAccountsComments = {};
42
+ for (const accountId in accountsComments) {
43
+ for (const accountComment of accountsComments[accountId]) {
44
+ if (accountComment.cid) {
45
+ commentCidsToAccountsComments[accountComment.cid] = {
46
+ accountId,
47
+ accountCommentIndex: accountComment.index,
48
+ };
49
+ }
50
+ }
51
+ }
52
+ return commentCidsToAccountsComments;
53
+ };
54
+ const cloneWithoutFunctions = (value) => {
55
+ if (Array.isArray(value)) {
56
+ return value
57
+ .map((entry) => cloneWithoutFunctions(entry))
58
+ .filter((entry) => entry !== undefined);
59
+ }
60
+ if (!value || typeof value !== "object") {
61
+ return typeof value === "function" ? undefined : value;
62
+ }
63
+ const clonedValue = {};
64
+ for (const key in value) {
65
+ if (typeof value[key] === "function") {
66
+ continue;
67
+ }
68
+ const clonedChild = cloneWithoutFunctions(value[key]);
69
+ if (clonedChild !== undefined) {
70
+ clonedValue[key] = clonedChild;
71
+ }
72
+ }
73
+ return clonedValue;
74
+ };
75
+ const compactStoredCommentAuthor = (author) => {
76
+ if (!author || typeof author !== "object") {
77
+ return undefined;
78
+ }
79
+ const compactAuthor = cloneWithoutFunctions({
80
+ address: author.address,
81
+ shortAddress: author.shortAddress,
82
+ displayName: author.displayName,
83
+ avatar: author.avatar,
84
+ flair: author.flair,
85
+ });
86
+ return compactAuthor && Object.keys(compactAuthor).length > 0 ? compactAuthor : undefined;
87
+ };
88
+ const compactStoredOriginalComment = (originalComment) => {
89
+ if (!originalComment || typeof originalComment !== "object") {
90
+ return undefined;
91
+ }
92
+ const compactOriginalComment = cloneWithoutFunctions({
93
+ cid: originalComment.cid,
94
+ content: originalComment.content,
95
+ title: originalComment.title,
96
+ link: originalComment.link,
97
+ linkWidth: originalComment.linkWidth,
98
+ linkHeight: originalComment.linkHeight,
99
+ linkHtmlTagName: originalComment.linkHtmlTagName,
100
+ thumbnailUrl: originalComment.thumbnailUrl,
101
+ media: originalComment.media,
102
+ spoiler: originalComment.spoiler,
103
+ nsfw: originalComment.nsfw,
104
+ deleted: originalComment.deleted,
105
+ removed: originalComment.removed,
106
+ reason: originalComment.reason,
107
+ quotedCids: originalComment.quotedCids,
108
+ parentCid: originalComment.parentCid,
109
+ postCid: originalComment.postCid,
110
+ communityAddress: originalComment.communityAddress,
111
+ timestamp: originalComment.timestamp,
112
+ author: compactStoredCommentAuthor(originalComment.author),
113
+ });
114
+ return compactOriginalComment && Object.keys(compactOriginalComment).length > 0
115
+ ? compactOriginalComment
116
+ : undefined;
117
+ };
118
+ const compactStoredReplies = (replies) => {
119
+ if (!replies || typeof replies !== "object") {
120
+ return undefined;
121
+ }
122
+ const compactReplies = cloneWithoutFunctions(Object.fromEntries(Object.entries(replies).filter(([replyKey]) => replyKey !== "pages" && replyKey !== "clients")));
123
+ return compactReplies && Object.keys(compactReplies).length > 0 ? compactReplies : undefined;
124
+ };
125
+ export const sanitizeAccountCommentForState = (comment) => {
126
+ var _a;
127
+ const sanitizedComment = cloneWithoutFunctions(Object.assign(Object.assign({}, comment), { signer: undefined, raw: undefined, replies: (comment === null || comment === void 0 ? void 0 : comment.replies)
128
+ ? Object.fromEntries(Object.entries(comment.replies).filter(([replyKey]) => replyKey !== "pages"))
129
+ : comment === null || comment === void 0 ? void 0 : comment.replies }));
130
+ if (!sanitizedComment || typeof sanitizedComment !== "object") {
131
+ return sanitizedComment;
132
+ }
133
+ if ((_a = sanitizedComment === null || sanitizedComment === void 0 ? void 0 : sanitizedComment.replies) === null || _a === void 0 ? void 0 : _a.pages) {
134
+ sanitizedComment.replies = Object.assign({}, sanitizedComment.replies);
135
+ delete sanitizedComment.replies.pages;
136
+ }
137
+ if ((sanitizedComment === null || sanitizedComment === void 0 ? void 0 : sanitizedComment.replies) && Object.keys(sanitizedComment.replies).length === 0) {
138
+ delete sanitizedComment.replies;
139
+ }
140
+ return sanitizedComment;
141
+ };
142
+ export const sanitizeStoredAccountComment = (comment) => {
143
+ const preprocessedComment = Object.assign(Object.assign({}, comment), { signer: undefined, clients: undefined, raw: undefined, replies: compactStoredReplies(comment === null || comment === void 0 ? void 0 : comment.replies), original: (comment === null || comment === void 0 ? void 0 : comment.edit) ? compactStoredOriginalComment(comment.original) : undefined });
144
+ const sanitizedComment = cloneWithoutFunctions(preprocessedComment);
145
+ if (!sanitizedComment || typeof sanitizedComment !== "object") {
146
+ return sanitizedComment;
147
+ }
148
+ if ((sanitizedComment === null || sanitizedComment === void 0 ? void 0 : sanitizedComment.replies) && Object.keys(sanitizedComment.replies).length === 0) {
149
+ delete sanitizedComment.replies;
150
+ }
151
+ if ((sanitizedComment === null || sanitizedComment === void 0 ? void 0 : sanitizedComment.original) && Object.keys(sanitizedComment.original).length === 0) {
152
+ delete sanitizedComment.original;
153
+ }
154
+ return sanitizedComment;
155
+ };
156
+ export const getAccountCommentsIndex = (accountComments) => {
157
+ const index = {
158
+ byCommunityAddress: {},
159
+ byParentCid: {},
160
+ };
161
+ for (const accountComment of accountComments || []) {
162
+ if (accountComment.communityAddress) {
163
+ if (!index.byCommunityAddress[accountComment.communityAddress]) {
164
+ index.byCommunityAddress[accountComment.communityAddress] = [];
165
+ }
166
+ index.byCommunityAddress[accountComment.communityAddress].push(accountComment.index);
167
+ }
168
+ if (accountComment.parentCid) {
169
+ if (!index.byParentCid[accountComment.parentCid]) {
170
+ index.byParentCid[accountComment.parentCid] = [];
171
+ }
172
+ index.byParentCid[accountComment.parentCid].push(accountComment.index);
173
+ }
174
+ }
175
+ return index;
176
+ };
177
+ export const getAccountsCommentsIndexes = (accountsComments) => {
178
+ const indexes = {};
179
+ for (const accountId in accountsComments) {
180
+ indexes[accountId] = getAccountCommentsIndex(accountsComments[accountId]);
181
+ }
182
+ return indexes;
183
+ };
184
+ const accountEditNonPropertyNames = new Set([
185
+ "author",
186
+ "signer",
187
+ "clientId",
188
+ "commentCid",
189
+ "communityAddress",
190
+ "communityAddress",
191
+ "timestamp",
192
+ ]);
193
+ const normalizeAccountEditForSummary = (accountEdit) => {
194
+ var _a;
195
+ const normalizedAccountEdit = Object.assign({}, accountEdit);
196
+ if (normalizedAccountEdit.commentModeration) {
197
+ Object.assign(normalizedAccountEdit, normalizedAccountEdit.commentModeration);
198
+ delete normalizedAccountEdit.commentModeration;
199
+ }
200
+ const communityEdit = (_a = normalizedAccountEdit.communityEdit) !== null && _a !== void 0 ? _a : normalizedAccountEdit.communityEdit;
201
+ if (communityEdit && typeof communityEdit === "object") {
202
+ Object.assign(normalizedAccountEdit, communityEdit);
203
+ }
204
+ delete normalizedAccountEdit.communityEdit;
205
+ delete normalizedAccountEdit.communityEdit;
206
+ return normalizedAccountEdit;
207
+ };
208
+ export const getAccountEditPropertySummary = (accountEdits) => {
209
+ var _a;
210
+ const accountEditPropertySummary = {};
211
+ for (const accountEdit of accountEdits || []) {
212
+ const normalizedAccountEdit = normalizeAccountEditForSummary(accountEdit);
213
+ for (const propertyName in normalizedAccountEdit) {
214
+ if (normalizedAccountEdit[propertyName] === undefined ||
215
+ accountEditNonPropertyNames.has(propertyName)) {
216
+ continue;
217
+ }
218
+ const previousTimestamp = ((_a = accountEditPropertySummary[propertyName]) === null || _a === void 0 ? void 0 : _a.timestamp) || 0;
219
+ if ((normalizedAccountEdit.timestamp || 0) >= previousTimestamp) {
220
+ accountEditPropertySummary[propertyName] = {
221
+ timestamp: normalizedAccountEdit.timestamp,
222
+ value: normalizedAccountEdit[propertyName],
223
+ };
224
+ }
225
+ }
226
+ }
227
+ return accountEditPropertySummary;
228
+ };
229
+ export const getAccountsEditsSummary = (accountEdits) => {
230
+ const summary = {};
231
+ for (const target in accountEdits || {}) {
232
+ summary[target] = getAccountEditPropertySummary(accountEdits[target]);
233
+ }
234
+ return summary;
235
+ };
236
+ // polyfill Promise.any, exported for test coverage of empty-array branch
237
+ const promiseAny = (promises) => new Promise((res, rej) => {
238
+ let count = promises.length;
239
+ if (count === 0)
240
+ return rej(Error("all promises rejected"));
241
+ promises.forEach((p) => Promise.resolve(p)
242
+ .then(res)
243
+ .catch((e) => {
244
+ if (--count === 0)
245
+ rej(Error("all promises rejected"));
246
+ }));
247
+ });
248
+ export const fetchCommentLinkDimensions = (link) => __awaiter(void 0, void 0, void 0, function* () {
249
+ if (!link) {
250
+ return {};
251
+ }
252
+ const fetchImageDimensions = (url) => new Promise((resolve, reject) => {
253
+ const image = new Image();
254
+ image.onload = () => {
255
+ // don't accept 0px value
256
+ if (!image.width || !image.height) {
257
+ return reject(Error(`failed fetching image dimensions for url '${url}'`));
258
+ }
259
+ resolve({
260
+ linkWidth: image.width,
261
+ linkHeight: image.height,
262
+ linkHtmlTagName: "img",
263
+ });
264
+ // remove image from memory
265
+ try {
266
+ image.src = "";
267
+ }
268
+ catch (e) { }
269
+ };
270
+ image.onerror = (error) => {
271
+ reject(Error(`failed fetching image dimensions for url '${url}'`));
272
+ };
273
+ // max loading time
274
+ const timeout = 10000;
275
+ setTimeout(() => reject(Error(`failed fetching image dimensions for url '${url}' timeout '${timeout}'`)), timeout);
276
+ // start loading
277
+ image.src = url;
278
+ });
279
+ const fetchVideoDimensions = (url) => new Promise((resolve, reject) => {
280
+ const video = document.createElement("video");
281
+ video.muted = true;
282
+ video.loop = false;
283
+ video.addEventListener("loadeddata", () => {
284
+ // don't accept 0px value
285
+ if (!video.videoWidth || !video.videoHeight) {
286
+ return reject(Error(`failed fetching video dimensions for url '${url}'`));
287
+ }
288
+ resolve({
289
+ linkWidth: video.videoWidth,
290
+ linkHeight: video.videoHeight,
291
+ linkHtmlTagName: "video",
292
+ });
293
+ // prevent video from playing
294
+ try {
295
+ video.pause();
296
+ }
297
+ catch (e) { }
298
+ // prevent video from loading
299
+ try {
300
+ video.src = "";
301
+ }
302
+ catch (e) { }
303
+ });
304
+ video.addEventListener("error", (error) => {
305
+ reject(Error(`failed fetching video dimensions for url '${url}'`));
306
+ });
307
+ // max loading time
308
+ const timeout = 30000;
309
+ setTimeout(() => reject(Error(`failed fetching video dimensions for url '${url}' timeout '${timeout}'`)), timeout);
310
+ // start loading
311
+ video.src = url;
312
+ });
313
+ const fetchAudio = (url) => new Promise((resolve, reject) => {
314
+ const audio = document.createElement("audio");
315
+ audio.addEventListener("loadeddata", () => {
316
+ resolve({
317
+ linkHtmlTagName: "audio",
318
+ });
319
+ try {
320
+ audio.pause();
321
+ }
322
+ catch (_a) { }
323
+ try {
324
+ audio.src = "";
325
+ }
326
+ catch (_b) { }
327
+ });
328
+ audio.addEventListener("error", () => reject(Error(`failed fetching audio html tag name for url '${url}'`)));
329
+ const timeout = 20000;
330
+ setTimeout(() => reject(Error(`failed fetching audio html tag name for url '${url}' timeout '${timeout}'`)), timeout);
331
+ audio.src = url;
332
+ });
333
+ try {
334
+ if (new URL(link).protocol !== "https:") {
335
+ throw Error(`failed fetching comment.link dimensions for link '${link}' not https protocol`);
336
+ }
337
+ const dimensions = yield promiseAny([
338
+ fetchImageDimensions(link),
339
+ fetchVideoDimensions(link),
340
+ fetchAudio(link),
341
+ ]);
342
+ return dimensions;
343
+ }
344
+ catch (error) {
345
+ log.error("fetchCommentLinkDimensions error", { error, link });
346
+ return {};
347
+ }
348
+ });
349
+ export const getInitAccountCommentsToUpdate = (accountsComments) => {
350
+ const accountCommentsToUpdate = [];
351
+ for (const accountId in accountsComments) {
352
+ for (const accountComment of accountsComments[accountId]) {
353
+ accountCommentsToUpdate.push({ accountComment, accountId });
354
+ }
355
+ }
356
+ // update newer comments first, more likely to have notifications
357
+ accountCommentsToUpdate.sort((a, b) => b.accountComment.timestamp - a.accountComment.timestamp);
358
+ // updating too many comments during init slows down fetching comments/subs
359
+ if (accountCommentsToUpdate.length > 10) {
360
+ accountCommentsToUpdate.length = 10;
361
+ }
362
+ // TODO: add some algo to fetch all notifications (even old), but not on init
363
+ // during downtimes when we're not fetching anything else
364
+ return accountCommentsToUpdate;
365
+ };
366
+ export const getAccountCommentDepth = (comment) => {
367
+ var _a, _b, _c;
368
+ if (!comment.parentCid) {
369
+ return 0;
370
+ }
371
+ let parentCommentDepth = (_a = commentsStore.getState().comments[comment.parentCid]) === null || _a === void 0 ? void 0 : _a.depth;
372
+ if (typeof parentCommentDepth === "number") {
373
+ return parentCommentDepth + 1;
374
+ }
375
+ parentCommentDepth = (_b = repliesPagesStore.getState().comments[comment.parentCid]) === null || _b === void 0 ? void 0 : _b.depth;
376
+ if (typeof parentCommentDepth === "number") {
377
+ return parentCommentDepth + 1;
378
+ }
379
+ parentCommentDepth = (_c = communitiesPagesStore.getState().comments[comment.parentCid]) === null || _c === void 0 ? void 0 : _c.depth;
380
+ if (typeof parentCommentDepth === "number") {
381
+ return parentCommentDepth + 1;
382
+ }
383
+ // if can't find the parent comment depth anywhere, don't include it with the account comment
384
+ // it will be added automatically when challenge verification is received
385
+ };
386
+ export const addShortAddressesToAccountComment = (comment) => {
387
+ comment = Object.assign({}, comment);
388
+ try {
389
+ comment.shortCommunityAddress = PkcJs.PKC.getShortAddress({
390
+ address: comment.communityAddress,
391
+ });
392
+ }
393
+ catch (e) { }
394
+ try {
395
+ comment.author = Object.assign({}, comment.author);
396
+ comment.author.shortAddress = PkcJs.PKC.getShortAddress({
397
+ address: comment.author.address,
398
+ });
399
+ }
400
+ catch (e) { }
401
+ return comment;
402
+ };
403
+ const utils = {
404
+ getAccountCommunities,
405
+ getCommentCidsToAccountsComments,
406
+ getAccountCommentsIndex,
407
+ getAccountsCommentsIndexes,
408
+ sanitizeAccountCommentForState,
409
+ sanitizeStoredAccountComment,
410
+ getAccountEditPropertySummary,
411
+ getAccountsEditsSummary,
412
+ fetchCommentLinkDimensions,
413
+ getInitAccountCommentsToUpdate,
414
+ getAccountCommentDepth,
415
+ addShortAddressesToAccountComment,
416
+ promiseAny,
417
+ };
418
+ export default utils;
419
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/stores/accounts/utils.ts"],"names":[],"mappings":";;;;;;;;;AAaA,OAAO,MAAM,MAAM,QAAQ,CAAC;AAC5B,OAAO,MAAM,MAAM,yBAAyB,CAAC;AAC7C,MAAM,GAAG,GAAG,MAAM,CAAC,uCAAuC,CAAC,CAAC;AAC5D,OAAO,aAAa,MAAM,aAAa,CAAC;AACxC,OAAO,iBAAiB,MAAM,kBAAkB,CAAC;AACjD,OAAO,qBAAqB,MAAM,sBAAsB,CAAC;AACzD,OAAO,KAAK,MAAM,kBAAkB,CAAC;AAErC,MAAM,oCAAoC,GAAG,CAAC,aAAqB,EAAE,WAAwB,EAAE,EAAE;;IAC/F,MAAM,KAAK,GAAyC,EAAE,CAAC;IACvD,KAAK,MAAM,gBAAgB,IAAI,WAAW,EAAE,CAAC;QAC3C,MAAM,IAAI,GAAG,MAAA,MAAA,WAAW,CAAC,gBAAgB,CAAC,0CAAE,KAAK,0CAAG,aAAa,CAAC,CAAC;QACnE,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,CAAC,qBAAqB,GAAG,KAAK,CAAC,GAAG,CAAC,eAAe,CAAC;YACxD,OAAO,EAAE,OAAO,CAAC,gBAAgB;SAClC,CAAC,CAAC;IACL,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC,CAAA,CAAC;IACd,IAAI,CAAC;QACH,OAAO,CAAC,MAAM,qBAAQ,OAAO,CAAC,MAAM,CAAE,CAAC;QACvC,OAAO,CAAC,MAAM,CAAC,YAAY,GAAG,KAAK,CAAC,GAAG,CAAC,eAAe,CAAC;YACtD,OAAO,EAAE,OAAO,CAAC,MAAM,CAAC,OAAO;SAChC,CAAC,CAAC;IACL,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC,CAAA,CAAC;IACd,OAAO,OAAO,CAAC;AACjB,CAAC,CAAC;AAEF,MAAM,KAAK,GAAG;IACZ,qBAAqB;IACrB,gCAAgC;IAChC,uBAAuB;IACvB,0BAA0B;IAC1B,8BAA8B;IAC9B,4BAA4B;IAC5B,6BAA6B;IAC7B,uBAAuB;IACvB,0BAA0B;IAC1B,8BAA8B;IAC9B,sBAAsB;IACtB,iCAAiC;IACjC,UAAU;CACX,CAAC;AAEF,eAAe,KAAK,CAAC","sourcesContent":["import {\n Account,\n Role,\n Communities,\n AccountComment,\n AccountsComments,\n AccountsCommentsIndexes,\n AccountCommentsIndex,\n CommentCidsToAccountsComments,\n Comment,\n AccountEdit,\n AccountEditsSummary,\n} from \"../../types\";\nimport assert from \"assert\";\nimport Logger from \"@pkcprotocol/pkc-logger\";\nconst log = Logger(\"bitsocial-react-hooks:accounts:stores\");\nimport commentsStore from \"../comments\";\nimport repliesPagesStore from \"../replies-pages\";\nimport communitiesPagesStore from \"../communities-pages\";\nimport PkcJs from \"../../lib/pkc-js\";\n\nconst getAuthorAddressRolesFromCommunities = (authorAddress: string, communities: Communities) => {\n const roles: { [communityAddress: string]: Role } = {};\n for (const communityAddress in communities) {\n const role = communities[communityAddress]?.roles?.[authorAddress];\n if (role) {\n roles[communityAddress] = role;\n }\n }\n return roles;\n};\n\nexport const getAccountCommunities = (account: Account, communities: Communities) => {\n assert(\n account?.author?.address && typeof account?.author?.address === \"string\",\n `accountsStore utils getAccountCommunities invalid account.author.address '${account?.author?.address}'`,\n );\n assert(\n communities && typeof communities === \"object\",\n `accountsStore utils getAccountCommunities invalid communities '${communities}'`,\n );\n\n const roles = getAuthorAddressRolesFromCommunities(account.author.address, communities);\n const accountCommunities = { ...account.communities };\n for (const communityAddress in roles) {\n accountCommunities[communityAddress] = { ...accountCommunities[communityAddress] };\n accountCommunities[communityAddress].role = roles[communityAddress];\n }\n return accountCommunities;\n};\n\nexport const getCommentCidsToAccountsComments = (accountsComments: AccountsComments) => {\n const commentCidsToAccountsComments: CommentCidsToAccountsComments = {};\n for (const accountId in accountsComments) {\n for (const accountComment of accountsComments[accountId]) {\n if (accountComment.cid) {\n commentCidsToAccountsComments[accountComment.cid] = {\n accountId,\n accountCommentIndex: accountComment.index,\n };\n }\n }\n }\n return commentCidsToAccountsComments;\n};\n\nconst cloneWithoutFunctions = (value: any): any => {\n if (Array.isArray(value)) {\n return value\n .map((entry) => cloneWithoutFunctions(entry))\n .filter((entry) => entry !== undefined);\n }\n if (!value || typeof value !== \"object\") {\n return typeof value === \"function\" ? undefined : value;\n }\n\n const clonedValue: Record<string, any> = {};\n for (const key in value) {\n if (typeof value[key] === \"function\") {\n continue;\n }\n const clonedChild = cloneWithoutFunctions(value[key]);\n if (clonedChild !== undefined) {\n clonedValue[key] = clonedChild;\n }\n }\n return clonedValue;\n};\n\nconst compactStoredCommentAuthor = (author: any) => {\n if (!author || typeof author !== \"object\") {\n return undefined;\n }\n\n const compactAuthor = cloneWithoutFunctions({\n address: author.address,\n shortAddress: author.shortAddress,\n displayName: author.displayName,\n avatar: author.avatar,\n flair: author.flair,\n });\n\n return compactAuthor && Object.keys(compactAuthor).length > 0 ? compactAuthor : undefined;\n};\n\nconst compactStoredOriginalComment = (originalComment: any) => {\n if (!originalComment || typeof originalComment !== \"object\") {\n return undefined;\n }\n\n const compactOriginalComment = cloneWithoutFunctions({\n cid: originalComment.cid,\n content: originalComment.content,\n title: originalComment.title,\n link: originalComment.link,\n linkWidth: originalComment.linkWidth,\n linkHeight: originalComment.linkHeight,\n linkHtmlTagName: originalComment.linkHtmlTagName,\n thumbnailUrl: originalComment.thumbnailUrl,\n media: originalComment.media,\n spoiler: originalComment.spoiler,\n nsfw: originalComment.nsfw,\n deleted: originalComment.deleted,\n removed: originalComment.removed,\n reason: originalComment.reason,\n quotedCids: originalComment.quotedCids,\n parentCid: originalComment.parentCid,\n postCid: originalComment.postCid,\n communityAddress: originalComment.communityAddress,\n timestamp: originalComment.timestamp,\n author: compactStoredCommentAuthor(originalComment.author),\n });\n\n return compactOriginalComment && Object.keys(compactOriginalComment).length > 0\n ? compactOriginalComment\n : undefined;\n};\n\nconst compactStoredReplies = (replies: any) => {\n if (!replies || typeof replies !== \"object\") {\n return undefined;\n }\n\n const compactReplies = cloneWithoutFunctions(\n Object.fromEntries(\n Object.entries(replies).filter(\n ([replyKey]) => replyKey !== \"pages\" && replyKey !== \"clients\",\n ),\n ),\n );\n\n return compactReplies && Object.keys(compactReplies).length > 0 ? compactReplies : undefined;\n};\n\nexport const sanitizeAccountCommentForState = (comment: Comment) => {\n const sanitizedComment = cloneWithoutFunctions({\n ...comment,\n signer: undefined,\n raw: undefined,\n replies: comment?.replies\n ? Object.fromEntries(\n Object.entries(comment.replies).filter(([replyKey]) => replyKey !== \"pages\"),\n )\n : comment?.replies,\n });\n\n if (!sanitizedComment || typeof sanitizedComment !== \"object\") {\n return sanitizedComment;\n }\n if (sanitizedComment?.replies?.pages) {\n sanitizedComment.replies = { ...sanitizedComment.replies };\n delete sanitizedComment.replies.pages;\n }\n if (sanitizedComment?.replies && Object.keys(sanitizedComment.replies).length === 0) {\n delete sanitizedComment.replies;\n }\n return sanitizedComment;\n};\n\nexport const sanitizeStoredAccountComment = (comment: Comment) => {\n const preprocessedComment = {\n ...comment,\n signer: undefined,\n clients: undefined,\n raw: undefined,\n replies: compactStoredReplies(comment?.replies),\n original: comment?.edit ? compactStoredOriginalComment(comment.original) : undefined,\n };\n const sanitizedComment = cloneWithoutFunctions(preprocessedComment);\n if (!sanitizedComment || typeof sanitizedComment !== \"object\") {\n return sanitizedComment;\n }\n if (sanitizedComment?.replies && Object.keys(sanitizedComment.replies).length === 0) {\n delete sanitizedComment.replies;\n }\n if (sanitizedComment?.original && Object.keys(sanitizedComment.original).length === 0) {\n delete sanitizedComment.original;\n }\n return sanitizedComment;\n};\n\nexport const getAccountCommentsIndex = (\n accountComments: AccountComment[] | undefined,\n): AccountCommentsIndex => {\n const index: AccountCommentsIndex = {\n byCommunityAddress: {},\n byParentCid: {},\n };\n for (const accountComment of accountComments || []) {\n if (accountComment.communityAddress) {\n if (!index.byCommunityAddress[accountComment.communityAddress]) {\n index.byCommunityAddress[accountComment.communityAddress] = [];\n }\n index.byCommunityAddress[accountComment.communityAddress].push(accountComment.index);\n }\n if (accountComment.parentCid) {\n if (!index.byParentCid[accountComment.parentCid]) {\n index.byParentCid[accountComment.parentCid] = [];\n }\n index.byParentCid[accountComment.parentCid].push(accountComment.index);\n }\n }\n return index;\n};\n\nexport const getAccountsCommentsIndexes = (accountsComments: AccountsComments) => {\n const indexes: AccountsCommentsIndexes = {};\n for (const accountId in accountsComments) {\n indexes[accountId] = getAccountCommentsIndex(accountsComments[accountId]);\n }\n return indexes;\n};\n\nconst accountEditNonPropertyNames = new Set([\n \"author\",\n \"signer\",\n \"clientId\",\n \"commentCid\",\n \"communityAddress\",\n \"communityAddress\",\n \"timestamp\",\n]);\n\nconst normalizeAccountEditForSummary = (accountEdit: AccountEdit) => {\n const normalizedAccountEdit = { ...accountEdit };\n if (normalizedAccountEdit.commentModeration) {\n Object.assign(normalizedAccountEdit, normalizedAccountEdit.commentModeration);\n delete normalizedAccountEdit.commentModeration;\n }\n const communityEdit = normalizedAccountEdit.communityEdit ?? normalizedAccountEdit.communityEdit;\n if (communityEdit && typeof communityEdit === \"object\") {\n Object.assign(normalizedAccountEdit, communityEdit);\n }\n delete normalizedAccountEdit.communityEdit;\n delete normalizedAccountEdit.communityEdit;\n return normalizedAccountEdit;\n};\n\nexport const getAccountEditPropertySummary = (accountEdits: AccountEdit[] | undefined) => {\n const accountEditPropertySummary: AccountEditsSummary[string] = {};\n for (const accountEdit of accountEdits || []) {\n const normalizedAccountEdit = normalizeAccountEditForSummary(accountEdit);\n for (const propertyName in normalizedAccountEdit) {\n if (\n normalizedAccountEdit[propertyName] === undefined ||\n accountEditNonPropertyNames.has(propertyName)\n ) {\n continue;\n }\n const previousTimestamp = accountEditPropertySummary[propertyName]?.timestamp || 0;\n if ((normalizedAccountEdit.timestamp || 0) >= previousTimestamp) {\n accountEditPropertySummary[propertyName] = {\n timestamp: normalizedAccountEdit.timestamp,\n value: normalizedAccountEdit[propertyName],\n };\n }\n }\n }\n return accountEditPropertySummary;\n};\n\nexport const getAccountsEditsSummary = (accountEdits: {\n [commentCidOrCommunityAddress: string]: AccountEdit[];\n}) => {\n const summary: AccountEditsSummary = {};\n for (const target in accountEdits || {}) {\n summary[target] = getAccountEditPropertySummary(accountEdits[target]);\n }\n return summary;\n};\n\ninterface CommentLinkDimensions {\n linkWidth?: number;\n linkHeight?: number;\n linkHtmlTagName?: \"img\" | \"video\" | \"audio\";\n}\n\n// polyfill Promise.any, exported for test coverage of empty-array branch\nconst promiseAny = <T>(promises: Promise<T>[]): Promise<T> =>\n new Promise((res, rej) => {\n let count = promises.length;\n if (count === 0) return rej(Error(\"all promises rejected\"));\n promises.forEach((p) =>\n Promise.resolve(p)\n .then(res)\n .catch((e) => {\n if (--count === 0) rej(Error(\"all promises rejected\"));\n }),\n );\n });\n\nexport const fetchCommentLinkDimensions = async (link: string): Promise<CommentLinkDimensions> => {\n if (!link) {\n return {};\n }\n\n const fetchImageDimensions = (url: string) =>\n new Promise<CommentLinkDimensions>((resolve, reject) => {\n const image = new Image();\n image.onload = () => {\n // don't accept 0px value\n if (!image.width || !image.height) {\n return reject(Error(`failed fetching image dimensions for url '${url}'`));\n }\n resolve({\n linkWidth: image.width,\n linkHeight: image.height,\n linkHtmlTagName: \"img\",\n });\n\n // remove image from memory\n try {\n image.src = \"\";\n } catch (e) {}\n };\n image.onerror = (error) => {\n reject(Error(`failed fetching image dimensions for url '${url}'`));\n };\n\n // max loading time\n const timeout = 10000;\n setTimeout(\n () =>\n reject(Error(`failed fetching image dimensions for url '${url}' timeout '${timeout}'`)),\n timeout,\n );\n\n // start loading\n image.src = url;\n });\n\n const fetchVideoDimensions = (url: string) =>\n new Promise<CommentLinkDimensions>((resolve, reject) => {\n const video = document.createElement(\"video\");\n video.muted = true;\n video.loop = false;\n video.addEventListener(\"loadeddata\", () => {\n // don't accept 0px value\n if (!video.videoWidth || !video.videoHeight) {\n return reject(Error(`failed fetching video dimensions for url '${url}'`));\n }\n resolve({\n linkWidth: video.videoWidth,\n linkHeight: video.videoHeight,\n linkHtmlTagName: \"video\",\n });\n // prevent video from playing\n try {\n video.pause();\n } catch (e) {}\n // prevent video from loading\n try {\n video.src = \"\";\n } catch (e) {}\n });\n video.addEventListener(\"error\", (error) => {\n reject(Error(`failed fetching video dimensions for url '${url}'`));\n });\n\n // max loading time\n const timeout = 30000;\n setTimeout(\n () =>\n reject(Error(`failed fetching video dimensions for url '${url}' timeout '${timeout}'`)),\n timeout,\n );\n\n // start loading\n video.src = url;\n });\n\n const fetchAudio = (url: string) =>\n new Promise<CommentLinkDimensions>((resolve, reject) => {\n const audio = document.createElement(\"audio\");\n audio.addEventListener(\"loadeddata\", () => {\n resolve({\n linkHtmlTagName: \"audio\",\n });\n try {\n audio.pause();\n } catch {}\n try {\n audio.src = \"\";\n } catch {}\n });\n audio.addEventListener(\"error\", () =>\n reject(Error(`failed fetching audio html tag name for url '${url}'`)),\n );\n\n const timeout = 20000;\n setTimeout(\n () =>\n reject(\n Error(`failed fetching audio html tag name for url '${url}' timeout '${timeout}'`),\n ),\n timeout,\n );\n\n audio.src = url;\n });\n\n try {\n if (new URL(link).protocol !== \"https:\") {\n throw Error(`failed fetching comment.link dimensions for link '${link}' not https protocol`);\n }\n const dimensions = await promiseAny([\n fetchImageDimensions(link),\n fetchVideoDimensions(link),\n fetchAudio(link),\n ]);\n return dimensions;\n } catch (error: any) {\n log.error(\"fetchCommentLinkDimensions error\", { error, link });\n return {};\n }\n};\n\nexport const getInitAccountCommentsToUpdate = (accountsComments: AccountsComments) => {\n const accountCommentsToUpdate: { accountComment: AccountComment; accountId: string }[] = [];\n for (const accountId in accountsComments) {\n for (const accountComment of accountsComments[accountId]) {\n accountCommentsToUpdate.push({ accountComment, accountId });\n }\n }\n\n // update newer comments first, more likely to have notifications\n accountCommentsToUpdate.sort((a, b) => b.accountComment.timestamp - a.accountComment.timestamp);\n\n // updating too many comments during init slows down fetching comments/subs\n if (accountCommentsToUpdate.length > 10) {\n accountCommentsToUpdate.length = 10;\n }\n\n // TODO: add some algo to fetch all notifications (even old), but not on init\n // during downtimes when we're not fetching anything else\n return accountCommentsToUpdate;\n};\n\nexport const getAccountCommentDepth = (comment: Comment) => {\n if (!comment.parentCid) {\n return 0;\n }\n let parentCommentDepth = commentsStore.getState().comments[comment.parentCid]?.depth;\n if (typeof parentCommentDepth === \"number\") {\n return parentCommentDepth + 1;\n }\n parentCommentDepth = repliesPagesStore.getState().comments[comment.parentCid]?.depth;\n if (typeof parentCommentDepth === \"number\") {\n return parentCommentDepth + 1;\n }\n parentCommentDepth = communitiesPagesStore.getState().comments[comment.parentCid]?.depth;\n if (typeof parentCommentDepth === \"number\") {\n return parentCommentDepth + 1;\n }\n // if can't find the parent comment depth anywhere, don't include it with the account comment\n // it will be added automatically when challenge verification is received\n};\n\nexport const addShortAddressesToAccountComment = (comment: Comment) => {\n comment = { ...comment };\n try {\n comment.shortCommunityAddress = PkcJs.PKC.getShortAddress({\n address: comment.communityAddress,\n });\n } catch (e) {}\n try {\n comment.author = { ...comment.author };\n comment.author.shortAddress = PkcJs.PKC.getShortAddress({\n address: comment.author.address,\n });\n } catch (e) {}\n return comment;\n};\n\nconst utils = {\n getAccountCommunities,\n getCommentCidsToAccountsComments,\n getAccountCommentsIndex,\n getAccountsCommentsIndexes,\n sanitizeAccountCommentForState,\n sanitizeStoredAccountComment,\n getAccountEditPropertySummary,\n getAccountsEditsSummary,\n fetchCommentLinkDimensions,\n getInitAccountCommentsToUpdate,\n getAccountCommentDepth,\n addShortAddressesToAccountComment,\n promiseAny,\n};\n\nexport default utils;\n"]}
@@ -0,0 +1,37 @@
1
+ import { AuthorCommentsOptions, Comment } from "../../types.js";
2
+ export declare const commentsPerPage = 25;
3
+ export declare const commentBufferSize = 50;
4
+ type AuthorsCommentsState = {
5
+ options: {
6
+ [authorCommentsName: string]: AuthorCommentsOptions;
7
+ };
8
+ loadedComments: {
9
+ [authorCommentsName: string]: Comment[];
10
+ };
11
+ hasMoreBufferedComments: {
12
+ [authorCommentsName: string]: boolean;
13
+ };
14
+ bufferedCommentCids: {
15
+ [authorAddress: string]: Set<string>;
16
+ };
17
+ nextCommentCidsToFetch: {
18
+ [authorAddress: string]: string | undefined;
19
+ };
20
+ shouldFetchNextComment: {
21
+ [authorAddress: string]: boolean;
22
+ };
23
+ lastCommentCids: {
24
+ [authorAddress: string]: string | undefined;
25
+ };
26
+ addAuthorCommentsToStore: Function;
27
+ setNextCommentCidsToFetch: Function;
28
+ incrementPageNumber: Function;
29
+ addBufferedCommentCid: Function;
30
+ updateLoadedComments: Function;
31
+ setLastCommentCid: Function;
32
+ };
33
+ declare const authorsCommentsStore: import("zustand").UseBoundStore<import("zustand").StoreApi<AuthorsCommentsState>>;
34
+ export declare const resetAuthorsCommentsStore: () => Promise<void>;
35
+ export declare const resetAuthorsCommentsDatabaseAndStore: () => Promise<void>;
36
+ export default authorsCommentsStore;
37
+ //# sourceMappingURL=authors-comments-store.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"authors-comments-store.d.ts","sourceRoot":"","sources":["../../../src/stores/authors-comments/authors-comments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