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

forwarded_messages.py « extensions - github.com/mrDoctorWho/vk4xmpp.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 24c3fa8e1e7fb7de67307ab4140028b71502862b (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
33
34
35
36
# coding: utf-8
# This file is a part of VK4XMPP transport
# © simpleApps, 2013 — 2015.

from datetime import datetime

if not require("attachments"):
	raise AssertionError("'forwardMessages' requires 'attachments'")

BASE_SPACER = chr(32) + unichr(183) + chr(32)


def parseForwardedMessages(self, msg, depth=0):
	body = ""
	if msg.has_key("fwd_messages"):
		spacer = BASE_SPACER * depth
		body = "\n" + spacer
		body += _("Forwarded messages:")
		fwd_messages = sorted(msg["fwd_messages"], sortMsg)
		for fwd in fwd_messages:
			source = fwd["uid"]
			date = fwd["date"]
			fwdBody = escape("", uhtml(compile_eol.sub("\n" + spacer + BASE_SPACER, fwd["body"])))
			date = datetime.fromtimestamp(date).strftime("%d.%m.%Y %H:%M:%S")
			name = self.vk.getUserData(source, notoken=True)["name"]
			body += "\n%s[%s] <%s> %s" % (spacer + BASE_SPACER, date, name, fwdBody)
			body += parseAttachments(self, fwd, spacer + (BASE_SPACER * 2))
			if depth < MAXIMUM_FORWARD_DEPTH: 
				body += parseForwardedMessages(self, fwd, (depth + 1))
	return body

if not isdef("MAXIMUM_FORWARD_DEPTH"):
	MAXIMUM_FORWARD_DEPTH = 29

registerHandler("msg01", parseForwardedMessages)