From 5e86d4a48a9f0867ac1383376658276e42d23180 Mon Sep 17 00:00:00 2001 From: Mads Marquart Date: Wed, 28 Aug 2019 17:39:49 +0200 Subject: [PATCH] Add method to convert a ThreadType to a subclass of Thread (e.g. Group) --- fbchat/_thread.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/fbchat/_thread.py b/fbchat/_thread.py index cdcab15..8d86578 100644 --- a/fbchat/_thread.py +++ b/fbchat/_thread.py @@ -16,6 +16,17 @@ class ThreadType(Enum): ROOM = 2 PAGE = 3 + def _to_class(self): + """Convert this enum value to the corresponding class.""" + from . import _user, _group, _page + + return { + ThreadType.USER: _user.User, + ThreadType.GROUP: _group.Group, + ThreadType.ROOM: _group.Room, + ThreadType.PAGE: _page.Page, + }[self] + class ThreadLocation(Enum): """Used to specify where a thread is located (inbox, pending, archived, other)."""