Mercurial > libervia-backend
annotate libervia/backend/models/core.py @ 4151:18026ce0819c
core (xmpp): message reception workflow refactoring:
- Call methods from a root async one instead of using Deferred callbacks chain.
- Use a queue to be sure to process messages in order.
author | Goffi <goffi@goffi.org> |
---|---|
date | Wed, 22 Nov 2023 14:50:35 +0100 |
parents | c36295487082 |
children | 98687eaa6a09 |
rev | line source |
---|---|
4149
c36295487082
core: introduce Pydantic based models in `libervia.backend.models.core`
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1 #!/usr/bin/env python3 |
c36295487082
core: introduce Pydantic based models in `libervia.backend.models.core`
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
2 |
c36295487082
core: introduce Pydantic based models in `libervia.backend.models.core`
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
3 # Libervia common models |
c36295487082
core: introduce Pydantic based models in `libervia.backend.models.core`
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
4 # Copyright (C) 2009-2023 Jérôme Poisson (goffi@goffi.org) |
c36295487082
core: introduce Pydantic based models in `libervia.backend.models.core`
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
5 |
c36295487082
core: introduce Pydantic based models in `libervia.backend.models.core`
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
6 # This program is free software: you can redistribute it and/or modify |
c36295487082
core: introduce Pydantic based models in `libervia.backend.models.core`
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
7 # it under the terms of the GNU Affero General Public License as published by |
c36295487082
core: introduce Pydantic based models in `libervia.backend.models.core`
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
8 # the Free Software Foundation, either version 3 of the License, or |
c36295487082
core: introduce Pydantic based models in `libervia.backend.models.core`
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
9 # (at your option) any later version. |
c36295487082
core: introduce Pydantic based models in `libervia.backend.models.core`
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
10 |
c36295487082
core: introduce Pydantic based models in `libervia.backend.models.core`
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
11 # This program is distributed in the hope that it will be useful, |
c36295487082
core: introduce Pydantic based models in `libervia.backend.models.core`
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
c36295487082
core: introduce Pydantic based models in `libervia.backend.models.core`
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
c36295487082
core: introduce Pydantic based models in `libervia.backend.models.core`
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
14 # GNU Affero General Public License for more details. |
c36295487082
core: introduce Pydantic based models in `libervia.backend.models.core`
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
15 |
c36295487082
core: introduce Pydantic based models in `libervia.backend.models.core`
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
16 # You should have received a copy of the GNU Affero General Public License |
c36295487082
core: introduce Pydantic based models in `libervia.backend.models.core`
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
17 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
c36295487082
core: introduce Pydantic based models in `libervia.backend.models.core`
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
18 |
c36295487082
core: introduce Pydantic based models in `libervia.backend.models.core`
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
19 from typing import Annotated, Literal |
c36295487082
core: introduce Pydantic based models in `libervia.backend.models.core`
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
20 |
c36295487082
core: introduce Pydantic based models in `libervia.backend.models.core`
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
21 from pydantic import BaseModel, Field, validator |
c36295487082
core: introduce Pydantic based models in `libervia.backend.models.core`
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
22 |
c36295487082
core: introduce Pydantic based models in `libervia.backend.models.core`
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
23 |
c36295487082
core: introduce Pydantic based models in `libervia.backend.models.core`
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
24 class MessageData(dict): |
c36295487082
core: introduce Pydantic based models in `libervia.backend.models.core`
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
25 pass |
c36295487082
core: introduce Pydantic based models in `libervia.backend.models.core`
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
26 |
c36295487082
core: introduce Pydantic based models in `libervia.backend.models.core`
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
27 |
c36295487082
core: introduce Pydantic based models in `libervia.backend.models.core`
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
28 class MessageUpdateData(BaseModel): |
c36295487082
core: introduce Pydantic based models in `libervia.backend.models.core`
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
29 type: str |
c36295487082
core: introduce Pydantic based models in `libervia.backend.models.core`
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
30 |
c36295487082
core: introduce Pydantic based models in `libervia.backend.models.core`
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
31 def __init__(self, **kwargs): |
c36295487082
core: introduce Pydantic based models in `libervia.backend.models.core`
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
32 if "type" not in kwargs: |
c36295487082
core: introduce Pydantic based models in `libervia.backend.models.core`
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
33 kwargs["type"] = "reactions" |
c36295487082
core: introduce Pydantic based models in `libervia.backend.models.core`
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
34 super().__init__(**kwargs) |
c36295487082
core: introduce Pydantic based models in `libervia.backend.models.core`
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
35 |
c36295487082
core: introduce Pydantic based models in `libervia.backend.models.core`
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
36 |
c36295487082
core: introduce Pydantic based models in `libervia.backend.models.core`
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
37 class MessageEditData(MessageUpdateData): |
c36295487082
core: introduce Pydantic based models in `libervia.backend.models.core`
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
38 message: dict[str, str] | None = Field( |
c36295487082
core: introduce Pydantic based models in `libervia.backend.models.core`
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
39 None, |
c36295487082
core: introduce Pydantic based models in `libervia.backend.models.core`
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
40 description=( |
c36295487082
core: introduce Pydantic based models in `libervia.backend.models.core`
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
41 "Updated message content, can be in several languages (key is language code " |
c36295487082
core: introduce Pydantic based models in `libervia.backend.models.core`
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
42 'or "" for default)' |
c36295487082
core: introduce Pydantic based models in `libervia.backend.models.core`
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
43 ), |
c36295487082
core: introduce Pydantic based models in `libervia.backend.models.core`
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
44 ) |
c36295487082
core: introduce Pydantic based models in `libervia.backend.models.core`
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
45 subject: dict[str, str] | None = Field( |
c36295487082
core: introduce Pydantic based models in `libervia.backend.models.core`
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
46 None, |
c36295487082
core: introduce Pydantic based models in `libervia.backend.models.core`
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
47 description=( |
c36295487082
core: introduce Pydantic based models in `libervia.backend.models.core`
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
48 "Updated subject of the message, can be in several languages (key is " |
c36295487082
core: introduce Pydantic based models in `libervia.backend.models.core`
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
49 'language code or "" for default)' |
c36295487082
core: introduce Pydantic based models in `libervia.backend.models.core`
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
50 ), |
c36295487082
core: introduce Pydantic based models in `libervia.backend.models.core`
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
51 ) |
c36295487082
core: introduce Pydantic based models in `libervia.backend.models.core`
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
52 mess_type: str | None = Field( |
c36295487082
core: introduce Pydantic based models in `libervia.backend.models.core`
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
53 None, |
c36295487082
core: introduce Pydantic based models in `libervia.backend.models.core`
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
54 description=( |
c36295487082
core: introduce Pydantic based models in `libervia.backend.models.core`
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
55 "Updated type of the message (cf RFC 6121 §5.2.2) + C.MESS_TYPE_INFO (system " |
c36295487082
core: introduce Pydantic based models in `libervia.backend.models.core`
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
56 "info)" |
c36295487082
core: introduce Pydantic based models in `libervia.backend.models.core`
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
57 ), |
c36295487082
core: introduce Pydantic based models in `libervia.backend.models.core`
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
58 ) |
c36295487082
core: introduce Pydantic based models in `libervia.backend.models.core`
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
59 |
c36295487082
core: introduce Pydantic based models in `libervia.backend.models.core`
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
60 |
c36295487082
core: introduce Pydantic based models in `libervia.backend.models.core`
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
61 class MessageReactionData(MessageUpdateData): |
c36295487082
core: introduce Pydantic based models in `libervia.backend.models.core`
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
62 reactions: dict[str, list[str]] = Field( |
c36295487082
core: introduce Pydantic based models in `libervia.backend.models.core`
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
63 description="Reaction to reacting entities mapping" |
c36295487082
core: introduce Pydantic based models in `libervia.backend.models.core`
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
64 ) |