19
19
20
20
from xmpp import NS_MUC_ADMIN , NS_MUC
21
21
from xmpp .protocol import Presence , Iq , Message , JID
22
+ import xmpp
23
+ import common
24
+ import threading
22
25
23
26
from handler import Handler
24
27
from config import config
@@ -34,9 +37,72 @@ def is_jid(jid):
34
37
if JID (jid ).getNode () != '' :
35
38
return True
36
39
40
+ class VcardSender (threading .Thread ):
41
+ """
42
+ avatar sending is really slow (don't know why...)
43
+ use a thread to send it...
44
+ """
45
+ def __init__ (self , connection ):
46
+ threading .Thread .__init__ (self )
47
+ self .connection = connection
48
+ self .handler = Handler ()
49
+
50
+ def run (self ):
51
+ self .send_vcard ()
52
+
53
+ def send_vcard (self ):
54
+ """
55
+ Method stolen from Gajim (thanks)
56
+ ## Copyright (C) 2006 Dimitur Kirov <dkirov AT gmail.com>
57
+ ## Junglecow J <junglecow AT gmail.com>
58
+ ## Copyright (C) 2006-2007 Tomasz Melcer <liori AT exroot.org>
59
+ ## Travis Shirk <travis AT pobox.com>
60
+ ## Nikos Kouremenos <kourem AT gmail.com>
61
+ ## Copyright (C) 2006-2008 Yann Leboulanger <asterix AT lagaule.org>
62
+ ## Copyright (C) 2007 Julien Pivotto <roidelapluie AT gmail.com>
63
+ ## Copyright (C) 2007-2008 Brendan Taylor <whateley AT gmail.com>
64
+ ## Jean-Marie Traissard <jim AT lapin.org>
65
+ ## Stephan Erb <steve-e AT h3c.de>
66
+ ## Copyright (C) 2008 Jonathan Schleifer <js-gajim AT webkeks.org>
67
+ (one of these people coded this method, probably)
68
+ """
69
+ if not self .connection :
70
+ return
71
+ vcard = {
72
+ "FN" :"Poezio tester" ,
73
+ }
74
+ photo_file_path = config .get ('photo' , '../data/poezio_80.png' )
75
+ (image , mime_type , sha1 ) = common .get_base64_from_file (photo_file_path )
76
+ if image :
77
+ vcard ['PHOTO' ] = {"TYPE" :mime_type ,"BINVAL" :image }
78
+ iq = xmpp .Iq (typ = 'set' )
79
+ iq2 = iq .setTag (xmpp .NS_VCARD + ' vCard' )
80
+ for i in vcard :
81
+ if i == 'jid' :
82
+ continue
83
+ if isinstance (vcard [i ], dict ):
84
+ iq3 = iq2 .addChild (i )
85
+ for j in vcard [i ]:
86
+ iq3 .addChild (j ).setData (vcard [i ][j ])
87
+ elif isinstance (vcard [i ], list ):
88
+ for j in vcard [i ]:
89
+ iq3 = iq2 .addChild (i )
90
+ for k in j :
91
+ iq3 .addChild (k ).setData (j [k ])
92
+ else :
93
+ iq2 .addChild (i ).setData (vcard [i ])
94
+ # id_ = self.connect.getAnId()
95
+ # iq.setID(id_)
96
+ self .connection .send (iq )
97
+ iq = xmpp .Iq (typ = 'set' )
98
+ iq2 = iq .setTag (xmpp .NS_VCARD_UPDATE )
99
+ iq2 .addChild ('PHOTO' ).setData (sha1 )
100
+ self .connection .send (iq )
101
+
37
102
class MultiUserChat (object ):
38
103
def __init__ (self , connection ):
39
104
self .connection = connection
105
+ self .vcard_sender = VcardSender (self .connection )
40
106
41
107
self .rooms = []
42
108
self .rn = {}
@@ -64,6 +130,7 @@ def on_connected(self, jid):
64
130
else :
65
131
nick = config .get ('default_nick' , 'poezio' )
66
132
self .handler .emit ('join-room' , room = roomname , nick = nick )
133
+ self .vcard_sender .start ()
67
134
68
135
def send_message (self , room , message ):
69
136
mes = Message (to = room )
0 commit comments