Update for feedback by @madsmtm

1. Add ThreadLocation Enum in models.
2. avoid using build-in name "type" as parameter name
3. replace ValueError with FBchatUserError

thanks to @madsmtm
This commit is contained in:
Tang
2017-10-03 03:05:08 +08:00
parent 2d027af71a
commit 8eb6b83411
2 changed files with 14 additions and 8 deletions

View File

@@ -748,12 +748,12 @@ class Client(object):
return list(reversed([graphql_to_message(message) for message in j['message_thread']['messages']['nodes']]))
def fetchThreadList(self, offset=0, limit=20, type='inbox'):
def fetchThreadList(self, offset=0, limit=20, thread_location=ThreadLocation.INBOX):
"""Get thread list of your facebook account
:param offset: The offset, from where in the list to recieve threads from
:param limit: Max. number of threads to retrieve. Capped at 20
:param type: (optional) "inbox", "pending", "archived"
:param thread_location: models.ThreadLocation: INBOX, PENDING, ARCHIVED or OTHER
:type offset: int
:type limit: int
:return: :class:`models.Thread` objects
@@ -764,16 +764,15 @@ class Client(object):
if limit > 20 or limit < 1:
raise FBchatUserError('`limit` should be between 1 and 20')
if type in ['inbox', 'pending', 'archived']:
if type == 'archived':
type = 'action:archived'
if thread_location in ThreadLocation:
loc_str = thread_location.value
else:
raise ValueError('thread_type must be "inbox", "pending" or "archived"')
raise FBchatUserError('"thread_location" must be a value of ThreadLocation')
data = {
'client' : self.client,
type + '[offset]' : offset,
type + '[limit]' : limit,
loc_str + '[offset]' : offset,
loc_str + '[limit]' : limit,
}
j = self._post(self.req_url.THREADS, data, fix_request=True, as_json=True)

View File

@@ -193,6 +193,13 @@ class ThreadType(Enum):
GROUP = 2
PAGE = 3
class ThreadLocation(Enum):
"""Used to specify where a thread is located (inbox, pending, archived, other)."""
INBOX = 'inbox'
PENDING = 'pending'
ARCHIVED = 'action:archived'
OTHER = 'other'
class TypingStatus(Enum):
"""Used to specify whether the user is typing or has stopped typing"""
STOPPED = 0