Commit 2cfe56bb authored by mathieui's avatar mathieui

Remove activity/mood/gaming/tune from poezio core

rationale: probably 0.1% of poezio users have ever used the commands,
and a very small number of users are using the PEP events like that.

It is better to unclutter the poezio source and add it as a plugin,
with less tight coupling.
parent ae0888bd
......@@ -414,9 +414,6 @@ use_bookmarks_method =
# will be displayed using their nick color if true.
#display_user_color_in_join_part = true
# Display user tune notifications as information messages or not
#display_tune_notifications = false
# Change the tab state when receiving chatroom messages.
# useful if you are connected to a high-volume chatroom and do not
# want it to appear in your tab bar as active. Highlights are still
......@@ -449,39 +446,6 @@ use_bookmarks_method =
# defaults to $XDG_CACHE_HOME/poezio/images.
#tmp_image_dir =
# Receive the tune notifications or not (in order to display information
# in the contact list).
# If this is set to false, then the display_tune_notifications
# option will be ignored.
#enable_user_tune = true
# Display user gaming notifications as information messages or not
#display_gaming_notifications = false
# Receive the gaming notifications or not (in order to display information
# in the contact list).
# If this is set to false, then the display_gaming_notifications
# option will be ignored.
#enable_user_gaming = true
# Display user mood notifications as information messages or not
#display_mood_notifications = false
# Receive the mood notifications or not (in order to display information
# in the contact list).
# If this is set to false, then the display_mood_notifications
# option will be ignored.
#enable_user_mood = true
# Display user activity notifications as information messages or not
#display_activity_notifications = false
# Receive the activity notifications or not (in order to display information
# in the contact list).
# If this is set to false, then the display_activity_notifications
# option will be ignored.
#enable_user_activity = true
# If set to true, use the nickname broadcasted by the user if none has been
# set manually.
#enable_user_nick = true
......
......@@ -239,28 +239,6 @@ These commands work in *any* tab.
.. versionadded:: 0.13
/activity
**Usage:** ``/activity [<general> [specific] [comment]]``
Send your current activity to your contacts (use the completion to cycle
through all the general and specific possible activities).
Nothing means "stop broadcasting an activity".
/mood
**Usage:** ``/mood [<mood> [comment]]``
Send your current mood to your contacts (use the completion to cycle
through all the possible moods).
Nothing means "stop broadcasting a mood".
/gaming
**Usage:** ``/gaming [<game name> [server address]]``
Send your current gaming activity to your contacts.
Nothing means "stop broadcasting a gaming activity".
/last_activity
**Usage:** ``/activity <jid>``
......
......@@ -324,37 +324,12 @@ to understand what is :ref:`carbons <carbons-details>` or
as mobile networks). It can however increase bandwidth usage.
It also requires server support.
enable_user_activity
**Default value:** ``true``
Set this to ``false`` if you don’t want to receive the activity of your contacts.
enable_user_gaming
**Default value:** ``true``
Set this to ``false`` if you don’t want to receive the gaming activity of your contacts.
enable_user_mood
**Default value:** ``true``
Set this to ``false`` if you don’t want to receive the mood of your contacts.
enable_user_nick
**Default value:** ``true``
Set to ``false`` if you don’t want your contacts to hint you their identity.
enable_user_tune
**Default value:** ``true``
If this is set to ``false``, you will no longer be subscribed to tune events,
and the :term:`display_tune_notifications` option will be ignored.
go_to_previous_tab_on_alt_number
**Default value:** ``false``
......@@ -406,34 +381,6 @@ to understand what is :ref:`carbons <carbons-details>` or
Use this option to force the use of local bookmarks if needed.
Anything but "false" will be counted as true.
display_gaming_notifications
**Default value:** ``false``
If set to true, notifications about the games your are playing
will be displayed in the info buffer as 'Gaming' messages.
display_tune_notifications
**Default value:** ``false``
If set to true, notifications about the music your contacts listen to
will be displayed in the info buffer as 'Tune' messages.
display_mood_notifications
**Default value:** ``false``
If set to true, notifications about the mood of your contacts
will be displayed in the info buffer as 'Mood' messages.
display_activity_notifications
**Default value:** ``false``
If set to true, notifications about the current activity of your contacts
will be displayed in the info buffer as 'Activity' messages.
enable_xhtml_im
**Default value:** ``true``
......
......@@ -165,21 +165,9 @@ class Connection(slixmpp.ClientXMPP):
self.register_plugin('xep_0198')
self.register_plugin('xep_0199')
if config.get('enable_user_tune'):
self.register_plugin('xep_0118')
if config.get('enable_user_nick'):
self.register_plugin('xep_0172')
if config.get('enable_user_mood'):
self.register_plugin('xep_0107')
if config.get('enable_user_activity'):
self.register_plugin('xep_0108')
if config.get('enable_user_gaming'):
self.register_plugin('xep_0196')
if config.get('send_poezio_info'):
info = {'name': 'poezio', 'version': options.custom_version}
if config.get('send_os_info'):
......
......@@ -11,7 +11,14 @@ the roster.
from collections import defaultdict
import logging
from typing import Dict, Iterator, List, Optional, Union
from typing import (
Any,
Dict,
Iterator,
List,
Optional,
Union,
)
from slixmpp import InvalidJID, JID
......@@ -73,10 +80,7 @@ class Contact:
self._name = ''
self.avatar = None
self.error = None
self.tune: Dict[str, str] = {}
self.gaming: Dict[str, str] = {}
self.mood = ''
self.activity = ''
self.rich_presence: Dict[str, Any] = defaultdict(lambda: None)
@property
def groups(self) -> List[str]:
......
......@@ -15,7 +15,6 @@ from slixmpp.xmlstream.handler import Callback
from slixmpp.xmlstream.matcher import StanzaPath
from poezio import common
from poezio import pep
from poezio import tabs
from poezio import multiuserchat as muc
from poezio.bookmarks import Bookmark
......@@ -938,71 +937,6 @@ class CommandCore:
if status else '')
self.core.information(msg, 'Info')
@command_args_parser.quoted(0, 2)
def mood(self, args):
"""
/mood [<mood> [text]]
"""
if not args:
return self.core.xmpp.plugin['xep_0107'].stop()
mood = args[0]
if mood not in pep.MOODS:
return self.core.information(
'%s is not a correct value for a mood.' % mood, 'Error')
if len(args) == 2:
text = args[1]
else:
text = None
self.core.xmpp.plugin['xep_0107'].publish_mood(
mood, text, callback=dumb_callback)
@command_args_parser.quoted(0, 3)
def activity(self, args):
"""
/activity [<general> [specific] [text]]
"""
length = len(args)
if not length:
return self.core.xmpp.plugin['xep_0108'].stop()
general = args[0]
if general not in pep.ACTIVITIES:
return self.core.information(
'%s is not a correct value for an activity' % general, 'Error')
specific = None
text = None
if length == 2:
if args[1] in pep.ACTIVITIES[general]:
specific = args[1]
else:
text = args[1]
elif length == 3:
specific = args[1]
text = args[2]
if specific and specific not in pep.ACTIVITIES[general]:
return self.core.information(
'%s is not a correct value '
'for an activity' % specific, 'Error')
self.core.xmpp.plugin['xep_0108'].publish_activity(
general, specific, text, callback=dumb_callback)
@command_args_parser.quoted(0, 2)
def gaming(self, args):
"""
/gaming [<game name> [server address]]
"""
if not args:
return self.core.xmpp.plugin['xep_0196'].stop()
name = args[0]
if len(args) > 1:
address = args[1]
else:
address = None
return self.core.xmpp.plugin['xep_0196'].publish_gaming(
name=name, server_address=address, callback=dumb_callback)
@command_args_parser.quoted(2, 1, [None])
async def invite(self, args):
"""/invite <to> <room> [reason]"""
......@@ -1200,12 +1134,6 @@ class CommandCore:
return
msg = args[0]
if config.get('enable_user_mood'):
self.core.xmpp.plugin['xep_0107'].stop()
if config.get('enable_user_activity'):
self.core.xmpp.plugin['xep_0108'].stop()
if config.get('enable_user_gaming'):
self.core.xmpp.plugin['xep_0196'].stop()
self.core.save_config()
self.core.plugin_manager.disable_plugins()
self.core.xmpp.add_event_handler(
......
......@@ -13,7 +13,6 @@ from functools import reduce
from slixmpp import JID
from poezio import common
from poezio import pep
from poezio import tabs
from poezio import xdg
from poezio.common import safeJID
......@@ -318,33 +317,6 @@ class CompletionCore:
comp = sorted(onlines) + sorted(offlines)
return Completion(the_input.new_completion, comp, n, quotify=True)
def activity(self, the_input):
"""Completion for /activity"""
n = the_input.get_argument_position(quoted=True)
args = common.shell_split(the_input.text)
if n == 1:
return Completion(
the_input.new_completion,
sorted(pep.ACTIVITIES.keys()),
n,
quotify=True)
elif n == 2:
if args[1] in pep.ACTIVITIES:
l = list(pep.ACTIVITIES[args[1]])
l.remove('category')
l.sort()
return Completion(the_input.new_completion, l, n, quotify=True)
def mood(self, the_input):
"""Completion for /mood"""
n = the_input.get_argument_position(quoted=True)
if n == 1:
return Completion(
the_input.new_completion,
sorted(pep.MOODS.keys()),
1,
quotify=True)
def last_activity(self, the_input):
"""
Completion for /last_activity <jid>
......
......@@ -297,22 +297,9 @@ class Core:
self.handler.on_vcard_avatar)
self.xmpp.add_event_handler("avatar_metadata_publish",
self.handler.on_0084_avatar)
if config.get('enable_user_tune'):
self.xmpp.add_event_handler("user_tune_publish",
self.handler.on_tune_event)
if config.get('enable_user_nick'):
self.xmpp.add_event_handler("user_nick_publish",
self.handler.on_nick_received)
if config.get('enable_user_mood'):
self.xmpp.add_event_handler("user_mood_publish",
self.handler.on_mood_event)
if config.get('enable_user_activity'):
self.xmpp.add_event_handler("user_activity_publish",
self.handler.on_activity_event)
if config.get('enable_user_gaming'):
self.xmpp.add_event_handler("user_gaming_publish",
self.handler.on_gaming_event)
all_stanzas = Callback('custom matcher', connection.MatchAll(None),
self.handler.incoming_stanza)
self.xmpp.register_handler(all_stanzas)
......@@ -525,12 +512,6 @@ class Core:
}
log.error("%s received. Exiting…", signals[sig])
if config.get('enable_user_mood'):
self.xmpp.plugin['xep_0107'].stop()
if config.get('enable_user_activity'):
self.xmpp.plugin['xep_0108'].stop()
if config.get('enable_user_gaming'):
self.xmpp.plugin['xep_0196'].stop()
self.plugin_manager.disable_plugins()
self.disconnect('%s received' % signals.get(sig))
self.xmpp.add_event_handler("disconnected", self.exit, disposable=True)
......@@ -1693,37 +1674,6 @@ class Core:
for command in get_commands(self.command, self.completion, self.plugin_manager):
self.register_command(**command)
if config.get('enable_user_activity'):
self.register_command(
'activity',
self.command.activity,
usage='[<general> [specific] [text]]',
desc='Send your current activity to your contacts '
'(use the completion). Nothing means '
'"stop broadcasting an activity".',
shortdesc='Send your activity.',
completion=self.completion.activity)
if config.get('enable_user_mood'):
self.register_command(
'mood',
self.command.mood,
usage='[<mood> [text]]',
desc='Send your current mood to your contacts '
'(use the completion). Nothing means '
'"stop broadcasting a mood".',
shortdesc='Send your mood.',
completion=self.completion.mood)
if config.get('enable_user_gaming'):
self.register_command(
'gaming',
self.command.gaming,
usage='[<game name> [server address]]',
desc='Send your current gaming activity to '
'your contacts. Nothing means "stop '
'broadcasting a gaming activity".',
shortdesc='Send your gaming activity.',
completion=None)
def check_blocking(self, features: List[str]):
if 'urn:xmpp:blocking' in features and not self.xmpp.anon:
self.register_command(
......
......@@ -27,7 +27,6 @@ from xml.etree import ElementTree as ET
from poezio import common
from poezio import fixes
from poezio import pep
from poezio import tabs
from poezio import xhtml
from poezio import multiuserchat as muc
......@@ -539,178 +538,6 @@ class HandlerCore:
else:
contact.name = ''
def on_gaming_event(self, message):
"""
Called when a pep notification for user gaming
is received
"""
contact = roster[message['from'].bare]
if not contact:
return
item = message['pubsub_event']['items']['item']
old_gaming = contact.gaming
xml_node = item.xml.find('{urn:xmpp:gaming:0}game')
# list(xml_node) checks whether there are children or not.
if xml_node is not None and list(xml_node):
item = item['gaming']
# only name and server_address are used for now
contact.gaming = {
'character_name': item['character_name'],
'character_profile': item['character_profile'],
'name': item['name'],
'level': item['level'],
'uri': item['uri'],
'server_name': item['server_name'],
'server_address': item['server_address'],
}
else:
contact.gaming = {}
if contact.gaming:
logger.log_roster_change(
contact.bare_jid, 'is playing %s' %
(common.format_gaming_string(contact.gaming)))
if old_gaming != contact.gaming and config.get_by_tabname(
'display_gaming_notifications', contact.bare_jid):
if contact.gaming:
self.core.information(
'%s is playing %s' % (contact.bare_jid,
common.format_gaming_string(
contact.gaming)), 'Gaming')
else:
self.core.information(contact.bare_jid + ' stopped playing.',
'Gaming')
def on_mood_event(self, message):
"""
Called when a pep notification for a user mood
is received.
"""
contact = roster[message['from'].bare]
if not contact:
return
roster.modified()
item = message['pubsub_event']['items']['item']
old_mood = contact.mood
xml_node = item.xml.find('{http://jabber.org/protocol/mood}mood')
# list(xml_node) checks whether there are children or not.
if xml_node is not None and list(xml_node):
mood = item['mood']['value']
if mood:
mood = pep.MOODS.get(mood, mood)
text = item['mood']['text']
if text:
mood = '%s (%s)' % (mood, text)
contact.mood = mood
else:
contact.mood = ''
else:
contact.mood = ''
if contact.mood:
logger.log_roster_change(contact.bare_jid,
'has now the mood: %s' % contact.mood)
if old_mood != contact.mood and config.get_by_tabname(
'display_mood_notifications', contact.bare_jid):
if contact.mood:
self.core.information(
'Mood from ' + contact.bare_jid + ': ' + contact.mood,
'Mood')
else:
self.core.information(
contact.bare_jid + ' stopped having their mood.', 'Mood')
def on_activity_event(self, message):
"""
Called when a pep notification for a user activity
is received.
"""
contact = roster[message['from'].bare]
if not contact:
return
roster.modified()
item = message['pubsub_event']['items']['item']
old_activity = contact.activity
xml_node = item.xml.find('{http://jabber.org/protocol/activity}activity')
# list(xml_node) checks whether there are children or not.
if xml_node is not None and list(xml_node):
try:
activity = item['activity']['value']
except ValueError:
return
if activity[0]:
general = pep.ACTIVITIES.get(activity[0])
s = general['category']
if activity[1]:
s = s + '/' + general.get(activity[1], 'other')
text = item['activity']['text']
if text:
s = '%s (%s)' % (s, text)
contact.activity = s
else:
contact.activity = ''
else:
contact.activity = ''
if contact.activity:
logger.log_roster_change(
contact.bare_jid, 'has now the activity %s' % contact.activity)
if old_activity != contact.activity and config.get_by_tabname(
'display_activity_notifications', contact.bare_jid):
if contact.activity:
self.core.information(
'Activity from ' + contact.bare_jid + ': ' +
contact.activity, 'Activity')
else:
self.core.information(
contact.bare_jid + ' stopped doing their activity.',
'Activity')
def on_tune_event(self, message):
"""
Called when a pep notification for a user tune
is received
"""
contact = roster[message['from'].bare]
if not contact:
return
roster.modified()
item = message['pubsub_event']['items']['item']
old_tune = contact.tune
xml_node = item.xml.find('{http://jabber.org/protocol/tune}tune')
# list(xml_node) checks whether there are children or not.
if xml_node is not None and list(xml_node):
item = item['tune']
contact.tune = {
'artist': item['artist'],
'length': item['length'],
'rating': item['rating'],
'source': item['source'],
'title': item['title'],
'track': item['track'],
'uri': item['uri']
}
else:
contact.tune = {}
if contact.tune:
logger.log_roster_change(
message['from'].bare, 'is now listening to %s' %
common.format_tune_string(contact.tune))
if old_tune != contact.tune and config.get_by_tabname(
'display_tune_notifications', contact.bare_jid):
if contact.tune:
self.core.information(
'Tune from ' + message['from'].bare + ': ' +
common.format_tune_string(contact.tune), 'Tune')
else:
self.core.information(
contact.bare_jid + ' stopped listening to music.', 'Tune')
def on_groupchat_message(self, message):
"""
Triggered whenever a message is received from a multi-user chat room.
......
"""
Collection of mappings for PEP moods/activities
extracted directly from the XEP
"""
from typing import Dict
MOODS: Dict[str, str] = {
'afraid': 'Afraid',
'amazed': 'Amazed',
'angry': 'Angry',
'amorous': 'Amorous',
'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',