Welcome to mirror list, hosted at ThFree Co, Russian Federation.

mod_msg_xhtml.py « modules - github.com/mrDoctorWho/vk4xmpp.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 8122a61c6391a7421b59f2b4b6b2da472237d1a1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# coding: utf-8
# This file is a part of VK4XMPP transport
# © simpleApps, 2013 — 2015.
# This module depends on mod_xhtml.

from __main__ import Users, logger
import xmpp
import mod_xhtml

def xhtml_handler(cl, msg):
	destination = msg.getTo().getStripped()
	source = msg.getFrom()
	if isinstance(source, (str, unicode)):
		logger.warning("Received message did not contain a valid jid: %s", msg)
		raise xmpp.NodeProcessed()
	source = source.getStripped()
	if source in Users and msg.getType() == "chat":
		user = Users[source]
		html = msg.getTag("html")
		if html and html.getTag("body"):  # XHTML-IM!
			logger.debug("fetched xhtml image from %s", source)
			try:
				xhtml = mod_xhtml.parseXHTML(user, html, source, destination)
			except Exception:
				xhtml = False
			if xhtml:
				raise xmpp.NodeProcessed()

MOD_TYPE = "message"
MOD_HANDLERS = ((xhtml_handler, "", "", True),)
MOD_FEATURES = [xmpp.NS_XHTML_IM]
MOD_FEATURES_USER = [xmpp.NS_XHTML_IM]