diff options
author | John Smith <mrdoctorwho@helldev.net> | 2018-12-24 16:05:24 +0300 |
---|---|---|
committer | John Smith <mrdoctorwho@helldev.net> | 2018-12-24 16:05:24 +0300 |
commit | a6f02bb396a8166dfb1051692273e5856b21e2bb (patch) | |
tree | 4f169824c53e8592d07238bac713568d004706a8 | |
parent | d35622d82961a43fd83a80c60ce6527e1dfb95a9 (diff) |
experimental OOB support
-rw-r--r-- | extensions/attachments.py | 27 | ||||
-rw-r--r-- | extensions/message_reader.py | 2 | ||||
-rw-r--r-- | library/defaults.py | 4 |
3 files changed, 29 insertions, 4 deletions
diff --git a/extensions/attachments.py b/extensions/attachments.py index f507abe..af3bed5 100644 --- a/extensions/attachments.py +++ b/extensions/attachments.py @@ -2,6 +2,7 @@ # This file is a part of VK4XMPP transport # © simpleApps, 2013 — 2016. +import re import urllib from printer import * @@ -11,7 +12,12 @@ WALL_COMMENT_LINK = "https://vk.com/wall%(owner_id)s_%(post_id)s?w=wall%(owner_i PHOTO_SIZES = ("src_xxxbig", "src_xxbig", "src_xbig", "src_big", "src", "url", "src_small") STICKER_SIZES = ("photo_256", "photo_128", "photo_64") +ATTACHMENT_REGEX = re.compile(r"^(Photo|Document|Sticker)\:\s(“.+?”\s—\s)?(?P<url>http[s]?:\/\/(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*\(\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+$)") + GLOBAL_USER_SETTINGS["parse_wall"] = {"value": 0, "label": "Parse wall attachments"} +GLOBAL_USER_SETTINGS["make_oob"] = {"value": 0, "label": "Allow OOB for attachments", + "desc": "Attach incoming files as attachments,\nso they would be displayed by your client (if supported)"} + # The attachments that don't require any special movements SIMPLE_ATTACHMENTS = {"doc": "Document: “%(title)s” — %(url)s", @@ -106,4 +112,23 @@ def parseAttachments(self, msg, spacer=""): result += body return result -registerHandler("msg01", parseAttachments)
\ No newline at end of file + +def attachments_msg03(msg, destination, source): + body = msg.getBody() + if body: + if msg.getType() == "groupchat": + user = Chat.getUserObject(destination) + else: + user = Users.get(destination) + if user and user.settings.make_oob: + match = ATTACHMENT_REGEX.match(body) + if match: + link = match.group("url") + url = msg.setTag("x", namespace=xmpp.NS_OOB) + url.setTagData("url", link) + msg.setBody(link) + + + +registerHandler("msg03", attachments_msg03) +registerHandler("msg01", parseAttachments) diff --git a/extensions/message_reader.py b/extensions/message_reader.py index 7d86f36..b7b6d72 100644 --- a/extensions/message_reader.py +++ b/extensions/message_reader.py @@ -3,7 +3,7 @@ # © simpleApps, 2014 (16.12.14 14:54PM GMT) — 2015. GLOBAL_USER_SETTINGS["typingreader"] = {"label": "Mark my messages as read when I compose message", "value": 0} -GLOBAL_USER_SETTINGS["read_on_displayed"] = {"label": "Mark my messages as read", "value": 0} +GLOBAL_USER_SETTINGS["read_on_displayed"] = {"label": "Mark my messages as read when I read them", "value": 0} def typingreader_watch(msg): jidFrom = msg.getFrom() diff --git a/library/defaults.py b/library/defaults.py index 15bc90d..7363f61 100644 --- a/library/defaults.py +++ b/library/defaults.py @@ -49,7 +49,7 @@ AdditionalAbout = "" allowBePublic = True # The features transport will advertise -TransportFeatures = {xmpp.NS_DELAY} +TransportFeatures = {xmpp.NS_DELAY, xmpp.NS_CHATSTATES, xmpp.NS_LAST, xmpp.NS_CHAT_MARKERS, xmpp.NS_OOB} # The features transport's users will advertise -UserFeatures = {xmpp.NS_CHATSTATES, xmpp.NS_LAST, xmpp.NS_CHAT_MARKERS}
\ No newline at end of file +UserFeatures = TransportFeatures # we don't use them all, but it seems some clients don't query transports' users (?)
\ No newline at end of file |