13
13
# See the License for the specific language governing permissions and
14
14
# limitations under the License.
15
15
import logging
16
- from typing import TYPE_CHECKING , Any , Dict , List , Optional , Tuple , Union
16
+ from typing import TYPE_CHECKING , Dict , List , Optional , Tuple , Union
17
17
18
18
import attr
19
19
@@ -57,6 +57,13 @@ class EmailPushAction(HttpPushAction):
57
57
received_ts : Optional [int ]
58
58
59
59
60
+ @attr .s (slots = True , frozen = True , auto_attribs = True )
61
+ class UserPushAction (EmailPushAction ):
62
+ topological_ordering : int
63
+ highlight : bool
64
+ profile_tag : str
65
+
66
+
60
67
@attr .s (slots = True , frozen = True , auto_attribs = True )
61
68
class NotifCounts :
62
69
notify_count : int
@@ -973,8 +980,10 @@ async def get_push_actions_for_user(
973
980
before : Optional [str ] = None ,
974
981
limit : int = 50 ,
975
982
only_highlight : bool = False ,
976
- ) -> List [Dict [str , Any ]]:
977
- def f (txn : LoggingTransaction ) -> List [Dict [str , Any ]]:
983
+ ) -> List [UserPushAction ]:
984
+ def f (
985
+ txn : LoggingTransaction ,
986
+ ) -> List [Tuple [str , str , int , int , str , bool , str , int ]]:
978
987
before_clause = ""
979
988
if before :
980
989
before_clause = "AND epa.stream_ordering < ?"
@@ -1001,12 +1010,22 @@ def f(txn: LoggingTransaction) -> List[Dict[str, Any]]:
1001
1010
" LIMIT ?" % (before_clause ,)
1002
1011
)
1003
1012
txn .execute (sql , args )
1004
- return self . db_pool . cursor_to_dict ( txn )
1013
+ return txn . fetchall () # type: ignore[return-value]
1005
1014
1006
1015
push_actions = await self .db_pool .runInteraction ("get_push_actions_for_user" , f )
1007
- for pa in push_actions :
1008
- pa ["actions" ] = _deserialize_action (pa ["actions" ], pa ["highlight" ])
1009
- return push_actions
1016
+ return [
1017
+ UserPushAction (
1018
+ event_id = row [0 ],
1019
+ room_id = row [1 ],
1020
+ stream_ordering = row [2 ],
1021
+ actions = _deserialize_action (row [4 ], row [5 ]),
1022
+ received_ts = row [7 ],
1023
+ topological_ordering = row [3 ],
1024
+ highlight = row [5 ],
1025
+ profile_tag = row [6 ],
1026
+ )
1027
+ for row in push_actions
1028
+ ]
1010
1029
1011
1030
1012
1031
def _action_has_highlight (actions : List [Union [dict , str ]]) -> bool :
0 commit comments