@droppii-org/chat-mobile 0.2.94 → 0.2.96
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.
- package/lib/module/config/api-endpoints.js +2 -1
- package/lib/module/config/api-endpoints.js.map +1 -1
- package/lib/module/hooks/groups/useJoinGroupByInviteLink.js +155 -0
- package/lib/module/hooks/groups/useJoinGroupByInviteLink.js.map +1 -0
- package/lib/module/hooks/groups/useResolveGroupInviteLink.js +18 -0
- package/lib/module/hooks/groups/useResolveGroupInviteLink.js.map +1 -0
- package/lib/module/hooks/query-keys.js +2 -1
- package/lib/module/hooks/query-keys.js.map +1 -1
- package/lib/module/screens/chat-detail/ChatListLegend.js +230 -72
- package/lib/module/screens/chat-detail/ChatListLegend.js.map +1 -1
- package/lib/module/screens/inbox/Inbox.js +11 -1
- package/lib/module/screens/inbox/Inbox.js.map +1 -1
- package/lib/module/services/endpoints.js +2 -1
- package/lib/module/services/endpoints.js.map +1 -1
- package/lib/module/services/groupInvite.js +12 -0
- package/lib/module/services/groupInvite.js.map +1 -0
- package/lib/module/translation/resources/i18n.js +6 -1
- package/lib/module/translation/resources/i18n.js.map +1 -1
- package/lib/module/types/chat.js +2 -0
- package/lib/module/types/chat.js.map +1 -1
- package/lib/module/utils/messageUtils.js +14 -4
- package/lib/module/utils/messageUtils.js.map +1 -1
- package/lib/typescript/src/config/api-endpoints.d.ts +1 -0
- package/lib/typescript/src/config/api-endpoints.d.ts.map +1 -1
- package/lib/typescript/src/hooks/groups/useJoinGroupByInviteLink.d.ts +21 -0
- package/lib/typescript/src/hooks/groups/useJoinGroupByInviteLink.d.ts.map +1 -0
- package/lib/typescript/src/hooks/groups/useResolveGroupInviteLink.d.ts +3 -0
- package/lib/typescript/src/hooks/groups/useResolveGroupInviteLink.d.ts.map +1 -0
- package/lib/typescript/src/hooks/query-keys.d.ts +1 -0
- package/lib/typescript/src/hooks/query-keys.d.ts.map +1 -1
- package/lib/typescript/src/screens/chat-detail/ChatListLegend.d.ts.map +1 -1
- package/lib/typescript/src/screens/inbox/Inbox.d.ts +4 -3
- package/lib/typescript/src/screens/inbox/Inbox.d.ts.map +1 -1
- package/lib/typescript/src/services/endpoints.d.ts +1 -0
- package/lib/typescript/src/services/endpoints.d.ts.map +1 -1
- package/lib/typescript/src/services/groupInvite.d.ts +5 -0
- package/lib/typescript/src/services/groupInvite.d.ts.map +1 -0
- package/lib/typescript/src/translation/resources/i18n.d.ts.map +1 -1
- package/lib/typescript/src/types/chat.d.ts +13 -2
- package/lib/typescript/src/types/chat.d.ts.map +1 -1
- package/lib/typescript/src/utils/messageUtils.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/config/api-endpoints.ts +2 -0
- package/src/hooks/groups/useJoinGroupByInviteLink.tsx +167 -0
- package/src/hooks/groups/useResolveGroupInviteLink.ts +20 -0
- package/src/hooks/query-keys.ts +2 -0
- package/src/screens/chat-detail/ChatListLegend.tsx +246 -71
- package/src/screens/inbox/Inbox.tsx +21 -2
- package/src/services/endpoints.ts +2 -0
- package/src/services/groupInvite.ts +15 -0
- package/src/translation/resources/i18n.ts +6 -0
- package/src/types/chat.ts +14 -8
- package/src/utils/messageUtils.ts +18 -3
|
@@ -10,7 +10,6 @@ import {
|
|
|
10
10
|
import {
|
|
11
11
|
ActivityIndicator,
|
|
12
12
|
DeviceEventEmitter,
|
|
13
|
-
Platform,
|
|
14
13
|
StyleSheet,
|
|
15
14
|
useWindowDimensions,
|
|
16
15
|
type View,
|
|
@@ -23,7 +22,10 @@ import Animated, {
|
|
|
23
22
|
type SharedValue,
|
|
24
23
|
} from 'react-native-reanimated';
|
|
25
24
|
import { KeyboardAwareLegendList } from '@legendapp/list/keyboard';
|
|
26
|
-
import {
|
|
25
|
+
import {
|
|
26
|
+
KeyboardEvents,
|
|
27
|
+
useGenericKeyboardHandler,
|
|
28
|
+
} from 'react-native-keyboard-controller';
|
|
27
29
|
import {
|
|
28
30
|
type LegendListRef,
|
|
29
31
|
type MaintainVisibleContentPositionConfig,
|
|
@@ -78,10 +80,36 @@ const ROW_MARGIN_IN_CLUSTER = KSpacingValue['0.25rem'];
|
|
|
78
80
|
|
|
79
81
|
const BUTTON_FADE_CONFIG = { duration: 200, easing: Easing.out(Easing.ease) };
|
|
80
82
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
//
|
|
84
|
-
|
|
83
|
+
const CONTENT_PADDING_VERTICAL = KSpacingValue['0.75rem'];
|
|
84
|
+
|
|
85
|
+
// How long past the duration the keyboard event reported the following loop
|
|
86
|
+
// keeps waiting for the live height to actually reach its target before giving
|
|
87
|
+
// up and snapping to it. Only a fallback: normally the loop ends the frame the
|
|
88
|
+
// keyboard does.
|
|
89
|
+
const FOLLOW_FALLBACK_MS = 120;
|
|
90
|
+
|
|
91
|
+
// How long the keyboard-following loop keeps claiming the list after its last
|
|
92
|
+
// frame. That frame's `setState` renders, lays out and emits its scroll event
|
|
93
|
+
// after the loop has returned, and that trailing event carries the same
|
|
94
|
+
// half-applied geometry the rest of the transition does.
|
|
95
|
+
const FOLLOW_SETTLE_MS = 200;
|
|
96
|
+
|
|
97
|
+
// Frames the keyboard-following loop keeps pinning after the reserved room has
|
|
98
|
+
// reached its target. The pin in the frame that sets the final padding runs
|
|
99
|
+
// before React has rendered it and before the native layout has applied, so it
|
|
100
|
+
// finds no room to scroll into. On iOS that goes unnoticed — the loop has many
|
|
101
|
+
// frames and a later one does the work — but Android's first loop frame
|
|
102
|
+
// already reports the finished height, so without a tail nothing ever scrolls
|
|
103
|
+
// and the last message stays behind the keyboard.
|
|
104
|
+
const FOLLOW_TAIL_FRAMES = 3;
|
|
105
|
+
|
|
106
|
+
// Passed as the list's `keyboardOffset` to switch KeyboardChatScrollView's own
|
|
107
|
+
// native `contentInset` off while leaving the rest of the component in place.
|
|
108
|
+
// Its `getEffectiveHeight` interpolates the live keyboard height into
|
|
109
|
+
// `[0, max(keyboardHeight - offset, 0)]`, so an offset no keyboard can exceed
|
|
110
|
+
// pins the inset at 0 for every frame of the transition. The keyboard's room is
|
|
111
|
+
// reserved as real content padding instead — see the keyboard effect below.
|
|
112
|
+
const DISABLE_NATIVE_KEYBOARD_INSET = 1_000_000;
|
|
85
113
|
|
|
86
114
|
const getRowMarginBottom = (position: GroupPosition): number =>
|
|
87
115
|
position === 'last' || position === 'solo'
|
|
@@ -149,10 +177,37 @@ export const ChatListLegend = memo(
|
|
|
149
177
|
const buttonOpacity = useSharedValue(0);
|
|
150
178
|
const isAtBottomRef = useRef(true);
|
|
151
179
|
const scrollDebounceRef = useRef<NodeJS.Timeout | undefined>(undefined);
|
|
152
|
-
//
|
|
153
|
-
//
|
|
180
|
+
// The state drives the content's bottom padding; the ref is the last
|
|
181
|
+
// value acted on, read synchronously inside the keyboard listener to
|
|
182
|
+
// drop Android's repeat events before they reach React.
|
|
183
|
+
const keyboardInsetRef = useRef(0);
|
|
154
184
|
const [keyboardInset, setKeyboardInset] = useState(0);
|
|
155
|
-
|
|
185
|
+
// The keyboard's live height, written on the UI thread and sampled from
|
|
186
|
+
// the JS thread by the tween below, so the content tracks the keyboard's
|
|
187
|
+
// real position instead of a guessed easing curve.
|
|
188
|
+
//
|
|
189
|
+
// `useGenericKeyboardHandler` rather than `useKeyboardHandler` /
|
|
190
|
+
// `useReanimatedKeyboardAnimation`: those call `useResizeMode()`, which
|
|
191
|
+
// reaches in and sets Android's soft input mode — `KeyboardProvider`
|
|
192
|
+
// already owns that here. The worklet only writes a SharedValue; calling
|
|
193
|
+
// `runOnJS` (or anything that reaches JS) from a keyboard worklet
|
|
194
|
+
// reliably crashes Reanimated with a reentrant-lock assertion.
|
|
195
|
+
// True while the keyboard-following loop below is driving the list.
|
|
196
|
+
const isFollowingKeyboardRef = useRef(false);
|
|
197
|
+
const liveKeyboardHeight = useSharedValue(0);
|
|
198
|
+
useGenericKeyboardHandler(
|
|
199
|
+
{
|
|
200
|
+
onMove: (e) => {
|
|
201
|
+
'worklet';
|
|
202
|
+
liveKeyboardHeight.value = e.height;
|
|
203
|
+
},
|
|
204
|
+
onEnd: (e) => {
|
|
205
|
+
'worklet';
|
|
206
|
+
liveKeyboardHeight.value = e.height;
|
|
207
|
+
},
|
|
208
|
+
},
|
|
209
|
+
[]
|
|
210
|
+
);
|
|
156
211
|
const rowRefsMap = useRef<Map<string, View | null>>(new Map());
|
|
157
212
|
// Set on a real touch-drag (`onScrollBeginDrag`), before onStartReached/
|
|
158
213
|
// onEndReached's threshold could fire. `onMomentumScrollBegin` was tried
|
|
@@ -491,6 +546,15 @@ export const ChatListLegend = memo(
|
|
|
491
546
|
|
|
492
547
|
const handleScroll = useCallback(
|
|
493
548
|
(e: any) => {
|
|
549
|
+
// The keyboard-following loop re-pins to the end on every frame, so
|
|
550
|
+
// the list is at the bottom for the whole transition by construction.
|
|
551
|
+
// The intermediate events it produces are not: content size and
|
|
552
|
+
// offset move a frame apart, and a reading taken between them says
|
|
553
|
+
// "not at bottom" and latches the scroll-to-bottom button on. The
|
|
554
|
+
// loop only runs when the list was already at the bottom, so there is
|
|
555
|
+
// nothing here to detect while it does.
|
|
556
|
+
if (isFollowingKeyboardRef.current) return;
|
|
557
|
+
|
|
494
558
|
const { contentOffset, contentSize, layoutMeasurement } = e.nativeEvent;
|
|
495
559
|
const isAtBottom =
|
|
496
560
|
contentOffset.y + layoutMeasurement.height >=
|
|
@@ -533,6 +597,17 @@ export const ChatListLegend = memo(
|
|
|
533
597
|
setShowBadge(false);
|
|
534
598
|
}, [hasMoreNew, onLoadMoreOld, scrollMessageToEnd, buttonOpacity]);
|
|
535
599
|
|
|
600
|
+
// `paddingBottom` here replaces the one `styles.content` sets via
|
|
601
|
+
// `paddingVertical`, so the base spacing has to be added back or the last
|
|
602
|
+
// message ends up flush against the composer.
|
|
603
|
+
const contentContainerStyle = useMemo(
|
|
604
|
+
() => [
|
|
605
|
+
styles.content,
|
|
606
|
+
{ paddingBottom: CONTENT_PADDING_VERTICAL + keyboardInset },
|
|
607
|
+
],
|
|
608
|
+
[keyboardInset]
|
|
609
|
+
);
|
|
610
|
+
|
|
536
611
|
const animatedButtonStyle = useAnimatedStyle(() => ({
|
|
537
612
|
opacity: buttonOpacity.value,
|
|
538
613
|
pointerEvents: buttonOpacity.value === 0 ? 'none' : 'auto',
|
|
@@ -547,72 +622,167 @@ export const ChatListLegend = memo(
|
|
|
547
622
|
};
|
|
548
623
|
}, []);
|
|
549
624
|
|
|
550
|
-
//
|
|
551
|
-
//
|
|
552
|
-
// willShow→willHide→willShow roughly every 1.3s for as long as the
|
|
553
|
-
// keyboard stays open (measured on device) — without this, every flap
|
|
554
|
-
// would fire another scroll. A real close still lands, just one tick
|
|
555
|
-
// later. Setting the same height twice is a no-op for the effect below,
|
|
556
|
-
// so a stable open only ever re-anchors once.
|
|
625
|
+
// Reserves the keyboard's room on the content and keeps the list pinned
|
|
626
|
+
// to the end for the length of each keyboard transition.
|
|
557
627
|
//
|
|
558
|
-
// JS
|
|
559
|
-
// that reaching into `useKeyboardHandler`'s worklets carries.
|
|
628
|
+
// JS thread only: no worklet, so none of the reentrant-lock crash risk
|
|
629
|
+
// that reaching into `useKeyboardHandler`'s worklets carries. The one
|
|
630
|
+
// worklet involved only writes `liveKeyboardHeight`, which this reads.
|
|
560
631
|
useEffect(() => {
|
|
561
|
-
let
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
632
|
+
let pendingSettle: ReturnType<typeof setTimeout> | undefined;
|
|
633
|
+
let pendingFrame: number | undefined;
|
|
634
|
+
const clearPending = () => {
|
|
635
|
+
if (pendingSettle) {
|
|
636
|
+
clearTimeout(pendingSettle);
|
|
637
|
+
pendingSettle = undefined;
|
|
638
|
+
}
|
|
639
|
+
if (pendingFrame !== undefined) {
|
|
640
|
+
cancelAnimationFrame(pendingFrame);
|
|
641
|
+
pendingFrame = undefined;
|
|
566
642
|
}
|
|
643
|
+
isFollowingKeyboardRef.current = false;
|
|
567
644
|
};
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
645
|
+
|
|
646
|
+
// Follows the keyboard frame by frame instead of setting the reserved
|
|
647
|
+
// room in one step.
|
|
648
|
+
//
|
|
649
|
+
// Set in one step the layout lift lands in a single frame — measured,
|
|
650
|
+
// 72 of the 302px the content had to travel arrived as an instant jump
|
|
651
|
+
// while only the remaining 230 were animated, and `scrollToEnd`'s own
|
|
652
|
+
// ~324ms curve then finished about 100ms after the keyboard had already
|
|
653
|
+
// stopped. Sampling `liveKeyboardHeight` each frame instead means the
|
|
654
|
+
// padding, and with it the content, is wherever the keyboard actually
|
|
655
|
+
// is — no easing curve to guess at, and the two cannot drift apart.
|
|
656
|
+
//
|
|
657
|
+
// `duration` is only a bound, for a transition whose reported height
|
|
658
|
+
// never quite reaches the event's target.
|
|
659
|
+
const followKeyboard = (to: number, duration: number) => {
|
|
660
|
+
const startedAt = Date.now();
|
|
661
|
+
const startedFrom = Math.max(
|
|
662
|
+
Math.abs(liveKeyboardHeight.value) - keyboardOffset,
|
|
663
|
+
0
|
|
664
|
+
);
|
|
665
|
+
let tailFrames = 0;
|
|
666
|
+
isFollowingKeyboardRef.current = true;
|
|
667
|
+
const step = () => {
|
|
668
|
+
const live = Math.max(
|
|
669
|
+
Math.abs(liveKeyboardHeight.value) - keyboardOffset,
|
|
670
|
+
0
|
|
580
671
|
);
|
|
672
|
+
// Tracks the keyboard rather than a timer, so the content never
|
|
673
|
+
// keeps travelling after the keyboard has stopped. The elapsed
|
|
674
|
+
// check is only a fallback for a transition whose reported height
|
|
675
|
+
// never quite reaches the target.
|
|
676
|
+
const reached = Math.abs(live - to) <= 1;
|
|
677
|
+
const timedOut =
|
|
678
|
+
!reached && Date.now() - startedAt >= duration + FOLLOW_FALLBACK_MS;
|
|
679
|
+
// Whether the keyboard moved at all decides what a timeout means. A
|
|
680
|
+
// `keyboardWillHide` the keyboard does not act on leaves the live
|
|
681
|
+
// height exactly where it was, and forcing the target there would
|
|
682
|
+
// collapse the room out from under a keyboard that is still up —
|
|
683
|
+
// which is what the old hide debounce was guarding against, at the
|
|
684
|
+
// cost of the list dropping a beat after the keyboard had gone. A
|
|
685
|
+
// real transition that merely stops a few px short of the height
|
|
686
|
+
// the event reported (iOS, measured ~4px) still has to land exactly
|
|
687
|
+
// on the target.
|
|
688
|
+
const moved = Math.abs(live - startedFrom) > 1;
|
|
689
|
+
if (reached) {
|
|
690
|
+
tailFrames += 1;
|
|
691
|
+
}
|
|
692
|
+
const done = timedOut || tailFrames >= FOLLOW_TAIL_FRAMES;
|
|
693
|
+
const settleTo = reached || (timedOut && moved) ? to : live;
|
|
694
|
+
|
|
695
|
+
setKeyboardInset(settleTo);
|
|
696
|
+
if (settleTo !== to) {
|
|
697
|
+
// Record what the room actually ended up as, or the dedupe in
|
|
698
|
+
// `applyInset` would swallow the next real transition to `to`.
|
|
699
|
+
keyboardInsetRef.current = settleTo;
|
|
700
|
+
}
|
|
701
|
+
// Re-pin every frame. Growing the padding only moves the content on
|
|
702
|
+
// its own while there is `alignItemsAtEndPadding` left to absorb
|
|
703
|
+
// it; once that is gone — any conversation taller than the viewport
|
|
704
|
+
// — the padding just extends the range and nothing moves until
|
|
705
|
+
// something scrolls, and `maintainScrollAtEnd` does not follow a
|
|
706
|
+
// content size change frame by frame (measured: one scroll event,
|
|
707
|
+
// at the very end). Unanimated on purpose: the keyboard is the
|
|
708
|
+
// animation, and an animated scroll here would start a second curve
|
|
709
|
+
// on top of it every frame.
|
|
710
|
+
listRef.current?.scrollToEnd({ animated: false });
|
|
711
|
+
|
|
712
|
+
if (done) {
|
|
713
|
+
pendingFrame = undefined;
|
|
714
|
+
// The loop only runs from a list that was at the bottom and it
|
|
715
|
+
// has just pinned it there again, so record that rather than
|
|
716
|
+
// waiting to re-derive it from a scroll event.
|
|
717
|
+
isAtBottomRef.current = true;
|
|
718
|
+
buttonOpacity.value = withTiming(0, BUTTON_FADE_CONFIG);
|
|
719
|
+
setShowBadge(false);
|
|
720
|
+
pendingSettle = setTimeout(() => {
|
|
721
|
+
pendingSettle = undefined;
|
|
722
|
+
isFollowingKeyboardRef.current = false;
|
|
723
|
+
}, FOLLOW_SETTLE_MS);
|
|
724
|
+
return;
|
|
725
|
+
}
|
|
726
|
+
pendingFrame = requestAnimationFrame(step);
|
|
727
|
+
};
|
|
728
|
+
pendingFrame = requestAnimationFrame(step);
|
|
729
|
+
};
|
|
730
|
+
|
|
731
|
+
const applyInset = (nextInset: number, duration: number) => {
|
|
732
|
+
// Android's event stream flaps willShow -> willHide -> willShow every
|
|
733
|
+
// ~1.3s for as long as the keyboard stays open (measured), so a
|
|
734
|
+
// repeated height must not restart the follow loop.
|
|
735
|
+
if (keyboardInsetRef.current === nextInset) return;
|
|
736
|
+
keyboardInsetRef.current = nextInset;
|
|
737
|
+
|
|
738
|
+
// Reserve the keyboard's room as real bottom padding on the content
|
|
739
|
+
// and let LegendList own it end to end. The native `contentInset` is
|
|
740
|
+
// switched off (see `keyboardOffset` on the list below), so this is
|
|
741
|
+
// the only thing compensating for the keyboard.
|
|
742
|
+
//
|
|
743
|
+
// The point is an invariant, not an offset: the scroll view's
|
|
744
|
+
// maximum content offset has to BE the visually correct position.
|
|
745
|
+
// Otherwise there is a band of legal resting offsets that all look
|
|
746
|
+
// wrong, and a drag settles somewhere inside it — which is the blank
|
|
747
|
+
// gap above the composer.
|
|
748
|
+
//
|
|
749
|
+
// A native inset cannot hold that invariant here. It widens the
|
|
750
|
+
// scroll range by the full keyboard height, but LegendList
|
|
751
|
+
// independently shrinks `alignItemsAtEndPadding` by the same amount
|
|
752
|
+
// and lifts the content through layout as well. Measured on a short
|
|
753
|
+
// conversation: the layout lift covered 258 of the 302 needed, so
|
|
754
|
+
// only 44 of scrolling was left to do while the range still ran to
|
|
755
|
+
// 302 — 258px of pure slack. As content padding the same 302 goes
|
|
756
|
+
// into `contentSize`, so `alignItemsAtEndPadding` falls out to zero,
|
|
757
|
+
// the range is exactly the lift required, and `scrollToEnd` (which
|
|
758
|
+
// reads LegendList's own metrics, and already offsets itself by
|
|
759
|
+
// `stylePaddingBottom`) lands on it.
|
|
760
|
+
//
|
|
761
|
+
// Skipped when the user has scrolled away from the bottom — opening
|
|
762
|
+
// the keyboard shouldn't yank them back down — but the padding still
|
|
763
|
+
// has to change, or the range would be wrong for them too.
|
|
764
|
+
if (!isAtBottomRef.current) {
|
|
765
|
+
setKeyboardInset(nextInset);
|
|
766
|
+
return;
|
|
581
767
|
}
|
|
582
|
-
|
|
768
|
+
followKeyboard(nextInset, duration);
|
|
583
769
|
};
|
|
584
770
|
|
|
585
771
|
const willShow = KeyboardEvents.addListener('keyboardWillShow', (e) => {
|
|
586
|
-
|
|
587
|
-
applyInset(Math.max(e.height - keyboardOffset, 0));
|
|
772
|
+
clearPending();
|
|
773
|
+
applyInset(Math.max(e.height - keyboardOffset, 0), e.duration);
|
|
588
774
|
});
|
|
589
|
-
const willHide = KeyboardEvents.addListener('keyboardWillHide', () => {
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
() => applyInset(0),
|
|
593
|
-
KEYBOARD_HIDE_DEBOUNCE_MS
|
|
594
|
-
);
|
|
775
|
+
const willHide = KeyboardEvents.addListener('keyboardWillHide', (e) => {
|
|
776
|
+
clearPending();
|
|
777
|
+
applyInset(0, e.duration);
|
|
595
778
|
});
|
|
779
|
+
|
|
596
780
|
return () => {
|
|
597
|
-
|
|
781
|
+
clearPending();
|
|
598
782
|
willShow.remove();
|
|
599
783
|
willHide.remove();
|
|
600
784
|
};
|
|
601
|
-
}, [keyboardOffset, listRef]);
|
|
602
|
-
|
|
603
|
-
// Re-anchors to the end once the keyboard's inset has landed, which puts
|
|
604
|
-
// the last message at exactly the spacing the closed-keyboard layout has
|
|
605
|
-
// (verified on device against both a 7-message and a long conversation).
|
|
606
|
-
// Skipped when the user has scrolled away from the bottom — opening the
|
|
607
|
-
// keyboard shouldn't yank them back down.
|
|
608
|
-
useEffect(() => {
|
|
609
|
-
if (!hasSeenFirstKeyboardInsetRef.current) {
|
|
610
|
-
hasSeenFirstKeyboardInsetRef.current = true;
|
|
611
|
-
return;
|
|
612
|
-
}
|
|
613
|
-
if (!isAtBottomRef.current) return;
|
|
614
|
-
scrollMessageToEnd({ animated: true, closeKeyboard: false });
|
|
615
|
-
}, [keyboardInset, scrollMessageToEnd]);
|
|
785
|
+
}, [buttonOpacity, keyboardOffset, listRef, liveKeyboardHeight]);
|
|
616
786
|
|
|
617
787
|
// This component can stay mounted across a conversationId change (e.g.
|
|
618
788
|
// navigation.replace reusing the same screen instance), so this ref must
|
|
@@ -749,21 +919,26 @@ export const ChatListLegend = memo(
|
|
|
749
919
|
// fetch instead of the default 250px window losing it.
|
|
750
920
|
drawDistance={800}
|
|
751
921
|
freeze={freeze}
|
|
752
|
-
keyboardOffset={
|
|
753
|
-
//
|
|
754
|
-
//
|
|
755
|
-
// top
|
|
756
|
-
//
|
|
757
|
-
//
|
|
758
|
-
//
|
|
759
|
-
//
|
|
760
|
-
// re-
|
|
922
|
+
keyboardOffset={DISABLE_NATIVE_KEYBOARD_INSET}
|
|
923
|
+
// iOS only. Left on, React Native recomputes and applies its own
|
|
924
|
+
// `contentInset` every time the keyboard moves — measured here as
|
|
925
|
+
// {top: 59, bottom: keyboardHeight}, both wrong. The bottom value
|
|
926
|
+
// over-insets by the safe area, and the phantom top one is worse:
|
|
927
|
+
// iOS rests a scroll view at `-contentInset.top`.
|
|
928
|
+
// That resting offset is what put the content 59pt low and hid the
|
|
929
|
+
// last message behind the composer the moment a touch let UIKit
|
|
930
|
+
// re-clamp. legend-list's own KeyboardAvoidingLegendList disables
|
|
931
|
+
// this for the same reason.
|
|
932
|
+
automaticallyAdjustContentInsets={false}
|
|
933
|
+
// No scroll shift from the library either — the content padding
|
|
934
|
+
// above is the single compensator. Measured with it on: a 302px
|
|
935
|
+
// keyboard produced a 604px lift, exactly double.
|
|
761
936
|
keyboardLiftBehavior="never"
|
|
762
937
|
scrollEventThrottle={16}
|
|
763
938
|
onScroll={handleScroll}
|
|
764
939
|
onScrollBeginDrag={handleScrollBeginDrag}
|
|
765
940
|
onLoad={handleListLoad}
|
|
766
|
-
contentContainerStyle={
|
|
941
|
+
contentContainerStyle={contentContainerStyle}
|
|
767
942
|
scrollIndicatorInsets={{ right: 1 }}
|
|
768
943
|
ListHeaderComponent={
|
|
769
944
|
<LegendChatLoadEarlier isLoading={moreOldLoading} />
|
|
@@ -811,7 +986,7 @@ const styles = StyleSheet.create({
|
|
|
811
986
|
position: 'relative',
|
|
812
987
|
},
|
|
813
988
|
content: {
|
|
814
|
-
paddingVertical:
|
|
989
|
+
paddingVertical: CONTENT_PADDING_VERTICAL,
|
|
815
990
|
flexGrow: 1,
|
|
816
991
|
},
|
|
817
992
|
scrollToBottomButton: {
|
|
@@ -9,17 +9,22 @@ import {
|
|
|
9
9
|
KRadiusValue,
|
|
10
10
|
KSpacingValue,
|
|
11
11
|
} from '@droppii/libs';
|
|
12
|
+
import {
|
|
13
|
+
GroupJoinSource,
|
|
14
|
+
type ConversationItem,
|
|
15
|
+
} from '@droppii/openim-rn-client-sdk';
|
|
12
16
|
import { MessagesTab } from './MessagesTab';
|
|
13
|
-
import type { ConversationItem } from '@droppii/openim-rn-client-sdk';
|
|
14
17
|
import { trans } from '../../translation';
|
|
15
18
|
import { CommunityTab } from './CommunityTab';
|
|
19
|
+
import { useJoinGroupByInviteLink } from '../../hooks/groups/useJoinGroupByInviteLink';
|
|
16
20
|
|
|
17
21
|
interface InboxProps {
|
|
18
22
|
onPressThread?: (item?: ConversationItem) => void;
|
|
19
23
|
onPressSearch?: () => void;
|
|
20
24
|
onPressEdit?: () => void;
|
|
21
25
|
onPressContact?: () => void;
|
|
22
|
-
onPressGroup?: (groupId: string) => void;
|
|
26
|
+
onPressGroup?: (groupId: string, groupJoinSource?: GroupJoinSource) => void;
|
|
27
|
+
groupInviteLinkCode?: string;
|
|
23
28
|
}
|
|
24
29
|
|
|
25
30
|
type TabRoute = { key: string; title: string };
|
|
@@ -36,8 +41,22 @@ const Inbox = memo(
|
|
|
36
41
|
onPressEdit,
|
|
37
42
|
onPressContact,
|
|
38
43
|
onPressGroup,
|
|
44
|
+
groupInviteLinkCode,
|
|
39
45
|
}: InboxProps) => {
|
|
40
46
|
const [index, setIndex] = useState(0);
|
|
47
|
+
|
|
48
|
+
const handleGroupInviteLinkAllowed = useCallback(
|
|
49
|
+
(target: { groupId: string; conversationId: string }) => {
|
|
50
|
+
onPressGroup?.(target.groupId, GroupJoinSource.QrCode);
|
|
51
|
+
},
|
|
52
|
+
[onPressGroup]
|
|
53
|
+
);
|
|
54
|
+
|
|
55
|
+
useJoinGroupByInviteLink({
|
|
56
|
+
code: groupInviteLinkCode,
|
|
57
|
+
onAllowed: handleGroupInviteLinkAllowed,
|
|
58
|
+
});
|
|
59
|
+
|
|
41
60
|
const [routes] = useState<TabRoute[]>(TabRoutes);
|
|
42
61
|
|
|
43
62
|
const renderScene = useCallback(
|
|
@@ -40,6 +40,8 @@ export const ENDPOINTS = {
|
|
|
40
40
|
stickerHistory: () => getApiEndpoint('stickerHistory'),
|
|
41
41
|
searchMessages: () => `${getApiEndpoint('messages')}/search`,
|
|
42
42
|
searchContacts: () => `${getApiEndpoint('contacts')}/search`,
|
|
43
|
+
groupJoinLink: (code: string) =>
|
|
44
|
+
`${getApiEndpoint('groupJoinLink')}/${code}`,
|
|
43
45
|
},
|
|
44
46
|
uploaderService: {
|
|
45
47
|
get uploadImage() {
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { apiInstance, unwrapEnvelope } from './apis';
|
|
2
|
+
import { getApiEndpoint } from '../config/api-endpoints';
|
|
3
|
+
import type { BaseResponse } from '../types/auth';
|
|
4
|
+
import type { GroupInviteLinkInfo } from '../types/chat';
|
|
5
|
+
|
|
6
|
+
export namespace GroupInviteService {
|
|
7
|
+
export const fetchGroupInviteLinkInfo = async (
|
|
8
|
+
code: string
|
|
9
|
+
): Promise<GroupInviteLinkInfo | null> => {
|
|
10
|
+
const res = await apiInstance?.get<BaseResponse<GroupInviteLinkInfo>>(
|
|
11
|
+
`${getApiEndpoint('groupJoinLink')}/${code}`
|
|
12
|
+
);
|
|
13
|
+
return unwrapEnvelope<GroupInviteLinkInfo>(res);
|
|
14
|
+
};
|
|
15
|
+
}
|
|
@@ -104,6 +104,7 @@ const i18nKey: Record<string, string> = {
|
|
|
104
104
|
'chat:group_message_unpinned_by': '{{sender}} đã bỏ ghim một tin nhắn',
|
|
105
105
|
'msg_type_member_enter': 'Đã tham gia nhóm',
|
|
106
106
|
'chat:member_enter_by': '{{sender}} đã tham gia nhóm',
|
|
107
|
+
'chat:member_enter_via_link': '{{sender}} đã tham gia nhóm qua link',
|
|
107
108
|
'msg_type_group_dismissed': 'Nhóm đã bị giải tán',
|
|
108
109
|
'chat:group_dismissed_by': '{{sender}} đã giải tán nhóm',
|
|
109
110
|
'msg_type_group_member_muted': 'Đã tắt tiếng thành viên',
|
|
@@ -227,6 +228,11 @@ const i18nKey: Record<string, string> = {
|
|
|
227
228
|
'group:access_blocked_desc':
|
|
228
229
|
'Bạn hiện không có quyền truy cập vào cuộc trò chuyện hoặc tin nhắn này.',
|
|
229
230
|
'group:access_blocked_button': 'Đã hiểu',
|
|
231
|
+
'group:join_group_confirm_title': 'Tham gia nhóm',
|
|
232
|
+
'group:join_group_confirm_button': 'Tham gia nhóm',
|
|
233
|
+
'group:invite_link_unavailable_title': 'Liên kết không còn khả dụng',
|
|
234
|
+
'group:invite_link_unavailable_desc':
|
|
235
|
+
'Liên kết đã bị thu hồi, thay thế hoặc nhóm không còn tồn tại. Vui lòng liên hệ người gửi để nhận liên kết mới.',
|
|
230
236
|
};
|
|
231
237
|
|
|
232
238
|
export default {
|
package/src/types/chat.ts
CHANGED
|
@@ -2,6 +2,7 @@ import {
|
|
|
2
2
|
MessageType,
|
|
3
3
|
type ConversationItem,
|
|
4
4
|
type GroupItem,
|
|
5
|
+
type GroupVisibility,
|
|
5
6
|
type MessageItem,
|
|
6
7
|
type SelfUserInfo,
|
|
7
8
|
} from '@droppii/openim-rn-client-sdk';
|
|
@@ -37,14 +38,7 @@ export interface ChatUIAdapter {
|
|
|
37
38
|
}
|
|
38
39
|
|
|
39
40
|
export type GenerateChatDetailLinkFn = (
|
|
40
|
-
params: Pick<
|
|
41
|
-
ChatDetailProps,
|
|
42
|
-
| 'targetConversationId'
|
|
43
|
-
| 'targetUserId'
|
|
44
|
-
| 'targetGroupId'
|
|
45
|
-
| 'targetBotId'
|
|
46
|
-
| 'targetMessageId'
|
|
47
|
-
>
|
|
41
|
+
params: Pick<ChatDetailProps, 'targetConversationId' | 'targetMessageId'>
|
|
48
42
|
) => string;
|
|
49
43
|
|
|
50
44
|
export interface ChatContextType {
|
|
@@ -407,3 +401,15 @@ export interface IContactSearchItem {
|
|
|
407
401
|
memberCount?: number;
|
|
408
402
|
description?: string;
|
|
409
403
|
}
|
|
404
|
+
|
|
405
|
+
/** Response shape of `GET /chat-service/v1/app/conversations/join-link/{code}`. */
|
|
406
|
+
export interface GroupInviteLinkInfo {
|
|
407
|
+
conversationId: string;
|
|
408
|
+
groupId: string;
|
|
409
|
+
groupName: string;
|
|
410
|
+
groupDescription: string;
|
|
411
|
+
groupVisibility: GroupVisibility;
|
|
412
|
+
groupAvatar: string;
|
|
413
|
+
isMember: boolean;
|
|
414
|
+
groupTotalMember: number;
|
|
415
|
+
}
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
5
|
import {
|
|
6
|
+
GroupJoinSource,
|
|
6
7
|
MessageType,
|
|
7
8
|
PeerType,
|
|
8
9
|
type ConversationItem,
|
|
@@ -196,6 +197,14 @@ export const resolveNotificationText = (
|
|
|
196
197
|
}
|
|
197
198
|
break;
|
|
198
199
|
}
|
|
200
|
+
case MessageType.MemberEnter: {
|
|
201
|
+
const joinSource = detail?.entrantUser?.joinSource;
|
|
202
|
+
if (joinSource === GroupJoinSource.QrCode) {
|
|
203
|
+
previewKey = 'chat:member_enter_via_link';
|
|
204
|
+
bySenderKey = 'chat:member_enter_via_link';
|
|
205
|
+
}
|
|
206
|
+
break;
|
|
207
|
+
}
|
|
199
208
|
default:
|
|
200
209
|
break;
|
|
201
210
|
}
|
|
@@ -433,10 +442,16 @@ export const getNotificationOpUserNickname = (
|
|
|
433
442
|
const parsed = JSON.parse(message.notificationElem.detail) as {
|
|
434
443
|
opUser?: { nickname?: string };
|
|
435
444
|
quitUser?: { nickname?: string };
|
|
445
|
+
entrantUser?: { nickname?: string };
|
|
436
446
|
};
|
|
437
|
-
// MemberQuit puts the leaver in `quitUser
|
|
438
|
-
//
|
|
439
|
-
|
|
447
|
+
// MemberQuit puts the leaver in `quitUser`
|
|
448
|
+
// MemberEnter puts the joiner in `entrantUser`
|
|
449
|
+
// every other group-notification content type uses `opUser` for the actor.
|
|
450
|
+
return (
|
|
451
|
+
parsed?.opUser?.nickname ??
|
|
452
|
+
parsed?.quitUser?.nickname ??
|
|
453
|
+
parsed?.entrantUser?.nickname
|
|
454
|
+
);
|
|
440
455
|
} catch {
|
|
441
456
|
return undefined;
|
|
442
457
|
}
|