mirror of
https://github.com/RYGhub/royalnet.git
synced 2024-11-23 19:44:20 +00:00
previous support
This commit is contained in:
parent
a4c9af91a0
commit
ac116c37a1
3 changed files with 11 additions and 3 deletions
|
@ -31,13 +31,14 @@ class ApiKei(PageStar):
|
|||
kpid = form["kpid"]
|
||||
convid = form["convid"]
|
||||
message = form.get("message")
|
||||
previous = form.get("previous")
|
||||
first = form.get("first", False)
|
||||
|
||||
person = await asyncify(session.query(self.alchemy.get(KeiPerson)).filter_by(kpid=kpid).one_or_none)
|
||||
if person is None:
|
||||
person = self.alchemy.get(KeiPerson)(kpid=kpid)
|
||||
session.add(person)
|
||||
message = self.alchemy.get(KeiMessage)(kei_person=person, message=message)
|
||||
message = self.alchemy.get(KeiMessage)(kei_person=person, message=message, previous=previous)
|
||||
session.add(message)
|
||||
await asyncify(session.commit)
|
||||
# Find conversation
|
||||
|
@ -55,7 +56,8 @@ class ApiKei(PageStar):
|
|||
try:
|
||||
result = await conv.next(session=session,
|
||||
person=person,
|
||||
message=message)
|
||||
message=message,
|
||||
previous=previous)
|
||||
except StopAsyncIteration:
|
||||
del self._conversations[convid]
|
||||
continue
|
||||
|
|
|
@ -18,6 +18,10 @@ class KeiMessage:
|
|||
def kei_person(self):
|
||||
return relationship("KeiPerson", foreign_keys=self.kei_person_id, backref="kei_messages")
|
||||
|
||||
@declared_attr
|
||||
def previous(self):
|
||||
return Column(String)
|
||||
|
||||
@declared_attr
|
||||
def message(self):
|
||||
return Column(String, nullable=False)
|
||||
|
|
|
@ -10,6 +10,7 @@ class Conversation:
|
|||
self._person = None
|
||||
self._session = None
|
||||
self._message = None
|
||||
self._previous = None
|
||||
|
||||
async def _generator(self):
|
||||
yield
|
||||
|
@ -21,10 +22,11 @@ class Conversation:
|
|||
await conv.generator.asend(None)
|
||||
return conv
|
||||
|
||||
async def next(self, session, person, message):
|
||||
async def next(self, session, person, message, previous):
|
||||
self._session = session
|
||||
self._person = person
|
||||
self._message = message
|
||||
self._previous = previous
|
||||
reply = await self.generator.asend(None)
|
||||
return reply
|
||||
|
||||
|
|
Loading…
Reference in a new issue