@@ -32,6 +32,7 @@ import {
32
32
actions as conversationActions ,
33
33
conversationChanged ,
34
34
conversationsChanged ,
35
+ markConversationFullyRead ,
35
36
MessageModelPropsWithoutConvoProps ,
36
37
ReduxConversationType ,
37
38
} from '../state/ducks/conversations' ;
@@ -1231,27 +1232,38 @@ export class ConversationModel extends Backbone.Model<ConversationAttributes> {
1231
1232
* Send read receipt if needed.
1232
1233
*/
1233
1234
public async markAllAsRead ( ) {
1234
- if ( this . isOpenGroupV2 ( ) ) {
1235
+ /**
1236
+ * when marking all as read, there is a bunch of things we need to do.
1237
+ * - we need to update all the messages in the DB not read yet for that conversation
1238
+ * - we need to send the read receipts if there is one needed for those messages
1239
+ * - we need to trigger a change on the redux store, so those messages are read AND mark the whole convo as read.
1240
+ * - we need to remove any notifications related to this conversation ID.
1241
+ *
1242
+ *
1243
+ * (if there is an expireTimer, we do it the slow way, handling each message separately)
1244
+ */
1245
+ const expireTimerSet = ! ! this . get ( 'expireTimer' ) ;
1246
+ if ( this . isOpenGroupV2 ( ) || ! expireTimerSet ) {
1235
1247
// for opengroups, we batch everything as there is no expiration timer to take care (and potentially a lot of messages)
1236
1248
1237
- await Data . markAllAsReadByConversationNoExpiration ( this . id ) ;
1249
+ const isOpenGroup = this . isOpenGroupV2 ( ) ;
1250
+ // if this is an opengroup there is no need to send read receipt, and so no need to fetch messages updated.
1251
+ const allReadMessages = await Data . markAllAsReadByConversationNoExpiration (
1252
+ this . id ,
1253
+ ! isOpenGroup
1254
+ ) ;
1238
1255
this . set ( { mentionedUs : false , unreadCount : 0 } ) ;
1239
1256
1240
1257
await this . commit ( ) ;
1241
- return ;
1242
- }
1243
-
1244
- // if the conversation has no expiration timer, we can also batch everything, but we also need to send read receipts potentially
1245
- // so we grab them from the db
1246
- if ( ! this . get ( 'expireTimer' ) ) {
1247
- const allReadMessages = await Data . markAllAsReadByConversationNoExpiration ( this . id ) ;
1248
- this . set ( { mentionedUs : false , unreadCount : 0 } ) ;
1249
- await this . commit ( ) ;
1250
- if ( allReadMessages . length ) {
1258
+ if ( ! this . isOpenGroupV2 ( ) && allReadMessages . length ) {
1251
1259
await this . sendReadReceiptsIfNeeded ( uniq ( allReadMessages ) ) ;
1252
1260
}
1261
+ Notifications . clearByConversationID ( this . id ) ;
1262
+ window . inboxStore ?. dispatch ( markConversationFullyRead ( this . id ) ) ;
1263
+
1253
1264
return ;
1254
1265
}
1266
+ // otherwise, do it the slow way
1255
1267
await this . markReadBouncy ( Date . now ( ) ) ;
1256
1268
}
1257
1269
0 commit comments