1# Copyright (C) 2018 Philipp Hörist <philipp AT hoerist.com> 2# 3# This file is part of nbxmpp. 4# 5# This program is free software; you can redistribute it and/or 6# modify it under the terms of the GNU General Public License 7# as published by the Free Software Foundation; either version 3 8# of the License, or (at your option) any later version. 9# 10# This program is distributed in the hope that it will be useful, 11# but WITHOUT ANY WARRANTY; without even the implied warranty of 12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13# GNU General Public License for more details. 14# 15# You should have received a copy of the GNU General Public License 16# along with this program; If not, see <http://www.gnu.org/licenses/>. 17 18from nbxmpp.namespaces import Namespace 19from nbxmpp.structs import StanzaHandler 20from nbxmpp.modules.base import BaseModule 21 22 23class Attention(BaseModule): 24 def __init__(self, client): 25 BaseModule.__init__(self, client) 26 27 self._client = client 28 self.handlers = [ 29 StanzaHandler(name='message', 30 callback=self._process_message_attention, 31 ns=Namespace.ATTENTION, 32 priority=15), 33 ] 34 35 def _process_message_attention(self, _client, stanza, properties): 36 attention = stanza.getTag('attention', namespace=Namespace.ATTENTION) 37 if attention is None: 38 return 39 40 if properties.is_mam_message: 41 return 42 43 if properties.is_carbon_message and properties.carbon.is_sent: 44 return 45 46 if stanza.getTag('delay', namespace=Namespace.DELAY2) is not None: 47 return 48 49 properties.attention = True 50