Improve things

This commit is contained in:
Tulir Asokan
2019-08-06 21:30:14 +03:00
parent 45f1dddb81
commit 8655f5903a
9 changed files with 72 additions and 41 deletions
+7 -14
View File
@@ -13,7 +13,7 @@
#
# 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/>.
from typing import Tuple, Optional, AsyncIterable, Union, Dict, TYPE_CHECKING
from typing import Tuple, Optional, Union, Dict, TYPE_CHECKING
from abc import ABC, abstractmethod
import asyncio
import logging
@@ -23,12 +23,12 @@ import time
from telethon.sessions import Session
from telethon.tl.patched import MessageService, Message
from telethon.tl.types import (
Channel, ChannelForbidden, Chat, ChatForbidden, MessageActionChannelMigrateFrom, PeerUser,
TypeUpdate, UpdateChannelPinnedMessage, UpdateChatPinnedMessage, UpdateChatParticipantAdmin,
UpdateChatParticipants, UpdateChatUserTyping, UpdateDeleteChannelMessages, UpdateNewMessage,
UpdateDeleteMessages, UpdateEditChannelMessage, UpdateEditMessage, UpdateNewChannelMessage,
UpdateReadHistoryOutbox, UpdateShortChatMessage, UpdateShortMessage, UpdateUserName,
UpdateUserPhoto, UpdateUserStatus, UpdateUserTyping, User, UserStatusOffline, UserStatusOnline)
Channel, Chat, MessageActionChannelMigrateFrom, PeerUser, TypeUpdate, UpdateChatPinnedMessage,
UpdateChannelPinnedMessage, UpdateChatParticipantAdmin, UpdateChatParticipants,
UpdateChatUserTyping, UpdateDeleteChannelMessages, UpdateNewMessage, UpdateDeleteMessages,
UpdateEditChannelMessage, UpdateEditMessage, UpdateNewChannelMessage, UpdateReadHistoryOutbox,
UpdateShortChatMessage, UpdateShortMessage, UpdateUserName, UpdateUserPhoto, UpdateUserStatus,
UpdateUserTyping, User, UserStatusOffline, UserStatusOnline)
from mautrix.types import UserID, PresenceState
from mautrix.errors import MatrixError
@@ -189,13 +189,6 @@ class AbstractUser(ABC):
if UPDATE_TIME:
UPDATE_TIME.labels(update_type=type(update).__name__).observe(time.time() - start_time)
def get_dialogs(self, limit: int = None) -> AsyncIterable[Union[User, Chat, Channel]]:
return (dialog.entity async for dialog in
self.client.iter_dialogs(limit=limit, ignore_migrated=True, archived=False)
if isinstance(dialog.entity, (ChatForbidden, ChannelForbidden))
or (isinstance(dialog.entity, Chat)
and (dialog.entity.deactivated or dialog.entity.left)))
@property
@abstractmethod
def name(self) -> str: