No need for special model attributes in Backend

This commit is contained in:
miruka 2020-05-10 15:12:59 -04:00
parent f4dca1c2c9
commit 97fdc214dd
3 changed files with 14 additions and 12 deletions

View File

@ -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,13 +75,11 @@ 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.clients: Dict[str, MatrixClient] = {}

View File

@ -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

View File

@ -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"