comparison libervia/backend/models/core.py @ 4162:98687eaa6a09

models (core): separate `MessageEditData` from `MessageEdition`: `MessageEditData` is used to carry a new `MessageData` when an edition has happened, while `MessageEdition` is used to send changes to do for a new edition.
author Goffi <goffi@goffi.org>
date Tue, 28 Nov 2023 17:37:02 +0100
parents c36295487082
children a1f7040b5a15
comparison
equal deleted inserted replaced
4161:2074b2bbe616 4162:98687eaa6a09
14 # GNU Affero General Public License for more details. 14 # GNU Affero General Public License for more details.
15 15
16 # You should have received a copy of the GNU Affero General Public License 16 # You should have received a copy of the GNU Affero General Public License
17 # along with this program. If not, see <http://www.gnu.org/licenses/>. 17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
18 18
19 from typing import Annotated, Literal 19 from pydantic import BaseModel, Field
20
21 from pydantic import BaseModel, Field, validator
22 20
23 21
24 class MessageData(dict): 22 class MessageData(dict):
25 pass 23 pass
26 24
32 if "type" not in kwargs: 30 if "type" not in kwargs:
33 kwargs["type"] = "reactions" 31 kwargs["type"] = "reactions"
34 super().__init__(**kwargs) 32 super().__init__(**kwargs)
35 33
36 34
37 class MessageEditData(MessageUpdateData): 35 class MessageEditData(MessageData):
38 message: dict[str, str] | None = Field( 36 """Data used when a new message edition has been received"""
39 None, 37 pass
40 description=(
41 "Updated message content, can be in several languages (key is language code "
42 'or "" for default)'
43 ),
44 )
45 subject: dict[str, str] | None = Field(
46 None,
47 description=(
48 "Updated subject of the message, can be in several languages (key is "
49 'language code or "" for default)'
50 ),
51 )
52 mess_type: str | None = Field(
53 None,
54 description=(
55 "Updated type of the message (cf RFC 6121 ยง5.2.2) + C.MESS_TYPE_INFO (system "
56 "info)"
57 ),
58 )
59 38
60 39
61 class MessageReactionData(MessageUpdateData): 40 class MessageReactionData(MessageUpdateData):
62 reactions: dict[str, list[str]] = Field( 41 reactions: dict[str, list[str]] = Field(
63 description="Reaction to reacting entities mapping" 42 description="Reaction to reacting entities mapping"
64 ) 43 )
44
45
46 class MessageEdition(BaseModel):
47 """Data used to send a message edition"""
48 message: dict[str, str]
49 subject: dict[str, str] = Field(default_factory=dict)
50 extra: dict[str, str] = Field(default_factory=dict)