From a18e21c476a803ed9b3fb74f3724280a11266400 Mon Sep 17 00:00:00 2001
From: Yann Leboulanger <asterix@lagaule.org>
Date: Thu, 9 Aug 2007 15:54:16 +0000
Subject: [PATCH] fix new contacts API in pep

---
 src/common/pep.py | 101 ++++++++++++++++++++++++----------------------
 1 file changed, 52 insertions(+), 49 deletions(-)

diff --git a/src/common/pep.py b/src/common/pep.py
index 9b65781a16..a4611c49ed 100644
--- a/src/common/pep.py
+++ b/src/common/pep.py
@@ -2,73 +2,76 @@ from common import gajim, xmpp
 
 def user_mood(items, name, jid):
 	(user, resource) = gajim.get_room_and_nick_from_fjid(jid)
-	contacts = gajim.contacts.get_contact(name, user, resource=resource)
+	contact = gajim.contacts.get_contact(name, user, resource=resource)
+	if not contact:
+		return
 	for item in items.getTags('item'):
 		child = item.getTag('mood')
 		if child is not None:
-			for contact in contacts:
-				if contact.mood.has_key('mood'):
-					del contact.mood['mood']
-				if contact.mood.has_key('text'):
-					del contact.mood['text']
-				for ch in child.getChildren():
-					if ch.getName() != 'text':
-						contact.mood['mood'] = ch.getName()
-					else:
-						contact.mood['text'] = ch.getData()
+			if contact.mood.has_key('mood'):
+				del contact.mood['mood']
+			if contact.mood.has_key('text'):
+				del contact.mood['text']
+			for ch in child.getChildren():
+				if ch.getName() != 'text':
+					contact.mood['mood'] = ch.getName()
+				else:
+					contact.mood['text'] = ch.getData()
 
 def user_tune(items, name, jid):
 	(user, resource) = gajim.get_room_and_nick_from_fjid(jid)
-	contacts = gajim.contacts.get_contact(name, user, resource=resource)
+	contact = gajim.contacts.get_contact(name, user, resource=resource)
+	if not contact:
+		return
 	for item in items.getTags('item'):
 		child = item.getTag('tune')
 		if child is not None:
-			for contact in contacts:
-				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']
-				for ch in child.getChildren():
-					if ch.getName() == 'artist':
-						contact.tune['artist'] = ch.getData()
-					elif ch.getName() == 'title':
-						contact.tune['title'] = ch.getData()
-					elif ch.getName() == 'source':
-						contact.tune['source'] = ch.getData()
-					elif ch.getName() == 'track':
-						contact.tune['track'] = ch.getData()
-					elif ch.getName() == 'length':
-						contact.tune['length'] = ch.getData()
+			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']
+			for ch in child.getChildren():
+				if ch.getName() == 'artist':
+					contact.tune['artist'] = ch.getData()
+				elif ch.getName() == 'title':
+					contact.tune['title'] = ch.getData()
+				elif ch.getName() == 'source':
+					contact.tune['source'] = ch.getData()
+				elif ch.getName() == 'track':
+					contact.tune['track'] = ch.getData()
+				elif ch.getName() == 'length':
+					contact.tune['length'] = ch.getData()
 
 def user_geoloc(items, name, jid):
 	pass
 
 def user_activity(items, name, jid):
 	(user, resource) = gajim.get_room_and_nick_from_fjid(jid)
-	contacts = gajim.contacts.get_contact(name, user, resource=resource)
+	contact = gajim.contacts.get_contact(name, user, resource=resource)
+	if not contact:
+		return
 	for item in items.getTags('item'):
 		child = item.getTag('activity')
 		if child is not None:
-			for contact in contacts:
-				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']
-				for ch in child.getChildren():
-					if ch.getName() != 'text':
-						contact.activity['activity'] = ch.getName()
-						for chi in ch.getChildren():
-							contact.activity['subactivity'] = chi.getName()
-					else:
-						contact.activity['text'] = ch.getData()
+			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']
+			for ch in child.getChildren():
+				if ch.getName() != 'text':
+					contact.activity['activity'] = ch.getName()
+					for chi in ch.getChildren():
+						contact.activity['subactivity'] = chi.getName()
+				else:
+					contact.activity['text'] = ch.getData()
 
 def user_send_mood(account, mood, message = ''):
 	item = xmpp.Node('mood', {'xmlns': xmpp.NS_MOOD})
-- 
GitLab