Skip to content

Commit

Permalink
TW-1283: Improvement for get pinned events in chat
Browse files Browse the repository at this point in the history
  • Loading branch information
nqhhdev authored and hoangdat committed Jan 17, 2024
1 parent 6f9c5a7 commit 2ba2378
Showing 1 changed file with 56 additions and 52 deletions.
108 changes: 56 additions & 52 deletions lib/pages/chat/chat.dart
Original file line number Diff line number Diff line change
Expand Up @@ -352,39 +352,6 @@ class ChatController extends State<Chat>
}
}

@override
void initState() {
registerPasteShortcutListeners();
keyboardVisibilityController.onChange.listen(_keyboardListener);
scrollController.addListener(_updateScrollController);
inputFocus.addListener(_inputFocusListener);
_loadDraft();
_tryLoadTimeline();
sendController.addListener(updateInputTextNotifier);
super.initState();
SchedulerBinding.instance.addPostFrameCallback((_) async {
if (room == null) {
return context.go("/error");
}
_handleReceivedShareFiles();

pinnedEventsController.getPinnedMessageAction(
room: room!,
isInitial: true,
);
});
}

@override
void didUpdateWidget(covariant Chat oldWidget) {
super.didUpdateWidget(oldWidget);
final highlightEventId =
GoRouterState.of(context).uri.queryParameters['event'];
if (highlightEventId != null) {
scrollToEventId(highlightEventId, highlight: true);
}
}

void _initUnreadLocation(String fullyRead) {
_markerReadLocation = fullyRead;
unreadReceivedMessageLocation = _findUnreadReceivedMessageLocation();
Expand All @@ -394,7 +361,9 @@ class ChatController extends State<Chat>
void _tryLoadTimeline() async {
loadTimelineFuture = _getTimeline();
try {
await loadTimelineFuture;
await loadTimelineFuture?.then((_) {
_initializePinnedEvents();
});
final fullyRead = room?.fullyRead;
if (fullyRead == null || fullyRead.isEmpty || fullyRead == '') {
setReadMarker();
Expand Down Expand Up @@ -447,24 +416,6 @@ class ChatController extends State<Chat>
}
}

@override
void dispose() {
unregisterPasteShortcutListeners();
timeline?.cancelSubscriptions();
timeline = null;
inputFocus.removeListener(_inputFocusListener);
focusSuggestionController.dispose();
_jumpToEventIdSubscription?.cancel();
pinnedEventsController.dispose();
_captionsController.dispose();
sendController.removeListener(updateInputTextNotifier);
sendController.dispose();
super.dispose();
}

@override
final TextEditingController sendController = TextEditingController();

final FocusSuggestionController focusSuggestionController =
FocusSuggestionController();

Expand Down Expand Up @@ -1551,6 +1502,59 @@ class ChatController extends State<Chat>
}
}

void _initializePinnedEvents() {
pinnedEventsController.getPinnedMessageAction(
room: room!,
isInitial: true,
);
}

@override
void initState() {
registerPasteShortcutListeners();
keyboardVisibilityController.onChange.listen(_keyboardListener);
scrollController.addListener(_updateScrollController);
inputFocus.addListener(_inputFocusListener);
_loadDraft();
_tryLoadTimeline();
sendController.addListener(updateInputTextNotifier);
super.initState();
SchedulerBinding.instance.addPostFrameCallback((_) async {
if (room == null) {
return context.go("/error");
}
_handleReceivedShareFiles();
});
}

@override
void didUpdateWidget(covariant Chat oldWidget) {
super.didUpdateWidget(oldWidget);
final highlightEventId =
GoRouterState.of(context).uri.queryParameters['event'];
if (highlightEventId != null) {
scrollToEventId(highlightEventId, highlight: true);
}
}

@override
void dispose() {
unregisterPasteShortcutListeners();
timeline?.cancelSubscriptions();
timeline = null;
inputFocus.removeListener(_inputFocusListener);
focusSuggestionController.dispose();
_jumpToEventIdSubscription?.cancel();
pinnedEventsController.dispose();
_captionsController.dispose();
sendController.removeListener(updateInputTextNotifier);
sendController.dispose();
super.dispose();
}

@override
final TextEditingController sendController = TextEditingController();

@override
Widget build(BuildContext context) {
return MouseRegion(
Expand Down

0 comments on commit 2ba2378

Please sign in to comment.