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/>.
|
|
|
|
##
|
|
|
|
|
2008-07-29 21:02:57 +02:00
|
|
|
MOODS = {
|
2010-02-08 15:08:40 +01:00
|
|
|
'afraid': _('Afraid'),
|
|
|
|
'amazed': _('Amazed'),
|
|
|
|
'amorous': _('Amorous'),
|
|
|
|
'angry': _('Angry'),
|
|
|
|
'annoyed': _('Annoyed'),
|
|
|
|
'anxious': _('Anxious'),
|
|
|
|
'aroused': _('Aroused'),
|
|
|
|
'ashamed': _('Ashamed'),
|
|
|
|
'bored': _('Bored'),
|
|
|
|
'brave': _('Brave'),
|
|
|
|
'calm': _('Calm'),
|
|
|
|
'cautious': _('Cautious'),
|
|
|
|
'cold': _('Cold'),
|
|
|
|
'confident': _('Confident'),
|
|
|
|
'confused': _('Confused'),
|
|
|
|
'contemplative': _('Contemplative'),
|
|
|
|
'contented': _('Contented'),
|
|
|
|
'cranky': _('Cranky'),
|
|
|
|
'crazy': _('Crazy'),
|
|
|
|
'creative': _('Creative'),
|
|
|
|
'curious': _('Curious'),
|
|
|
|
'dejected': _('Dejected'),
|
|
|
|
'depressed': _('Depressed'),
|
|
|
|
'disappointed': _('Disappointed'),
|
|
|
|
'disgusted': _('Disgusted'),
|
|
|
|
'dismayed': _('Dismayed'),
|
|
|
|
'distracted': _('Distracted'),
|
|
|
|
'embarrassed': _('Embarrassed'),
|
|
|
|
'envious': _('Envious'),
|
|
|
|
'excited': _('Excited'),
|
|
|
|
'flirtatious': _('Flirtatious'),
|
|
|
|
'frustrated': _('Frustrated'),
|
|
|
|
'grateful': _('Grateful'),
|
|
|
|
'grieving': _('Grieving'),
|
|
|
|
'grumpy': _('Grumpy'),
|
|
|
|
'guilty': _('Guilty'),
|
|
|
|
'happy': _('Happy'),
|
|
|
|
'hopeful': _('Hopeful'),
|
|
|
|
'hot': _('Hot'),
|
|
|
|
'humbled': _('Humbled'),
|
|
|
|
'humiliated': _('Humiliated'),
|
|
|
|
'hungry': _('Hungry'),
|
|
|
|
'hurt': _('Hurt'),
|
|
|
|
'impressed': _('Impressed'),
|
|
|
|
'in_awe': _('In Awe'),
|
|
|
|
'in_love': _('In Love'),
|
|
|
|
'indignant': _('Indignant'),
|
|
|
|
'interested': _('Interested'),
|
|
|
|
'intoxicated': _('Intoxicated'),
|
|
|
|
'invincible': _('Invincible'),
|
|
|
|
'jealous': _('Jealous'),
|
|
|
|
'lonely': _('Lonely'),
|
|
|
|
'lost': _('Lost'),
|
|
|
|
'lucky': _('Lucky'),
|
|
|
|
'mean': _('Mean'),
|
|
|
|
'moody': _('Moody'),
|
|
|
|
'nervous': _('Nervous'),
|
|
|
|
'neutral': _('Neutral'),
|
|
|
|
'offended': _('Offended'),
|
|
|
|
'outraged': _('Outraged'),
|
|
|
|
'playful': _('Playful'),
|
|
|
|
'proud': _('Proud'),
|
|
|
|
'relaxed': _('Relaxed'),
|
|
|
|
'relieved': _('Relieved'),
|
|
|
|
'remorseful': _('Remorseful'),
|
|
|
|
'restless': _('Restless'),
|
|
|
|
'sad': _('Sad'),
|
|
|
|
'sarcastic': _('Sarcastic'),
|
|
|
|
'satisfied': _('Satisfied'),
|
|
|
|
'serious': _('Serious'),
|
|
|
|
'shocked': _('Shocked'),
|
|
|
|
'shy': _('Shy'),
|
|
|
|
'sick': _('Sick'),
|
|
|
|
'sleepy': _('Sleepy'),
|
|
|
|
'spontaneous': _('Spontaneous'),
|
|
|
|
'stressed': _('Stressed'),
|
|
|
|
'strong': _('Strong'),
|
|
|
|
'surprised': _('Surprised'),
|
|
|
|
'thankful': _('Thankful'),
|
|
|
|
'thirsty': _('Thirsty'),
|
|
|
|
'tired': _('Tired'),
|
|
|
|
'undefined': _('Undefined'),
|
|
|
|
'weak': _('Weak'),
|
|
|
|
'worried': _('Worried')}
|
2008-07-22 23:08:52 +02:00
|
|
|
|
2008-07-28 22:57:56 +02:00
|
|
|
ACTIVITIES = {
|
2012-11-15 11:05:10 +01:00
|
|
|
'doing_chores': {'category': _('Doing Chores'),
|
|
|
|
'buying_groceries': _('Buying Groceries'),
|
|
|
|
'cleaning': _('Cleaning'),
|
|
|
|
'cooking': _('Cooking'),
|
|
|
|
'doing_maintenance': _('Doing Maintenance'),
|
|
|
|
'doing_the_dishes': _('Doing the Dishes'),
|
|
|
|
'doing_the_laundry': _('Doing the Laundry'),
|
|
|
|
'gardening': _('Gardening'),
|
|
|
|
'running_an_errand': _('Running an Errand'),
|
|
|
|
'walking_the_dog': _('Walking the Dog')},
|
|
|
|
'drinking': {'category': _('Drinking'),
|
2012-11-15 11:19:02 +01:00
|
|
|
'having_a_beer': _('Having a Beer'),
|
2012-11-15 11:05:10 +01:00
|
|
|
'having_coffee': _('Having Coffee'),
|
|
|
|
'having_tea': _('Having Tea')},
|
|
|
|
'eating': {'category': _('Eating'),
|
|
|
|
'having_a_snack': _('Having a Snack'),
|
|
|
|
'having_breakfast': _('Having Breakfast'),
|
|
|
|
'having_dinner': _('Having Dinner'),
|
|
|
|
'having_lunch': _('Having Lunch')},
|
|
|
|
'exercising': {'category': _('Exercising'),
|
|
|
|
'cycling': _('Cycling'),
|
|
|
|
'dancing': _('Dancing'),
|
|
|
|
'hiking': _('Hiking'),
|
|
|
|
'jogging': _('Jogging'),
|
|
|
|
'playing_sports': _('Playing Sports'),
|
|
|
|
'running': _('Running'),
|
|
|
|
'skiing': _('Skiing'),
|
|
|
|
'swimming': _('Swimming'),
|
|
|
|
'working_out': _('Working out')},
|
|
|
|
'grooming': {'category': _('Grooming'),
|
|
|
|
'at_the_spa': _('At the Spa'),
|
|
|
|
'brushing_teeth': _('Brushing Teeth'),
|
|
|
|
'getting_a_haircut': _('Getting a Haircut'),
|
|
|
|
'shaving': _('Shaving'),
|
|
|
|
'taking_a_bath': _('Taking a Bath'),
|
|
|
|
'taking_a_shower': _('Taking a Shower')},
|
2010-02-08 15:08:40 +01:00
|
|
|
'having_appointment': {'category': _('Having an Appointment')},
|
2012-11-15 11:05:10 +01:00
|
|
|
'inactive': {'category': _('Inactive'),
|
|
|
|
'day_off': _('Day Off'),
|
|
|
|
'hanging_out': _('Hanging out'),
|
|
|
|
'hiding': _('Hiding'),
|
|
|
|
'on_vacation': _('On Vacation'),
|
|
|
|
'praying': _('Praying'),
|
|
|
|
'scheduled_holiday': _('Scheduled Holiday'),
|
|
|
|
'sleeping': _('Sleeping'),
|
|
|
|
'thinking': _('Thinking')},
|
|
|
|
'relaxing': {'category': _('Relaxing'),
|
2013-01-06 12:41:26 +01:00
|
|
|
'fishing': _('Fishing'),
|
|
|
|
'gaming': _('Gaming'),
|
2012-11-15 11:05:10 +01:00
|
|
|
'going_out': _('Going out'),
|
|
|
|
'partying': _('Partying'),
|
|
|
|
'reading': _('Reading'),
|
|
|
|
'rehearsing': _('Rehearsing'),
|
|
|
|
'shopping': _('Shopping'),
|
|
|
|
'smoking': _('Smoking'),
|
|
|
|
'socializing': _('Socializing'),
|
|
|
|
'sunbathing': _('Sunbathing'),
|
|
|
|
'watching_tv': _('Watching TV'),
|
|
|
|
'watching_a_movie': _('Watching a Movie')},
|
|
|
|
'talking': {'category': _('Talking'),
|
|
|
|
'in_real_life': _('In Real Life'),
|
|
|
|
'on_the_phone': _('On the Phone'),
|
|
|
|
'on_video_phone': _('On Video Phone')},
|
|
|
|
'traveling': {'category': _('Traveling'),
|
|
|
|
'commuting': _('Commuting'),
|
|
|
|
'cycling': _('Cycling'),
|
|
|
|
'driving': _('Driving'),
|
|
|
|
'in_a_car': _('In a Car'),
|
|
|
|
'on_a_bus': _('On a Bus'),
|
|
|
|
'on_a_plane': _('On a Plane'),
|
|
|
|
'on_a_train': _('On a Train'),
|
|
|
|
'on_a_trip': _('On a Trip'),
|
|
|
|
'walking': _('Walking')},
|
|
|
|
'working': {'category': _('Working'),
|
|
|
|
'coding': _('Coding'),
|
|
|
|
'in_a_meeting': _('In a Meeting'),
|
|
|
|
'studying': _('Studying'),
|
|
|
|
'writing': _('Writing')}}
|
2008-07-28 22:57:56 +02:00
|
|
|
|
2009-11-14 22:31:27 +01:00
|
|
|
TUNE_DATA = ['artist', 'title', 'source', 'track', 'length']
|
|
|
|
|
2012-11-15 11:44:48 +01:00
|
|
|
LOCATION_DATA = {
|
|
|
|
'accuracy': _('accuracy'),
|
|
|
|
'alt': _('alt'),
|
|
|
|
'area': _('area'),
|
|
|
|
'bearing': _('bearing'),
|
|
|
|
'building': _('building'),
|
|
|
|
'country': _('country'),
|
|
|
|
'countrycode': _('countrycode'),
|
|
|
|
'datum': _('datum'),
|
|
|
|
'description': _('description'),
|
|
|
|
'error': _('error'),
|
|
|
|
'floor': _('floor'),
|
|
|
|
'lat': _('lat'),
|
|
|
|
'locality': _('locality'),
|
|
|
|
'lon': _('lon'),
|
|
|
|
'postalcode': _('postalcode'),
|
|
|
|
'region': _('region'),
|
|
|
|
'room': _('room'),
|
|
|
|
'speed': _('speed'),
|
|
|
|
'street': _('street'),
|
|
|
|
'text': _('text'),
|
|
|
|
'timestamp': _('timestamp'),
|
|
|
|
'uri': _('uri')}
|
2009-12-07 18:32:42 +01:00
|
|
|
|
2013-07-29 21:41:01 +02:00
|
|
|
from gi.repository import GLib
|
2009-11-22 22:07:48 +01:00
|
|
|
|
2009-11-14 19:56:15 +01:00
|
|
|
import logging
|
|
|
|
log = logging.getLogger('gajim.c.pep')
|
|
|
|
|
2012-12-09 21:37:51 +01:00
|
|
|
import nbxmpp
|
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
|
|
|
|
2009-11-14 20:48:33 +01:00
|
|
|
class UserMoodPEP(AbstractPEP):
|
2010-02-08 15:08:40 +01:00
|
|
|
'''XEP-0107: User Mood'''
|
|
|
|
|
2012-08-22 12:55:57 +02:00
|
|
|
type_ = 'mood'
|
2012-12-09 21:37:51 +01:00
|
|
|
namespace = nbxmpp.NS_MOOD
|
2010-02-08 15:08:40 +01:00
|
|
|
|
|
|
|
def _extract_info(self, items):
|
|
|
|
mood_dict = {}
|
|
|
|
|
|
|
|
for item in items.getTags('item'):
|
|
|
|
mood_tag = item.getTag('mood')
|
|
|
|
if mood_tag:
|
|
|
|
for child in mood_tag.getChildren():
|
|
|
|
name = child.getName().strip()
|
|
|
|
if name == 'text':
|
|
|
|
mood_dict['text'] = child.getData()
|
|
|
|
else:
|
|
|
|
mood_dict['mood'] = name
|
|
|
|
|
|
|
|
retracted = items.getTag('retract') or not 'mood' in mood_dict
|
|
|
|
return (mood_dict, retracted)
|
|
|
|
|
|
|
|
def asMarkupText(self):
|
|
|
|
assert not self._retracted
|
|
|
|
untranslated_mood = self._pep_specific_data['mood']
|
|
|
|
mood = self._translate_mood(untranslated_mood)
|
2013-07-29 21:41:01 +02:00
|
|
|
markuptext = '<b>%s</b>' % GLib.markup_escape_text(mood)
|
2010-02-08 15:08:40 +01:00
|
|
|
if 'text' in self._pep_specific_data:
|
|
|
|
text = self._pep_specific_data['text']
|
2013-07-29 21:41:01 +02:00
|
|
|
markuptext += ' (%s)' % GLib.markup_escape_text(text)
|
2010-02-08 15:08:40 +01:00
|
|
|
return markuptext
|
|
|
|
|
|
|
|
def _translate_mood(self, mood):
|
|
|
|
if mood in MOODS:
|
|
|
|
return MOODS[mood]
|
|
|
|
else:
|
|
|
|
return mood
|
2009-11-22 22:14:05 +01:00
|
|
|
|
2009-11-14 20:48:33 +01:00
|
|
|
|
|
|
|
class UserTunePEP(AbstractPEP):
|
2010-02-08 15:08:40 +01:00
|
|
|
'''XEP-0118: User Tune'''
|
2009-11-26 12:58:12 +01:00
|
|
|
|
2012-08-22 12:55:57 +02:00
|
|
|
type_ = 'tune'
|
2012-12-09 21:37:51 +01:00
|
|
|
namespace = nbxmpp.NS_TUNE
|
2009-11-26 12:58:12 +01:00
|
|
|
|
2010-02-08 15:08:40 +01:00
|
|
|
def _extract_info(self, items):
|
|
|
|
tune_dict = {}
|
2009-11-26 12:58:12 +01:00
|
|
|
|
2010-02-08 15:08:40 +01:00
|
|
|
for item in items.getTags('item'):
|
|
|
|
tune_tag = item.getTag('tune')
|
|
|
|
if tune_tag:
|
|
|
|
for child in tune_tag.getChildren():
|
|
|
|
name = child.getName().strip()
|
|
|
|
data = child.getData().strip()
|
|
|
|
if child.getName() in TUNE_DATA:
|
|
|
|
tune_dict[name] = data
|
2009-11-26 12:58:12 +01:00
|
|
|
|
2010-02-08 15:08:40 +01:00
|
|
|
retracted = items.getTag('retract') or not ('artist' in tune_dict or
|
2012-11-15 11:05:10 +01:00
|
|
|
'title' in tune_dict)
|
2010-02-08 15:08:40 +01:00
|
|
|
return (tune_dict, retracted)
|
2009-11-26 12:58:12 +01:00
|
|
|
|
2010-02-08 15:08:40 +01:00
|
|
|
def asMarkupText(self):
|
|
|
|
assert not self._retracted
|
|
|
|
tune = self._pep_specific_data
|
2009-11-15 10:55:31 +01:00
|
|
|
|
2010-02-08 15:08:40 +01:00
|
|
|
artist = tune.get('artist', _('Unknown Artist'))
|
2013-07-29 21:41:01 +02:00
|
|
|
artist = GLib.markup_escape_text(artist)
|
2009-11-26 12:58:12 +01:00
|
|
|
|
2010-02-08 15:08:40 +01:00
|
|
|
title = tune.get('title', _('Unknown Title'))
|
2013-07-29 21:41:01 +02:00
|
|
|
title = GLib.markup_escape_text(title)
|
2009-11-15 10:55:31 +01:00
|
|
|
|
2010-02-08 15:08:40 +01:00
|
|
|
source = tune.get('source', _('Unknown Source'))
|
2013-07-29 21:41:01 +02:00
|
|
|
source = GLib.markup_escape_text(source)
|
2009-11-15 10:55:31 +01:00
|
|
|
|
2010-02-08 15:08:40 +01:00
|
|
|
tune_string = _('<b>"%(title)s"</b> by <i>%(artist)s</i>\n'
|
|
|
|
'from <i>%(source)s</i>') % {'title': title,
|
|
|
|
'artist': artist, 'source': source}
|
|
|
|
return tune_string
|
2009-11-26 12:58:12 +01:00
|
|
|
|
2009-11-14 20:48:33 +01:00
|
|
|
|
|
|
|
class UserActivityPEP(AbstractPEP):
|
2010-02-08 15:08:40 +01:00
|
|
|
'''XEP-0108: User Activity'''
|
|
|
|
|
2012-08-22 12:55:57 +02:00
|
|
|
type_ = 'activity'
|
2012-12-09 21:37:51 +01:00
|
|
|
namespace = nbxmpp.NS_ACTIVITY
|
2010-02-08 15:08:40 +01:00
|
|
|
|
|
|
|
def _extract_info(self, items):
|
|
|
|
activity_dict = {}
|
|
|
|
|
|
|
|
for item in items.getTags('item'):
|
|
|
|
activity_tag = item.getTag('activity')
|
|
|
|
if activity_tag:
|
|
|
|
for child in activity_tag.getChildren():
|
|
|
|
name = child.getName().strip()
|
|
|
|
data = child.getData().strip()
|
|
|
|
if name == 'text':
|
|
|
|
activity_dict['text'] = data
|
|
|
|
else:
|
|
|
|
activity_dict['activity'] = name
|
|
|
|
for subactivity in child.getChildren():
|
|
|
|
subactivity_name = subactivity.getName().strip()
|
|
|
|
activity_dict['subactivity'] = subactivity_name
|
|
|
|
|
|
|
|
retracted = items.getTag('retract') or not 'activity' in activity_dict
|
|
|
|
return (activity_dict, retracted)
|
|
|
|
|
|
|
|
def asMarkupText(self):
|
|
|
|
assert not self._retracted
|
|
|
|
pep = self._pep_specific_data
|
|
|
|
activity = pep['activity']
|
|
|
|
subactivity = pep['subactivity'] if 'subactivity' in pep else None
|
|
|
|
text = pep['text'] if 'text' in pep else None
|
|
|
|
|
|
|
|
if activity in ACTIVITIES:
|
|
|
|
# Translate standard activities
|
|
|
|
if subactivity in ACTIVITIES[activity]:
|
|
|
|
subactivity = ACTIVITIES[activity][subactivity]
|
|
|
|
activity = ACTIVITIES[activity]['category']
|
|
|
|
|
2013-07-29 21:41:01 +02:00
|
|
|
markuptext = '<b>' + GLib.markup_escape_text(activity)
|
2010-02-08 15:08:40 +01:00
|
|
|
if subactivity:
|
2013-07-29 21:41:01 +02:00
|
|
|
markuptext += ': ' + GLib.markup_escape_text(subactivity)
|
2010-02-08 15:08:40 +01:00
|
|
|
markuptext += '</b>'
|
|
|
|
if text:
|
2013-07-29 21:41:01 +02:00
|
|
|
markuptext += ' (%s)' % GLib.markup_escape_text(text)
|
2010-02-08 15:08:40 +01:00
|
|
|
return markuptext
|
2009-11-26 12:58:12 +01:00
|
|
|
|
|
|
|
|
2009-11-14 20:48:33 +01:00
|
|
|
class UserNicknamePEP(AbstractPEP):
|
2010-02-08 15:08:40 +01:00
|
|
|
'''XEP-0172: User Nickname'''
|
2009-11-26 12:58:12 +01:00
|
|
|
|
2012-08-22 12:55:57 +02:00
|
|
|
type_ = 'nickname'
|
2012-12-09 21:37:51 +01:00
|
|
|
namespace = nbxmpp.NS_NICK
|
2009-11-26 12:58:12 +01:00
|
|
|
|
2010-02-08 15:08:40 +01:00
|
|
|
def _extract_info(self, items):
|
|
|
|
nick = ''
|
|
|
|
for item in items.getTags('item'):
|
|
|
|
child = item.getTag('nick')
|
|
|
|
if child:
|
|
|
|
nick = child.getData()
|
|
|
|
break
|
2009-11-26 12:58:12 +01:00
|
|
|
|
2010-02-08 15:08:40 +01:00
|
|
|
retracted = items.getTag('retract') or not nick
|
|
|
|
return (nick, retracted)
|
2009-11-26 12:58:12 +01:00
|
|
|
|
2010-02-08 15:08:40 +01:00
|
|
|
def _update_contacts(self, jid, account):
|
|
|
|
nick = '' if self._retracted else self._pep_specific_data
|
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
|
|
|
contact.contact_name = nick
|
2009-11-26 12:58:12 +01:00
|
|
|
|
2010-02-08 15:08:40 +01:00
|
|
|
def _update_account(self, account):
|
|
|
|
if self._retracted:
|
2017-08-13 13:18:56 +02:00
|
|
|
app.nicks[account] = app.config.get_per('accounts', account, 'name')
|
2010-02-08 15:08:40 +01:00
|
|
|
else:
|
2017-08-13 13:18:56 +02:00
|
|
|
app.nicks[account] = self._pep_specific_data
|
2009-11-15 11:11:51 +01:00
|
|
|
|
2009-11-26 12:58:12 +01:00
|
|
|
|
2009-12-07 18:32:42 +01:00
|
|
|
class UserLocationPEP(AbstractPEP):
|
2010-02-08 15:08:40 +01:00
|
|
|
'''XEP-0080: User Location'''
|
2009-12-07 18:32:42 +01:00
|
|
|
|
2012-08-22 12:55:57 +02:00
|
|
|
type_ = 'location'
|
2012-12-09 21:37:51 +01:00
|
|
|
namespace = nbxmpp.NS_LOCATION
|
2009-12-07 18:32:42 +01:00
|
|
|
|
2010-02-08 15:08:40 +01:00
|
|
|
def _extract_info(self, items):
|
|
|
|
location_dict = {}
|
2009-12-07 18:32:42 +01:00
|
|
|
|
2010-02-08 15:08:40 +01:00
|
|
|
for item in items.getTags('item'):
|
|
|
|
location_tag = item.getTag('geoloc')
|
|
|
|
if location_tag:
|
|
|
|
for child in location_tag.getChildren():
|
|
|
|
name = child.getName().strip()
|
|
|
|
data = child.getData().strip()
|
|
|
|
if child.getName() in LOCATION_DATA:
|
|
|
|
location_dict[name] = data
|
2009-12-07 18:32:42 +01:00
|
|
|
|
2010-02-08 15:08:40 +01:00
|
|
|
retracted = items.getTag('retract') or not location_dict
|
|
|
|
return (location_dict, retracted)
|
2009-12-07 18:32:42 +01:00
|
|
|
|
2010-02-08 15:08:40 +01:00
|
|
|
def _update_account(self, account):
|
|
|
|
AbstractPEP._update_account(self, account)
|
2017-08-13 13:18:56 +02:00
|
|
|
con = app.connections[account].location_info = \
|
2010-02-08 15:08:40 +01:00
|
|
|
self._pep_specific_data
|
2009-12-07 23:16:30 +01:00
|
|
|
|
2010-02-08 15:08:40 +01:00
|
|
|
def asMarkupText(self):
|
|
|
|
assert not self._retracted
|
|
|
|
location = self._pep_specific_data
|
|
|
|
location_string = ''
|
2009-12-07 18:32:42 +01:00
|
|
|
|
2010-02-08 15:08:40 +01:00
|
|
|
for entry in location.keys():
|
|
|
|
text = location[entry]
|
2013-07-29 21:41:01 +02:00
|
|
|
text = GLib.markup_escape_text(text)
|
2012-11-15 11:44:48 +01:00
|
|
|
# Translate standart location tag
|
|
|
|
tag = LOCATION_DATA.get(entry, entry)
|
2010-02-08 15:08:40 +01:00
|
|
|
location_string += '\n<b>%(tag)s</b>: %(text)s' % \
|
2012-11-15 11:44:48 +01:00
|
|
|
{'tag': tag.capitalize(), 'text': text}
|
2009-12-07 18:32:42 +01:00
|
|
|
|
2010-02-08 15:08:40 +01:00
|
|
|
return location_string.strip()
|
2009-12-07 18:32:42 +01:00
|
|
|
|
|
|
|
|
2017-09-16 11:49:31 +02:00
|
|
|
class AvatarNotificationPEP(AbstractPEP):
|
|
|
|
'''XEP-0084: Avatars'''
|
|
|
|
|
|
|
|
type_ = 'avatar-notification'
|
|
|
|
namespace = 'urn:xmpp:avatar:metadata'
|
|
|
|
|
|
|
|
def _extract_info(self, items):
|
2017-11-17 19:19:59 +01:00
|
|
|
self.avatar = None
|
2017-09-16 11:49:31 +02:00
|
|
|
for item in items.getTags('item'):
|
|
|
|
info = item.getTag('metadata').getTag('info')
|
2017-11-17 19:19:59 +01:00
|
|
|
if info is not None:
|
|
|
|
self.avatar = info.getAttrs()
|
2017-09-16 11:49:31 +02:00
|
|
|
break
|
|
|
|
|
2017-11-17 19:19:59 +01:00
|
|
|
return (None, False)
|
2017-09-16 11:49:31 +02:00
|
|
|
|
|
|
|
def _on_receive(self, jid, account):
|
|
|
|
con = app.connections[account]
|
2017-11-17 19:19:59 +01:00
|
|
|
if self.avatar is None:
|
|
|
|
# Remove avatar
|
|
|
|
app.log('avatar').debug('Remove (Pubsub): %s', jid)
|
|
|
|
app.contacts.set_avatar(account, jid, None)
|
|
|
|
own_jid = con.get_own_jid().getStripped()
|
|
|
|
app.logger.set_avatar_sha(own_jid, jid, None)
|
|
|
|
app.interface.update_avatar(account, jid)
|
|
|
|
else:
|
|
|
|
sha = app.contacts.get_avatar_sha(account, jid)
|
|
|
|
app.log('avatar').info(
|
|
|
|
'Update (Pubsub): %s %s', jid, self.avatar['id'])
|
|
|
|
if sha == self.avatar['id']:
|
|
|
|
app.log('avatar').info(
|
|
|
|
'Avatar already known (Pubsub): %s %s',
|
|
|
|
jid, self.avatar['id'])
|
|
|
|
return
|
|
|
|
app.log('avatar').info('Request (Pubsub): %s', jid)
|
|
|
|
con.send_pb_retrieve(jid, 'urn:xmpp:avatar:data',
|
|
|
|
self.avatar['id'])
|
2017-09-16 11:49:31 +02:00
|
|
|
|
|
|
|
|
|
|
|
SUPPORTED_PERSONAL_USER_EVENTS = [
|
|
|
|
UserMoodPEP, UserTunePEP, UserActivityPEP,
|
|
|
|
UserNicknamePEP, UserLocationPEP, AvatarNotificationPEP]
|