Simplify online chat solution
This commit is contained in:
parent
992cd5b1f6
commit
624e0c2ffe
@ -69,8 +69,6 @@
|
|||||||
"\n",
|
"\n",
|
||||||
"class UserService(object):\n",
|
"class UserService(object):\n",
|
||||||
"\n",
|
"\n",
|
||||||
" __metaclass__ = Singleton\n",
|
|
||||||
"\n",
|
|
||||||
" def __init__(self):\n",
|
" def __init__(self):\n",
|
||||||
" self.users_by_id = {} # key: user id, value: User\n",
|
" self.users_by_id = {} # key: user id, value: User\n",
|
||||||
"\n",
|
"\n",
|
||||||
@ -145,16 +143,7 @@
|
|||||||
" UNREAD = 0\n",
|
" UNREAD = 0\n",
|
||||||
" READ = 1\n",
|
" READ = 1\n",
|
||||||
" ACCEPTED = 2\n",
|
" ACCEPTED = 2\n",
|
||||||
" REJECTED = 3\n",
|
" REJECTED = 3"
|
||||||
"\n",
|
|
||||||
"\n",
|
|
||||||
"class Singleton(type):\n",
|
|
||||||
"\n",
|
|
||||||
" _instances = {}\n",
|
|
||||||
" def __call__(cls, *args, **kwargs):\n",
|
|
||||||
" if cls not in cls._instances:\n",
|
|
||||||
" cls._instances[cls] = super(Singleton, cls).__call__(*args, **kwargs)\n",
|
|
||||||
" return cls._instances[cls]"
|
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
|
@ -3,8 +3,6 @@ from abc import ABCMeta
|
|||||||
|
|
||||||
class UserService(object):
|
class UserService(object):
|
||||||
|
|
||||||
__metaclass__ = Singleton
|
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.users_by_id = {} # key: user id, value: User
|
self.users_by_id = {} # key: user id, value: User
|
||||||
|
|
||||||
@ -38,8 +36,8 @@ class User(object):
|
|||||||
class Chat(metaclass=ABCMeta):
|
class Chat(metaclass=ABCMeta):
|
||||||
|
|
||||||
def __init__(self, chat_id):
|
def __init__(self, chat_id):
|
||||||
self.users = []
|
|
||||||
self.chat_id = chat_id
|
self.chat_id = chat_id
|
||||||
|
self.users = []
|
||||||
self.messages = []
|
self.messages = []
|
||||||
|
|
||||||
|
|
||||||
@ -80,12 +78,3 @@ class RequestStatus(Enum):
|
|||||||
READ = 1
|
READ = 1
|
||||||
ACCEPTED = 2
|
ACCEPTED = 2
|
||||||
REJECTED = 3
|
REJECTED = 3
|
||||||
|
|
||||||
|
|
||||||
class Singleton(type):
|
|
||||||
|
|
||||||
_instances = {}
|
|
||||||
def __call__(cls, *args, **kwargs):
|
|
||||||
if cls not in cls._instances:
|
|
||||||
cls._instances[cls] = super(Singleton, cls).__call__(*args, **kwargs)
|
|
||||||
return cls._instances[cls]
|
|
Loading…
Reference in New Issue
Block a user