def get_most_recent_incoming_chat(self, after=-1) -> Optional["ChatNode"]: r = self._db_read_one( """ SELECT uuid FROM Chats WHERE speaker != ? AND time >= ? ORDER BY time DESC LIMIT 1 """, self.self_memid, after, ) if r: return ChatNode(self, r[0]) else: return None
def get_chat_by_id(self, memid: str) -> "ChatNode": return ChatNode(self, memid)
def get_recent_chats(self, n=1) -> List["ChatNode"]: """Return a list of at most n chats""" r = self._db_read("SELECT uuid FROM Chats ORDER BY time DESC LIMIT ?", n) return [ChatNode(self, m) for m, in reversed(r)]
def add_chat(self, speaker_memid: str, chat: str) -> str: return ChatNode.create(self, speaker_memid, chat)