diff --git a/keipack/stars/api_kei.py b/keipack/stars/api_kei.py index 0d815fd9..3c4aaa4f 100644 --- a/keipack/stars/api_kei.py +++ b/keipack/stars/api_kei.py @@ -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 diff --git a/keipack/tables/keimessages.py b/keipack/tables/keimessages.py index 2f747750..577907ed 100644 --- a/keipack/tables/keimessages.py +++ b/keipack/tables/keimessages.py @@ -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) diff --git a/keipack/utils/conversation.py b/keipack/utils/conversation.py index fb3b81ab..3e06f574 100644 --- a/keipack/utils/conversation.py +++ b/keipack/utils/conversation.py @@ -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