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,7 +1,7 @@
1 1
 from datetime import datetime
2
-from math import floor
3 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 6
 class Reaction(BaseModel):
7 7
     reaction: str
@@ -45,10 +45,17 @@ class Message(BaseModel):
45 45
     is_unsent: bool | None = None
46 46
     is_geoblocked_for_viewer: bool
47 47
 
48
+    _id: str = PrivateAttr(default_factory=lambda: str(uuid4()))
49
+
48 50
     def __str__(self) -> str:
49 51
         dt = datetime.fromtimestamp(self.timestamp_ms / 1000)
50 52
         dt_str = dt.strftime("%d/%m/%Y, %H:%M:%S")
51 53
         return f"{self.sender_name}({dt_str}) : {self.content}"
52 54
 
53 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