-
-
Notifications
You must be signed in to change notification settings - Fork 88
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
add chatlist changed event #2850
Conversation
I'd rather have it named |
Removing |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Android just registers for all events that could change the chatlist:
eventCenter.addObserver(DcContext.DC_EVENT_CHAT_MODIFIED, this);
eventCenter.addObserver(DcContext.DC_EVENT_CONTACTS_CHANGED, this);
eventCenter.addObserver(DcContext.DC_EVENT_INCOMING_MSG, this);
eventCenter.addObserver(DcContext.DC_EVENT_MSGS_CHANGED, this);
[Note: the next four events can only do changes within existing chats]
eventCenter.addObserver(DcContext.DC_EVENT_MSGS_NOTICED, this);
eventCenter.addObserver(DcContext.DC_EVENT_MSG_DELIVERED, this);
eventCenter.addObserver(DcContext.DC_EVENT_MSG_FAILED, this);
eventCenter.addObserver(DcContext.DC_EVENT_MSG_READ, this);
and then debounces chatlist reloading to 100ms (loadChatlistAsync()
) (it also registers for CONNECTIVITY_CHANGED
and SELFAVATAR_CHANGED
but doesn't reload the chatlist for these events). And in the most cases, these events do mean that the chatlist has to be reloaded, so we don't do many unnecessary reloads.
I'm not totally sure about this PR, as it introduces a place where things can go wrong. Like, we could forget a place where we would have to emit ChatListChanged.
It looks like the first four events above can add/remove/reorder chats and require a full chatlist reload, while the last four events only do changes within existing chats.
Maybe you can use these events in Desktop, too?
If this works for you, too, we should probably point out in the documentation that these are the events that can be used for chatlist reloading.
@@ -301,10 +302,12 @@ impl ChatId { | |||
Chattype::Group => { | |||
info!(context, "Can't block groups yet, deleting the chat"); | |||
self.delete(context).await?; | |||
context.emit_event(EventType::ChatListChanged); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Emitting the event is already done in delete()
// This event is fired when the ordering or contents of the chatlist change, | ||
// for changes in individual chat list items listen to `IncomingMsg`, `MsgsNoticed`, `MsgDelivered`, `MsgFailed`, `MsgRead` and `ChatModified` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does "or contents" mean that the event is also fired if something within a chatlist item changed (like, a read receipt was received for the last message you sent and now two green checkmarks are shown)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no, I'm open for suggestion on how to make this more clear
well, "sometimes" seems to be a bit understated here - in fact, so, in practice, so, not sure if the added complexity and the doubled events help much here. and i agree, we should not merge that now, we are in release phase and there are already lots of moving targets and bug came in by revamped things, and this again has the potential to break things badly, esp. when we start to modify existing events. also, as desktop handles the events as they are already ("also desktop already emulates this event"), it seems not be helpful for current issues or needed urgently. |
Android and iOS don't always display the chatlist. But sure maybe it's better for now to just put a |
but they could, this is not an issue with the current events when listening to the interesting ones as @Hocuri pointed out above.
+1 - these affects blocking contacts only. i suggest to close this pr, do that in another pr and go for w30 or so then :) there are bigger fishes to get :) i would not be up for revamping the event system currently. |
we thought that over recently, as already pointed out above, it makes sense to introduce a DC_EVENT_CHATLIST_CHANGED in addition to the existing events. however, that would make sense only of that new DC_EVENT_CHATLIST_CHANGED is debounced and only be emitted when all messages and updates arrived, avoiding UIs being blocked by lots of updates. we could introduce that new event easily, and the chatlists would just listen to that event instead of DC_EVENT_MSGS_CHANGED/DC_EVENT_INCOMING_MSG (that part is also the gist of this pr). |
adds an event that signals the ui to reload the chatlist. (when order changes or items are added/removed)
currently
DC_EVENT_MSGS_CHANGED
with chatid 0 is sometimes used for that, but it's missing at some places.so in the long run I think it would make sense to deprecate
DC_EVENT_MSGS_CHANGED
and replace it with more distict/specific smaller events.also desktop already emulates this event, so merging this can remove that logic from the desktop code.