11// SPDX-License-Identifier: GPL-2.0-only WITH linking exception
2- // SPDX-FileCopyrightText: 2021-2024 grommunio GmbH
2+ // SPDX-FileCopyrightText: 2021-2025 grommunio GmbH
33// This file is part of Gromox.
44#include < algorithm>
55#include < cassert>
@@ -712,6 +712,11 @@ POPULATING_NODE::~POPULATING_NODE()
712712 free (folder_ids.pll );
713713}
714714
715+ /* *
716+ * Construct pseudo-packets for different clients based on who is watching
717+ * @folder_id/@message_id. The output ID_ARRAYS is referencing db data, so
718+ * watch your lifetimes. (The ID_ARRAYS object must not outlive @db).
719+ */
715720static db_conn::ID_ARRAYS db_engine_classify_id_array (const db_base &db,
716721 unsigned int bits, uint64_t folder_id, uint64_t message_id) try
717722{
@@ -720,8 +725,10 @@ static db_conn::ID_ARRAYS db_engine_classify_id_array(const db_base &db,
720725 if (!(sub.notification_type & bits))
721726 continue ;
722727 if (sub.b_whole || (sub.folder_id == folder_id &&
723- sub.message_id == message_id))
724- out[sub.remote_id ].push_back (sub.sub_id );
728+ sub.message_id == message_id)) {
729+ auto rid = sub.remote_id .has_value () ? sub.remote_id ->c_str () : nullptr ;
730+ out[rid].push_back (sub.sub_id );
731+ }
725732 }
726733 return out;
727734} catch (const std::bad_alloc &) {
@@ -3845,8 +3852,10 @@ void db_conn::notify_message_movecopy(BOOL b_copy, uint64_t folder_id,
38453852 continue ;
38463853 }
38473854 if (pnsub->b_whole || (pnsub->folder_id == old_fid &&
3848- pnsub->message_id == old_mid))
3849- recv_list[pnsub->remote_id ].push_back (pnsub->sub_id );
3855+ pnsub->message_id == old_mid)) {
3856+ auto rid = sub.remote_id .has_value () ? sub.remote_id ->c_str () : nullptr ;
3857+ recv_list[rid].push_back (pnsub->sub_id );
3858+ }
38503859 }
38513860 if (recv_list.size () > 0 ) {
38523861 datagram.dir = deconst (dir);
@@ -3896,8 +3905,10 @@ void db_conn::notify_folder_movecopy(BOOL b_copy, uint64_t parent_id,
38963905 }
38973906 if (pnsub->b_whole ||
38983907 (pnsub->folder_id == folder_id && pnsub->message_id == 0 ) ||
3899- (pnsub->folder_id == old_fid && pnsub->message_id == 0 ))
3900- recv_list[pnsub->remote_id ].push_back (pnsub->sub_id );
3908+ (pnsub->folder_id == old_fid && pnsub->message_id == 0 )) {
3909+ auto rid = sub.remote_id .has_value () ? sub.remote_id ->c_str () : nullptr ;
3910+ recv_list[rid].push_back (pnsub->sub_id );
3911+ }
39013912 }
39023913 if (recv_list.size () > 0 ) {
39033914 datagram.dir = deconst (dir);
0 commit comments