Fix bugs in manual bridging that were added by the previous fix

This commit is contained in:
Tulir Asokan
2020-10-30 19:55:43 +02:00
parent 5cc0afef85
commit 2b6cffc8ef
2 changed files with 7 additions and 18 deletions
+2 -7
View File
@@ -13,7 +13,7 @@
# #
# You should have received a copy of the GNU Affero General Public License # You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>. # along with this program. If not, see <https://www.gnu.org/licenses/>.
from typing import Optional, Tuple, Coroutine, Dict, Any from typing import Optional, Tuple, Awaitable
import asyncio import asyncio
from telethon.tl.types import ChatForbidden, ChannelForbidden from telethon.tl.types import ChatForbidden, ChannelForbidden
@@ -105,8 +105,7 @@ async def bridge(evt: CommandEvent) -> EventID:
async def cleanup_old_portal_while_bridging(evt: CommandEvent, portal: "po.Portal" async def cleanup_old_portal_while_bridging(evt: CommandEvent, portal: "po.Portal"
) -> Tuple[ ) -> Tuple[bool, Optional[Awaitable[None]]]:
bool, Optional[Coroutine[None, None, None]]]:
if not portal.mxid: if not portal.mxid:
await evt.reply("The portal seems to have lost its Matrix room between you" await evt.reply("The portal seems to have lost its Matrix room between you"
"calling `$cmdprefix+sp bridge` and this command.\n\n" "calling `$cmdprefix+sp bridge` and this command.\n\n"
@@ -156,10 +155,6 @@ async def confirm_bridge(evt: CommandEvent) -> Optional[EventID]:
evt.sender.command_status = None evt.sender.command_status = None
is_logged_in = await evt.sender.is_logged_in() and not status["force_use_bot"] is_logged_in = await evt.sender.is_logged_in() and not status["force_use_bot"]
async with portal._room_create_lock: async with portal._room_create_lock:
if portal.mxid:
return await evt.reply("The portal seems to have created a Matrix room while you were "
"calling this command.\n\n"
"Please start over by calling the bridge command again.")
await _locked_confirm_bridge(evt, portal=portal, room_id=bridge_to_mxid, await _locked_confirm_bridge(evt, portal=portal, room_id=bridge_to_mxid,
is_logged_in=is_logged_in) is_logged_in=is_logged_in)
+5 -11
View File
@@ -302,9 +302,6 @@ class BasePortal(MautrixBasePortal, ABC):
await self.cleanup_room(self.main_intent, self.mxid, message, puppets_only) await self.cleanup_room(self.main_intent, self.mxid, message, puppets_only)
if delete: if delete:
await self.delete() await self.delete()
else:
self.delete_matrix()
self.mxid = None
# endregion # endregion
# region Database conversion # region Database conversion
@@ -331,21 +328,18 @@ class BasePortal(MautrixBasePortal, ABC):
async def delete(self) -> None: async def delete(self) -> None:
self.delete_sync() self.delete_sync()
def delete_matrix(self) -> None:
try:
del self.by_mxid[self.mxid]
except KeyError:
pass
DBMessage.delete_all(self.mxid)
def delete_sync(self) -> None: def delete_sync(self) -> None:
try: try:
del self.by_tgid[self.tgid_full] del self.by_tgid[self.tgid_full]
except KeyError: except KeyError:
pass pass
try:
del self.by_mxid[self.mxid]
except KeyError:
pass
if self._db_instance: if self._db_instance:
self._db_instance.delete() self._db_instance.delete()
self.delete_matrix() DBMessage.delete_all(self.mxid)
self.deleted = True self.deleted = True
@classmethod @classmethod