From 125cdb2a460401911a6b17274705f088ed518331 Mon Sep 17 00:00:00 2001
From: Yann Leboulanger <asterix@lagaule.org>
Date: Thu, 8 Jul 2004 19:46:24 +0000
Subject: [PATCH] support of error messages

---
 core/core.py             | 10 ++++++++--
 plugins/gtkgui/gtkgui.py | 10 ++++++++++
 2 files changed, 18 insertions(+), 2 deletions(-)

diff --git a/core/core.py b/core/core.py
index 4490850fc4..400a387af1 100644
--- a/core/core.py
+++ b/core/core.py
@@ -118,8 +118,13 @@ class GajimCore:
 
 	def messageCB(self, con, msg):
 		"""Called when we recieve a message"""
-		self.hub.sendPlugin('MSG', self.connexions[con], \
-			(str(msg.getFrom()), msg.getBody()))
+		if msg.getType() == 'error':
+			self.hub.sendPlugin('MSGERROR', self.connexions[con], \
+				(str(msg.getFrom()), msg.getErrorCode(), msg.getError(), \
+				msg.getBody()))
+		else:
+			self.hub.sendPlugin('MSG', self.connexions[con], \
+				(str(msg.getFrom()), msg.getBody()))
 	# END messageCB
 
 	def presenceCB(self, con, prs):
@@ -522,6 +527,7 @@ def loadPlugins(gc):
 			gc.hub.register(mod, 'STATUS')
 			gc.hub.register(mod, 'NOTIFY')
 			gc.hub.register(mod, 'MSG')
+			gc.hub.register(mod, 'MSGERROR')
 			gc.hub.register(mod, 'MSGSENT')
 			gc.hub.register(mod, 'SUBSCRIBED')
 			gc.hub.register(mod, 'UNSUBSCRIBED')
diff --git a/plugins/gtkgui/gtkgui.py b/plugins/gtkgui/gtkgui.py
index 565556b80a..a62155efec 100644
--- a/plugins/gtkgui/gtkgui.py
+++ b/plugins/gtkgui/gtkgui.py
@@ -1590,6 +1590,14 @@ class plugin:
 			jid = string.replace(jid, '@', '')
 		self.roster.on_message(jid, array[1], account)
 		
+	def handle_event_msgerror(self, account, array):
+		#('MSG', account, (user, error_code, error_msg, msg))
+		jid = string.split(array[0], '/')[0]
+		if string.find(jid, "@") <= 0:
+			jid = string.replace(jid, '@', '')
+		self.roster.on_message(jid, _("error while sending") + " \"%s\" ( %s )"%\
+			(array[3], array[2]), account)
+		
 	def handle_event_subscribe(self, account, array):
 		#('SUBSCRIBE', account, (jid, text))
 		authorize_Window(self, array[0], array[1], account)
@@ -1695,6 +1703,8 @@ class plugin:
 				self.handle_event_notify(ev[1], ev[2])
 			elif ev[0] == 'MSG':
 				self.handle_event_msg(ev[1], ev[2])
+			elif ev[0] == 'MSGERROR':
+				self.handle_event_msgerror(ev[1], ev[2])
 			elif ev[0] == 'SUBSCRIBE':
 				self.handle_event_subscribe(ev[1], ev[2])
 			elif ev[0] == 'SUBSCRIBED':
-- 
GitLab