Browse Source

message implémente un identifiant généré automatiquement

feature/message_filters
Figg 9 months ago
parent
commit
27a7516a57
1 changed files with 10 additions and 3 deletions
  1. 10
    3
      million/model/message.py

+ 10
- 3
million/model/message.py View File

1
 from datetime import datetime
1
 from datetime import datetime
2
-from math import floor
3
 from typing import Any, List
2
 from typing import Any, List
4
-from pydantic import BaseModel
3
+from uuid import uuid4
4
+from pydantic import BaseModel, PrivateAttr, computed_field
5
 
5
 
6
 class Reaction(BaseModel):
6
 class Reaction(BaseModel):
7
     reaction: str
7
     reaction: str
45
     is_unsent: bool | None = None
45
     is_unsent: bool | None = None
46
     is_geoblocked_for_viewer: bool
46
     is_geoblocked_for_viewer: bool
47
 
47
 
48
+    _id: str = PrivateAttr(default_factory=lambda: str(uuid4()))
49
+
48
     def __str__(self) -> str:
50
     def __str__(self) -> str:
49
         dt = datetime.fromtimestamp(self.timestamp_ms / 1000)
51
         dt = datetime.fromtimestamp(self.timestamp_ms / 1000)
50
         dt_str = dt.strftime("%d/%m/%Y, %H:%M:%S")
52
         dt_str = dt.strftime("%d/%m/%Y, %H:%M:%S")
51
         return f"{self.sender_name}({dt_str}) : {self.content}"
53
         return f"{self.sender_name}({dt_str}) : {self.content}"
52
 
54
 
53
     def __hash__(self) -> int:
55
     def __hash__(self) -> int:
54
-        return hash(self.sender_name + str(self.timestamp_ms))
56
+        return hash(self.item_id)
57
+    
58
+    @computed_field
59
+    @property
60
+    def item_id(self) -> str:
61
+        return self._id

Loading…
Cancel
Save