Merge pull request #211 from WeiTang114/fetch_pending_thread_2
Enable fetching pending/archived threads
This commit is contained in:
@@ -748,11 +748,12 @@ class Client(object):
|
|||||||
|
|
||||||
return list(reversed([graphql_to_message(message) for message in j['message_thread']['messages']['nodes']]))
|
return list(reversed([graphql_to_message(message) for message in j['message_thread']['messages']['nodes']]))
|
||||||
|
|
||||||
def fetchThreadList(self, offset=0, limit=20):
|
def fetchThreadList(self, offset=0, limit=20, thread_location=ThreadLocation.INBOX):
|
||||||
"""Get thread list of your facebook account
|
"""Get thread list of your facebook account
|
||||||
|
|
||||||
:param offset: The offset, from where in the list to recieve threads from
|
: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 limit: Max. number of threads to retrieve. Capped at 20
|
||||||
|
:param thread_location: models.ThreadLocation: INBOX, PENDING, ARCHIVED or OTHER
|
||||||
:type offset: int
|
:type offset: int
|
||||||
:type limit: int
|
:type limit: int
|
||||||
:return: :class:`models.Thread` objects
|
:return: :class:`models.Thread` objects
|
||||||
@@ -763,10 +764,15 @@ class Client(object):
|
|||||||
if limit > 20 or limit < 1:
|
if limit > 20 or limit < 1:
|
||||||
raise FBchatUserError('`limit` should be between 1 and 20')
|
raise FBchatUserError('`limit` should be between 1 and 20')
|
||||||
|
|
||||||
|
if thread_location in ThreadLocation:
|
||||||
|
loc_str = thread_location.value
|
||||||
|
else:
|
||||||
|
raise FBchatUserError('"thread_location" must be a value of ThreadLocation')
|
||||||
|
|
||||||
data = {
|
data = {
|
||||||
'client' : self.client,
|
'client' : self.client,
|
||||||
'inbox[offset]' : offset,
|
loc_str + '[offset]' : offset,
|
||||||
'inbox[limit]' : limit,
|
loc_str + '[limit]' : limit,
|
||||||
}
|
}
|
||||||
|
|
||||||
j = self._post(self.req_url.THREADS, data, fix_request=True, as_json=True)
|
j = self._post(self.req_url.THREADS, data, fix_request=True, as_json=True)
|
||||||
@@ -774,6 +780,7 @@ class Client(object):
|
|||||||
raise FBchatException('Missing payload: {}, with data: {}'.format(j, data))
|
raise FBchatException('Missing payload: {}, with data: {}'.format(j, data))
|
||||||
|
|
||||||
participants = {}
|
participants = {}
|
||||||
|
if 'participants' in j['payload']:
|
||||||
for p in j['payload']['participants']:
|
for p in j['payload']['participants']:
|
||||||
if p['type'] == 'page':
|
if p['type'] == 'page':
|
||||||
participants[p['fbid']] = Page(p['fbid'], url=p['href'], photo=p['image_src'], name=p['name'])
|
participants[p['fbid']] = Page(p['fbid'], url=p['href'], photo=p['image_src'], name=p['name'])
|
||||||
@@ -783,6 +790,7 @@ class Client(object):
|
|||||||
raise FBchatException('A participant had an unknown type {}: {}'.format(p['type'], p))
|
raise FBchatException('A participant had an unknown type {}: {}'.format(p['type'], p))
|
||||||
|
|
||||||
entries = []
|
entries = []
|
||||||
|
if 'threads' in j['payload']:
|
||||||
for k in j['payload']['threads']:
|
for k in j['payload']['threads']:
|
||||||
if k['thread_type'] == 1:
|
if k['thread_type'] == 1:
|
||||||
if k['other_user_fbid'] not in participants:
|
if k['other_user_fbid'] not in participants:
|
||||||
|
@@ -193,6 +193,13 @@ class ThreadType(Enum):
|
|||||||
GROUP = 2
|
GROUP = 2
|
||||||
PAGE = 3
|
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):
|
class TypingStatus(Enum):
|
||||||
"""Used to specify whether the user is typing or has stopped typing"""
|
"""Used to specify whether the user is typing or has stopped typing"""
|
||||||
STOPPED = 0
|
STOPPED = 0
|
||||||
|
Reference in New Issue
Block a user