fix: markseen_msgs(): Mark reactions to specified messages as seen too (#7884)#7904
fix: markseen_msgs(): Mark reactions to specified messages as seen too (#7884)#7904
Conversation
2d25772 to
13a064d
Compare
13a064d to
fd6dcca
Compare
d38a41d to
b3a8c81
Compare
i checked android and iOS, here since forever, markseen_msgs is called unconditionally, so also for outgoing ones. @nicodh can you check that for desktop as well? @iequidoo i think, this information should be added to the docs as well, smth as "as markseen_msgs() is used also for synchronisation and to track last position, it should be called unconditionally for all messages that scroll into view, including outgoing and status messages" (or whatever the exact reason is) |
ffdba8c to
adad045
Compare
Done |
adad045 to
5d091ee
Compare
5d091ee to
a0e1a4b
Compare
| }, | ||
| |rows| { | ||
| for row in rows { | ||
| msgs.push(row?); |
There was a problem hiding this comment.
Can query_map_vec be used?
There was a problem hiding this comment.
Unfortunately, we need many SQL queries here because different id and rfc724_mid are passed in each query, so it won't help a lot, we'll still need to join the returned vectors.
| " | ||
| SELECT COUNT(*) FROM msgs WHERE | ||
| state=? AND | ||
| (hidden=0 OR hidden=1) AND |
There was a problem hiding this comment.
I don't understand what hidden=0 OR hidden=1 means. Can this be removed? Is it a way to check for NULL? Does NULL ever get inserted?
There was a problem hiding this comment.
It's a way to employ msgs_index7 ON msgs (state, hidden, chat_id). Unfortunately, SQLite doesn't track all values used for a particular column, so it can't use the index because it thinks that it should iterate over all messages having state specified before. I made some experiments earlier that confirm this behavior, though i didn't repeat them for this PR.
But it seems that i made a mistake here, OR should be the final operator connecting AND-terms. The relevant docs are here: https://sqlite.org/queryplanner.html#_or_connected_terms_in_the_where_clause. Better to use hidden IN (0,1), it defenitely works well with the index because i recently measured it in 677a799.
There was a problem hiding this comment.
EXPLAIN QUERY PLAN UPDATE msgs SET state=? WHERE state=? AND chat_id=? AND timestamp<?;
QUERY PLAN
`--SEARCH msgs USING INDEX msgs_index7 (state=?)
EXPLAIN QUERY PLAN UPDATE msgs SET state=? WHERE state=? AND hidden IN (0,1) AND chat_id=? AND timestamp<?;
QUERY PLAN
`--SEARCH msgs USING INDEX msgs_index7 (state=? AND hidden=? AND chat_id=? AND timestamp<?)There was a problem hiding this comment.
I ran it on my db, so it employs also timestamp because i'm testing some locally added db migrations. But anyway, w/o hidden IN (0,1) it can't even use chat_id.
There was a problem hiding this comment.
Maybe we already add timestamp to msgs_index7? I see many places where it would be useful, e.g. calc_sort_timestamp(), building chatlists etc.
#7884) This allows to remove notifications for reactions from other devices. NB: UIs should pass all messages to markseen_msgs(), incl. outgoing ones. markseen_msgs() should be called when a message comes into view or when a reaction for a message being in view arrives. Also don't emit `MsgsNoticed` from receive_imf_inner() if the chat still contains fresh hidden messages, i.e. include reactions into this logic, to avoid removing notifications for reactions until they are seen on another device.
a0e1a4b to
dbb027d
Compare
This allows to remove notifications for reactions from other devices. NB: UIs should pass all messages to markseen_msgs(), incl. outgoing ones. markseen_msgs() should be called when a message comes into view or when a reaction for a message being in view arrives.
Also don't emit
MsgsNoticedfrom receive_imf_inner() if the chat still contains fresh hidden messages, i.e. include reactions into this logic, to avoid removing notifications for reactions until they are seen on another device.Close #7884