Fix Event.source for messages we send

This commit is contained in:
miruka 2020-02-12 08:10:59 -04:00
parent f922204644
commit 9a0969adf5
3 changed files with 18 additions and 12 deletions

View File

@ -168,7 +168,6 @@ class Event(ModelItem):
id: str = field()
event_id: str = field()
event_type: Type[nio.Event] = field()
source: Optional[nio.Event] = field()
date: datetime = field()
sender_id: str = field()
sender_name: str = field()
@ -186,7 +185,7 @@ class Event(ModelItem):
target_avatar: str = ""
is_local_echo: bool = False
local_event_type: Optional[Type[nio.Event]] = None
source: Optional[nio.Event] = None
media_url: str = ""
media_title: str = ""
@ -216,11 +215,11 @@ class Event(ModelItem):
return [link[2] for link in lxml.html.iterlinks(text)]
@property
def serialized(self) -> Dict[str, Any]:
dct = super().serialized
dct["source"] = dct["source"].__dict__
return dct
def serialize_field(self, field: str) -> Any:
if field == "source":
return self.source.__dict__ if self.source else {}
return super().serialize_field(field)
@dataclass

View File

@ -43,7 +43,11 @@ class ModelItem:
new_index = self.parent_model._sorted_data.index(self)
ModelItemFieldChanged(
self.parent_model.sync_id, old_index, new_index, name, value,
self.parent_model.sync_id,
old_index,
new_index,
name,
self.serialize_field(name),
)
@ -51,13 +55,16 @@ class ModelItem:
raise NotImplementedError()
def serialize_field(self, field: str) -> Any:
return serialize_value_for_qml(getattr(self, field), json_lists=True)
@property
def serialized(self) -> Dict[str, Any]:
"""Return this item as a dict ready to be passed to QML."""
return {
name: serialize_value_for_qml(getattr(self, name), json_lists=True)
for name in dir(self)
name: self.serialize_field(name) for name in dir(self)
if not (
name.startswith("_") or name in ("parent_model", "serialized")
)

View File

@ -83,7 +83,7 @@ QtObject {
function onModelItemFieldChanged(syncId, oldIndex, newIndex, field, value){
// print("change", syncId, oldIndex, newIndex, field, value)
print("change", syncId, oldIndex, newIndex, field, value)
const model = ModelStore.get(syncId)
model.setProperty(oldIndex, field, value)