Skip to content
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

notify adding reactions #6072

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
Open

notify adding reactions #6072

wants to merge 10 commits into from

Conversation

r10s
Copy link
Member

@r10s r10s commented Oct 19, 2024

this PR adds an event for reactions received for one's own messages.

this will allow UIs to add notification for these reactions.

this is how it looks like on iOS' lockscreen using deltachat/deltachat-ios#2331:

@link2xt
Copy link
Collaborator

link2xt commented Oct 20, 2024

I thought Android relies on getFreshMsgs to return what should currently be in the notifications, but apparently it is not the case.

Wonder if we should deprecate getFreshMsgs and replace it with getFreshMsgCount(0) or something like this. Counting messages should be cheaper than passing arrays around.

@r10s
Copy link
Member Author

r10s commented Oct 20, 2024

at least on android, notifications are driven by DC_EVENT_INCOMING_MSG - and with this PR also DC_EVENT_INCOMING_REACTION.
i did not look further into getFreshMsg() when i realised that the reactions have no ID :)

but yes, it seems at least on android only getFreshMsg().length is used - having that as getFreshMsgsCount(0) would be nicely fitting to other places where the API uses this pattern. i did not check other OS yet, however

@@ -1482,6 +1482,15 @@ async fn add_parts(
Reaction::from(reaction_str.as_str()),
)
.await?;
if mime_parser.incoming && in_fresh {
if let Some((msg_id, _)) = rfc724_mid_exists(context, mime_in_reply_to).await? {
context.emit_event(EventType::IncomingReaction {
Copy link
Collaborator

Choose a reason for hiding this comment

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

But this emits an event for any reaction, not only to one's own sent message

Copy link
Member Author

@r10s r10s Oct 20, 2024

Choose a reason for hiding this comment

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

you're right, the condition is not sufficient (in_fresh was also wrong, fixed that and added a little test)

Copy link
Member Author

Choose a reason for hiding this comment

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

But this emits an event for any reaction, not only to one's own sent message

should be be fixed by the last commit.

not sure, however, how to test the absence of an event - the event loop should be empty, maybe test for that? @iequidoo do you know, how that can be done or even have better ideas?

Copy link
Collaborator

@iequidoo iequidoo Oct 20, 2024

Choose a reason for hiding this comment

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

You can use EventType::Test as a fence, just emit it and check that the next event is Test. That means there are no other events in the queue. Almost all the core code emits events "synchronously", there should be no parallel tasks continuing emitting events, so i think such a check is fine

deltachat-ffi/deltachat.h Outdated Show resolved Hide resolved
deltachat-ffi/deltachat.h Outdated Show resolved Hide resolved
@r10s r10s marked this pull request as ready for review October 20, 2024 16:35
)
.await?;
let is_fresh_reaction = !seen && !fetching_existing_messages;
if mime_parser.incoming && is_fresh_reaction && !reaction.is_empty() {
if let Some((msg_id, _)) = rfc724_mid_exists(context, mime_in_reply_to).await? {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I suggest to move this code to set_msg_reaction() somehow, at least there's already a call to rfc724_mid_exists(), though still the msgs table isn't accessed there, so Message::load_from_db() may be needed, but i think the check whether the message is outgoing can be merged into some existing SQL statement there

Copy link
Member Author

Choose a reason for hiding this comment

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

hm, not sure adding complexity to the function and if it is worth optimising here too much, at the level of SQL.

but set_msg_reaction() could return MsgId, so that the additional call to rfc724_mid_exists() is not needed

@@ -1484,7 +1484,7 @@ async fn add_parts(
)
.await?;
let is_fresh_reaction = !seen && !fetching_existing_messages;
if mime_parser.incoming && is_fresh_reaction {
if mime_parser.incoming && is_fresh_reaction && !reaction.is_empty() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why not emit an event when a reaction is removed? The user will continue thinking there's a reaction that doesn't exist anymore. But that would require a translation for "unreacted" or smth like this, have no better idea

Copy link
Member Author

@r10s r10s Oct 20, 2024

Choose a reason for hiding this comment

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

yes, maybe. not sure if it is worth going that path, seems a cornercase, sort of "edit" - would we eg. notify all edits in case we have an edit function at some point? also, the removal is not even shown in-app. i see these notification more as "sth. was happening", not that the user tracks all notifications and then knows the final state :) eg. on iOS these things may even be accumulated as "2 messages, 3 reactions".

so, let's focus in this PR on notify adding reactions, it is a big inprovement already. we can always iterate, maybe let's see if that is really a real-world problem :)

do whatsapp/signal/telegram show a notification for a removed reaction?

@r10s r10s changed the title notify reactions notify adding reactions Oct 20, 2024
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.

3 participants