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

View File

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

View File

@ -83,7 +83,7 @@ QtObject {
function onModelItemFieldChanged(syncId, oldIndex, newIndex, field, value){ 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) const model = ModelStore.get(syncId)
model.setProperty(oldIndex, field, value) model.setProperty(oldIndex, field, value)