mirror of
https://git.anonymousland.org/anonymousland/synapse.git
synced 2025-08-17 17:20:31 -04:00
Merge remote-tracking branch 'upstream/release-v1.50'
This commit is contained in:
commit
e9caf56ca0
205 changed files with 4905 additions and 2749 deletions
|
@ -177,12 +177,12 @@ class EmailPusher(Pusher):
|
|||
return
|
||||
|
||||
for push_action in unprocessed:
|
||||
received_at = push_action["received_ts"]
|
||||
received_at = push_action.received_ts
|
||||
if received_at is None:
|
||||
received_at = 0
|
||||
notif_ready_at = received_at + DELAY_BEFORE_MAIL_MS
|
||||
|
||||
room_ready_at = self.room_ready_to_notify_at(push_action["room_id"])
|
||||
room_ready_at = self.room_ready_to_notify_at(push_action.room_id)
|
||||
|
||||
should_notify_at = max(notif_ready_at, room_ready_at)
|
||||
|
||||
|
@ -193,23 +193,23 @@ class EmailPusher(Pusher):
|
|||
# to be delivered.
|
||||
|
||||
reason: EmailReason = {
|
||||
"room_id": push_action["room_id"],
|
||||
"room_id": push_action.room_id,
|
||||
"now": self.clock.time_msec(),
|
||||
"received_at": received_at,
|
||||
"delay_before_mail_ms": DELAY_BEFORE_MAIL_MS,
|
||||
"last_sent_ts": self.get_room_last_sent_ts(push_action["room_id"]),
|
||||
"throttle_ms": self.get_room_throttle_ms(push_action["room_id"]),
|
||||
"last_sent_ts": self.get_room_last_sent_ts(push_action.room_id),
|
||||
"throttle_ms": self.get_room_throttle_ms(push_action.room_id),
|
||||
}
|
||||
|
||||
await self.send_notification(unprocessed, reason)
|
||||
|
||||
await self.save_last_stream_ordering_and_success(
|
||||
max(ea["stream_ordering"] for ea in unprocessed)
|
||||
max(ea.stream_ordering for ea in unprocessed)
|
||||
)
|
||||
|
||||
# we update the throttle on all the possible unprocessed push actions
|
||||
for ea in unprocessed:
|
||||
await self.sent_notif_update_throttle(ea["room_id"], ea)
|
||||
await self.sent_notif_update_throttle(ea.room_id, ea)
|
||||
break
|
||||
else:
|
||||
if soonest_due_at is None or should_notify_at < soonest_due_at:
|
||||
|
@ -284,10 +284,10 @@ class EmailPusher(Pusher):
|
|||
# THROTTLE_RESET_AFTER_MS after the previous one that triggered a
|
||||
# notif, we release the throttle. Otherwise, the throttle is increased.
|
||||
time_of_previous_notifs = await self.store.get_time_of_last_push_action_before(
|
||||
notified_push_action["stream_ordering"]
|
||||
notified_push_action.stream_ordering
|
||||
)
|
||||
|
||||
time_of_this_notifs = notified_push_action["received_ts"]
|
||||
time_of_this_notifs = notified_push_action.received_ts
|
||||
|
||||
if time_of_previous_notifs is not None and time_of_this_notifs is not None:
|
||||
gap = time_of_this_notifs - time_of_previous_notifs
|
||||
|
|
|
@ -192,7 +192,7 @@ class HttpPusher(Pusher):
|
|||
"http-push",
|
||||
tags={
|
||||
"authenticated_entity": self.user_id,
|
||||
"event_id": push_action["event_id"],
|
||||
"event_id": push_action.event_id,
|
||||
"app_id": self.app_id,
|
||||
"app_display_name": self.app_display_name,
|
||||
},
|
||||
|
@ -202,7 +202,7 @@ class HttpPusher(Pusher):
|
|||
if processed:
|
||||
http_push_processed_counter.inc()
|
||||
self.backoff_delay = HttpPusher.INITIAL_BACKOFF_SEC
|
||||
self.last_stream_ordering = push_action["stream_ordering"]
|
||||
self.last_stream_ordering = push_action.stream_ordering
|
||||
pusher_still_exists = (
|
||||
await self.store.update_pusher_last_stream_ordering_and_success(
|
||||
self.app_id,
|
||||
|
@ -245,7 +245,7 @@ class HttpPusher(Pusher):
|
|||
self.pushkey,
|
||||
)
|
||||
self.backoff_delay = HttpPusher.INITIAL_BACKOFF_SEC
|
||||
self.last_stream_ordering = push_action["stream_ordering"]
|
||||
self.last_stream_ordering = push_action.stream_ordering
|
||||
await self.store.update_pusher_last_stream_ordering(
|
||||
self.app_id,
|
||||
self.pushkey,
|
||||
|
@ -268,17 +268,17 @@ class HttpPusher(Pusher):
|
|||
break
|
||||
|
||||
async def _process_one(self, push_action: HttpPushAction) -> bool:
|
||||
if "notify" not in push_action["actions"]:
|
||||
if "notify" not in push_action.actions:
|
||||
return True
|
||||
|
||||
tweaks = push_rule_evaluator.tweaks_for_actions(push_action["actions"])
|
||||
tweaks = push_rule_evaluator.tweaks_for_actions(push_action.actions)
|
||||
badge = await push_tools.get_badge_count(
|
||||
self.hs.get_datastore(),
|
||||
self.user_id,
|
||||
group_by_room=self._group_unread_count_by_room,
|
||||
)
|
||||
|
||||
event = await self.store.get_event(push_action["event_id"], allow_none=True)
|
||||
event = await self.store.get_event(push_action.event_id, allow_none=True)
|
||||
if event is None:
|
||||
return True # It's been redacted
|
||||
rejected = await self.dispatch_push(event, tweaks, badge)
|
||||
|
|
|
@ -232,15 +232,13 @@ class Mailer:
|
|||
reason: The notification that was ready and is the cause of an email
|
||||
being sent.
|
||||
"""
|
||||
rooms_in_order = deduped_ordered_list([pa["room_id"] for pa in push_actions])
|
||||
rooms_in_order = deduped_ordered_list([pa.room_id for pa in push_actions])
|
||||
|
||||
notif_events = await self.store.get_events(
|
||||
[pa["event_id"] for pa in push_actions]
|
||||
)
|
||||
notif_events = await self.store.get_events([pa.event_id for pa in push_actions])
|
||||
|
||||
notifs_by_room: Dict[str, List[EmailPushAction]] = {}
|
||||
for pa in push_actions:
|
||||
notifs_by_room.setdefault(pa["room_id"], []).append(pa)
|
||||
notifs_by_room.setdefault(pa.room_id, []).append(pa)
|
||||
|
||||
# collect the current state for all the rooms in which we have
|
||||
# notifications
|
||||
|
@ -264,7 +262,7 @@ class Mailer:
|
|||
await concurrently_execute(_fetch_room_state, rooms_in_order, 3)
|
||||
|
||||
# actually sort our so-called rooms_in_order list, most recent room first
|
||||
rooms_in_order.sort(key=lambda r: -(notifs_by_room[r][-1]["received_ts"] or 0))
|
||||
rooms_in_order.sort(key=lambda r: -(notifs_by_room[r][-1].received_ts or 0))
|
||||
|
||||
rooms: List[RoomVars] = []
|
||||
|
||||
|
@ -356,7 +354,7 @@ class Mailer:
|
|||
# Check if one of the notifs is an invite event for the user.
|
||||
is_invite = False
|
||||
for n in notifs:
|
||||
ev = notif_events[n["event_id"]]
|
||||
ev = notif_events[n.event_id]
|
||||
if ev.type == EventTypes.Member and ev.state_key == user_id:
|
||||
if ev.content.get("membership") == Membership.INVITE:
|
||||
is_invite = True
|
||||
|
@ -376,7 +374,7 @@ class Mailer:
|
|||
if not is_invite:
|
||||
for n in notifs:
|
||||
notifvars = await self._get_notif_vars(
|
||||
n, user_id, notif_events[n["event_id"]], room_state_ids
|
||||
n, user_id, notif_events[n.event_id], room_state_ids
|
||||
)
|
||||
|
||||
# merge overlapping notifs together.
|
||||
|
@ -444,15 +442,15 @@ class Mailer:
|
|||
"""
|
||||
|
||||
results = await self.store.get_events_around(
|
||||
notif["room_id"],
|
||||
notif["event_id"],
|
||||
notif.room_id,
|
||||
notif.event_id,
|
||||
before_limit=CONTEXT_BEFORE,
|
||||
after_limit=CONTEXT_AFTER,
|
||||
)
|
||||
|
||||
ret: NotifVars = {
|
||||
"link": self._make_notif_link(notif),
|
||||
"ts": notif["received_ts"],
|
||||
"ts": notif.received_ts,
|
||||
"messages": [],
|
||||
}
|
||||
|
||||
|
@ -516,7 +514,7 @@ class Mailer:
|
|||
|
||||
ret: MessageVars = {
|
||||
"event_type": event.type,
|
||||
"is_historical": event.event_id != notif["event_id"],
|
||||
"is_historical": event.event_id != notif.event_id,
|
||||
"id": event.event_id,
|
||||
"ts": event.origin_server_ts,
|
||||
"sender_name": sender_name,
|
||||
|
@ -610,7 +608,7 @@ class Mailer:
|
|||
# See if one of the notifs is an invite event for the user
|
||||
invite_event = None
|
||||
for n in notifs:
|
||||
ev = notif_events[n["event_id"]]
|
||||
ev = notif_events[n.event_id]
|
||||
if ev.type == EventTypes.Member and ev.state_key == user_id:
|
||||
if ev.content.get("membership") == Membership.INVITE:
|
||||
invite_event = ev
|
||||
|
@ -659,7 +657,7 @@ class Mailer:
|
|||
if len(notifs) == 1:
|
||||
# There is just the one notification, so give some detail
|
||||
sender_name = None
|
||||
event = notif_events[notifs[0]["event_id"]]
|
||||
event = notif_events[notifs[0].event_id]
|
||||
if ("m.room.member", event.sender) in room_state_ids:
|
||||
state_event_id = room_state_ids[("m.room.member", event.sender)]
|
||||
state_event = await self.store.get_event(state_event_id)
|
||||
|
@ -753,9 +751,9 @@ class Mailer:
|
|||
# are already in descending received_ts.
|
||||
sender_ids = {}
|
||||
for n in notifs:
|
||||
sender = notif_events[n["event_id"]].sender
|
||||
sender = notif_events[n.event_id].sender
|
||||
if sender not in sender_ids:
|
||||
sender_ids[sender] = n["event_id"]
|
||||
sender_ids[sender] = n.event_id
|
||||
|
||||
# Get the actual member events (in order to calculate a pretty name for
|
||||
# the room).
|
||||
|
@ -830,17 +828,17 @@ class Mailer:
|
|||
if self.hs.config.email.email_riot_base_url:
|
||||
return "%s/#/room/%s/%s" % (
|
||||
self.hs.config.email.email_riot_base_url,
|
||||
notif["room_id"],
|
||||
notif["event_id"],
|
||||
notif.room_id,
|
||||
notif.event_id,
|
||||
)
|
||||
elif self.app_name == "Vector":
|
||||
# need /beta for Universal Links to work on iOS
|
||||
return "https://vector.im/beta/#/room/%s/%s" % (
|
||||
notif["room_id"],
|
||||
notif["event_id"],
|
||||
notif.room_id,
|
||||
notif.event_id,
|
||||
)
|
||||
else:
|
||||
return "https://matrix.to/#/%s/%s" % (notif["room_id"], notif["event_id"])
|
||||
return "https://matrix.to/#/%s/%s" % (notif.room_id, notif.event_id)
|
||||
|
||||
def _make_unsubscribe_link(
|
||||
self, user_id: str, app_id: str, email_address: str
|
||||
|
|
|
@ -17,9 +17,10 @@ import logging
|
|||
import re
|
||||
from typing import Any, Dict, List, Optional, Pattern, Tuple, Union
|
||||
|
||||
from matrix_common.regex import glob_to_regex, to_word_pattern
|
||||
|
||||
from synapse.events import EventBase
|
||||
from synapse.types import JsonDict, UserID
|
||||
from synapse.util import glob_to_regex, re_word_boundary
|
||||
from synapse.util.caches.lrucache import LruCache
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
@ -184,7 +185,7 @@ class PushRuleEvaluatorForEvent:
|
|||
r = regex_cache.get((display_name, False, True), None)
|
||||
if not r:
|
||||
r1 = re.escape(display_name)
|
||||
r1 = re_word_boundary(r1)
|
||||
r1 = to_word_pattern(r1)
|
||||
r = re.compile(r1, flags=re.IGNORECASE)
|
||||
regex_cache[(display_name, False, True)] = r
|
||||
|
||||
|
@ -213,7 +214,7 @@ def _glob_matches(glob: str, value: str, word_boundary: bool = False) -> bool:
|
|||
try:
|
||||
r = regex_cache.get((glob, True, word_boundary), None)
|
||||
if not r:
|
||||
r = glob_to_regex(glob, word_boundary)
|
||||
r = glob_to_regex(glob, word_boundary=word_boundary)
|
||||
regex_cache[(glob, True, word_boundary)] = r
|
||||
return bool(r.search(value))
|
||||
except re.error:
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
# limitations under the License.
|
||||
from typing import Dict
|
||||
|
||||
from synapse.api.constants import ReceiptTypes
|
||||
from synapse.events import EventBase
|
||||
from synapse.push.presentable_names import calculate_room_name, name_from_member_event
|
||||
from synapse.storage import Storage
|
||||
|
@ -23,7 +24,7 @@ async def get_badge_count(store: DataStore, user_id: str, group_by_room: bool) -
|
|||
invites = await store.get_invited_rooms_for_local_user(user_id)
|
||||
joins = await store.get_rooms_for_user(user_id)
|
||||
|
||||
my_receipts_by_room = await store.get_receipts_for_user(user_id, "m.read")
|
||||
my_receipts_by_room = await store.get_receipts_for_user(user_id, ReceiptTypes.READ)
|
||||
|
||||
badge = len(invites)
|
||||
|
||||
|
@ -36,7 +37,7 @@ async def get_badge_count(store: DataStore, user_id: str, group_by_room: bool) -
|
|||
room_id, user_id, last_unread_event_id
|
||||
)
|
||||
)
|
||||
if notifs["notify_count"] == 0:
|
||||
if notifs.notify_count == 0:
|
||||
continue
|
||||
|
||||
if group_by_room:
|
||||
|
@ -44,7 +45,7 @@ async def get_badge_count(store: DataStore, user_id: str, group_by_room: bool) -
|
|||
badge += 1
|
||||
else:
|
||||
# increment the badge count by the number of unread messages in the room
|
||||
badge += notifs["notify_count"]
|
||||
badge += notifs.notify_count
|
||||
return badge
|
||||
|
||||
|
||||
|
|
|
@ -27,6 +27,7 @@ from synapse.push.pusher import PusherFactory
|
|||
from synapse.replication.http.push import ReplicationRemovePusherRestServlet
|
||||
from synapse.types import JsonDict, RoomStreamToken
|
||||
from synapse.util.async_helpers import concurrently_execute
|
||||
from synapse.util.threepids import canonicalise_email
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from synapse.server import HomeServer
|
||||
|
@ -113,7 +114,9 @@ class PusherPool:
|
|||
"""
|
||||
|
||||
if kind == "email":
|
||||
email_owner = await self.store.get_user_id_by_threepid("email", pushkey)
|
||||
email_owner = await self.store.get_user_id_by_threepid(
|
||||
"email", canonicalise_email(pushkey)
|
||||
)
|
||||
if email_owner != user_id:
|
||||
raise SynapseError(400, "Email not found", Codes.THREEPID_NOT_FOUND)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue