12
12
# See the License for the specific language governing permissions and
13
13
# limitations under the License.
14
14
import logging
15
- from typing import (
16
- TYPE_CHECKING ,
17
- Collection ,
18
- Dict ,
19
- FrozenSet ,
20
- Iterable ,
21
- List ,
22
- Optional ,
23
- Tuple ,
24
- )
15
+ from typing import TYPE_CHECKING , Dict , FrozenSet , Iterable , List , Optional , Tuple
25
16
26
17
import attr
27
18
@@ -253,13 +244,19 @@ async def get_annotations_for_event(
253
244
254
245
return filtered_results
255
246
256
- async def get_threads_for_events (
257
- self , event_ids : Collection [str ], user_id : str , ignored_users : FrozenSet [str ]
247
+ async def _get_threads_for_events (
248
+ self ,
249
+ events_by_id : Dict [str , EventBase ],
250
+ relations_by_id : Dict [str , str ],
251
+ user_id : str ,
252
+ ignored_users : FrozenSet [str ],
258
253
) -> Dict [str , _ThreadAggregation ]:
259
254
"""Get the bundled aggregations for threads for the requested events.
260
255
261
256
Args:
262
- event_ids: Events to get aggregations for threads.
257
+ events_by_id: A map of event_id to events to get aggregations for threads.
258
+ relations_by_id: A map of event_id to the relation type, if one exists
259
+ for that event.
263
260
user_id: The user requesting the bundled aggregations.
264
261
ignored_users: The users ignored by the requesting user.
265
262
@@ -270,6 +267,9 @@ async def get_threads_for_events(
270
267
"""
271
268
user = UserID .from_string (user_id )
272
269
270
+ # It is not valid to start a thread on an event which itself relates to another event.
271
+ event_ids = [eid for eid in events_by_id .keys () if eid not in relations_by_id ]
272
+
273
273
# Fetch thread summaries.
274
274
summaries = await self ._main_store .get_thread_summaries (event_ids )
275
275
@@ -340,7 +340,8 @@ async def get_threads_for_events(
340
340
count = thread_count ,
341
341
# If there's a thread summary it must also exist in the
342
342
# participated dictionary.
343
- current_user_participated = participated [event_id ],
343
+ current_user_participated = events_by_id [event_id ].sender == user_id
344
+ or participated [event_id ],
344
345
)
345
346
346
347
return results
@@ -398,9 +399,9 @@ async def get_bundled_aggregations(
398
399
# events to be fetched. Thus, we check those first!
399
400
400
401
# Fetch thread summaries (but only for the directly requested events).
401
- threads = await self .get_threads_for_events (
402
- # It is not valid to start a thread on an event which itself relates to another event.
403
- [ eid for eid in events_by_id . keys () if eid not in relations_by_id ] ,
402
+ threads = await self ._get_threads_for_events (
403
+ events_by_id ,
404
+ relations_by_id ,
404
405
user_id ,
405
406
ignored_users ,
406
407
)
0 commit comments