Skip to content
This repository was archived by the owner on Apr 26, 2024. It is now read-only.

Commit 15212f5

Browse files
committed
Merge commit '77b4711bc' into anoa/dinsic_release_1_21_x
* commit '77b4711bc': Add cross-signing sigs to the `keys` object (#8234) Unread counts fixes (#8254) Fix a regression from calling read_templates. (#8252)
2 parents 7059e87 + 77b4711 commit 15212f5

File tree

8 files changed

+25
-39
lines changed

8 files changed

+25
-39
lines changed

changelog.d/8234.misc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Refactor queries for device keys and cross-signatures.

changelog.d/8252.feature

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Use the default template file when its equivalent is not found in a custom template directory.

changelog.d/8254.feature

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Add unread messages count to sync responses, as specified in [MSC2654](https://github.com/matrix-org/matrix-doc/pull/2654).

synapse/config/saml2_config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ def read_config(self, config, **kwargs):
171171

172172
self.saml2_error_html_template = self.read_templates(
173173
["saml_error.html"], saml2_config.get("template_dir")
174-
)
174+
)[0]
175175

176176
def _default_saml_config_dict(
177177
self, required_attributes: set, optional_attributes: set

synapse/push/push_tools.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ async def get_badge_count(store, user_id):
3636
)
3737
# return one badge count per conversation, as count per
3838
# message is so noisy as to be almost useless
39-
badge += 1 if notifs["unread_count"] else 0
39+
badge += 1 if notifs["notify_count"] else 0
4040
return badge
4141

4242

synapse/storage/databases/main/devices.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -291,15 +291,9 @@ async def _get_device_update_edus_by_remote(
291291
prev_id = stream_id
292292

293293
if device is not None:
294-
key_json = device.key_json
295-
if key_json:
296-
result["keys"] = db_to_json(key_json)
297-
298-
if device.signatures:
299-
for sig_user_id, sigs in device.signatures.items():
300-
result["keys"].setdefault("signatures", {}).setdefault(
301-
sig_user_id, {}
302-
).update(sigs)
294+
keys = device.keys
295+
if keys:
296+
result["keys"] = keys
303297

304298
device_display_name = device.display_name
305299
if device_display_name:

synapse/storage/databases/main/end_to_end_keys.py

Lines changed: 14 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,8 @@ class DeviceKeyLookupResult:
4343

4444
# the key data from e2e_device_keys_json. Typically includes fields like
4545
# "algorithm", "keys" (including the curve25519 identity key and the ed25519 signing
46-
# key) and "signatures" (a signature of the structure by the ed25519 key)
47-
key_json = attr.ib(type=Optional[str])
48-
49-
# cross-signing sigs on this device.
50-
# dict from (signing user_id)->(signing device_id)->sig
51-
signatures = attr.ib(type=Optional[Dict[str, Dict[str, str]]], factory=dict)
46+
# key) and "signatures" (a map from (user id) to (key id/device_id) to signature.)
47+
keys = attr.ib(type=Optional[JsonDict])
5248

5349

5450
class EndToEndKeyWorkerStore(SQLBaseStore):
@@ -70,15 +66,9 @@ async def get_e2e_device_keys_for_federation_query(
7066
for device_id, device in user_devices.items():
7167
result = {"device_id": device_id}
7268

73-
key_json = device.key_json
74-
if key_json:
75-
result["keys"] = db_to_json(key_json)
76-
77-
if device.signatures:
78-
for sig_user_id, sigs in device.signatures.items():
79-
result["keys"].setdefault("signatures", {}).setdefault(
80-
sig_user_id, {}
81-
).update(sigs)
69+
keys = device.keys
70+
if keys:
71+
result["keys"] = keys
8272

8373
device_display_name = device.display_name
8474
if device_display_name:
@@ -114,16 +104,11 @@ async def get_e2e_device_keys_for_cs_api(
114104
for user_id, device_keys in results.items():
115105
rv[user_id] = {}
116106
for device_id, device_info in device_keys.items():
117-
r = db_to_json(device_info.key_json)
107+
r = device_info.keys
118108
r["unsigned"] = {}
119109
display_name = device_info.display_name
120110
if display_name is not None:
121111
r["unsigned"]["device_display_name"] = display_name
122-
if device_info.signatures:
123-
for sig_user_id, sigs in device_info.signatures.items():
124-
r.setdefault("signatures", {}).setdefault(
125-
sig_user_id, {}
126-
).update(sigs)
127112
rv[user_id][device_id] = r
128113

129114
return rv
@@ -140,6 +125,9 @@ async def get_e2e_device_keys_and_signatures(
140125
Any cross-signatures made on the keys by the owner of the device are also
141126
included.
142127
128+
The cross-signatures are added to the `signatures` field within the `keys`
129+
object in the response.
130+
143131
Args:
144132
query_list: List of pairs of user_ids and device_ids. Device id can be None
145133
to indicate "all devices for this user"
@@ -170,7 +158,7 @@ async def get_e2e_device_keys_and_signatures(
170158
(user_id, device_id)
171159
for user_id, dev in result.items()
172160
for device_id, d in dev.items()
173-
if d is not None
161+
if d is not None and d.keys is not None
174162
)
175163

176164
for batch in batch_iter(signature_query, 50):
@@ -183,8 +171,9 @@ async def get_e2e_device_keys_and_signatures(
183171
# add each cross-signing signature to the correct device in the result dict.
184172
for (user_id, key_id, device_id, signature) in cross_sigs_result:
185173
target_device_result = result[user_id][device_id]
186-
target_device_signatures = target_device_result.signatures
187-
174+
target_device_signatures = target_device_result.keys.setdefault(
175+
"signatures", {}
176+
)
188177
signing_user_signatures = target_device_signatures.setdefault(
189178
user_id, {}
190179
)
@@ -240,7 +229,7 @@ def _get_e2e_device_keys_txn(
240229
if include_deleted_devices:
241230
deleted_devices.remove((user_id, device_id))
242231
result.setdefault(user_id, {})[device_id] = DeviceKeyLookupResult(
243-
display_name, key_json
232+
display_name, db_to_json(key_json) if key_json else None
244233
)
245234

246235
if include_deleted_devices:

synapse/storage/databases/main/schema/delta/58/15unread_count.sql

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919

2020
-- Add columns to event_push_actions and event_push_actions_staging to track unread
2121
-- messages and calculate unread counts.
22-
ALTER TABLE event_push_actions_staging ADD COLUMN unread SMALLINT NOT NULL DEFAULT 0;
23-
ALTER TABLE event_push_actions ADD COLUMN unread SMALLINT NOT NULL DEFAULT 0;
22+
ALTER TABLE event_push_actions_staging ADD COLUMN unread SMALLINT;
23+
ALTER TABLE event_push_actions ADD COLUMN unread SMALLINT;
2424

2525
-- Add column to event_push_summary
26-
ALTER TABLE event_push_summary ADD COLUMN unread_count BIGINT NOT NULL DEFAULT 0;
26+
ALTER TABLE event_push_summary ADD COLUMN unread_count BIGINT;

0 commit comments

Comments
 (0)