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

message_reader.py « extensions - github.com/mrDoctorWho/vk4xmpp.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 8decf3f60ccbc4d9603e469285afeaf987ce4a74 (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
37
38
39
40
41
42
43
44
# coding: utf-8
# This file is a part of VK4XMPP transport
# © 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 when I read them", "value": 0}

def typingreader_watch(msg):
	jidFrom = msg.getFrom()
	source = jidFrom.getStripped()
	destination = msg.getTo().getStripped()
	if msg.getType() == "chat" and source in Users:
		user = Users[source]
		uid = vk2xmpp(destination)
		if uid in user.lastMsgByUser:
			lastMsgID = user.lastMsgByUser[uid]
			if lastMsgID > user.lastMarkedMessage:
				if user.settings.typingreader and msg.getTag("composing", namespace=xmpp.NS_CHATSTATES):
					typingreader_markasread(user, lastMsgID)
				if user.settings.read_on_displayed and (msg.getTag("displayed", namespace=xmpp.NS_CHAT_MARKERS)
					or msg.getTag("active", namespace=xmpp.NS_CHATSTATES)):
					typingreader_markasread(user, lastMsgID)


def typingreader_markasread(user, mid):
	user.vk.method("messages.markAsRead", {"message_ids": mid})
	# try to ensure that we don't skip further messages unmarked (doesn't work properly though)
	if user.lastMarkedMessage < mid:
		user.lastMarkedMessage = user.lastMsgID


def typingreader_add(msg, destination, source):
	if destination in Users:
		user = Users[destination]
		if user.settings.read_on_displayed:
			msg.setTag("markable", namespace=xmpp.NS_CHAT_MARKERS)


def typingreader_init(user):
	user.lastMarkedMessage = 0


registerHandler("msg02", typingreader_watch)
registerHandler("evt07", typingreader_init)