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"]
|
kpid = form["kpid"]
|
||||||
convid = form["convid"]
|
convid = form["convid"]
|
||||||
message = form.get("message")
|
message = form.get("message")
|
||||||
|
previous = form.get("previous")
|
||||||
first = form.get("first", False)
|
first = form.get("first", False)
|
||||||
|
|
||||||
person = await asyncify(session.query(self.alchemy.get(KeiPerson)).filter_by(kpid=kpid).one_or_none)
|
person = await asyncify(session.query(self.alchemy.get(KeiPerson)).filter_by(kpid=kpid).one_or_none)
|
||||||
if person is None:
|
if person is None:
|
||||||
person = self.alchemy.get(KeiPerson)(kpid=kpid)
|
person = self.alchemy.get(KeiPerson)(kpid=kpid)
|
||||||
session.add(person)
|
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)
|
session.add(message)
|
||||||
await asyncify(session.commit)
|
await asyncify(session.commit)
|
||||||
# Find conversation
|
# Find conversation
|
||||||
|
@ -55,7 +56,8 @@ class ApiKei(PageStar):
|
||||||
try:
|
try:
|
||||||
result = await conv.next(session=session,
|
result = await conv.next(session=session,
|
||||||
person=person,
|
person=person,
|
||||||
message=message)
|
message=message,
|
||||||
|
previous=previous)
|
||||||
except StopAsyncIteration:
|
except StopAsyncIteration:
|
||||||
del self._conversations[convid]
|
del self._conversations[convid]
|
||||||
continue
|
continue
|
||||||
|
|
|
@ -18,6 +18,10 @@ class KeiMessage:
|
||||||
def kei_person(self):
|
def kei_person(self):
|
||||||
return relationship("KeiPerson", foreign_keys=self.kei_person_id, backref="kei_messages")
|
return relationship("KeiPerson", foreign_keys=self.kei_person_id, backref="kei_messages")
|
||||||
|
|
||||||
|
@declared_attr
|
||||||
|
def previous(self):
|
||||||
|
return Column(String)
|
||||||
|
|
||||||
@declared_attr
|
@declared_attr
|
||||||
def message(self):
|
def message(self):
|
||||||
return Column(String, nullable=False)
|
return Column(String, nullable=False)
|
||||||
|
|
|
@ -10,6 +10,7 @@ class Conversation:
|
||||||
self._person = None
|
self._person = None
|
||||||
self._session = None
|
self._session = None
|
||||||
self._message = None
|
self._message = None
|
||||||
|
self._previous = None
|
||||||
|
|
||||||
async def _generator(self):
|
async def _generator(self):
|
||||||
yield
|
yield
|
||||||
|
@ -21,10 +22,11 @@ class Conversation:
|
||||||
await conv.generator.asend(None)
|
await conv.generator.asend(None)
|
||||||
return conv
|
return conv
|
||||||
|
|
||||||
async def next(self, session, person, message):
|
async def next(self, session, person, message, previous):
|
||||||
self._session = session
|
self._session = session
|
||||||
self._person = person
|
self._person = person
|
||||||
self._message = message
|
self._message = message
|
||||||
|
self._previous = previous
|
||||||
reply = await self.generator.asend(None)
|
reply = await self.generator.asend(None)
|
||||||
return reply
|
return reply
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue