Skip to content

Keep topics data up-to-date by handling events #1508

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

PIG208
Copy link
Member

@PIG208 PIG208 commented May 9, 2025

This is a follow-up to #1500.

Fixes: #1499

@PIG208 PIG208 force-pushed the pr-topics-2 branch 4 times, most recently from 0670f6a to 6632f36 Compare May 13, 2025 20:40
Copy link
Member

@gnprice gnprice left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @PIG208 for drafting this!

Generally this approach looks good. We'll have someone else pick it up from here.

I skimmed through the key points of the logic; some high-level comments below.

(For whoever picks this up next: do read through all the details yourself in addition to the points I've commented on, and follow the steps in Zulip's guide to continuing unfinished work.)

Comment on lines +434 to +498
bool handleMessageEvent(MessageEvent event) {
if (event.message is! StreamMessage) return false;
final StreamMessage(:streamId, :topic) = event.message as StreamMessage;

final latestMessageIdsByTopic = _latestMessageIdsByStreamTopic[streamId];
if (latestMessageIdsByTopic == null) return false;
assert(!latestMessageIdsByTopic.containsKey(topic)
|| latestMessageIdsByTopic[topic]! < event.message.id);
latestMessageIdsByTopic[topic] = event.message.id;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One thing we'll want to think through in how this part of the model should work is how to handle the fetch/event race which it introduces.

An example of that is that I think this assert isn't correct — we could do a fetch that learns about a topic with a new message, and only later get the MessageEvent about that message.

For an example of where we've reasoned through this sort of fetch/event race before, see the implementation of reconcileMessages in lib/model/message.dart .

Comment on lines +247 to +306
Future<void> fetchTopics(int streamId) async {
final result = await _apiGetStreamTopics(connection, streamId: streamId,
allowEmptyTopicName: true);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if we've already successfully fetched the list for this channel? In that case I think we want to show the existing list (which, after all, this class will have been keeping up to date) rather than make a new fetch.

Comment on lines +455 to +515
final origLatestMessageIdsByTopics = _latestMessageIdsByStreamTopic[origStreamId];
if (propagateMode == PropagateMode.changeAll
&& origLatestMessageIdsByTopics != null) {
shouldNotify = origLatestMessageIdsByTopics.remove(origTopic) != null;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this might be the right logic to have, but there are some edge cases it doesn't handle. So this code should have comments pointing out those cases and explaining why we're choosing to not handle them.

Comment on lines +228 to +235
// The message with `maxId` might not remain in `topic` since we last fetch
// the list of topics. Make sure we check for that before passing `maxId`
// to the topic action sheet.
// See also: [ChannelStore.getStreamTopics]
final message = store.messages[maxId];
final isMaxIdInTopic = message is StreamMessage
&& message.streamId == streamId
&& message.topic.isSameAs(topic);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm. This will mean that if we just don't happen to have any messages from that topic in MessageStore — for example, because it's not a topic that's included in the very last messages — then we won't give the user the option to resolve or unresolve the topic from this screen. That seems unfortunate.

What happens if we go ahead and use this message ID even though it might turn out to no longer be in the topic?

@gnprice
Copy link
Member

gnprice commented Jul 23, 2025

Hmm, infra failure in CI:

Downloading Linux x64 Dart SDK from Flutter engine 2d053c11840d49924aefe84dabb94545a3f9282e...
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed

  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
100   255  100   255    0     0   3658      0 --:--:-- --:--:-- --:--:--  3695
[/home/runner/flutter/bin/cache/dart-sdk-linux-x64.zip]
  End-of-central-directory signature not found.  Either this file is not
  a zipfile, or it constitutes one disk of a multi-part archive.  In the
  latter case the central directory and zipfile comment will be found on
  the last disk(s) of this archive.
unzip:  cannot find zipfile directory in one of /home/runner/flutter/bin/cache/dart-sdk-linux-x64.zip or
        /home/runner/flutter/bin/cache/dart-sdk-linux-x64.zip.zip, and cannot find /home/runner/flutter/bin/cache/dart-sdk-linux-x64.zip.ZIP, period.

It appears that the downloaded file is corrupt; please try again.
If this problem persists, please report the problem at:
  https://github.com/flutter/flutter/issues/new?template=01_activation.yml

That's the same symptom as at #1688 (comment) , when Flutter's origin/main diverged from its origin/master. But I just fetched in my Flutter clone to check, and both those branches are at the same commit flutter/flutter@f277865a8 — so the cause this time is different.

And in fact there doesn't seem to be a commit in the upstream repo with the commit ID from that failure output:
flutter/flutter@2d053c1

@gnprice
Copy link
Member

gnprice commented Jul 23, 2025

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Keep topic-list page updated, by tracking topics in ChannelStore
2 participants