Mercurial > libervia-backend
annotate libervia/backend/models/core.py @ 4332:71c939e34ca6
XEP-0373 (OX): Adjust to gpgme updates: generate with explicit algorithm and subkeys
author | Syndace <me@syndace.dev> |
---|---|
date | Sat, 13 Jul 2024 18:28:28 +0200 |
parents | ffc43219e0b2 |
children |
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 |
4162
98687eaa6a09
models (core): separate `MessageEditData` from `MessageEdition`:
Goffi <goffi@goffi.org>
parents:
4149
diff
changeset
|
19 from pydantic import BaseModel, Field |
4149
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 |
c36295487082
core: introduce Pydantic based models in `libervia.backend.models.core`
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
22 class MessageData(dict): |
c36295487082
core: introduce Pydantic based models in `libervia.backend.models.core`
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
23 pass |
c36295487082
core: introduce Pydantic based models in `libervia.backend.models.core`
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
24 |
c36295487082
core: introduce Pydantic based models in `libervia.backend.models.core`
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
25 |
c36295487082
core: introduce Pydantic based models in `libervia.backend.models.core`
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
26 class MessageUpdateData(BaseModel): |
c36295487082
core: introduce Pydantic based models in `libervia.backend.models.core`
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
27 type: str |
c36295487082
core: introduce Pydantic based models in `libervia.backend.models.core`
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
28 |
c36295487082
core: introduce Pydantic based models in `libervia.backend.models.core`
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
29 def __init__(self, **kwargs): |
c36295487082
core: introduce Pydantic based models in `libervia.backend.models.core`
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
30 if "type" not in kwargs: |
c36295487082
core: introduce Pydantic based models in `libervia.backend.models.core`
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
31 kwargs["type"] = "reactions" |
c36295487082
core: introduce Pydantic based models in `libervia.backend.models.core`
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
32 super().__init__(**kwargs) |
c36295487082
core: introduce Pydantic based models in `libervia.backend.models.core`
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
33 |
c36295487082
core: introduce Pydantic based models in `libervia.backend.models.core`
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
34 |
c36295487082
core: introduce Pydantic based models in `libervia.backend.models.core`
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
35 class MessageReactionData(MessageUpdateData): |
c36295487082
core: introduce Pydantic based models in `libervia.backend.models.core`
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
36 reactions: dict[str, list[str]] = Field( |
c36295487082
core: introduce Pydantic based models in `libervia.backend.models.core`
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
37 description="Reaction to reacting entities mapping" |
c36295487082
core: introduce Pydantic based models in `libervia.backend.models.core`
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
38 ) |
4162
98687eaa6a09
models (core): separate `MessageEditData` from `MessageEdition`:
Goffi <goffi@goffi.org>
parents:
4149
diff
changeset
|
39 |
98687eaa6a09
models (core): separate `MessageEditData` from `MessageEdition`:
Goffi <goffi@goffi.org>
parents:
4149
diff
changeset
|
40 |
98687eaa6a09
models (core): separate `MessageEditData` from `MessageEdition`:
Goffi <goffi@goffi.org>
parents:
4149
diff
changeset
|
41 class MessageEdition(BaseModel): |
98687eaa6a09
models (core): separate `MessageEditData` from `MessageEdition`:
Goffi <goffi@goffi.org>
parents:
4149
diff
changeset
|
42 """Data used to send a message edition""" |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4166
diff
changeset
|
43 |
4162
98687eaa6a09
models (core): separate `MessageEditData` from `MessageEdition`:
Goffi <goffi@goffi.org>
parents:
4149
diff
changeset
|
44 message: dict[str, str] |
98687eaa6a09
models (core): separate `MessageEditData` from `MessageEdition`:
Goffi <goffi@goffi.org>
parents:
4149
diff
changeset
|
45 subject: dict[str, str] = Field(default_factory=dict) |
98687eaa6a09
models (core): separate `MessageEditData` from `MessageEdition`:
Goffi <goffi@goffi.org>
parents:
4149
diff
changeset
|
46 extra: dict[str, str] = Field(default_factory=dict) |
4296
ffc43219e0b2
core (models): add new models for `DiscoIdentity` and `JID`:
Goffi <goffi@goffi.org>
parents:
4270
diff
changeset
|
47 |
ffc43219e0b2
core (models): add new models for `DiscoIdentity` and `JID`:
Goffi <goffi@goffi.org>
parents:
4270
diff
changeset
|
48 |
ffc43219e0b2
core (models): add new models for `DiscoIdentity` and `JID`:
Goffi <goffi@goffi.org>
parents:
4270
diff
changeset
|
49 class DiscoIdentity(BaseModel): |
ffc43219e0b2
core (models): add new models for `DiscoIdentity` and `JID`:
Goffi <goffi@goffi.org>
parents:
4270
diff
changeset
|
50 """A single disco identity |
ffc43219e0b2
core (models): add new models for `DiscoIdentity` and `JID`:
Goffi <goffi@goffi.org>
parents:
4270
diff
changeset
|
51 |
ffc43219e0b2
core (models): add new models for `DiscoIdentity` and `JID`:
Goffi <goffi@goffi.org>
parents:
4270
diff
changeset
|
52 Note that an XMPP entity may have several disco identities. |
ffc43219e0b2
core (models): add new models for `DiscoIdentity` and `JID`:
Goffi <goffi@goffi.org>
parents:
4270
diff
changeset
|
53 """ |
ffc43219e0b2
core (models): add new models for `DiscoIdentity` and `JID`:
Goffi <goffi@goffi.org>
parents:
4270
diff
changeset
|
54 |
ffc43219e0b2
core (models): add new models for `DiscoIdentity` and `JID`:
Goffi <goffi@goffi.org>
parents:
4270
diff
changeset
|
55 name: str |
ffc43219e0b2
core (models): add new models for `DiscoIdentity` and `JID`:
Goffi <goffi@goffi.org>
parents:
4270
diff
changeset
|
56 category: str |
ffc43219e0b2
core (models): add new models for `DiscoIdentity` and `JID`:
Goffi <goffi@goffi.org>
parents:
4270
diff
changeset
|
57 type: str |