~emersion/goguma

7f45c97a468279a618a26b80b14b82ce21ec0618 — Simon Ser 12 days ago 3ea4f40
page/buffer: don't mark read if not scrolled to bottom
1 files changed, 15 insertions(+), 3 deletions(-)

M lib/page/buffer.dart
M lib/page/buffer.dart => lib/page/buffer.dart +15 -3
@@ 85,6 85,7 @@ class _BufferPageState extends State<BufferPage> with WidgetsBindingObserver, Si
	bool _chatHistoryLoading = false;
	int _initialScrollIndex = 0;
	bool _isAtTop = false;
	bool _isAtBottom = false;

	bool _initialChatHistoryLoaded = false;
	bool _showJumpToBottom = false;


@@ 107,6 108,7 @@ class _BufferPageState extends State<BufferPage> with WidgetsBindingObserver, Si
		var buffer = context.read<BufferModel>();
		if (buffer.messages.length >= 1000) {
			_setInitialChatHistoryLoaded();
			_updateBufferFocus();
			return;
		}



@@ 125,20 127,29 @@ class _BufferPageState extends State<BufferPage> with WidgetsBindingObserver, Si

	void _handleScroll() {
		var positions = _itemPositionsListener.itemPositions.value;
		if (positions.isEmpty) {
			return;
		}

		var buffer = context.read<BufferModel>();
		var isAtTop = positions.last.index == buffer.messages.length - 1;
		var isAtTop = positions.any((pos) => pos.index == buffer.messages.length - 1);
		if (!_isAtTop && isAtTop) {
			_fetchChatHistory();
		}
		_isAtTop = isAtTop;

		var showJumpToBottom = positions.first.index >= 20;
		var showJumpToBottom = positions.any((pos) => pos.index >= 20);
		if (_showJumpToBottom != showJumpToBottom) {
			setState(() {
				_showJumpToBottom = showJumpToBottom;
			});
		}

		var isAtBottom = positions.any((pos) => pos.index < 2);
		if (_isAtBottom != isAtBottom) {
			_isAtBottom = isAtBottom;
			_updateBufferFocus();
		}
	}

	Future<void> _fetchChatHistory() async {


@@ 239,7 250,8 @@ class _BufferPageState extends State<BufferPage> with WidgetsBindingObserver, Si
	void _updateBufferFocus() {
		var buffer = context.read<BufferModel>();
		var state = WidgetsBinding.instance.lifecycleState ?? AppLifecycleState.resumed;
		buffer.focused = state == AppLifecycleState.resumed && _activated;
		var positions = _itemPositionsListener.itemPositions.value;
		buffer.focused = state == AppLifecycleState.resumed && _activated && _isAtBottom;
		if (buffer.focused) {
			_markRead();
		}