mirror of
https://git.anonymousland.org/anonymousland/synapse.git
synced 2025-08-15 19:00:23 -04:00
Do not consider events by ignored users for bundled aggregations (#12235)
Consider the requester's ignored users when calculating the
bundled aggregations.
See #12285 / 4df10d3214
for corresponding changes for the `/relations` endpoint.
This commit is contained in:
parent
3cdf5a1386
commit
772bad2562
6 changed files with 427 additions and 45 deletions
|
@ -1137,16 +1137,27 @@ class RelationIgnoredUserTestCase(BaseRelationsTestCase):
|
|||
"""Relations sent from an ignored user should be ignored."""
|
||||
|
||||
def _test_ignored_user(
|
||||
self, allowed_event_ids: List[str], ignored_event_ids: List[str]
|
||||
) -> None:
|
||||
self,
|
||||
relation_type: str,
|
||||
allowed_event_ids: List[str],
|
||||
ignored_event_ids: List[str],
|
||||
) -> Tuple[JsonDict, JsonDict]:
|
||||
"""
|
||||
Fetch the relations and ensure they're all there, then ignore user2, and
|
||||
repeat.
|
||||
|
||||
Returns:
|
||||
A tuple of two JSON dictionaries, each are bundled aggregations, the
|
||||
first is from before the user is ignored, and the second is after.
|
||||
"""
|
||||
# Get the relations.
|
||||
event_ids = self._get_related_events()
|
||||
self.assertCountEqual(event_ids, allowed_event_ids + ignored_event_ids)
|
||||
|
||||
# And the bundled aggregations.
|
||||
before_aggregations = self._get_bundled_aggregations()
|
||||
self.assertIn(relation_type, before_aggregations)
|
||||
|
||||
# Ignore user2 and re-do the requests.
|
||||
self.get_success(
|
||||
self.store.add_account_data_for_user(
|
||||
|
@ -1160,6 +1171,12 @@ class RelationIgnoredUserTestCase(BaseRelationsTestCase):
|
|||
event_ids = self._get_related_events()
|
||||
self.assertCountEqual(event_ids, allowed_event_ids)
|
||||
|
||||
# And the bundled aggregations.
|
||||
after_aggregations = self._get_bundled_aggregations()
|
||||
self.assertIn(relation_type, after_aggregations)
|
||||
|
||||
return before_aggregations[relation_type], after_aggregations[relation_type]
|
||||
|
||||
def test_annotation(self) -> None:
|
||||
"""Annotations should ignore"""
|
||||
# Send 2 from us, 2 from the to be ignored user.
|
||||
|
@ -1184,7 +1201,26 @@ class RelationIgnoredUserTestCase(BaseRelationsTestCase):
|
|||
)
|
||||
ignored_event_ids.append(channel.json_body["event_id"])
|
||||
|
||||
self._test_ignored_user(allowed_event_ids, ignored_event_ids)
|
||||
before_aggregations, after_aggregations = self._test_ignored_user(
|
||||
RelationTypes.ANNOTATION, allowed_event_ids, ignored_event_ids
|
||||
)
|
||||
|
||||
self.assertCountEqual(
|
||||
before_aggregations["chunk"],
|
||||
[
|
||||
{"type": "m.reaction", "key": "a", "count": 2},
|
||||
{"type": "m.reaction", "key": "b", "count": 1},
|
||||
{"type": "m.reaction", "key": "c", "count": 1},
|
||||
],
|
||||
)
|
||||
|
||||
self.assertCountEqual(
|
||||
after_aggregations["chunk"],
|
||||
[
|
||||
{"type": "m.reaction", "key": "a", "count": 1},
|
||||
{"type": "m.reaction", "key": "b", "count": 1},
|
||||
],
|
||||
)
|
||||
|
||||
def test_reference(self) -> None:
|
||||
"""Annotations should ignore"""
|
||||
|
@ -1196,7 +1232,18 @@ class RelationIgnoredUserTestCase(BaseRelationsTestCase):
|
|||
)
|
||||
ignored_event_ids = [channel.json_body["event_id"]]
|
||||
|
||||
self._test_ignored_user(allowed_event_ids, ignored_event_ids)
|
||||
before_aggregations, after_aggregations = self._test_ignored_user(
|
||||
RelationTypes.REFERENCE, allowed_event_ids, ignored_event_ids
|
||||
)
|
||||
|
||||
self.assertCountEqual(
|
||||
[e["event_id"] for e in before_aggregations["chunk"]],
|
||||
allowed_event_ids + ignored_event_ids,
|
||||
)
|
||||
|
||||
self.assertCountEqual(
|
||||
[e["event_id"] for e in after_aggregations["chunk"]], allowed_event_ids
|
||||
)
|
||||
|
||||
def test_thread(self) -> None:
|
||||
"""Annotations should ignore"""
|
||||
|
@ -1208,7 +1255,23 @@ class RelationIgnoredUserTestCase(BaseRelationsTestCase):
|
|||
)
|
||||
ignored_event_ids = [channel.json_body["event_id"]]
|
||||
|
||||
self._test_ignored_user(allowed_event_ids, ignored_event_ids)
|
||||
before_aggregations, after_aggregations = self._test_ignored_user(
|
||||
RelationTypes.THREAD, allowed_event_ids, ignored_event_ids
|
||||
)
|
||||
|
||||
self.assertEqual(before_aggregations["count"], 2)
|
||||
self.assertTrue(before_aggregations["current_user_participated"])
|
||||
# The latest thread event has some fields that don't matter.
|
||||
self.assertEqual(
|
||||
before_aggregations["latest_event"]["event_id"], ignored_event_ids[0]
|
||||
)
|
||||
|
||||
self.assertEqual(after_aggregations["count"], 1)
|
||||
self.assertTrue(after_aggregations["current_user_participated"])
|
||||
# The latest thread event has some fields that don't matter.
|
||||
self.assertEqual(
|
||||
after_aggregations["latest_event"]["event_id"], allowed_event_ids[0]
|
||||
)
|
||||
|
||||
|
||||
class RelationRedactionTestCase(BaseRelationsTestCase):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue