Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 19 additions & 7 deletions matrix_client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
from .errors import MatrixRequestError, MatrixUnexpectedResponse
from .room import Room
from .user import User
from enum import Enum
from threading import Thread
from time import sleep
from uuid import uuid4
Expand All @@ -27,11 +26,24 @@


# Cache constants used when instantiating Matrix Client to specify level of caching
class CACHE(Enum):
NONE = -1
SOME = 0
ALL = 1
class Enum(object):
def __init__(self, **kwargs):
self._values = kwargs.values()
for k, v in kwargs.items():
setattr(self, k, v)

def __contains__(self, item):
return item in self._values

class Cache(Enum):
def __init__(self):
Enum.__init__(self,
NONE = -1,
SOME = 0,
ALL = 1
)

CACHE = Cache()

class MatrixClient(object):
"""
Expand Down Expand Up @@ -121,7 +133,7 @@ def __init__(self, base_url, token=None, user_id=None,
self.invite_listeners = []
self.left_listeners = []
self.ephemeral_listeners = []
if isinstance(cache_level, CACHE):
if cache_level in CACHE:
self._cache_level = cache_level
else:
self._cache_level = CACHE.ALL
Expand Down Expand Up @@ -497,7 +509,7 @@ def _process_state_event(self, state_event, current_room):
etype = state_event["type"]

# Don't keep track of room state if caching turned off
if self._cache_level.value >= 0:
if self._cache_level >= 0:
if etype == "m.room.name":
current_room.name = state_event["content"].get("name", None)
elif etype == "m.room.canonical_alias":
Expand Down