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.
This commit is contained in:
Goffi 2023-11-28 17:37:02 +01:00
commit c9c886480e

View file

@ -16,9 +16,7 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from typing import Annotated, Literal
from pydantic import BaseModel, Field, validator
from pydantic import BaseModel, Field
class MessageData(dict):
@ -34,31 +32,19 @@ class MessageUpdateData(BaseModel):
super().__init__(**kwargs)
class MessageEditData(MessageUpdateData):
message: dict[str, str] | None = Field(
None,
description=(
"Updated message content, can be in several languages (key is language code "
'or "" for default)'
),
)
subject: dict[str, str] | None = Field(
None,
description=(
"Updated subject of the message, can be in several languages (key is "
'language code or "" for default)'
),
)
mess_type: str | None = Field(
None,
description=(
"Updated type of the message (cf RFC 6121 §5.2.2) + C.MESS_TYPE_INFO (system "
"info)"
),
)
class MessageEditData(MessageData):
"""Data used when a new message edition has been received"""
pass
class MessageReactionData(MessageUpdateData):
reactions: dict[str, list[str]] = Field(
description="Reaction to reacting entities mapping"
)
class MessageEdition(BaseModel):
"""Data used to send a message edition"""
message: dict[str, str]
subject: dict[str, str] = Field(default_factory=dict)
extra: dict[str, str] = Field(default_factory=dict)