Temporary agents and chats
This commit is contained in:
1 parent
fe596761dc
commit
e07f8ee05f
15 files changed
+447
-172
No files matched your search
@@ -0,0 +1,87 @@
|
||||
|
||||
def generate_tmp_id(app):
|
||||
app.tmp.id_counter += 1
|
||||
return "tmp-" + str(app.tmp.id_counter)
|
||||
|
||||
def is_tmp_id(id):
|
||||
return type(id) == str and id.startswith("tmp-")
|
||||
|
||||
class State:
|
||||
def __init__(self):
|
||||
self.id_counter = 0
|
||||
self.agents = {}
|
||||
self.chats = {}
|
||||
self.threads = {}
|
||||
|
||||
# list of temporary agent ids that belong to a real user
|
||||
self.user_agents = {}
|
||||
# list of temporary chat ids that belong to a real user
|
||||
self.user_chats = {}
|
||||
# list of temporary chat ids where a real agent is participating
|
||||
self.participating = {}
|
||||
|
||||
def get_user_agents(self, user_id):
|
||||
if user_id not in self.user_agents:
|
||||
self.user_agents[user_id] = []
|
||||
return self.user_agents[user_id]
|
||||
|
||||
def get_user_chats(self, user_id):
|
||||
if user_id not in self.user_chats:
|
||||
self.user_chats[user_id] = []
|
||||
return self.user_chats[user_id]
|
||||
|
||||
class Agent:
|
||||
def create(app, user_id, name, agentname, main_chat_id, description="", picture=None, kind='default', data={}):
|
||||
self = Agent()
|
||||
|
||||
self.id = None
|
||||
self.user_id = user_id
|
||||
self.name = name
|
||||
self.agentname = agentname
|
||||
self.main_chat_id = main_chat_id
|
||||
self.description = description
|
||||
self.picture = picture
|
||||
self.kind = kind
|
||||
self.data = data
|
||||
|
||||
self.id = generate_tmp_id(app)
|
||||
app.tmp.agents[self.id] = self
|
||||
app.tmp.get_user_agents(user_id).append(self.id)
|
||||
|
||||
return self
|
||||
|
||||
class Chat:
|
||||
def create(app, user_id, name, description="", picture=None, ordering=None):
|
||||
self = Chat()
|
||||
self._app = app
|
||||
|
||||
self.id = None
|
||||
self.user_id = user_id
|
||||
self.name = name
|
||||
self.description = description
|
||||
self.picture = picture
|
||||
self.ordering = ordering
|
||||
|
||||
self.messages = []
|
||||
self.threads = []
|
||||
self.participants = []
|
||||
|
||||
self.id = generate_tmp_id(app)
|
||||
app.tmp.chats[self.id] = self
|
||||
app.tmp.get_user_chats(user_id).append(self.id)
|
||||
|
||||
return self
|
||||
|
||||
class Thread:
|
||||
def create(app, chat_id, name):
|
||||
self = Thread()
|
||||
|
||||
self.chat_id = chat_id
|
||||
self.name = name
|
||||
self.id = generate_tmp_id(app)
|
||||
|
||||
app.tmp.threads[self.id] = self
|
||||
app.tmp.chats[chat_id].threads.append(self.id)
|
||||
|
||||
return self
|
||||
|
||||
Reference in new issue
Block a user