2008-08-15 19:31:51 +02:00
|
|
|
# -*- coding:utf-8 -*-
|
2008-08-15 05:39:27 +02:00
|
|
|
## src/common/pep.py
|
|
|
|
##
|
|
|
|
## Copyright (C) 2007 Piotr Gaczkowski <doomhammerng AT gmail.com>
|
2014-01-02 09:33:54 +01:00
|
|
|
## Copyright (C) 2007-2014 Yann Leboulanger <asterix AT lagaule.org>
|
2008-08-15 05:39:27 +02:00
|
|
|
## Copyright (C) 2008 Brendan Taylor <whateley AT gmail.com>
|
|
|
|
## Jean-Marie Traissard <jim AT lapin.org>
|
2009-04-12 20:13:37 +02:00
|
|
|
## Jonathan Schleifer <js-common.gajim AT webkeks.org>
|
2008-08-15 05:39:27 +02:00
|
|
|
## 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/>.
|
|
|
|
##
|
|
|
|
|
2009-11-14 19:56:15 +01:00
|
|
|
import logging
|
|
|
|
log = logging.getLogger('gajim.c.pep')
|
|
|
|
|
2017-08-13 13:18:56 +02:00
|
|
|
from gajim.common import app
|
2009-11-14 19:56:15 +01:00
|
|
|
|
2009-11-15 10:55:31 +01:00
|
|
|
|
2009-11-14 20:48:33 +01:00
|
|
|
class AbstractPEP(object):
|
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:
|
2012-08-22 12:55:57 +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)
|
|
|
|
else:
|
|
|
|
return None
|
|
|
|
|
|
|
|
def __init__(self, jid, account, items):
|
|
|
|
self._pep_specific_data, self._retracted = self._extract_info(items)
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
def asMarkupText(self):
|
|
|
|
'''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-07-06 19:55:13 +02:00
|
|
|
SUPPORTED_PERSONAL_USER_EVENTS = []
|