@repzo/widget-react-native 1.4.0 → 1.5.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 (51) hide show
  1. package/CHANGELOG.md +36 -0
  2. package/README.md +36 -2
  3. package/lib/commonjs/api/client.js +29 -5
  4. package/lib/commonjs/api/client.js.map +1 -1
  5. package/lib/commonjs/index.js.map +1 -1
  6. package/lib/commonjs/state/user-update-queue.js +168 -0
  7. package/lib/commonjs/state/user-update-queue.js.map +1 -0
  8. package/lib/commonjs/state/widget-store.js +27 -4
  9. package/lib/commonjs/state/widget-store.js.map +1 -1
  10. package/lib/commonjs/types.js.map +1 -1
  11. package/lib/commonjs/ui/screens/chat/ChatView.js +14 -1
  12. package/lib/commonjs/ui/screens/chat/ChatView.js.map +1 -1
  13. package/lib/module/api/client.js +27 -4
  14. package/lib/module/api/client.js.map +1 -1
  15. package/lib/module/index.js.map +1 -1
  16. package/lib/module/state/user-update-queue.js +163 -0
  17. package/lib/module/state/user-update-queue.js.map +1 -0
  18. package/lib/module/state/widget-store.js +27 -4
  19. package/lib/module/state/widget-store.js.map +1 -1
  20. package/lib/module/types.js.map +1 -1
  21. package/lib/module/ui/screens/chat/ChatView.js +14 -1
  22. package/lib/module/ui/screens/chat/ChatView.js.map +1 -1
  23. package/lib/typescript/commonjs/api/client.d.ts +8 -2
  24. package/lib/typescript/commonjs/api/client.d.ts.map +1 -1
  25. package/lib/typescript/commonjs/index.d.ts +5 -0
  26. package/lib/typescript/commonjs/index.d.ts.map +1 -1
  27. package/lib/typescript/commonjs/state/user-update-queue.d.ts +62 -0
  28. package/lib/typescript/commonjs/state/user-update-queue.d.ts.map +1 -0
  29. package/lib/typescript/commonjs/state/widget-store.d.ts +4 -0
  30. package/lib/typescript/commonjs/state/widget-store.d.ts.map +1 -1
  31. package/lib/typescript/commonjs/types.d.ts +12 -0
  32. package/lib/typescript/commonjs/types.d.ts.map +1 -1
  33. package/lib/typescript/commonjs/ui/screens/chat/ChatView.d.ts.map +1 -1
  34. package/lib/typescript/module/api/client.d.ts +8 -2
  35. package/lib/typescript/module/api/client.d.ts.map +1 -1
  36. package/lib/typescript/module/index.d.ts +5 -0
  37. package/lib/typescript/module/index.d.ts.map +1 -1
  38. package/lib/typescript/module/state/user-update-queue.d.ts +62 -0
  39. package/lib/typescript/module/state/user-update-queue.d.ts.map +1 -0
  40. package/lib/typescript/module/state/widget-store.d.ts +4 -0
  41. package/lib/typescript/module/state/widget-store.d.ts.map +1 -1
  42. package/lib/typescript/module/types.d.ts +12 -0
  43. package/lib/typescript/module/types.d.ts.map +1 -1
  44. package/lib/typescript/module/ui/screens/chat/ChatView.d.ts.map +1 -1
  45. package/package.json +1 -1
  46. package/src/api/client.ts +33 -4
  47. package/src/index.tsx +5 -0
  48. package/src/state/user-update-queue.ts +178 -0
  49. package/src/state/widget-store.ts +25 -2
  50. package/src/types.ts +12 -0
  51. package/src/ui/screens/chat/ChatView.tsx +14 -1
package/src/types.ts CHANGED
@@ -300,6 +300,18 @@ export interface BootOptions {
300
300
  * @since 1.4.0
301
301
  */
302
302
  youPrefix?: boolean;
303
+ /**
304
+ * Pace `updateUser()` so an app that calls it on a timer or on every
305
+ * location fix can't flood Workstation (default true). Values Workstation
306
+ * already has aren't sent again; up to 20 updates go out at once, then one
307
+ * every 90 seconds (20 per 30 minutes). Calls in between are merged, newest
308
+ * value per key, and sent on the next allowed update, so nothing is lost and
309
+ * `updateUser()` resolves right away for them. A rate-limit answer from
310
+ * Workstation is waited out and retried the same way. False sends every
311
+ * call straight away, as before 1.5.0.
312
+ * @since 1.5.0
313
+ */
314
+ throttleUpdateUser?: boolean;
303
315
  }
304
316
 
305
317
  /** An option in the composer's attach menu. */
@@ -211,6 +211,18 @@ export function ChatView({
211
211
  // it. Scrolled up, scrolling first let the list hold its place as the new
212
212
  // row arrived, which could cut the scroll short.
213
213
  const followSend = useRef(false);
214
+ // Set by a tap on Send until the composer re-renders. Taps that pile up
215
+ // while the JS thread is busy (a slow phone, the host app at work) are all
216
+ // handled before React re-renders, so each still sees the typed text and
217
+ // would send it again. A ref changes at once: only the first goes out.
218
+ const sendTapped = useRef(false);
219
+
220
+ // After every render, and after the send button has taken this render's
221
+ // handler (its own effect runs first): from here a tap sees the composer as
222
+ // the last send left it.
223
+ useEffect(() => {
224
+ sendTapped.current = false;
225
+ });
214
226
 
215
227
  useEffect(() => {
216
228
  if (prefillText) setInput(prefillText);
@@ -361,7 +373,8 @@ export function ChatView({
361
373
 
362
374
  const handleSend = () => {
363
375
  const trimmed = input.trim();
364
- if (!canSend) return;
376
+ if (!canSend || sendTapped.current) return;
377
+ sendTapped.current = true;
365
378
  setInput('');
366
379
  if (typingStopTimer.current) clearTimeout(typingStopTimer.current);
367
380
  onTyping(false);