2018-09-05 02:59:34 +02:00
|
|
|
# Copyright (C) 2007 Piotr Gaczkowski <doomhammerng AT gmail.com>
|
|
|
|
# Copyright (C) 2007-2014 Yann Leboulanger <asterix AT lagaule.org>
|
|
|
|
# Copyright (C) 2008 Brendan Taylor <whateley AT gmail.com>
|
|
|
|
# Jean-Marie Traissard <jim AT lapin.org>
|
|
|
|
# Jonathan Schleifer <js-common.gajim AT webkeks.org>
|
|
|
|
# Stephan Erb <steve-e AT h3c.de>
|
|
|
|
#
|
|
|
|
# This file is part of Gajim.
|
|
|
|
#
|
|
|
|
# Gajim is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published
|
|
|
|
# by the Free Software Foundation; version 3 only.
|
|
|
|
#
|
|
|
|
# Gajim is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with Gajim. If not, see <http://www.gnu.org/licenses/>.
|
2008-08-15 05:39:27 +02:00
|
|
|
|
2018-09-21 23:55:57 +02:00
|
|
|
from typing import Any # pylint: disable=unused-import
|
|
|
|
from typing import List # pylint: disable=unused-import
|
|
|
|
|
2009-11-14 19:56:15 +01:00
|
|
|
import logging
|
|
|
|
|
2017-08-13 13:18:56 +02:00
|
|
|
from gajim.common import app
|
2009-11-14 19:56:15 +01:00
|
|
|
|
2018-09-21 23:55:57 +02:00
|
|
|
log = logging.getLogger('gajim.c.pep')
|
2009-11-15 10:55:31 +01:00
|
|
|
|
2018-09-16 11:56:56 +02:00
|
|
|
class AbstractPEP:
|
2009-11-26 12:58:12 +01:00
|
|
|
|
2012-08-22 12:55:57 +02:00
|
|
|
type_ = ''
|
2010-02-08 15:08:40 +01:00
|
|
|
namespace = ''
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def get_tag_as_PEP(cls, jid, account, event_tag):
|
|
|
|
items = event_tag.getTag('items', {'node': cls.namespace})
|
|
|
|
if items:
|
2018-09-17 18:57:00 +02:00
|
|
|
log.debug('Received PEP "user %s" from %s', cls.type_, jid)
|
2010-02-08 15:08:40 +01:00
|
|
|
return cls(jid, account, items)
|
2018-09-18 10:14:04 +02:00
|
|
|
return None
|
2010-02-08 15:08:40 +01:00
|
|
|
|
|
|
|
def __init__(self, jid, account, items):
|
2018-09-12 00:01:54 +02:00
|
|
|
self.data, self._retracted = self._extract_info(items)
|
2010-02-08 15:08:40 +01:00
|
|
|
|
|
|
|
self._update_contacts(jid, account)
|
2017-08-13 13:18:56 +02:00
|
|
|
if jid == app.get_jid_from_account(account):
|
2010-02-08 15:08:40 +01:00
|
|
|
self._update_account(account)
|
2017-09-16 11:49:31 +02:00
|
|
|
self._on_receive(jid, account)
|
2010-02-08 15:08:40 +01:00
|
|
|
|
|
|
|
def _extract_info(self, items):
|
|
|
|
'''To be implemented by subclasses'''
|
|
|
|
raise NotImplementedError
|
|
|
|
|
|
|
|
def _update_contacts(self, jid, account):
|
2017-08-13 13:18:56 +02:00
|
|
|
for contact in app.contacts.get_contacts(account, jid):
|
2010-02-08 15:08:40 +01:00
|
|
|
if self._retracted:
|
2012-08-22 12:55:57 +02:00
|
|
|
if self.type_ in contact.pep:
|
|
|
|
del contact.pep[self.type_]
|
2010-02-08 15:08:40 +01:00
|
|
|
else:
|
2012-08-22 12:55:57 +02:00
|
|
|
contact.pep[self.type_] = self
|
2010-02-08 15:08:40 +01:00
|
|
|
|
|
|
|
def _update_account(self, account):
|
2017-08-13 13:18:56 +02:00
|
|
|
acc = app.connections[account]
|
2010-02-08 15:08:40 +01:00
|
|
|
if self._retracted:
|
2012-08-22 12:55:57 +02:00
|
|
|
if self.type_ in acc.pep:
|
|
|
|
del acc.pep[self.type_]
|
2010-02-08 15:08:40 +01:00
|
|
|
else:
|
2012-08-22 12:55:57 +02:00
|
|
|
acc.pep[self.type_] = self
|
2010-02-08 15:08:40 +01:00
|
|
|
|
2018-09-13 23:56:12 +02:00
|
|
|
def as_markup_text(self):
|
2010-02-08 15:08:40 +01:00
|
|
|
'''SHOULD be implemented by subclasses'''
|
|
|
|
return ''
|
2009-11-26 12:58:12 +01:00
|
|
|
|
2017-09-16 11:49:31 +02:00
|
|
|
def _on_receive(self, jid, account):
|
|
|
|
'''SHOULD be implemented by subclasses'''
|
|
|
|
pass
|
|
|
|
|
2009-11-26 12:58:12 +01:00
|
|
|
|
2018-09-21 23:55:57 +02:00
|
|
|
SUPPORTED_PERSONAL_USER_EVENTS = [] # type: List[Any]
|