Corp/backend/notifications/push_actions.py
2026-09-07 19:43:48 +03:00

79 lines
1.7 KiB
Python

from django.core import signing
PUSH_READ_SALT = "notifications.push.read.v1"
PUSH_REPLY_SALT = "notifications.push.reply.v1"
PUSH_AVATAR_SALT = "notifications.push.avatar.v1"
PUSH_READ_MAX_AGE_SECONDS = 7 * 24 * 60 * 60
PUSH_REPLY_MAX_AGE_SECONDS = 24 * 60 * 60
PUSH_AVATAR_MAX_AGE_SECONDS = 30 * 24 * 60 * 60
def build_push_read_token(
*,
notification_id: int,
user_id: int,
chat_id: int,
message_id: int,
) -> str:
return signing.dumps(
{
"notification_id": notification_id,
"user_id": user_id,
"chat_id": chat_id,
"message_id": message_id,
},
salt=PUSH_READ_SALT,
compress=True,
)
def load_push_read_token(token: str) -> dict:
return signing.loads(
token,
salt=PUSH_READ_SALT,
max_age=PUSH_READ_MAX_AGE_SECONDS,
)
def build_push_reply_token(
*,
notification_id: int,
user_id: int,
chat_id: int,
message_id: int,
) -> str:
return signing.dumps(
{
"notification_id": notification_id,
"user_id": user_id,
"chat_id": chat_id,
"message_id": message_id,
},
salt=PUSH_REPLY_SALT,
compress=True,
)
def load_push_reply_token(token: str) -> dict:
return signing.loads(
token,
salt=PUSH_REPLY_SALT,
max_age=PUSH_REPLY_MAX_AGE_SECONDS,
)
def build_push_avatar_token(path: str) -> str:
return signing.dumps(
{"path": path},
salt=PUSH_AVATAR_SALT,
compress=True,
)
def load_push_avatar_token(token: str) -> dict:
return signing.loads(
token,
salt=PUSH_AVATAR_SALT,
max_age=PUSH_AVATAR_MAX_AGE_SECONDS,
)