File: beeper.py

package info (click to toggle)
mautrix-python 0.20.7-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,812 kB
  • sloc: python: 19,103; makefile: 16
file content (64 lines) | stat: -rw-r--r-- 1,961 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# Copyright (c) 2022 Tulir Asokan
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
from typing import Optional

from attr import dataclass

from ..primitive import EventID, RoomID, SessionID
from ..util import SerializableAttrs, SerializableEnum, field
from .base import BaseRoomEvent
from .message import RelatesTo


class MessageStatusReason(SerializableEnum):
    GENERIC_ERROR = "m.event_not_handled"
    UNSUPPORTED = "com.beeper.unsupported_event"
    UNDECRYPTABLE = "com.beeper.undecryptable_event"
    TOO_OLD = "m.event_too_old"
    NETWORK_ERROR = "m.foreign_network_error"
    NO_PERMISSION = "m.no_permission"

    @property
    def checkpoint_status(self):
        from mautrix.util.message_send_checkpoint import MessageSendCheckpointStatus

        if self == MessageStatusReason.UNSUPPORTED:
            return MessageSendCheckpointStatus.UNSUPPORTED
        elif self == MessageStatusReason.TOO_OLD:
            return MessageSendCheckpointStatus.TIMEOUT
        return MessageSendCheckpointStatus.PERM_FAILURE


class MessageStatus(SerializableEnum):
    SUCCESS = "SUCCESS"
    PENDING = "PENDING"
    RETRIABLE = "FAIL_RETRIABLE"
    FAIL = "FAIL_PERMANENT"


@dataclass(kw_only=True)
class BeeperMessageStatusEventContent(SerializableAttrs):
    relates_to: RelatesTo = field(json="m.relates_to")
    network: str = ""
    status: Optional[MessageStatus] = None

    reason: Optional[MessageStatusReason] = None
    error: Optional[str] = None
    message: Optional[str] = None

    last_retry: Optional[EventID] = None


@dataclass
class BeeperMessageStatusEvent(BaseRoomEvent, SerializableAttrs):
    content: BeeperMessageStatusEventContent


@dataclass
class BeeperRoomKeyAckEventContent(SerializableAttrs):
    room_id: RoomID
    session_id: SessionID
    first_message_index: int