[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):
|
def user_mood(items, name, jid):
|
||||||
has_child = False
|
has_child = False
|
||||||
|
retract = False
|
||||||
mood = None
|
mood = None
|
||||||
text = None
|
text = None
|
||||||
for item in items.getTags('item'):
|
for item in items.getTags('item'):
|
||||||
|
@ -13,6 +14,9 @@ def user_mood(items, name, jid):
|
||||||
mood = ch.getName()
|
mood = ch.getName()
|
||||||
else:
|
else:
|
||||||
text = ch.getData()
|
text = ch.getData()
|
||||||
|
if items.getTag('retract') is not None:
|
||||||
|
retract = True
|
||||||
|
|
||||||
if jid == gajim.get_jid_from_account(name):
|
if jid == gajim.get_jid_from_account(name):
|
||||||
acc = gajim.connections[name]
|
acc = gajim.connections[name]
|
||||||
if has_child:
|
if has_child:
|
||||||
|
@ -24,6 +28,11 @@ def user_mood(items, name, jid):
|
||||||
acc.mood['mood'] = mood
|
acc.mood['mood'] = mood
|
||||||
if text is not None:
|
if text is not None:
|
||||||
acc.mood['text'] = text
|
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)
|
(user, resource) = gajim.get_room_and_nick_from_fjid(jid)
|
||||||
contact = gajim.contacts.get_contact(name, user, resource=resource)
|
contact = gajim.contacts.get_contact(name, user, resource=resource)
|
||||||
|
@ -38,9 +47,15 @@ def user_mood(items, name, jid):
|
||||||
contact.mood['mood'] = mood
|
contact.mood['mood'] = mood
|
||||||
if text is not None:
|
if text is not None:
|
||||||
contact.mood['text'] = text
|
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):
|
def user_tune(items, name, jid):
|
||||||
has_child = False
|
has_child = False
|
||||||
|
retract = False
|
||||||
artist = None
|
artist = None
|
||||||
title = None
|
title = None
|
||||||
source = None
|
source = None
|
||||||
|
@ -62,6 +77,8 @@ def user_tune(items, name, jid):
|
||||||
track = ch.getData()
|
track = ch.getData()
|
||||||
elif ch.getName() == 'length':
|
elif ch.getName() == 'length':
|
||||||
length = ch.getData()
|
length = ch.getData()
|
||||||
|
if items.getTag('retract') is not None:
|
||||||
|
retract = True
|
||||||
|
|
||||||
if jid == gajim.get_jid_from_account(name):
|
if jid == gajim.get_jid_from_account(name):
|
||||||
acc = gajim.connections[name]
|
acc = gajim.connections[name]
|
||||||
|
@ -86,6 +103,17 @@ def user_tune(items, name, jid):
|
||||||
acc.tune['track'] = track
|
acc.tune['track'] = track
|
||||||
if length is not None:
|
if length is not None:
|
||||||
acc.tune['length'] = length
|
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)
|
(user, resource) = gajim.get_room_and_nick_from_fjid(jid)
|
||||||
contact = gajim.contacts.get_contact(name, user, resource=resource)
|
contact = gajim.contacts.get_contact(name, user, resource=resource)
|
||||||
|
@ -112,12 +140,24 @@ def user_tune(items, name, jid):
|
||||||
contact.tune['track'] = track
|
contact.tune['track'] = track
|
||||||
if length is not None:
|
if length is not None:
|
||||||
contact.tune['length'] = length
|
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):
|
def user_geoloc(items, name, jid):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def user_activity(items, name, jid):
|
def user_activity(items, name, jid):
|
||||||
has_child = False
|
has_child = False
|
||||||
|
retract = False
|
||||||
activity = None
|
activity = None
|
||||||
subactivity = None
|
subactivity = None
|
||||||
text = None
|
text = None
|
||||||
|
@ -133,6 +173,8 @@ def user_activity(items, name, jid):
|
||||||
subactivity = chi.getName()
|
subactivity = chi.getName()
|
||||||
else:
|
else:
|
||||||
text = ch.getData()
|
text = ch.getData()
|
||||||
|
if items.getTag('retract') is not None:
|
||||||
|
retract = True
|
||||||
|
|
||||||
if jid == gajim.get_jid_from_account(name):
|
if jid == gajim.get_jid_from_account(name):
|
||||||
acc = gajim.connections[name]
|
acc = gajim.connections[name]
|
||||||
|
@ -149,6 +191,13 @@ def user_activity(items, name, jid):
|
||||||
acc.activity['subactivity'] = subactivity
|
acc.activity['subactivity'] = subactivity
|
||||||
if text is not None:
|
if text is not None:
|
||||||
acc.activity['text'] = text
|
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)
|
(user, resource) = gajim.get_room_and_nick_from_fjid(jid)
|
||||||
contact = gajim.contacts.get_contact(name, user, resource=resource)
|
contact = gajim.contacts.get_contact(name, user, resource=resource)
|
||||||
|
@ -167,6 +216,13 @@ def user_activity(items, name, jid):
|
||||||
contact.activity['subactivity'] = subactivity
|
contact.activity['subactivity'] = subactivity
|
||||||
if text is not None:
|
if text is not None:
|
||||||
contact.activity['text'] = text
|
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 = ''):
|
def user_send_mood(account, mood, message = ''):
|
||||||
if not gajim.config.get('publish_mood'):
|
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)
|
item.addChild(payload=items)
|
||||||
|
|
||||||
gajim.connections[account].send_pb_publish('', xmpp.NS_TUNE, item, '0')
|
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)
|
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):
|
def send_pb_delete(self, jid, node):
|
||||||
'''Deletes node.'''
|
'''Deletes node.'''
|
||||||
query = xmpp.Iq('set', to=jid)
|
query = xmpp.Iq('set', to=jid)
|
||||||
|
|
|
@ -536,7 +536,7 @@ class PreferencesWindow:
|
||||||
if not widget.get_active():
|
if not widget.get_active():
|
||||||
for account in gajim.connections:
|
for account in gajim.connections:
|
||||||
if gajim.connections[account].pep_supported:
|
if gajim.connections[account].pep_supported:
|
||||||
pep.user_send_mood(account, '')
|
pep.user_retract_mood(account)
|
||||||
self.on_checkbutton_toggled(widget, 'publish_mood')
|
self.on_checkbutton_toggled(widget, 'publish_mood')
|
||||||
helpers.update_optional_features()
|
helpers.update_optional_features()
|
||||||
|
|
||||||
|
@ -544,7 +544,7 @@ class PreferencesWindow:
|
||||||
if not widget.get_active():
|
if not widget.get_active():
|
||||||
for account in gajim.connections:
|
for account in gajim.connections:
|
||||||
if gajim.connections[account].pep_supported:
|
if gajim.connections[account].pep_supported:
|
||||||
pep.user_send_activity(account, '')
|
pep.user_retract_activity(account)
|
||||||
self.on_checkbutton_toggled(widget, 'publish_activity')
|
self.on_checkbutton_toggled(widget, 'publish_activity')
|
||||||
helpers.update_optional_features()
|
helpers.update_optional_features()
|
||||||
|
|
||||||
|
@ -552,7 +552,9 @@ class PreferencesWindow:
|
||||||
if not widget.get_active():
|
if not widget.get_active():
|
||||||
for account in gajim.connections:
|
for account in gajim.connections:
|
||||||
if gajim.connections[account].pep_supported:
|
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_send_tune(account, '')
|
||||||
|
pep.user_retract_tune(account)
|
||||||
self.on_checkbutton_toggled(widget, 'publish_tune')
|
self.on_checkbutton_toggled(widget, 'publish_tune')
|
||||||
helpers.update_optional_features()
|
helpers.update_optional_features()
|
||||||
gajim.interface.roster.enable_syncing_status_msg_from_current_music_track(
|
gajim.interface.roster.enable_syncing_status_msg_from_current_music_track(
|
||||||
|
|
|
@ -332,7 +332,8 @@ class ChooseGPGKeyDialog:
|
||||||
|
|
||||||
class ChangeActivityDialog:
|
class ChangeActivityDialog:
|
||||||
activities = \
|
activities = \
|
||||||
{'doing_chores': ['buying_groceries', 'cleaning', 'cooking',
|
{'None': [],
|
||||||
|
'doing_chores': ['buying_groceries', 'cleaning', 'cooking',
|
||||||
'doing_maintenance', 'doing_the_dishes', 'doing_the_laundry',
|
'doing_maintenance', 'doing_the_dishes', 'doing_the_laundry',
|
||||||
'gardening', 'running_an_errand', 'walking_the_dog'],
|
'gardening', 'running_an_errand', 'walking_the_dog'],
|
||||||
'drinking': ['having_a_beer', 'having_coffee', 'having_tea'],
|
'drinking': ['having_a_beer', 'having_coffee', 'having_tea'],
|
||||||
|
@ -408,6 +409,9 @@ class ChangeActivityDialog:
|
||||||
subactivity = self.liststore2[active2][1].decode('utf-8')
|
subactivity = self.liststore2[active2][1].decode('utf-8')
|
||||||
message = self.entry.get_text().decode('utf-8')
|
message = self.entry.get_text().decode('utf-8')
|
||||||
from common import pep
|
from common import pep
|
||||||
|
if activity == 'None':
|
||||||
|
pep.user_retract_activity(self.account)
|
||||||
|
else:
|
||||||
pep.user_send_activity(self.account, activity,
|
pep.user_send_activity(self.account, activity,
|
||||||
subactivity, message)
|
subactivity, message)
|
||||||
self.window.destroy()
|
self.window.destroy()
|
||||||
|
@ -416,7 +420,7 @@ class ChangeActivityDialog:
|
||||||
self.window.destroy()
|
self.window.destroy()
|
||||||
|
|
||||||
class ChangeMoodDialog:
|
class ChangeMoodDialog:
|
||||||
moods = ['afraid', 'amazed', 'angry', 'annoyed', 'anxious',
|
moods = ['None', 'afraid', 'amazed', 'angry', 'annoyed', 'anxious',
|
||||||
'aroused', 'ashamed', 'bored', 'brave', 'calm',
|
'aroused', 'ashamed', 'bored', 'brave', 'calm',
|
||||||
'cold', 'confused', 'contented', 'cranky', 'curious',
|
'cold', 'confused', 'contented', 'cranky', 'curious',
|
||||||
'depressed', 'disappointed', 'disgusted', 'distracted',
|
'depressed', 'disappointed', 'disgusted', 'distracted',
|
||||||
|
@ -460,6 +464,9 @@ class ChangeMoodDialog:
|
||||||
mood = self.liststore[active][1].decode('utf-8')
|
mood = self.liststore[active][1].decode('utf-8')
|
||||||
message = self.entry.get_text().decode('utf-8')
|
message = self.entry.get_text().decode('utf-8')
|
||||||
from common import pep
|
from common import pep
|
||||||
|
if mood == 'None':
|
||||||
|
pep.user_retract_mood(self.account)
|
||||||
|
else:
|
||||||
pep.user_send_mood(self.account, mood, message)
|
pep.user_send_mood(self.account, mood, message)
|
||||||
self.window.destroy()
|
self.window.destroy()
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue