mirror of
https://mau.dev/maunium/synapse.git
synced 2024-11-19 08:24:25 +01:00
Merge pull request #504 from matrix-org/erikj/highlight_count
Return highlight_count in /sync
This commit is contained in:
commit
05f78b3b52
3 changed files with 40 additions and 8 deletions
|
@ -55,6 +55,7 @@ class JoinedSyncResult(collections.namedtuple("JoinedSyncResult", [
|
||||||
"ephemeral",
|
"ephemeral",
|
||||||
"account_data",
|
"account_data",
|
||||||
"unread_notification_count",
|
"unread_notification_count",
|
||||||
|
"unread_highlight_count",
|
||||||
])):
|
])):
|
||||||
__slots__ = []
|
__slots__ = []
|
||||||
|
|
||||||
|
@ -292,9 +293,14 @@ class SyncHandler(BaseHandler):
|
||||||
notifs = yield self.unread_notifs_for_room_id(
|
notifs = yield self.unread_notifs_for_room_id(
|
||||||
room_id, sync_config, ephemeral_by_room
|
room_id, sync_config, ephemeral_by_room
|
||||||
)
|
)
|
||||||
|
|
||||||
notif_count = None
|
notif_count = None
|
||||||
|
highlight_count = None
|
||||||
if notifs is not None:
|
if notifs is not None:
|
||||||
notif_count = len(notifs)
|
notif_count = len(notifs)
|
||||||
|
highlight_count = len([
|
||||||
|
1 for notif in notifs if _action_has_highlight(notif["actions"])
|
||||||
|
])
|
||||||
|
|
||||||
current_state = yield self.get_state_at(room_id, now_token)
|
current_state = yield self.get_state_at(room_id, now_token)
|
||||||
|
|
||||||
|
@ -307,6 +313,7 @@ class SyncHandler(BaseHandler):
|
||||||
room_id, tags_by_room, account_data_by_room
|
room_id, tags_by_room, account_data_by_room
|
||||||
),
|
),
|
||||||
unread_notification_count=notif_count,
|
unread_notification_count=notif_count,
|
||||||
|
unread_highlight_count=highlight_count,
|
||||||
))
|
))
|
||||||
|
|
||||||
def account_data_for_user(self, account_data):
|
def account_data_for_user(self, account_data):
|
||||||
|
@ -529,9 +536,14 @@ class SyncHandler(BaseHandler):
|
||||||
notifs = yield self.unread_notifs_for_room_id(
|
notifs = yield self.unread_notifs_for_room_id(
|
||||||
room_id, sync_config, all_ephemeral_by_room
|
room_id, sync_config, all_ephemeral_by_room
|
||||||
)
|
)
|
||||||
|
|
||||||
notif_count = None
|
notif_count = None
|
||||||
|
highlight_count = None
|
||||||
if notifs is not None:
|
if notifs is not None:
|
||||||
notif_count = len(notifs)
|
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:
|
||||||
|
@ -553,7 +565,8 @@ 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_notification_count=notif_count,
|
||||||
|
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)
|
||||||
|
|
||||||
|
@ -692,9 +705,14 @@ class SyncHandler(BaseHandler):
|
||||||
notifs = yield self.unread_notifs_for_room_id(
|
notifs = yield self.unread_notifs_for_room_id(
|
||||||
room_id, sync_config, ephemeral_by_room
|
room_id, sync_config, ephemeral_by_room
|
||||||
)
|
)
|
||||||
|
|
||||||
notif_count = None
|
notif_count = None
|
||||||
|
highlight_count = None
|
||||||
if notifs is not None:
|
if notifs is not None:
|
||||||
notif_count = len(notifs)
|
notif_count = len(notifs)
|
||||||
|
highlight_count = len([
|
||||||
|
1 for notif in notifs if _action_has_highlight(notif["actions"])
|
||||||
|
])
|
||||||
|
|
||||||
room_sync = JoinedSyncResult(
|
room_sync = JoinedSyncResult(
|
||||||
room_id=room_id,
|
room_id=room_id,
|
||||||
|
@ -705,6 +723,7 @@ class SyncHandler(BaseHandler):
|
||||||
room_id, tags_by_room, account_data_by_room
|
room_id, tags_by_room, account_data_by_room
|
||||||
),
|
),
|
||||||
unread_notification_count=notif_count,
|
unread_notification_count=notif_count,
|
||||||
|
unread_highlight_count=highlight_count,
|
||||||
)
|
)
|
||||||
|
|
||||||
logger.debug("Room sync: %r", room_sync)
|
logger.debug("Room sync: %r", room_sync)
|
||||||
|
@ -850,8 +869,19 @@ class SyncHandler(BaseHandler):
|
||||||
notifs = yield self.store.get_unread_event_push_actions_by_room_for_user(
|
notifs = yield self.store.get_unread_event_push_actions_by_room_for_user(
|
||||||
room_id, sync_config.user.to_string(), last_unread_event_id
|
room_id, sync_config.user.to_string(), last_unread_event_id
|
||||||
)
|
)
|
||||||
else:
|
defer.returnValue(notifs)
|
||||||
|
|
||||||
# There is no new information in this period, so your notification
|
# There is no new information in this period, so your notification
|
||||||
# count is whatever it was last time.
|
# count is whatever it was last time.
|
||||||
defer.returnValue(None)
|
defer.returnValue(None)
|
||||||
defer.returnValue(notifs)
|
|
||||||
|
|
||||||
|
def _action_has_highlight(actions):
|
||||||
|
for action in actions:
|
||||||
|
try:
|
||||||
|
if action.get("set_tweak", None) == "highlight":
|
||||||
|
return action.get("value", True)
|
||||||
|
except AttributeError:
|
||||||
|
pass
|
||||||
|
|
||||||
|
return False
|
||||||
|
|
|
@ -313,6 +313,7 @@ class SyncRestServlet(RestServlet):
|
||||||
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_notification_count"] = room.unread_notification_count
|
||||||
|
result["unread_highlight_count"] = room.unread_highlight_count
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
|
@ -17,7 +17,7 @@ from ._base import SQLBaseStore
|
||||||
from twisted.internet import defer
|
from twisted.internet import defer
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
import simplejson as json
|
import ujson as json
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
@ -84,7 +84,8 @@ class EventPushActionsStore(SQLBaseStore):
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
return [
|
return [
|
||||||
{"event_id": row[0], "actions": row[1]} for row in txn.fetchall()
|
{"event_id": row[0], "actions": json.loads(row[1])}
|
||||||
|
for row in txn.fetchall()
|
||||||
]
|
]
|
||||||
|
|
||||||
ret = yield self.runInteraction(
|
ret = yield self.runInteraction(
|
||||||
|
|
Loading…
Reference in a new issue