Compare commits
8 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
13d0dc4ba4 | ||
|
64125a1aca | ||
|
4feae03092 | ||
|
5f993c2bf8 | ||
|
35bbcbffba | ||
|
5faca54d67 | ||
|
82496b8e04 | ||
|
2d74ec7823 |
@@ -17,7 +17,7 @@ from .client import *
|
|||||||
|
|
||||||
|
|
||||||
__copyright__ = 'Copyright 2015 - {} by Taehoon Kim'.format(datetime.now().year)
|
__copyright__ = 'Copyright 2015 - {} by Taehoon Kim'.format(datetime.now().year)
|
||||||
__version__ = '1.0.4'
|
__version__ = '1.0.7'
|
||||||
__license__ = 'BSD'
|
__license__ = 'BSD'
|
||||||
__author__ = 'Taehoon Kim; Moreels Pieter-Jan; Mads Marquart'
|
__author__ = 'Taehoon Kim; Moreels Pieter-Jan; Mads Marquart'
|
||||||
__email__ = 'carpedm20@gmail.com'
|
__email__ = 'carpedm20@gmail.com'
|
||||||
|
@@ -427,6 +427,9 @@ class Client(object):
|
|||||||
for key in j['payload']:
|
for key in j['payload']:
|
||||||
k = j['payload'][key]
|
k = j['payload'][key]
|
||||||
if k['type'] in ['user', 'friend']:
|
if k['type'] in ['user', 'friend']:
|
||||||
|
if k['id'] in ['0', 0]:
|
||||||
|
# Skip invalid users
|
||||||
|
pass
|
||||||
users.append(User(k['id'], first_name=k.get('firstName'), url=k.get('uri'), photo=k.get('thumbSrc'), name=k.get('name'), is_friend=k.get('is_friend'), gender=GENDERS[k.get('gender')]))
|
users.append(User(k['id'], first_name=k.get('firstName'), url=k.get('uri'), photo=k.get('thumbSrc'), name=k.get('name'), is_friend=k.get('is_friend'), gender=GENDERS[k.get('gender')]))
|
||||||
|
|
||||||
return users
|
return users
|
||||||
@@ -736,7 +739,7 @@ class Client(object):
|
|||||||
raise Exception('A thread was not in participants: {}'.format(j['payload']))
|
raise Exception('A thread was not in participants: {}'.format(j['payload']))
|
||||||
entries.append(participants[k['other_user_fbid']])
|
entries.append(participants[k['other_user_fbid']])
|
||||||
elif k['thread_type'] == 2:
|
elif k['thread_type'] == 2:
|
||||||
entries.append(Group(k['thread_fbid'], participants=[p.strip('fbid:') for p in k['participants']], photo=k['image_src'], name=k['name']))
|
entries.append(Group(k['thread_fbid'], participants=set([p.strip('fbid:') for p in k['participants']]), photo=k['image_src'], name=k['name']))
|
||||||
else:
|
else:
|
||||||
raise Exception('A thread had an unknown thread type: {}'.format(k))
|
raise Exception('A thread had an unknown thread type: {}'.format(k))
|
||||||
|
|
||||||
@@ -1009,6 +1012,7 @@ class Client(object):
|
|||||||
:type thread_type: models.ThreadType
|
:type thread_type: models.ThreadType
|
||||||
:raises: Exception if request failed
|
:raises: Exception if request failed
|
||||||
"""
|
"""
|
||||||
|
|
||||||
thread_id, thread_type = self._getThread(thread_id, thread_type)
|
thread_id, thread_type = self._getThread(thread_id, thread_type)
|
||||||
|
|
||||||
if thread_type == ThreadType.USER:
|
if thread_type == ThreadType.USER:
|
||||||
@@ -1021,6 +1025,8 @@ class Client(object):
|
|||||||
data['log_message_data[name]'] = title
|
data['log_message_data[name]'] = title
|
||||||
data['log_message_type'] = 'log:thread-name'
|
data['log_message_type'] = 'log:thread-name'
|
||||||
|
|
||||||
|
return self._doSendRequest(data)
|
||||||
|
|
||||||
def changeNickname(self, nickname, user_id, thread_id=None, thread_type=ThreadType.USER):
|
def changeNickname(self, nickname, user_id, thread_id=None, thread_type=ThreadType.USER):
|
||||||
"""
|
"""
|
||||||
Changes the nickname of a user in a thread
|
Changes the nickname of a user in a thread
|
||||||
@@ -1285,7 +1291,7 @@ class Client(object):
|
|||||||
|
|
||||||
# Color change
|
# Color change
|
||||||
elif delta_type == "change_thread_theme":
|
elif delta_type == "change_thread_theme":
|
||||||
new_color = ThreadColor(delta["untypedData"]["theme_color"])
|
new_color = graphql_color_to_enum(delta["untypedData"]["theme_color"])
|
||||||
thread_id, thread_type = getThreadIdAndThreadType(metadata)
|
thread_id, thread_type = getThreadIdAndThreadType(metadata)
|
||||||
self.onColorChange(mid=mid, author_id=author_id, new_color=new_color, thread_id=thread_id,
|
self.onColorChange(mid=mid, author_id=author_id, new_color=new_color, thread_id=thread_id,
|
||||||
thread_type=thread_type, ts=ts, metadata=metadata, msg=m)
|
thread_type=thread_type, ts=ts, metadata=metadata, msg=m)
|
||||||
@@ -1347,7 +1353,7 @@ class Client(object):
|
|||||||
threads = [getThreadIdAndThreadType({"threadKey": thr}) for thr in delta.get("threadKeys")]
|
threads = [getThreadIdAndThreadType({"threadKey": thr}) for thr in delta.get("threadKeys")]
|
||||||
|
|
||||||
# thread_id, thread_type = getThreadIdAndThreadType(delta)
|
# thread_id, thread_type = getThreadIdAndThreadType(delta)
|
||||||
self.onMarkedSeen(threads=threads, seen_ts=seen_ts, delivered_ts=delivered_ts, metadata=delta, msg=m)
|
self.onMarkedSeen(threads=threads, seen_ts=seen_ts, ts=delivered_ts, metadata=delta, msg=m)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
# New message
|
# New message
|
||||||
|
@@ -26,9 +26,11 @@ class ConcatJSONDecoder(json.JSONDecoder):
|
|||||||
def graphql_color_to_enum(color):
|
def graphql_color_to_enum(color):
|
||||||
if color is None:
|
if color is None:
|
||||||
return None
|
return None
|
||||||
|
if len(color) == 0:
|
||||||
|
return ThreadColor.MESSENGER_BLUE
|
||||||
try:
|
try:
|
||||||
return ThreadColor('#{}'.format(color[2:].lower()))
|
return ThreadColor('#{}'.format(color[2:].lower()))
|
||||||
except KeyError:
|
except KeyError, ValueError:
|
||||||
raise Exception('Could not get ThreadColor from color: {}'.format(color))
|
raise Exception('Could not get ThreadColor from color: {}'.format(color))
|
||||||
|
|
||||||
def get_customization_info(thread):
|
def get_customization_info(thread):
|
||||||
@@ -44,7 +46,7 @@ def get_customization_info(thread):
|
|||||||
rtn['nicknames'] = {}
|
rtn['nicknames'] = {}
|
||||||
for k in info['participant_customizations']:
|
for k in info['participant_customizations']:
|
||||||
rtn['nicknames'][k['participant_id']] = k.get('nickname')
|
rtn['nicknames'][k['participant_id']] = k.get('nickname')
|
||||||
else:
|
elif info.get('participant_customizations'):
|
||||||
_id = thread.get('thread_key', {}).get('other_user_id') or thread.get('id')
|
_id = thread.get('thread_key', {}).get('other_user_id') or thread.get('id')
|
||||||
if info['participant_customizations'][0]['participant_id'] == _id:
|
if info['participant_customizations'][0]['participant_id'] == _id:
|
||||||
rtn['nickname'] = info['participant_customizations'][0]
|
rtn['nickname'] = info['participant_customizations'][0]
|
||||||
@@ -102,7 +104,7 @@ def graphql_to_group(group):
|
|||||||
c_info = get_customization_info(group)
|
c_info = get_customization_info(group)
|
||||||
return Group(
|
return Group(
|
||||||
group['thread_key']['thread_fbid'],
|
group['thread_key']['thread_fbid'],
|
||||||
participants=[node['messaging_actor']['id'] for node in group['all_participants']['nodes']],
|
participants=set([node['messaging_actor']['id'] for node in group['all_participants']['nodes']]),
|
||||||
nicknames=c_info.get('nicknames'),
|
nicknames=c_info.get('nicknames'),
|
||||||
color=c_info.get('color'),
|
color=c_info.get('color'),
|
||||||
emoji=c_info.get('emoji'),
|
emoji=c_info.get('emoji'),
|
||||||
|
@@ -66,8 +66,8 @@ class User(Thread):
|
|||||||
|
|
||||||
|
|
||||||
class Group(Thread):
|
class Group(Thread):
|
||||||
#: List of the group thread's participant user IDs
|
#: Unique list (set) of the group thread's participant user IDs
|
||||||
participants = list
|
participants = set
|
||||||
#: Dict, containing user nicknames mapped to their IDs
|
#: Dict, containing user nicknames mapped to their IDs
|
||||||
nicknames = dict
|
nicknames = dict
|
||||||
#: A :class:`ThreadColor`. The groups's message color
|
#: A :class:`ThreadColor`. The groups's message color
|
||||||
@@ -75,7 +75,7 @@ class Group(Thread):
|
|||||||
#: The groups's default emoji
|
#: The groups's default emoji
|
||||||
emoji = str
|
emoji = str
|
||||||
|
|
||||||
def __init__(self, uid, participants=[], nicknames=[], color=None, emoji=None, **kwargs):
|
def __init__(self, uid, participants=set(), nicknames=[], color=None, emoji=None, **kwargs):
|
||||||
"""Represents a Facebook group. Inherits `Thread`"""
|
"""Represents a Facebook group. Inherits `Thread`"""
|
||||||
super(Group, self).__init__(ThreadType.GROUP, uid, **kwargs)
|
super(Group, self).__init__(ThreadType.GROUP, uid, **kwargs)
|
||||||
self.participants = participants
|
self.participants = participants
|
||||||
|
Reference in New Issue
Block a user