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

Commit

Permalink
Merge branch 'develop' into babolivier/mark_unread
Browse files Browse the repository at this point in the history
  • Loading branch information
babolivier committed Jun 15, 2020
2 parents c2b4621 + 7d2532b commit 6efb2b0
Show file tree
Hide file tree
Showing 57 changed files with 363 additions and 292 deletions.
1 change: 1 addition & 0 deletions changelog.d/7648.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
In working mode, ensure that replicated data has not already been received.
1 change: 1 addition & 0 deletions changelog.d/7688.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix "Starting db txn 'get_completed_ui_auth_stages' from sentinel context" warning. The bug was introduced in 1.13.0rc1.
1 change: 1 addition & 0 deletions changelog.d/7689.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Compare the URI and method during user interactive authentication (instead of the URI twice). Bug introduced in 1.13.0rc1.
1 change: 1 addition & 0 deletions changelog.d/7692.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Replace uses of `six.iterkeys`/`iteritems`/`itervalues` with `keys()`/`items()`/`values()`.
4 changes: 1 addition & 3 deletions synapse/api/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
import logging
from typing import Optional

from six import itervalues

import pymacaroons
from netaddr import IPAddress

Expand Down Expand Up @@ -90,7 +88,7 @@ def check_from_context(self, room_version: str, event, context, do_sig_check=Tru
event, prev_state_ids, for_verification=True
)
auth_events = yield self.store.get_events(auth_events_ids)
auth_events = {(e.type, e.state_key): e for e in itervalues(auth_events)}
auth_events = {(e.type, e.state_key): e for e in auth_events.values()}

room_version_obj = KNOWN_ROOM_VERSIONS[room_version]
event_auth.check(
Expand Down
3 changes: 1 addition & 2 deletions synapse/api/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import logging
from typing import Dict, List

from six import iteritems
from six.moves import http_client

from canonicaljson import json
Expand Down Expand Up @@ -497,7 +496,7 @@ def cs_error(msg, code=Codes.UNKNOWN, **kwargs):
A dict representing the error response JSON.
"""
err = {"error": msg, "errcode": code}
for key, value in iteritems(kwargs):
for key, value in kwargs.items():
err[key] = value
return err

Expand Down
5 changes: 5 additions & 0 deletions synapse/app/generic_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -738,6 +738,11 @@ async def _process_and_notify(self, stream_name, instance_name, token, rows):
except Exception:
logger.exception("Error processing replication")

async def on_position(self, stream_name: str, instance_name: str, token: int):
await super().on_position(stream_name, instance_name, token)
# Also call on_rdata to ensure that stream positions are properly reset.
await self.on_rdata(stream_name, instance_name, token, [])

def stop_pusher(self, user_id, app_id, pushkey):
if not self.notify_pushers:
return
Expand Down
6 changes: 2 additions & 4 deletions synapse/app/homeserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@
import resource
import sys

from six import iteritems

from prometheus_client import Gauge

from twisted.application import service
Expand Down Expand Up @@ -525,7 +523,7 @@ def phone_stats_home(hs, stats, stats_process=_stats_process):
stats["total_nonbridged_users"] = total_nonbridged_users

daily_user_type_results = yield hs.get_datastore().count_daily_user_type()
for name, count in iteritems(daily_user_type_results):
for name, count in daily_user_type_results.items():
stats["daily_user_type_" + name] = count

room_count = yield hs.get_datastore().get_room_count()
Expand All @@ -537,7 +535,7 @@ def phone_stats_home(hs, stats, stats_process=_stats_process):
stats["daily_messages"] = yield hs.get_datastore().count_daily_messages()

r30_results = yield hs.get_datastore().count_r30_users()
for name, count in iteritems(r30_results):
for name, count in r30_results.items():
stats["r30_users_" + name] = count

daily_sent_messages = yield hs.get_datastore().count_daily_sent_messages()
Expand Down
4 changes: 1 addition & 3 deletions synapse/events/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@
from distutils.util import strtobool
from typing import Dict, Optional, Type

import six

from unpaddedbase64 import encode_base64

from synapse.api.room_versions import EventFormatVersions, RoomVersion, RoomVersions
Expand Down Expand Up @@ -290,7 +288,7 @@ def items(self):
return list(self._dict.items())

def keys(self):
return six.iterkeys(self._dict)
return self._dict.keys()

def prev_event_ids(self):
"""Returns the list of prev event IDs. The order matches the order
Expand Down
4 changes: 1 addition & 3 deletions synapse/events/snapshot.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
# limitations under the License.
from typing import Optional, Union

from six import iteritems

import attr
from frozendict import frozendict

Expand Down Expand Up @@ -341,7 +339,7 @@ def _encode_state_dict(state_dict):
if state_dict is None:
return None

return [(etype, state_key, v) for (etype, state_key), v in iteritems(state_dict)]
return [(etype, state_key, v) for (etype, state_key), v in state_dict.items()]


def _decode_state_dict(input):
Expand Down
4 changes: 2 additions & 2 deletions synapse/federation/federation_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ def callback(_, pdu: EventBase):
# *actual* redacted copy to be on the safe side.)
redacted_event = prune_event(pdu)
if set(redacted_event.keys()) == set(pdu.keys()) and set(
six.iterkeys(redacted_event.content)
) == set(six.iterkeys(pdu.content)):
redacted_event.content.keys()
) == set(pdu.content.keys()):
logger.info(
"Event %s seems to have been redacted; using our redacted "
"copy",
Expand Down
7 changes: 3 additions & 4 deletions synapse/federation/federation_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
from typing import Any, Callable, Dict, List, Match, Optional, Tuple, Union

import six
from six import iteritems

from canonicaljson import json
from prometheus_client import Counter
Expand Down Expand Up @@ -534,9 +533,9 @@ async def on_claim_client_keys(
",".join(
(
"%s for %s:%s" % (key_id, user_id, device_id)
for user_id, user_keys in iteritems(json_result)
for device_id, device_keys in iteritems(user_keys)
for key_id, _ in iteritems(device_keys)
for user_id, user_keys in json_result.items()
for device_id, device_keys in user_keys.items()
for key_id, _ in device_keys.items()
)
),
)
Expand Down
8 changes: 3 additions & 5 deletions synapse/federation/send_queue.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@
from collections import namedtuple
from typing import Dict, List, Tuple, Type

from six import iteritems

from sortedcontainers import SortedDict

from twisted.internet import defer
Expand Down Expand Up @@ -327,7 +325,7 @@ async def get_replication_rows(
# stream position.
keyed_edus = {v: k for k, v in self.keyed_edu_changed.items()[i:j]}

for ((destination, edu_key), pos) in iteritems(keyed_edus):
for ((destination, edu_key), pos) in keyed_edus.items():
rows.append(
(
pos,
Expand Down Expand Up @@ -530,10 +528,10 @@ def process_rows_for_federation(transaction_queue, rows):
states=[state], destinations=destinations
)

for destination, edu_map in iteritems(buff.keyed_edus):
for destination, edu_map in buff.keyed_edus.items():
for key, edu in edu_map.items():
transaction_queue.send_edu(edu, key)

for destination, edu_list in iteritems(buff.edus):
for destination, edu_list in buff.edus.items():
for edu in edu_list:
transaction_queue.send_edu(edu, None)
4 changes: 1 addition & 3 deletions synapse/federation/sender/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
import logging
from typing import Dict, Hashable, Iterable, List, Optional, Set, Tuple

from six import itervalues

from prometheus_client import Counter

from twisted.internet import defer
Expand Down Expand Up @@ -218,7 +216,7 @@ async def handle_room_events(events: Iterable[EventBase]) -> None:
defer.gatherResults(
[
run_in_background(handle_room_events, evs)
for evs in itervalues(events_by_room)
for evs in events_by_room.values()
],
consumeErrors=True,
)
Expand Down
4 changes: 1 addition & 3 deletions synapse/handlers/appservice.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@

import logging

from six import itervalues

from prometheus_client import Counter

from twisted.internet import defer
Expand Down Expand Up @@ -125,7 +123,7 @@ def handle_room_events(events):
defer.gatherResults(
[
run_in_background(handle_room_events, evs)
for evs in itervalues(events_by_room)
for evs in events_by_room.values()
],
consumeErrors=True,
)
Expand Down
2 changes: 1 addition & 1 deletion synapse/handlers/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ async def check_auth(

# Convert the URI and method to strings.
uri = request.uri.decode("utf-8")
method = request.uri.decode("utf-8")
method = request.method.decode("utf-8")

# If there's no session ID, create a new session.
if not sid:
Expand Down
14 changes: 6 additions & 8 deletions synapse/handlers/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
import logging
from typing import Any, Dict, Optional

from six import iteritems, itervalues

from twisted.internet import defer

from synapse.api import errors
Expand Down Expand Up @@ -159,7 +157,7 @@ def get_user_ids_changed(self, user_id, from_token):
# The user may have left the room
# TODO: Check if they actually did or if we were just invited.
if room_id not in room_ids:
for key, event_id in iteritems(current_state_ids):
for key, event_id in current_state_ids.items():
etype, state_key = key
if etype != EventTypes.Member:
continue
Expand All @@ -182,7 +180,7 @@ def get_user_ids_changed(self, user_id, from_token):
log_kv(
{"event": "encountered empty previous state", "room_id": room_id}
)
for key, event_id in iteritems(current_state_ids):
for key, event_id in current_state_ids.items():
etype, state_key = key
if etype != EventTypes.Member:
continue
Expand All @@ -198,10 +196,10 @@ def get_user_ids_changed(self, user_id, from_token):

# Check if we've joined the room? If so we just blindly add all the users to
# the "possibly changed" users.
for state_dict in itervalues(prev_state_ids):
for state_dict in prev_state_ids.values():
member_event = state_dict.get((EventTypes.Member, user_id), None)
if not member_event or member_event != current_member_id:
for key, event_id in iteritems(current_state_ids):
for key, event_id in current_state_ids.items():
etype, state_key = key
if etype != EventTypes.Member:
continue
Expand All @@ -211,14 +209,14 @@ def get_user_ids_changed(self, user_id, from_token):
# If there has been any change in membership, include them in the
# possibly changed list. We'll check if they are joined below,
# and we're not toooo worried about spuriously adding users.
for key, event_id in iteritems(current_state_ids):
for key, event_id in current_state_ids.items():
etype, state_key = key
if etype != EventTypes.Member:
continue

# check if this member has changed since any of the extremities
# at the stream_ordering, and add them to the list if so.
for state_dict in itervalues(prev_state_ids):
for state_dict in prev_state_ids.values():
prev_event_id = state_dict.get(key, None)
if not prev_event_id or prev_event_id != event_id:
if state_key != user_id:
Expand Down
14 changes: 6 additions & 8 deletions synapse/handlers/e2e_keys.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@

import logging

from six import iteritems

import attr
from canonicaljson import encode_canonical_json, json
from signedjson.key import decode_verify_key_bytes
Expand Down Expand Up @@ -135,7 +133,7 @@ def query_devices(self, query_body, timeout, from_user_id):
remote_queries_not_in_cache = {}
if remote_queries:
query_list = []
for user_id, device_ids in iteritems(remote_queries):
for user_id, device_ids in remote_queries.items():
if device_ids:
query_list.extend((user_id, device_id) for device_id in device_ids)
else:
Expand All @@ -145,9 +143,9 @@ def query_devices(self, query_body, timeout, from_user_id):
user_ids_not_in_cache,
remote_results,
) = yield self.store.get_user_devices_from_cache(query_list)
for user_id, devices in iteritems(remote_results):
for user_id, devices in remote_results.items():
user_devices = results.setdefault(user_id, {})
for device_id, device in iteritems(devices):
for device_id, device in devices.items():
keys = device.get("keys", None)
device_display_name = device.get("device_display_name", None)
if keys:
Expand Down Expand Up @@ -446,9 +444,9 @@ def claim_client_keys(destination):
",".join(
(
"%s for %s:%s" % (key_id, user_id, device_id)
for user_id, user_keys in iteritems(json_result)
for device_id, device_keys in iteritems(user_keys)
for key_id, _ in iteritems(device_keys)
for user_id, user_keys in json_result.items()
for device_id, device_keys in user_keys.items()
for key_id, _ in device_keys.items()
)
),
)
Expand Down
6 changes: 2 additions & 4 deletions synapse/handlers/e2e_room_keys.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@

import logging

from six import iteritems

from twisted.internet import defer

from synapse.api.errors import (
Expand Down Expand Up @@ -205,8 +203,8 @@ def upload_room_keys(self, user_id, version, room_keys):
)
to_insert = [] # batch the inserts together
changed = False # if anything has changed, we need to update the etag
for room_id, room in iteritems(room_keys["rooms"]):
for session_id, room_key in iteritems(room["sessions"]):
for room_id, room in room_keys["rooms"].items():
for session_id, room_key in room["sessions"].items():
if not isinstance(room_key["is_verified"], bool):
msg = (
"is_verified must be a boolean in keys for session %s in"
Expand Down
Loading

0 comments on commit 6efb2b0

Please sign in to comment.