mirror of
https://github.com/matrix-org/matrix-rust-sdk.git
synced 2026-06-10 09:24:20 -04:00
This patch fixes cyclic reference of `Client` in `ThreadSubscriptionCatchup`. `ThreadSubscriptionCatchup` starts a task that call `thread_subscriptions_catchup_task`. This function captures a clone of `ThreadSubscriptionCatchup` (why not…) which contains a `WeakClient`, all good, no cycle here! However, the real task (not the function) captures `Client` to call `enabled_thread_subscriptions` to know if the function `thread_subscriptions_catchup_task` must be called. Consequently, the task captures a clone of `Client`, boom, we have a cycle. This patch fixes the problem by spawning the task if and only if `Client::enabled_thread_subscriptions` returns `Ok(true)`. This check is done outside the task. It seems saner and avoid creating this cycle. Consequently, the `ThreadSubscriptionCatchup::new` method becomes `async`, which is perfectly fine as it was already wrapper inside an `async` block when initialised by the `Client`.