Move graphql_to_extensible_attachment into _message.py
This commit is contained in:
@@ -8,7 +8,7 @@ from random import choice
|
|||||||
from bs4 import BeautifulSoup as bs
|
from bs4 import BeautifulSoup as bs
|
||||||
from mimetypes import guess_type
|
from mimetypes import guess_type
|
||||||
from collections import OrderedDict
|
from collections import OrderedDict
|
||||||
from . import _file
|
from . import _file, _message
|
||||||
from ._util import *
|
from ._util import *
|
||||||
from .models import *
|
from .models import *
|
||||||
from .graphql import *
|
from .graphql import *
|
||||||
@@ -3077,7 +3077,7 @@ class Client(object):
|
|||||||
)
|
)
|
||||||
|
|
||||||
elif mercury.get("extensible_attachment"):
|
elif mercury.get("extensible_attachment"):
|
||||||
attachment = graphql_to_extensible_attachment(
|
attachment = _message.graphql_to_extensible_attachment(
|
||||||
mercury["extensible_attachment"]
|
mercury["extensible_attachment"]
|
||||||
)
|
)
|
||||||
if isinstance(attachment, UnsentMessage):
|
if isinstance(attachment, UnsentMessage):
|
||||||
|
@@ -3,7 +3,7 @@
|
|||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
import json
|
import json
|
||||||
import re
|
import re
|
||||||
from . import _file
|
from . import _file, _message
|
||||||
from .models import *
|
from .models import *
|
||||||
from ._util import *
|
from ._util import *
|
||||||
|
|
||||||
@@ -28,26 +28,6 @@ class ConcatJSONDecoder(json.JSONDecoder):
|
|||||||
# End shameless copy
|
# End shameless copy
|
||||||
|
|
||||||
|
|
||||||
def graphql_to_extensible_attachment(a):
|
|
||||||
story = a.get("story_attachment")
|
|
||||||
if not story:
|
|
||||||
return None
|
|
||||||
|
|
||||||
target = story.get("target")
|
|
||||||
if not target:
|
|
||||||
return UnsentMessage(uid=a.get("legacy_attachment_id"))
|
|
||||||
|
|
||||||
_type = target["__typename"]
|
|
||||||
if _type == "MessageLocation":
|
|
||||||
return LocationAttachment._from_graphql(story)
|
|
||||||
elif _type == "MessageLiveLocation":
|
|
||||||
return LiveLocationAttachment._from_graphql(story)
|
|
||||||
elif _type in ["ExternalUrl", "Story"]:
|
|
||||||
return ShareAttachment._from_graphql(story)
|
|
||||||
|
|
||||||
return None
|
|
||||||
|
|
||||||
|
|
||||||
def graphql_to_quick_reply(q, is_response=False):
|
def graphql_to_quick_reply(q, is_response=False):
|
||||||
data = dict()
|
data = dict()
|
||||||
_type = q.get("content_type").lower()
|
_type = q.get("content_type").lower()
|
||||||
@@ -113,7 +93,9 @@ def graphql_to_message(message):
|
|||||||
graphql_to_quick_reply(quick_replies, is_response=True)
|
graphql_to_quick_reply(quick_replies, is_response=True)
|
||||||
]
|
]
|
||||||
if message.get("extensible_attachment") is not None:
|
if message.get("extensible_attachment") is not None:
|
||||||
attachment = graphql_to_extensible_attachment(message["extensible_attachment"])
|
attachment = _message.graphql_to_extensible_attachment(
|
||||||
|
message["extensible_attachment"]
|
||||||
|
)
|
||||||
if isinstance(attachment, UnsentMessage):
|
if isinstance(attachment, UnsentMessage):
|
||||||
rtn.unsent = True
|
rtn.unsent = True
|
||||||
elif attachment:
|
elif attachment:
|
||||||
|
@@ -3,6 +3,7 @@ from __future__ import unicode_literals
|
|||||||
|
|
||||||
import attr
|
import attr
|
||||||
from string import Formatter
|
from string import Formatter
|
||||||
|
from . import _attachment, _location
|
||||||
from ._core import Enum
|
from ._core import Enum
|
||||||
|
|
||||||
|
|
||||||
@@ -137,3 +138,23 @@ class Message(object):
|
|||||||
|
|
||||||
message = cls(text=result, mentions=mentions)
|
message = cls(text=result, mentions=mentions)
|
||||||
return message
|
return message
|
||||||
|
|
||||||
|
|
||||||
|
def graphql_to_extensible_attachment(data):
|
||||||
|
story = data.get("story_attachment")
|
||||||
|
if not story:
|
||||||
|
return None
|
||||||
|
|
||||||
|
target = story.get("target")
|
||||||
|
if not target:
|
||||||
|
return _attachment.UnsentMessage(uid=data.get("legacy_attachment_id"))
|
||||||
|
|
||||||
|
_type = target["__typename"]
|
||||||
|
if _type == "MessageLocation":
|
||||||
|
return _location.LocationAttachment._from_graphql(story)
|
||||||
|
elif _type == "MessageLiveLocation":
|
||||||
|
return _location.LiveLocationAttachment._from_graphql(story)
|
||||||
|
elif _type in ["ExternalUrl", "Story"]:
|
||||||
|
return _attachment.ShareAttachment._from_graphql(story)
|
||||||
|
|
||||||
|
return None
|
||||||
|
@@ -8,7 +8,6 @@ from ._graphql import (
|
|||||||
FLAGS,
|
FLAGS,
|
||||||
WHITESPACE,
|
WHITESPACE,
|
||||||
ConcatJSONDecoder,
|
ConcatJSONDecoder,
|
||||||
graphql_to_extensible_attachment,
|
|
||||||
graphql_to_quick_reply,
|
graphql_to_quick_reply,
|
||||||
graphql_to_message,
|
graphql_to_message,
|
||||||
graphql_to_thread,
|
graphql_to_thread,
|
||||||
|
Reference in New Issue
Block a user