mirror of
https://github.com/element-hq/synapse.git
synced 2024-11-26 03:25:53 +03:00
Closer to right
This commit is contained in:
parent
87d95615d4
commit
61cea4e9b7
2 changed files with 157 additions and 12 deletions
|
@ -1324,9 +1324,10 @@ class PersistEventsStore:
|
|||
)
|
||||
sliding_sync_joined_rooms_insert_map["room_type"] = room_type
|
||||
elif event_id == room_encryption_event_id:
|
||||
is_encrypted = event_json.get("content", {}).get(
|
||||
encryption_algorithm = event_json.get("content", {}).get(
|
||||
EventContentFields.ENCRYPTION_ALGORITHM
|
||||
)
|
||||
is_encrypted = encryption_algorithm is not None
|
||||
sliding_sync_joined_rooms_insert_map["is_encrypted"] = is_encrypted
|
||||
elif event_id == room_name_event_id:
|
||||
room_name = event_json.get("content", {}).get(
|
||||
|
@ -1459,9 +1460,10 @@ class PersistEventsStore:
|
|||
room_type
|
||||
)
|
||||
elif event_type == EventTypes.RoomEncryption:
|
||||
is_encrypted = event_json.get("content", {}).get(
|
||||
encryption_algorithm = event_json.get("content", {}).get(
|
||||
EventContentFields.ENCRYPTION_ALGORITHM
|
||||
)
|
||||
is_encrypted = encryption_algorithm is not None
|
||||
sliding_sync_non_joined_rooms_insert_map["is_encrypted"] = (
|
||||
is_encrypted
|
||||
)
|
||||
|
@ -1483,14 +1485,18 @@ class PersistEventsStore:
|
|||
# TODO: Only do this for non-join membership
|
||||
txn.execute_batch(
|
||||
f"""
|
||||
WITH data_table (room_id, user_id, membership_event_id, membership, event_stream_ordering, {", ".join(insert_keys)}) AS (
|
||||
VALUES (
|
||||
?, ?, ?,
|
||||
(SELECT membership FROM room_memberships WHERE event_id = ?),
|
||||
(SELECT stream_ordering FROM events WHERE event_id = ?),
|
||||
{", ".join("?" for _ in insert_values)}
|
||||
)
|
||||
)
|
||||
INSERT INTO sliding_sync_non_join_memberships
|
||||
(room_id, user_id, membership_event_id, membership, event_stream_ordering, {", ".join(insert_keys)})
|
||||
VALUES (
|
||||
?, ?, ?,
|
||||
(SELECT membership FROM room_memberships WHERE event_id = ?),
|
||||
(SELECT stream_ordering FROM events WHERE event_id = ?),
|
||||
{", ".join("?" for _ in insert_values)}
|
||||
)
|
||||
SELECT * FROM data_table
|
||||
WHERE membership != ?
|
||||
ON CONFLICT (room_id, user_id)
|
||||
DO UPDATE SET
|
||||
membership_event_id = EXCLUDED.membership_event_id,
|
||||
|
@ -1505,6 +1511,7 @@ class PersistEventsStore:
|
|||
membership_event_id,
|
||||
membership_event_id,
|
||||
membership_event_id,
|
||||
Membership.JOIN,
|
||||
]
|
||||
+ list(insert_values)
|
||||
for membership_event_id, user_id in membership_event_id_to_user_id_map.items()
|
||||
|
|
|
@ -24,7 +24,7 @@ from typing import List, Optional
|
|||
|
||||
from twisted.test.proto_helpers import MemoryReactor
|
||||
|
||||
from synapse.api.constants import EventTypes, Membership
|
||||
from synapse.api.constants import EventTypes, Membership, EventContentFields, RoomTypes
|
||||
from synapse.api.room_versions import RoomVersions
|
||||
from synapse.events import EventBase
|
||||
from synapse.federation.federation_base import event_from_pdu_json
|
||||
|
@ -499,9 +499,14 @@ class SlidingSyncPrePopulatedTablesTestCase(HomeserverTestCase):
|
|||
room.register_servlets,
|
||||
]
|
||||
|
||||
def test_TODO(self) -> None:
|
||||
def prepare(
|
||||
self, reactor: MemoryReactor, clock: Clock, homeserver: HomeServer
|
||||
) -> None:
|
||||
self.store = self.hs.get_datastores().main
|
||||
|
||||
def test_room_with_no_info(self) -> None:
|
||||
"""
|
||||
TODO
|
||||
Test room that doesn't have a room type, encryption, or name.
|
||||
"""
|
||||
user1_id = self.register_user("user1", "pass")
|
||||
user1_tok = self.login(user1_id, "pass")
|
||||
|
@ -513,6 +518,121 @@ class SlidingSyncPrePopulatedTablesTestCase(HomeserverTestCase):
|
|||
# User1 joins the room
|
||||
self.helper.join(room_id1, user1_id, tok=user1_tok)
|
||||
|
||||
sliding_sync_joined_rooms_results = self.get_success(
|
||||
self.store.db_pool.simple_select_list(
|
||||
"sliding_sync_joined_rooms", None, retcols=("*",)
|
||||
)
|
||||
)
|
||||
logger.info(
|
||||
"sliding_sync_joined_rooms %s",
|
||||
sliding_sync_joined_rooms_results,
|
||||
)
|
||||
|
||||
sliding_sync_non_join_memberships_results = self.get_success(
|
||||
self.store.db_pool.simple_select_list(
|
||||
"sliding_sync_non_join_memberships", None, retcols=("*",)
|
||||
)
|
||||
)
|
||||
logger.info(
|
||||
"sliding_sync_non_join_memberships %s",
|
||||
sliding_sync_non_join_memberships_results,
|
||||
)
|
||||
|
||||
def test_room_with_info(self) -> None:
|
||||
"""
|
||||
TODO
|
||||
"""
|
||||
user1_id = self.register_user("user1", "pass")
|
||||
user1_tok = self.login(user1_id, "pass")
|
||||
user2_id = self.register_user("user2", "pass")
|
||||
user2_tok = self.login(user2_id, "pass")
|
||||
|
||||
room_id1 = self.helper.create_room_as(user2_id, tok=user2_tok)
|
||||
# Add a room name
|
||||
self.helper.send_state(
|
||||
room_id1,
|
||||
EventTypes.Name,
|
||||
{"name": "my super duper room"},
|
||||
tok=user2_tok,
|
||||
)
|
||||
# Encrypt the room
|
||||
self.helper.send_state(
|
||||
room_id1,
|
||||
EventTypes.RoomEncryption,
|
||||
{EventContentFields.ENCRYPTION_ALGORITHM: "m.megolm.v1.aes-sha2"},
|
||||
tok=user2_tok,
|
||||
)
|
||||
|
||||
# User1 joins the room
|
||||
self.helper.join(room_id1, user1_id, tok=user1_tok)
|
||||
|
||||
sliding_sync_joined_rooms_results = self.get_success(
|
||||
self.store.db_pool.simple_select_list(
|
||||
"sliding_sync_joined_rooms", None, retcols=("*",)
|
||||
)
|
||||
)
|
||||
logger.info(
|
||||
"sliding_sync_joined_rooms %s",
|
||||
sliding_sync_joined_rooms_results,
|
||||
)
|
||||
|
||||
sliding_sync_non_join_memberships_results = self.get_success(
|
||||
self.store.db_pool.simple_select_list(
|
||||
"sliding_sync_non_join_memberships", None, retcols=("*",)
|
||||
)
|
||||
)
|
||||
logger.info(
|
||||
"sliding_sync_non_join_memberships %s",
|
||||
sliding_sync_non_join_memberships_results,
|
||||
)
|
||||
|
||||
def test_space_room_with_info(self) -> None:
|
||||
"""
|
||||
TODO
|
||||
"""
|
||||
user1_id = self.register_user("user1", "pass")
|
||||
user1_tok = self.login(user1_id, "pass")
|
||||
user2_id = self.register_user("user2", "pass")
|
||||
user2_tok = self.login(user2_id, "pass")
|
||||
|
||||
space_room_id = self.helper.create_room_as(
|
||||
user2_id,
|
||||
tok=user2_tok,
|
||||
extra_content={
|
||||
"creation_content": {EventContentFields.ROOM_TYPE: RoomTypes.SPACE}
|
||||
},
|
||||
)
|
||||
# Add a room name
|
||||
self.helper.send_state(
|
||||
space_room_id,
|
||||
EventTypes.Name,
|
||||
{"name": "my super duper space"},
|
||||
tok=user2_tok,
|
||||
)
|
||||
|
||||
# User1 joins the room
|
||||
self.helper.join(space_room_id, user1_id, tok=user1_tok)
|
||||
|
||||
sliding_sync_joined_rooms_results = self.get_success(
|
||||
self.store.db_pool.simple_select_list(
|
||||
"sliding_sync_joined_rooms", None, retcols=("*",)
|
||||
)
|
||||
)
|
||||
logger.info(
|
||||
"sliding_sync_joined_rooms %s",
|
||||
sliding_sync_joined_rooms_results,
|
||||
)
|
||||
|
||||
sliding_sync_non_join_memberships_results = self.get_success(
|
||||
self.store.db_pool.simple_select_list(
|
||||
"sliding_sync_non_join_memberships", None, retcols=("*",)
|
||||
)
|
||||
)
|
||||
logger.info(
|
||||
"sliding_sync_non_join_memberships %s",
|
||||
sliding_sync_non_join_memberships_results,
|
||||
)
|
||||
|
||||
def test_server_left_room(self) -> None:
|
||||
"""
|
||||
TODO
|
||||
|
@ -533,4 +653,22 @@ class SlidingSyncPrePopulatedTablesTestCase(HomeserverTestCase):
|
|||
# User1 leaves the room
|
||||
self.helper.leave(room_id1, user1_id, tok=user1_tok)
|
||||
|
||||
# TODO: Server left room test
|
||||
sliding_sync_joined_rooms_results = self.get_success(
|
||||
self.store.db_pool.simple_select_list(
|
||||
"sliding_sync_joined_rooms", None, retcols=("*",)
|
||||
)
|
||||
)
|
||||
logger.info(
|
||||
"sliding_sync_joined_rooms %s",
|
||||
sliding_sync_joined_rooms_results,
|
||||
)
|
||||
|
||||
sliding_sync_non_join_memberships_results = self.get_success(
|
||||
self.store.db_pool.simple_select_list(
|
||||
"sliding_sync_non_join_memberships", None, retcols=("*",)
|
||||
)
|
||||
)
|
||||
logger.info(
|
||||
"sliding_sync_non_join_memberships %s",
|
||||
sliding_sync_non_join_memberships_results,
|
||||
)
|
||||
|
|
Loading…
Reference in a new issue