Catch 403 error when getting offline user presence

It's possible to get a MatrixForbidden error when trying to retrieve a
offline room member's presence, if that member actually left the room
but the server hasn't yet sent the update.
This commit is contained in:
miruka 2020-07-21 21:02:28 -04:00
parent a402c7657a
commit 8c1d7a868e

View File

@ -36,8 +36,8 @@ from nio.crypto import async_generator_from_data
from . import __app_name__, __display_name__, utils from . import __app_name__, __display_name__, utils
from .errors import ( from .errors import (
BadMimeType, InvalidUserId, InvalidUserInContext, MatrixBadGateway, BadMimeType, InvalidUserId, InvalidUserInContext, MatrixBadGateway,
MatrixError, MatrixNotFound, MatrixTooLarge, MatrixUnauthorized, MatrixError, MatrixForbidden, MatrixNotFound, MatrixTooLarge,
UneededThumbnail, UserFromOtherServerDisallowed, MatrixUnauthorized, UneededThumbnail, UserFromOtherServerDisallowed,
) )
from .html_markdown import HTML_PROCESSOR as HTML from .html_markdown import HTML_PROCESSOR as HTML
from .media_cache import Media, Thumbnail from .media_cache import Media, Thumbnail
@ -1389,8 +1389,11 @@ class MatrixClient(nio.AsyncClient):
if not self.models["accounts"][self.user_id].presence_support: if not self.models["accounts"][self.user_id].presence_support:
return return
async with self.backend.concurrent_get_presence_limit: try:
resp = await self.get_presence(user_id) async with self.backend.concurrent_get_presence_limit:
resp = await self.get_presence(user_id)
except MatrixForbidden:
return
await self.nio_callbacks.onPresenceEvent(nio.PresenceEvent( await self.nio_callbacks.onPresenceEvent(nio.PresenceEvent(
user_id = resp.user_id, user_id = resp.user_id,