[Florob] ability to retract pubsub events. fixes #3913
This commit is contained in:
parent
75ffe12157
commit
2560f844c1
|
@ -2,6 +2,7 @@ from common import gajim, xmpp
|
|||
|
||||
def user_mood(items, name, jid):
|
||||
has_child = False
|
||||
retract = False
|
||||
mood = None
|
||||
text = None
|
||||
for item in items.getTags('item'):
|
||||
|
@ -13,6 +14,9 @@ def user_mood(items, name, jid):
|
|||
mood = ch.getName()
|
||||
else:
|
||||
text = ch.getData()
|
||||
if items.getTag('retract') is not None:
|
||||
retract = True
|
||||
|
||||
if jid == gajim.get_jid_from_account(name):
|
||||
acc = gajim.connections[name]
|
||||
if has_child:
|
||||
|
@ -24,6 +28,11 @@ def user_mood(items, name, jid):
|
|||
acc.mood['mood'] = mood
|
||||
if text is not None:
|
||||
acc.mood['text'] = text
|
||||
elif retract:
|
||||
if acc.mood.has_key('mood'):
|
||||
del acc.mood['mood']
|
||||
if acc.mood.has_key('text'):
|
||||
del acc.mood['text']
|
||||
|
||||
(user, resource) = gajim.get_room_and_nick_from_fjid(jid)
|
||||
contact = gajim.contacts.get_contact(name, user, resource=resource)
|
||||
|
@ -38,9 +47,15 @@ def user_mood(items, name, jid):
|
|||
contact.mood['mood'] = mood
|
||||
if text is not None:
|
||||
contact.mood['text'] = text
|
||||
elif retract:
|
||||
if contact.mood.has_key('mood'):
|
||||
del contact.mood['mood']
|
||||
if contact.mood.has_key('text'):
|
||||
del contact.mood['text']
|
||||
|
||||
def user_tune(items, name, jid):
|
||||
has_child = False
|
||||
retract = False
|
||||
artist = None
|
||||
title = None
|
||||
source = None
|
||||
|
@ -62,6 +77,8 @@ def user_tune(items, name, jid):
|
|||
track = ch.getData()
|
||||
elif ch.getName() == 'length':
|
||||
length = ch.getData()
|
||||
if items.getTag('retract') is not None:
|
||||
retract = True
|
||||
|
||||
if jid == gajim.get_jid_from_account(name):
|
||||
acc = gajim.connections[name]
|
||||
|
@ -86,6 +103,17 @@ def user_tune(items, name, jid):
|
|||
acc.tune['track'] = track
|
||||
if length is not None:
|
||||
acc.tune['length'] = length
|
||||
elif retract:
|
||||
if acc.tune.has_key('artist'):
|
||||
del acc.tune['artist']
|
||||
if acc.tune.has_key('title'):
|
||||
del acc.tune['title']
|
||||
if acc.tune.has_key('source'):
|
||||
del acc.tune['source']
|
||||
if acc.tune.has_key('track'):
|
||||
del acc.tune['track']
|
||||
if acc.tune.has_key('length'):
|
||||
del acc.tune['length']
|
||||
|
||||
(user, resource) = gajim.get_room_and_nick_from_fjid(jid)
|
||||
contact = gajim.contacts.get_contact(name, user, resource=resource)
|
||||
|
@ -112,12 +140,24 @@ def user_tune(items, name, jid):
|
|||
contact.tune['track'] = track
|
||||
if length is not None:
|
||||
contact.tune['length'] = length
|
||||
elif retract:
|
||||
if contact.tune.has_key('artist'):
|
||||
del contact.tune['artist']
|
||||
if contact.tune.has_key('title'):
|
||||
del contact.tune['title']
|
||||
if contact.tune.has_key('source'):
|
||||
del contact.tune['source']
|
||||
if contact.tune.has_key('track'):
|
||||
del contact.tune['track']
|
||||
if contact.tune.has_key('length'):
|
||||
del contact.tune['length']
|
||||
|
||||
def user_geoloc(items, name, jid):
|
||||
pass
|
||||
|
||||
def user_activity(items, name, jid):
|
||||
has_child = False
|
||||
retract = False
|
||||
activity = None
|
||||
subactivity = None
|
||||
text = None
|
||||
|
@ -133,6 +173,8 @@ def user_activity(items, name, jid):
|
|||
subactivity = chi.getName()
|
||||
else:
|
||||
text = ch.getData()
|
||||
if items.getTag('retract') is not None:
|
||||
retract = True
|
||||
|
||||
if jid == gajim.get_jid_from_account(name):
|
||||
acc = gajim.connections[name]
|
||||
|
@ -149,6 +191,13 @@ def user_activity(items, name, jid):
|
|||
acc.activity['subactivity'] = subactivity
|
||||
if text is not None:
|
||||
acc.activity['text'] = text
|
||||
elif retract:
|
||||
if acc.activity.has_key('activity'):
|
||||
del acc.activity['activity']
|
||||
if acc.activity.has_key('subactivity'):
|
||||
del acc.activity['subactivity']
|
||||
if acc.activity.has_key('text'):
|
||||
del acc.activity['text']
|
||||
|
||||
(user, resource) = gajim.get_room_and_nick_from_fjid(jid)
|
||||
contact = gajim.contacts.get_contact(name, user, resource=resource)
|
||||
|
@ -167,6 +216,13 @@ def user_activity(items, name, jid):
|
|||
contact.activity['subactivity'] = subactivity
|
||||
if text is not None:
|
||||
contact.activity['text'] = text
|
||||
elif retract:
|
||||
if contact.activity.has_key('activity'):
|
||||
del contact.activity['activity']
|
||||
if contact.activity.has_key('subactivity'):
|
||||
del contact.activity['subactivity']
|
||||
if contact.activity.has_key('text'):
|
||||
del contact.activity['text']
|
||||
|
||||
def user_send_mood(account, mood, message = ''):
|
||||
if not gajim.config.get('publish_mood'):
|
||||
|
@ -218,3 +274,12 @@ def user_send_tune(account, artist = '', title = '', source = '', track = 0,leng
|
|||
item.addChild(payload=items)
|
||||
|
||||
gajim.connections[account].send_pb_publish('', xmpp.NS_TUNE, item, '0')
|
||||
|
||||
def user_retract_mood(account):
|
||||
gajim.connections[account].send_pb_retract('', xmpp.NS_MOOD, '0')
|
||||
|
||||
def user_retract_activity(account):
|
||||
gajim.connections[account].send_pb_retract('', xmpp.NS_ACTIVITY, '0')
|
||||
|
||||
def user_retract_tune(account):
|
||||
gajim.connections[account].send_pb_retract('', xmpp.NS_TUNE, '0')
|
||||
|
|
|
@ -44,6 +44,15 @@ class ConnectionPubSub:
|
|||
|
||||
self.connection.send(query)
|
||||
|
||||
def send_pb_retract(self, jid, node, id):
|
||||
'''Delete item from a node'''
|
||||
query = xmpp.Iq('set', to=jid)
|
||||
r = query.addChild('pubsub', namespace=xmpp.NS_PUBSUB)
|
||||
r = r.addChild('retract', {'node': node, 'notify': '1'})
|
||||
r = r.addChild('item', {'id': id})
|
||||
|
||||
self.connection.send(query)
|
||||
|
||||
def send_pb_delete(self, jid, node):
|
||||
'''Deletes node.'''
|
||||
query = xmpp.Iq('set', to=jid)
|
||||
|
|
|
@ -536,7 +536,7 @@ class PreferencesWindow:
|
|||
if not widget.get_active():
|
||||
for account in gajim.connections:
|
||||
if gajim.connections[account].pep_supported:
|
||||
pep.user_send_mood(account, '')
|
||||
pep.user_retract_mood(account)
|
||||
self.on_checkbutton_toggled(widget, 'publish_mood')
|
||||
helpers.update_optional_features()
|
||||
|
||||
|
@ -544,7 +544,7 @@ class PreferencesWindow:
|
|||
if not widget.get_active():
|
||||
for account in gajim.connections:
|
||||
if gajim.connections[account].pep_supported:
|
||||
pep.user_send_activity(account, '')
|
||||
pep.user_retract_activity(account)
|
||||
self.on_checkbutton_toggled(widget, 'publish_activity')
|
||||
helpers.update_optional_features()
|
||||
|
||||
|
@ -552,7 +552,9 @@ class PreferencesWindow:
|
|||
if not widget.get_active():
|
||||
for account in gajim.connections:
|
||||
if gajim.connections[account].pep_supported:
|
||||
# As many implementations don't support retracting items, we send a "Stopped" event first
|
||||
pep.user_send_tune(account, '')
|
||||
pep.user_retract_tune(account)
|
||||
self.on_checkbutton_toggled(widget, 'publish_tune')
|
||||
helpers.update_optional_features()
|
||||
gajim.interface.roster.enable_syncing_status_msg_from_current_music_track(
|
||||
|
|
|
@ -332,7 +332,8 @@ class ChooseGPGKeyDialog:
|
|||
|
||||
class ChangeActivityDialog:
|
||||
activities = \
|
||||
{'doing_chores': ['buying_groceries', 'cleaning', 'cooking',
|
||||
{'None': [],
|
||||
'doing_chores': ['buying_groceries', 'cleaning', 'cooking',
|
||||
'doing_maintenance', 'doing_the_dishes', 'doing_the_laundry',
|
||||
'gardening', 'running_an_errand', 'walking_the_dog'],
|
||||
'drinking': ['having_a_beer', 'having_coffee', 'having_tea'],
|
||||
|
@ -408,7 +409,10 @@ class ChangeActivityDialog:
|
|||
subactivity = self.liststore2[active2][1].decode('utf-8')
|
||||
message = self.entry.get_text().decode('utf-8')
|
||||
from common import pep
|
||||
pep.user_send_activity(self.account, activity,
|
||||
if activity == 'None':
|
||||
pep.user_retract_activity(self.account)
|
||||
else:
|
||||
pep.user_send_activity(self.account, activity,
|
||||
subactivity, message)
|
||||
self.window.destroy()
|
||||
|
||||
|
@ -416,7 +420,7 @@ class ChangeActivityDialog:
|
|||
self.window.destroy()
|
||||
|
||||
class ChangeMoodDialog:
|
||||
moods = ['afraid', 'amazed', 'angry', 'annoyed', 'anxious',
|
||||
moods = ['None', 'afraid', 'amazed', 'angry', 'annoyed', 'anxious',
|
||||
'aroused', 'ashamed', 'bored', 'brave', 'calm',
|
||||
'cold', 'confused', 'contented', 'cranky', 'curious',
|
||||
'depressed', 'disappointed', 'disgusted', 'distracted',
|
||||
|
@ -460,7 +464,10 @@ class ChangeMoodDialog:
|
|||
mood = self.liststore[active][1].decode('utf-8')
|
||||
message = self.entry.get_text().decode('utf-8')
|
||||
from common import pep
|
||||
pep.user_send_mood(self.account, mood, message)
|
||||
if mood == 'None':
|
||||
pep.user_retract_mood(self.account)
|
||||
else:
|
||||
pep.user_send_mood(self.account, mood, message)
|
||||
self.window.destroy()
|
||||
|
||||
def on_cancel_button_clicked(self, widget):
|
||||
|
|
Loading…
Reference in New Issue