mirror of
https://mau.dev/maunium/synapse.git
synced 2024-11-19 08:24:25 +01:00
Merge branch 'develop' into push_badge_counts
This commit is contained in:
commit
ccf9387d57
3 changed files with 36 additions and 36 deletions
|
@ -53,16 +53,23 @@ class BaseHandler(object):
|
||||||
self.event_builder_factory = hs.get_event_builder_factory()
|
self.event_builder_factory = hs.get_event_builder_factory()
|
||||||
|
|
||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
def _filter_events_for_clients(self, users, events):
|
def _filter_events_for_clients(self, user_tuples, events):
|
||||||
""" Returns dict of user_id -> list of events that user is allowed to
|
""" Returns dict of user_id -> list of events that user is allowed to
|
||||||
see.
|
see.
|
||||||
"""
|
"""
|
||||||
|
# If there is only one user, just get the state for that one user,
|
||||||
|
# otherwise just get all the state.
|
||||||
|
if len(user_tuples) == 1:
|
||||||
|
types = (
|
||||||
|
(EventTypes.RoomHistoryVisibility, ""),
|
||||||
|
(EventTypes.Member, user_tuples[0][0]),
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
types = None
|
||||||
|
|
||||||
event_id_to_state = yield self.store.get_state_for_events(
|
event_id_to_state = yield self.store.get_state_for_events(
|
||||||
frozenset(e.event_id for e in events),
|
frozenset(e.event_id for e in events),
|
||||||
types=(
|
types=types
|
||||||
(EventTypes.RoomHistoryVisibility, ""),
|
|
||||||
(EventTypes.Member, None),
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
|
|
||||||
forgotten = yield defer.gatherResults([
|
forgotten = yield defer.gatherResults([
|
||||||
|
@ -122,7 +129,7 @@ class BaseHandler(object):
|
||||||
for event in events
|
for event in events
|
||||||
if allowed(event, user_id, is_guest)
|
if allowed(event, user_id, is_guest)
|
||||||
]
|
]
|
||||||
for user_id, is_guest in users
|
for user_id, is_guest in user_tuples
|
||||||
})
|
})
|
||||||
|
|
||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
|
|
|
@ -54,8 +54,7 @@ class JoinedSyncResult(collections.namedtuple("JoinedSyncResult", [
|
||||||
"state", # dict[(str, str), FrozenEvent]
|
"state", # dict[(str, str), FrozenEvent]
|
||||||
"ephemeral",
|
"ephemeral",
|
||||||
"account_data",
|
"account_data",
|
||||||
"unread_notification_count",
|
"unread_notifications",
|
||||||
"unread_highlight_count",
|
|
||||||
])):
|
])):
|
||||||
__slots__ = []
|
__slots__ = []
|
||||||
|
|
||||||
|
@ -294,11 +293,10 @@ class SyncHandler(BaseHandler):
|
||||||
room_id, sync_config, ephemeral_by_room
|
room_id, sync_config, ephemeral_by_room
|
||||||
)
|
)
|
||||||
|
|
||||||
notif_count = None
|
unread_notifications = {}
|
||||||
highlight_count = None
|
|
||||||
if notifs is not None:
|
if notifs is not None:
|
||||||
notif_count = len(notifs)
|
unread_notifications["notification_count"] = len(notifs)
|
||||||
highlight_count = len([
|
unread_notifications["highlight_count"] = len([
|
||||||
1 for notif in notifs if _action_has_highlight(notif["actions"])
|
1 for notif in notifs if _action_has_highlight(notif["actions"])
|
||||||
])
|
])
|
||||||
|
|
||||||
|
@ -312,8 +310,7 @@ class SyncHandler(BaseHandler):
|
||||||
account_data=self.account_data_for_room(
|
account_data=self.account_data_for_room(
|
||||||
room_id, tags_by_room, account_data_by_room
|
room_id, tags_by_room, account_data_by_room
|
||||||
),
|
),
|
||||||
unread_notification_count=notif_count,
|
unread_notifications=unread_notifications,
|
||||||
unread_highlight_count=highlight_count,
|
|
||||||
))
|
))
|
||||||
|
|
||||||
def account_data_for_user(self, account_data):
|
def account_data_for_user(self, account_data):
|
||||||
|
@ -533,18 +530,6 @@ class SyncHandler(BaseHandler):
|
||||||
else:
|
else:
|
||||||
prev_batch = now_token
|
prev_batch = now_token
|
||||||
|
|
||||||
notifs = yield self.unread_notifs_for_room_id(
|
|
||||||
room_id, sync_config, all_ephemeral_by_room
|
|
||||||
)
|
|
||||||
|
|
||||||
notif_count = None
|
|
||||||
highlight_count = None
|
|
||||||
if notifs is not None:
|
|
||||||
notif_count = len(notifs)
|
|
||||||
highlight_count = len([
|
|
||||||
1 for notif in notifs if _action_has_highlight(notif["actions"])
|
|
||||||
])
|
|
||||||
|
|
||||||
just_joined = yield self.check_joined_room(sync_config, state)
|
just_joined = yield self.check_joined_room(sync_config, state)
|
||||||
if just_joined:
|
if just_joined:
|
||||||
logger.debug("User has just joined %s: needs full state",
|
logger.debug("User has just joined %s: needs full state",
|
||||||
|
@ -565,12 +550,23 @@ class SyncHandler(BaseHandler):
|
||||||
account_data=self.account_data_for_room(
|
account_data=self.account_data_for_room(
|
||||||
room_id, tags_by_room, account_data_by_room
|
room_id, tags_by_room, account_data_by_room
|
||||||
),
|
),
|
||||||
unread_notification_count=notif_count,
|
unread_notifications={},
|
||||||
unread_highlight_count=highlight_count,
|
|
||||||
)
|
)
|
||||||
logger.debug("Result for room %s: %r", room_id, room_sync)
|
logger.debug("Result for room %s: %r", room_id, room_sync)
|
||||||
|
|
||||||
if room_sync:
|
if room_sync:
|
||||||
|
notifs = yield self.unread_notifs_for_room_id(
|
||||||
|
room_id, sync_config, all_ephemeral_by_room
|
||||||
|
)
|
||||||
|
|
||||||
|
if notifs is not None:
|
||||||
|
notif_dict = room_sync.unread_notifications
|
||||||
|
notif_dict["notification_count"] = len(notifs)
|
||||||
|
notif_dict["highlight_count"] = len([
|
||||||
|
1 for notif in notifs
|
||||||
|
if _action_has_highlight(notif["actions"])
|
||||||
|
])
|
||||||
|
|
||||||
joined.append(room_sync)
|
joined.append(room_sync)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
|
@ -708,11 +704,10 @@ class SyncHandler(BaseHandler):
|
||||||
room_id, sync_config, all_ephemeral_by_room
|
room_id, sync_config, all_ephemeral_by_room
|
||||||
)
|
)
|
||||||
|
|
||||||
notif_count = None
|
unread_notifications = {}
|
||||||
highlight_count = None
|
|
||||||
if notifs is not None:
|
if notifs is not None:
|
||||||
notif_count = len(notifs)
|
unread_notifications["notification_count"] = len(notifs)
|
||||||
highlight_count = len([
|
unread_notifications["highlight_count"] = len([
|
||||||
1 for notif in notifs if _action_has_highlight(notif["actions"])
|
1 for notif in notifs if _action_has_highlight(notif["actions"])
|
||||||
])
|
])
|
||||||
|
|
||||||
|
@ -724,8 +719,7 @@ class SyncHandler(BaseHandler):
|
||||||
account_data=self.account_data_for_room(
|
account_data=self.account_data_for_room(
|
||||||
room_id, tags_by_room, account_data_by_room
|
room_id, tags_by_room, account_data_by_room
|
||||||
),
|
),
|
||||||
unread_notification_count=notif_count,
|
unread_notifications=unread_notifications,
|
||||||
unread_highlight_count=highlight_count,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
logger.debug("Room sync: %r", room_sync)
|
logger.debug("Room sync: %r", room_sync)
|
||||||
|
|
|
@ -312,8 +312,7 @@ class SyncRestServlet(RestServlet):
|
||||||
if joined:
|
if joined:
|
||||||
ephemeral_events = filter.filter_room_ephemeral(room.ephemeral)
|
ephemeral_events = filter.filter_room_ephemeral(room.ephemeral)
|
||||||
result["ephemeral"] = {"events": ephemeral_events}
|
result["ephemeral"] = {"events": ephemeral_events}
|
||||||
result["unread_notification_count"] = room.unread_notification_count
|
result["unread_notifications"] = room.unread_notifications
|
||||||
result["unread_highlight_count"] = room.unread_highlight_count
|
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue