From 97fdc214dd9c31e5cf3e26b6f95def8de3224cb8 Mon Sep 17 00:00:00 2001 From: miruka Date: Sun, 10 May 2020 15:12:59 -0400 Subject: [PATCH] No need for special model attributes in Backend --- src/backend/backend.py | 13 +++++-------- src/backend/models/model_store.py | 10 +++++++--- src/backend/models/special_models.py | 3 ++- 3 files changed, 14 insertions(+), 12 deletions(-) diff --git a/src/backend/backend.py b/src/backend/backend.py index 1b8f4303..012fe355 100644 --- a/src/backend/backend.py +++ b/src/backend/backend.py @@ -20,7 +20,6 @@ from .models.filters import FieldSubstringFilter from .models.items import Account from .models.model import Model from .models.model_store import ModelStore -from .models.special_models import AllRooms, MatchingAccounts from .user_files import Accounts, History, Theme, UISettings, UIState # Logging configuration @@ -76,14 +75,12 @@ class Backend: def __init__(self) -> None: self.appdirs = AppDirs(appname=__app_name__, roaming=True) - self.saved_accounts: Accounts = Accounts(self) - self.ui_settings: UISettings = UISettings(self) - self.ui_state: UIState = UIState(self) - self.history: History = History(self) + self.saved_accounts = Accounts(self) + self.ui_settings = UISettings(self) + self.ui_state = UIState(self) + self.history = History(self) - self.all_rooms = AllRooms() - self.matching_accounts = MatchingAccounts(self.all_rooms) - self.models = ModelStore() + self.models = ModelStore() self.clients: Dict[str, MatrixClient] = {} diff --git a/src/backend/models/model_store.py b/src/backend/models/model_store.py index c5c1e0f0..1e135648 100644 --- a/src/backend/models/model_store.py +++ b/src/backend/models/model_store.py @@ -2,11 +2,11 @@ from collections import UserDict from dataclasses import dataclass, field -from typing import Dict, Type +from typing import Dict from . import SyncId from .model import Model -from .special_models import FilteredMembers +from .special_models import AllRooms, FilteredMembers, MatchingAccounts @dataclass(frozen=True) @@ -28,7 +28,11 @@ class ModelStore(UserDict): model: Model - if is_tuple and len(key) == 3 and key[2] == "filtered_members": + if key == "all_rooms": + model = AllRooms() + elif key == "matching_accounts": + model = MatchingAccounts(self["all_rooms"]) + elif is_tuple and len(key) == 3 and key[2] == "filtered_members": model = FilteredMembers(user_id=key[0], room_id=key[1]) else: model = Model(sync_id=key) # type: ignore diff --git a/src/backend/models/special_models.py b/src/backend/models/special_models.py index 7c788945..7fd01cd4 100644 --- a/src/backend/models/special_models.py +++ b/src/backend/models/special_models.py @@ -20,10 +20,11 @@ class AllRooms(FieldSubstringFilter): class MatchingAccounts(ModelFilter): def __init__(self, all_rooms: AllRooms) -> None: - super().__init__(sync_id="matching_accounts") self.all_rooms = all_rooms self.all_rooms.items_changed_callbacks.append(self.refilter) + super().__init__(sync_id="matching_accounts") + def accept_source(self, source: Model) -> bool: return source.sync_id == "accounts"