From da9425228e77a6ed2d15aec8cccdb9c3f69a060e Mon Sep 17 00:00:00 2001 From: Manuel Cortez Date: Fri, 11 Jan 2019 17:00:58 -0600 Subject: [PATCH] Added some code to catch user_typing event. Needs view implementation --- src/controller/buffers.py | 2 ++ src/controller/mainController.py | 7 +++++++ src/presenters/longpollthread.py | 2 ++ 3 files changed, 11 insertions(+) diff --git a/src/controller/buffers.py b/src/controller/buffers.py index b561c9d..971b45c 100644 --- a/src/controller/buffers.py +++ b/src/controller/buffers.py @@ -1,6 +1,7 @@ # -*- coding: utf-8 -*- """ A buffer is a (virtual) list of items. All items belong to a category (wall posts, messages, persons...)""" from __future__ import unicode_literals +import time import random import logging import webbrowser @@ -952,6 +953,7 @@ class chatBuffer(baseBuffer): super(chatBuffer, self).__init__(*args, **kwargs) self.reads = [] self.chats = dict() + self.peer_typing = 0 def parse_attachments(self, post): attachments = [] diff --git a/src/controller/mainController.py b/src/controller/mainController.py index 093a801..86d3d86 100644 --- a/src/controller/mainController.py +++ b/src/controller/mainController.py @@ -123,6 +123,7 @@ class Controller(object): pub.subscribe(self.handle_longpoll_read_timeout, "longpoll-read-timeout") pub.subscribe(self.create_buffer, "create_buffer") pub.subscribe(self.create_empty_buffer, "create_empty_buffer") + pub.subscribe(self.user_typing, "user-typing") widgetUtils.connect_event(self.window, widgetUtils.CLOSE_EVENT, self.exit) widgetUtils.connect_event(self.window, widgetUtils.MENU, self.update_buffer, menuitem=self.window.update_buffer) widgetUtils.connect_event(self.window, widgetUtils.MENU, self.check_for_updates, menuitem=self.window.check_for_updates) @@ -397,6 +398,12 @@ class Controller(object): sound = "friend_offline.ogg" self.notify(msg, sound, self.session.settings["chat"]["notifications"]) + def user_typing(self, obj): + buffer = self.search_chat_buffer(obj.user_id) + if buffer != None and buffer == self.get_current_buffer(): + user = self.session.get_user_name(obj.user_id) + output.speak(_("{user1_nom} is typing...").format(**user)) + def get_chat(self, obj=None): """ Searches or creates a chat buffer with the id of the user that is sending or receiving a message. obj vk_api.longpoll.EventType: an event wich defines some data from the vk's long poll server.""" diff --git a/src/presenters/longpollthread.py b/src/presenters/longpollthread.py index 6162984..1cc16d6 100644 --- a/src/presenters/longpollthread.py +++ b/src/presenters/longpollthread.py @@ -23,5 +23,7 @@ class worker(threading.Thread): pub.sendMessage("user-online", event=event) elif event.type == VkEventType.USER_OFFLINE: pub.sendMessage("user-offline", event=event) + elif event.type == VkEventType.USER_TYPING: + pub.sendMessage("user-typing", event=event) except: pub.sendMessage("longpoll-read-timeout") \ No newline at end of file