Skip to content
Snippets Groups Projects
Commit 9172cd01 authored by Tulir Asokan's avatar Tulir Asokan :cat2:
Browse files

Don't send non-error refreshing notices if temporary_disconnect_notices is disabled

parent d62c4939
No related branches found
No related tags found
No related merge requests found
...@@ -67,4 +67,4 @@ async def ping(evt: CommandEvent) -> None: ...@@ -67,4 +67,4 @@ async def ping(evt: CommandEvent) -> None:
@command_handler(needs_auth=True, management_only=True, help_section=SECTION_CONNECTION, @command_handler(needs_auth=True, management_only=True, help_section=SECTION_CONNECTION,
help_text="\"Refresh\" the Facebook Messenger page") help_text="\"Refresh\" the Facebook Messenger page")
async def refresh(evt: CommandEvent) -> None: async def refresh(evt: CommandEvent) -> None:
await evt.sender.refresh() await evt.sender.refresh(force_notice=True)
...@@ -38,6 +38,8 @@ config: Config ...@@ -38,6 +38,8 @@ config: Config
class User(BaseUser): class User(BaseUser):
temp_disconnect_notices: bool = True
by_mxid: Dict[UserID, 'User'] = {} by_mxid: Dict[UserID, 'User'] = {}
by_fbid: Dict[str, 'User'] = {} by_fbid: Dict[str, 'User'] = {}
...@@ -229,16 +231,18 @@ class User(BaseUser): ...@@ -229,16 +231,18 @@ class User(BaseUser):
await self.send_bridge_notice("Fatal error while trying to refresh after connection " await self.send_bridge_notice("Fatal error while trying to refresh after connection "
"error (see logs for more info)", important=True) "error (see logs for more info)", important=True)
async def refresh(self) -> None: async def refresh(self, force_notice: bool = False) -> None:
event_id = None event_id = None
self._is_refreshing = True self._is_refreshing = True
if self.listener: if self.listener:
event_id = await self.send_bridge_notice("Disconnecting Messenger MQTT connection " if self.temp_disconnect_notices or force_notice:
"for session refresh...") event_id = await self.send_bridge_notice("Disconnecting Messenger MQTT connection "
"for session refresh...")
self.listener.disconnect() self.listener.disconnect()
if self.listen_task: if self.listen_task:
await self.listen_task await self.listen_task
event_id = await self.send_bridge_notice("Refreshing session...", edit=event_id) if self.temp_disconnect_notices or force_notice:
event_id = await self.send_bridge_notice("Refreshing session...", edit=event_id)
try: try:
ok = await self.load_session(_override=True, _raise_errors=True) ok = await self.load_session(_override=True, _raise_errors=True)
except fbchat.FacebookError as e: except fbchat.FacebookError as e:
...@@ -248,12 +252,12 @@ class User(BaseUser): ...@@ -248,12 +252,12 @@ class User(BaseUser):
await self.send_bridge_notice("Failed to refresh Messenger session: unknown error " await self.send_bridge_notice("Failed to refresh Messenger session: unknown error "
"(see logs for more details)", edit=event_id) "(see logs for more details)", edit=event_id)
else: else:
if ok: if not ok:
await self.send_bridge_notice("Successfully refreshed Messenger session",
edit=event_id)
else:
await self.send_bridge_notice("Failed to refresh Messenger session: " await self.send_bridge_notice("Failed to refresh Messenger session: "
"not logged in", edit=event_id) "not logged in", edit=event_id)
elif self.temp_disconnect_notices or force_notice:
await self.send_bridge_notice("Successfully refreshed Messenger session",
edit=event_id)
finally: finally:
self._is_refreshing = False self._is_refreshing = False
...@@ -510,12 +514,12 @@ class User(BaseUser): ...@@ -510,12 +514,12 @@ class User(BaseUser):
await self.send_bridge_notice("Connected to Facebook Messenger after being " await self.send_bridge_notice("Connected to Facebook Messenger after being "
f"disconnected for {duration} seconds, syncing chats...") f"disconnected for {duration} seconds, syncing chats...")
await self.sync_threads() await self.sync_threads()
elif config["bridge.temporary_disconnect_notices"]: elif self.temp_disconnect_notices:
await self.send_bridge_notice("Connected to Facebook Messenger") await self.send_bridge_notice("Connected to Facebook Messenger")
async def on_disconnect(self, evt: fbchat.Disconnect) -> None: async def on_disconnect(self, evt: fbchat.Disconnect) -> None:
self.is_connected = False self.is_connected = False
if config["bridge.temporary_disconnect_notices"]: if self.temp_disconnect_notices:
await self.send_bridge_notice(f"Disconnected from Facebook Messenger: {evt.reason}") await self.send_bridge_notice(f"Disconnected from Facebook Messenger: {evt.reason}")
async def on_resync(self) -> None: async def on_resync(self) -> None:
...@@ -643,4 +647,5 @@ def init(context: 'Context') -> Iterable[Awaitable[bool]]: ...@@ -643,4 +647,5 @@ def init(context: 'Context') -> Iterable[Awaitable[bool]]:
global config global config
User.az, config, User.loop = context.core User.az, config, User.loop = context.core
User._community_helper = CommunityHelper(User.az) User._community_helper = CommunityHelper(User.az)
User.temp_disconnect_notices = config["bridge.temporary_disconnect_notices"]
return (user.load_session() for user in User.get_all()) return (user.load_session() for user in User.get_all())
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment