From 68e2f70371414435cd4248a3cf0a1a6c8d44e97b Mon Sep 17 00:00:00 2001 From: Andrew Ferrazzutti Date: Sun, 10 Apr 2022 23:05:43 -0400 Subject: [PATCH] Remove incomplete inbound reaction handlers for now --- matrix_appservice_kakaotalk/db/__init__.py | 4 +- matrix_appservice_kakaotalk/db/reaction.py | 101 ------------------ .../db/upgrade/v01_initial_revision.py | 12 --- matrix_appservice_kakaotalk/matrix.py | 7 +- matrix_appservice_kakaotalk/portal.py | 4 +- 5 files changed, 8 insertions(+), 120 deletions(-) delete mode 100644 matrix_appservice_kakaotalk/db/reaction.py diff --git a/matrix_appservice_kakaotalk/db/__init__.py b/matrix_appservice_kakaotalk/db/__init__.py index 8c3c932..22a68f4 100644 --- a/matrix_appservice_kakaotalk/db/__init__.py +++ b/matrix_appservice_kakaotalk/db/__init__.py @@ -3,13 +3,12 @@ from mautrix.util.async_db import Database from .message import Message from .portal import Portal from .puppet import Puppet -from .reaction import Reaction from .upgrade import upgrade_table from .user import User def init(db: Database) -> None: - for table in (Portal, Message, Reaction, User, Puppet): + for table in (Portal, Message, User, Puppet): table.db = db @@ -17,7 +16,6 @@ __all__ = [ "upgrade_table", "init", "Message", - "Reaction", "Portal", "ThreadType", "Puppet", diff --git a/matrix_appservice_kakaotalk/db/reaction.py b/matrix_appservice_kakaotalk/db/reaction.py deleted file mode 100644 index 714458e..0000000 --- a/matrix_appservice_kakaotalk/db/reaction.py +++ /dev/null @@ -1,101 +0,0 @@ -# matrix-appservice-kakaotalk - A Matrix-KakaoTalk puppeting bridge. -# Copyright (C) 2022 Tulir Asokan, Andrew Ferrazzutti -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . -from __future__ import annotations - -from typing import TYPE_CHECKING, ClassVar - -from asyncpg import Record -from attr import dataclass - -from mautrix.types import EventID, RoomID -from mautrix.util.async_db import Database - -fake_db = Database.create("") if TYPE_CHECKING else None - - -@dataclass -class Reaction: - db: ClassVar[Database] = fake_db - - mxid: EventID - mx_room: RoomID - kt_msgid: str - kt_receiver: int - kt_sender: int - reaction: str - - @classmethod - def _from_row(cls, row: Record | None) -> Reaction | None: - if row is None: - return None - return cls(**row) - - @classmethod - async def get_by_message_ktid(cls, kt_msgid: str, kt_receiver: int) -> dict[int, Reaction]: - q = ( - "SELECT mxid, mx_room, kt_msgid, kt_receiver, kt_sender, reaction " - "FROM reaction WHERE kt_msgid=$1 AND kt_receiver=$2" - ) - rows = await cls.db.fetch(q, kt_msgid, kt_receiver) - row_gen = (cls._from_row(row) for row in rows) - return {react.kt_sender: react for react in row_gen} - - @classmethod - async def get_by_ktid(cls, kt_msgid: str, kt_receiver: int, kt_sender: int) -> Reaction | None: - q = ( - "SELECT mxid, mx_room, kt_msgid, kt_receiver, kt_sender, reaction " - "FROM reaction WHERE kt_msgid=$1 AND kt_receiver=$2 AND kt_sender=$3" - ) - row = await cls.db.fetchrow(q, kt_msgid, kt_receiver, kt_sender) - return cls._from_row(row) - - @classmethod - async def get_by_mxid(cls, mxid: EventID, mx_room: RoomID) -> Reaction | None: - q = ( - "SELECT mxid, mx_room, kt_msgid, kt_receiver, kt_sender, reaction " - "FROM reaction WHERE mxid=$1 AND mx_room=$2" - ) - row = await cls.db.fetchrow(q, mxid, mx_room) - return cls._from_row(row) - - @property - def _values(self): - return ( - self.mxid, - self.mx_room, - self.kt_msgid, - self.kt_receiver, - self.kt_sender, - self.reaction, - ) - - async def insert(self) -> None: - q = ( - "INSERT INTO reaction (mxid, mx_room, kt_msgid, kt_receiver, kt_sender, reaction) " - "VALUES ($1, $2, $3, $4, $5, $6)" - ) - await self.db.execute(q, *self._values) - - async def delete(self) -> None: - q = "DELETE FROM reaction WHERE kt_msgid=$1 AND kt_receiver=$2 AND kt_sender=$3" - await self.db.execute(q, self.kt_msgid, self.kt_receiver, self.kt_sender) - - async def save(self) -> None: - q = ( - "UPDATE reaction SET mxid=$1, mx_room=$2, reaction=$6 " - "WHERE kt_msgid=$3 AND kt_receiver=$4 AND kt_sender=$5" - ) - await self.db.execute(q, *self._values) diff --git a/matrix_appservice_kakaotalk/db/upgrade/v01_initial_revision.py b/matrix_appservice_kakaotalk/db/upgrade/v01_initial_revision.py index e490c62..c64826b 100644 --- a/matrix_appservice_kakaotalk/db/upgrade/v01_initial_revision.py +++ b/matrix_appservice_kakaotalk/db/upgrade/v01_initial_revision.py @@ -85,15 +85,3 @@ async def create_v1_tables(conn: Connection) -> None: UNIQUE (mxid, mx_room) )""" ) - await conn.execute( - """CREATE TABLE reaction ( - mxid TEXT, - mx_room TEXT, - kt_msgid TEXT, - kt_receiver BIGINT, - kt_sender BIGINT, - reaction TEXT, - PRIMARY KEY (kt_msgid, kt_receiver, kt_sender), - UNIQUE (mxid, mx_room) - )""" - ) diff --git a/matrix_appservice_kakaotalk/matrix.py b/matrix_appservice_kakaotalk/matrix.py index 472df1b..1930502 100644 --- a/matrix_appservice_kakaotalk/matrix.py +++ b/matrix_appservice_kakaotalk/matrix.py @@ -22,11 +22,8 @@ from mautrix.types import ( Event, EventID, EventType, - ReactionEvent, - ReactionEventContent, ReceiptEvent, RedactionEvent, - RelationType, RoomID, SingleReceiptEventContent, UserID, @@ -122,6 +119,7 @@ class MatrixHandler(BaseMatrixHandler): await portal.handle_matrix_redaction(user, event_id, redaction_event_id) + """ TODO @classmethod async def handle_reaction( cls, @@ -147,6 +145,7 @@ class MatrixHandler(BaseMatrixHandler): await portal.handle_matrix_reaction( user, event_id, content.relates_to.event_id, content.relates_to.key ) + """ async def handle_read_receipt( self, @@ -170,6 +169,8 @@ class MatrixHandler(BaseMatrixHandler): if evt.type == EventType.ROOM_REDACTION: evt: RedactionEvent await self.handle_redaction(evt.room_id, evt.sender, evt.redacts, evt.event_id) + """ TODO elif evt.type == EventType.REACTION: evt: ReactionEvent await self.handle_reaction(evt.room_id, evt.sender, evt.event_id, evt.content) + """ diff --git a/matrix_appservice_kakaotalk/portal.py b/matrix_appservice_kakaotalk/portal.py index 391328a..b68744d 100644 --- a/matrix_appservice_kakaotalk/portal.py +++ b/matrix_appservice_kakaotalk/portal.py @@ -934,10 +934,12 @@ class Portal(DBPortal, BasePortal): raise NotImplementedError("Only message and reaction redactions are supported") """ + """ TODO async def handle_matrix_reaction( self, sender: u.User, event_id: EventID, reacting_to: EventID, reaction: str ) -> None: - self.log.info("TODO: handle_matrix_reaction") + pass + """ async def handle_matrix_leave(self, user: u.User) -> None: if self.is_direct: