annotate plugins/plugin_xep_0045.py @ 137:227394eb080c

Primitivus: menu are now managed and fully working - new class MenuRoller for manager different menus - Chat window now create is own menu - some menu items added for general/contact menus
author Goffi <goffi@goffi.org>
date Fri, 16 Jul 2010 20:25:06 +0800
parents 7201851d9aed
children 9ee4a1d0d7fb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
72
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
1 #!/usr/bin/python
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
2 # -*- coding: utf-8 -*-
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
3
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
4 """
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
5 SAT plugin for managing xep-0045
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
6 Copyright (C) 2009, 2010 Jérôme Poisson (goffi@goffi.org)
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
7
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
8 This program is free software: you can redistribute it and/or modify
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
9 it under the terms of the GNU General Public License as published by
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
10 the Free Software Foundation, either version 3 of the License, or
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
11 (at your option) any later version.
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
12
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
13 This program is distributed in the hope that it will be useful,
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
16 GNU General Public License for more details.
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
17
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
18 You should have received a copy of the GNU General Public License
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
19 along with this program. If not, see <http://www.gnu.org/licenses/>.
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
20 """
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
21
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
22 from logging import debug, info, warning, error
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
23 from twisted.words.xish import domish
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
24 from twisted.internet import protocol, defer, threads, reactor
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
25 from twisted.words.protocols.jabber import client, jid, xmlstream
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
26 from twisted.words.protocols.jabber import error as jab_error
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
27 from twisted.words.protocols.jabber.xmlstream import IQ
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
28 import os.path
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
29 import pdb
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
30
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
31 from zope.interface import implements
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
32
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
33 from wokkel import disco, iwokkel, muc
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
34
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
35 from base64 import b64decode
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
36 from hashlib import sha1
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
37 from time import sleep
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
38
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
39 try:
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
40 from twisted.words.protocols.xmlstream import XMPPHandler
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
41 except ImportError:
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
42 from wokkel.subprotocols import XMPPHandler
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
43
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
44 AVATAR_PATH = "/avatars"
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
45
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
46 IQ_GET = '/iq[@type="get"]'
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
47 NS_VCARD = 'vcard-temp'
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
48 VCARD_REQUEST = IQ_GET + '/vCard[@xmlns="' + NS_VCARD + '"]' #TODO: manage requests
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
49
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
50 PRESENCE = '/presence'
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
51 NS_VCARD_UPDATE = 'vcard-temp:x:update'
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
52 VCARD_UPDATE = PRESENCE + '/x[@xmlns="' + NS_VCARD_UPDATE + '"]'
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
53
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
54 PLUGIN_INFO = {
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
55 "name": "XEP 0045 Plugin",
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
56 "import_name": "XEP_0045",
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
57 "type": "XEP",
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
58 "protocols": ["XEP-0045"],
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
59 "dependencies": [],
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
60 "main": "XEP_0045",
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
61 "handler": "yes",
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
62 "description": _("""Implementation of Multi-User Chat""")
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
63 }
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
64
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
65 class XEP_0045():
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
66
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
67 def __init__(self, host):
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
68 info(_("Plugin XEP_0045 initialization"))
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
69 self.host = host
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
70 self.clients={}
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
71 host.bridge.addMethod("joinMUC", ".communication", in_sign='ssss', out_sign='', method=self.join)
78
ace2af8abc5a Added method to know which MUC are joined, and which subjects were received.
Goffi <goffi@goffi.org>
parents: 77
diff changeset
72 host.bridge.addMethod("getRoomJoined", ".communication", in_sign='s', out_sign='a(ssass)', method=self.getRoomJoined)
ace2af8abc5a Added method to know which MUC are joined, and which subjects were received.
Goffi <goffi@goffi.org>
parents: 77
diff changeset
73 host.bridge.addMethod("getRoomSubjects", ".communication", in_sign='s', out_sign='a(sss)', method=self.getRoomSubjects)
73
9d113b5471e6 Dynamic signal addition in bridge
Goffi <goffi@goffi.org>
parents: 72
diff changeset
74 host.bridge.addSignal("roomJoined", ".communication", signature='ssasss') #args: room_id, room_service, room_nicks, user_nick, profile
74
6e3a06b4dd36 plugin xep-0045: added roomUserJoined and roomUserLeft signals
Goffi <goffi@goffi.org>
parents: 73
diff changeset
75 host.bridge.addSignal("roomUserJoined", ".communication", signature='sssa{ss}s') #args: room_id, room_service, user_nick, user_data, profile
6e3a06b4dd36 plugin xep-0045: added roomUserJoined and roomUserLeft signals
Goffi <goffi@goffi.org>
parents: 73
diff changeset
76 host.bridge.addSignal("roomUserLeft", ".communication", signature='sssa{ss}s') #args: room_id, room_service, user_nick, user_data, profile
76
8becde8a967c MUC: added subject management
Goffi <goffi@goffi.org>
parents: 75
diff changeset
77 host.bridge.addSignal("roomNewSubject", ".communication", signature='ssss') #args: room_id, room_service, subject, profile
72
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
78
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
79 def __check_profile(self, profile):
75
7322a41f8a8e Basic user joined/left management
Goffi <goffi@goffi.org>
parents: 74
diff changeset
80 """check if profile is used and connected
7322a41f8a8e Basic user joined/left management
Goffi <goffi@goffi.org>
parents: 74
diff changeset
81 if profile known but disconnected, remove it from known profiles
7322a41f8a8e Basic user joined/left management
Goffi <goffi@goffi.org>
parents: 74
diff changeset
82 @param profile: profile to check
7322a41f8a8e Basic user joined/left management
Goffi <goffi@goffi.org>
parents: 74
diff changeset
83 @return: True if the profile is known and connected, else False"""
72
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
84 if not profile or not self.clients.has_key(profile) or not self.host.isConnected(profile):
91
39c672544593 Tarot: bidding phase
Goffi <goffi@goffi.org>
parents: 78
diff changeset
85 error (_('Unknown or disconnected profile (%s)') % profile)
72
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
86 if self.clients.has_key(profile):
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
87 del self.clients[profile]
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
88 return False
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
89 return True
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
90
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
91 def __room_joined(self, room, profile):
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
92 """Called when the user is in the requested room"""
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
93 room_jid = room.roomIdentifier+'@'+room.service
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
94 self.clients[profile].joined_rooms[room_jid] = room
75
7322a41f8a8e Basic user joined/left management
Goffi <goffi@goffi.org>
parents: 74
diff changeset
95 self.host.bridge.roomJoined(room.roomIdentifier, room.service, [user.nick for user in room.roster.values()], room.nick, profile)
72
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
96
75
7322a41f8a8e Basic user joined/left management
Goffi <goffi@goffi.org>
parents: 74
diff changeset
97 def __err_joining_room(self, failure, profile):
72
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
98 """Called when something is going wrong when joining the room"""
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
99 error ("Error when joining the room")
76
8becde8a967c MUC: added subject management
Goffi <goffi@goffi.org>
parents: 75
diff changeset
100 #TODO: gof: send an error message throught the bridge
72
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
101
78
ace2af8abc5a Added method to know which MUC are joined, and which subjects were received.
Goffi <goffi@goffi.org>
parents: 77
diff changeset
102 def getRoomJoined(self, profile_key='@DEFAULT@'):
ace2af8abc5a Added method to know which MUC are joined, and which subjects were received.
Goffi <goffi@goffi.org>
parents: 77
diff changeset
103 """Return room where user is"""
ace2af8abc5a Added method to know which MUC are joined, and which subjects were received.
Goffi <goffi@goffi.org>
parents: 77
diff changeset
104 profile = self.host.memory.getProfileName(profile_key)
ace2af8abc5a Added method to know which MUC are joined, and which subjects were received.
Goffi <goffi@goffi.org>
parents: 77
diff changeset
105 result = []
ace2af8abc5a Added method to know which MUC are joined, and which subjects were received.
Goffi <goffi@goffi.org>
parents: 77
diff changeset
106 if not self.__check_profile(profile):
ace2af8abc5a Added method to know which MUC are joined, and which subjects were received.
Goffi <goffi@goffi.org>
parents: 77
diff changeset
107 return result
ace2af8abc5a Added method to know which MUC are joined, and which subjects were received.
Goffi <goffi@goffi.org>
parents: 77
diff changeset
108 for room in self.clients[profile].joined_rooms.values():
ace2af8abc5a Added method to know which MUC are joined, and which subjects were received.
Goffi <goffi@goffi.org>
parents: 77
diff changeset
109 result.append((room.roomIdentifier, room.service, [user.nick for user in room.roster.values()], room.nick))
ace2af8abc5a Added method to know which MUC are joined, and which subjects were received.
Goffi <goffi@goffi.org>
parents: 77
diff changeset
110 return result
ace2af8abc5a Added method to know which MUC are joined, and which subjects were received.
Goffi <goffi@goffi.org>
parents: 77
diff changeset
111
93
2f87651a5ad8 Tarot game: basic trick
Goffi <goffi@goffi.org>
parents: 91
diff changeset
112 def getRoomNick(self, room_jid, profile_key='@DEFAULT@'):
2f87651a5ad8 Tarot game: basic trick
Goffi <goffi@goffi.org>
parents: 91
diff changeset
113 """return nick used in room by user
2f87651a5ad8 Tarot game: basic trick
Goffi <goffi@goffi.org>
parents: 91
diff changeset
114 @param room_jid: unicode room id
2f87651a5ad8 Tarot game: basic trick
Goffi <goffi@goffi.org>
parents: 91
diff changeset
115 @profile_key: profile
2f87651a5ad8 Tarot game: basic trick
Goffi <goffi@goffi.org>
parents: 91
diff changeset
116 @return: nick or empty string in case of error"""
2f87651a5ad8 Tarot game: basic trick
Goffi <goffi@goffi.org>
parents: 91
diff changeset
117 profile = self.host.memory.getProfileName(profile_key)
2f87651a5ad8 Tarot game: basic trick
Goffi <goffi@goffi.org>
parents: 91
diff changeset
118 if not self.__check_profile(profile) or not self.clients[profile].joined_rooms.has_key(room_jid):
2f87651a5ad8 Tarot game: basic trick
Goffi <goffi@goffi.org>
parents: 91
diff changeset
119 return ''
2f87651a5ad8 Tarot game: basic trick
Goffi <goffi@goffi.org>
parents: 91
diff changeset
120 return self.clients[profile].joined_rooms[room_jid].nick
2f87651a5ad8 Tarot game: basic trick
Goffi <goffi@goffi.org>
parents: 91
diff changeset
121
2f87651a5ad8 Tarot game: basic trick
Goffi <goffi@goffi.org>
parents: 91
diff changeset
122
78
ace2af8abc5a Added method to know which MUC are joined, and which subjects were received.
Goffi <goffi@goffi.org>
parents: 77
diff changeset
123 def getRoomSubjects(self, profile_key='@DEFAULT@'):
ace2af8abc5a Added method to know which MUC are joined, and which subjects were received.
Goffi <goffi@goffi.org>
parents: 77
diff changeset
124 """Return received subjects of rooms"""
ace2af8abc5a Added method to know which MUC are joined, and which subjects were received.
Goffi <goffi@goffi.org>
parents: 77
diff changeset
125 profile = self.host.memory.getProfileName(profile_key)
ace2af8abc5a Added method to know which MUC are joined, and which subjects were received.
Goffi <goffi@goffi.org>
parents: 77
diff changeset
126 if not self.__check_profile(profile):
ace2af8abc5a Added method to know which MUC are joined, and which subjects were received.
Goffi <goffi@goffi.org>
parents: 77
diff changeset
127 return []
ace2af8abc5a Added method to know which MUC are joined, and which subjects were received.
Goffi <goffi@goffi.org>
parents: 77
diff changeset
128 return self.clients[profile].rec_subjects.values()
ace2af8abc5a Added method to know which MUC are joined, and which subjects were received.
Goffi <goffi@goffi.org>
parents: 77
diff changeset
129
72
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
130 def join(self, service, roomId, nick, profile_key='@DEFAULT@'):
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
131 profile = self.host.memory.getProfileName(profile_key)
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
132 if not self.__check_profile(profile):
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
133 return
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
134 room_jid = roomId+'@'+service
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
135 if self.clients[profile].joined_rooms.has_key(room_jid):
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
136 warning(_('%(profile)s is already in room %(room_jid)s') % {'profile':profile, 'room_jid':room_jid})
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
137 return
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
138 info (_("[%(profile)s] is joining room %(room)s with nick %(nick)s") % {'profile':profile,'room':roomId+'@'+service, 'nick':nick})
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
139 self.clients[profile].join(service, roomId, nick).addCallbacks(self.__room_joined, self.__err_joining_room, callbackKeywords={'profile':profile}, errbackKeywords={'profile':profile})
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
140
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
141 def getHandler(self, profile):
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
142 #reactor.callLater(15,self.join,"conference.necton2.int", "test", "Goffi \o/", profile)
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
143 self.clients[profile] = SatMUCClient(self)
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
144 return self.clients[profile]
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
145
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
146
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
147
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
148 class SatMUCClient (muc.MUCClient):
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
149 #implements(iwokkel.IDisco)
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
150
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
151 def __init__(self, plugin_parent):
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
152 self.plugin_parent = plugin_parent
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
153 self.host = plugin_parent.host
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
154 muc.MUCClient.__init__(self)
78
ace2af8abc5a Added method to know which MUC are joined, and which subjects were received.
Goffi <goffi@goffi.org>
parents: 77
diff changeset
155 self.joined_rooms = {}
ace2af8abc5a Added method to know which MUC are joined, and which subjects were received.
Goffi <goffi@goffi.org>
parents: 77
diff changeset
156 self.rec_subjects = {}
72
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
157 print "init SatMUCClient OK"
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
158
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
159 def receivedGroupChat(self, room, user, body):
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
160 debug('receivedGroupChat: room=%s user=%s body=%s', room, user, body)
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
161
74
6e3a06b4dd36 plugin xep-0045: added roomUserJoined and roomUserLeft signals
Goffi <goffi@goffi.org>
parents: 73
diff changeset
162 def userJoinedRoom(self, room, user):
6e3a06b4dd36 plugin xep-0045: added roomUserJoined and roomUserLeft signals
Goffi <goffi@goffi.org>
parents: 73
diff changeset
163 debug (_("user %(nick)s has joined room (%(room_id)s)") % {'nick':user.nick, 'room_id':room.occupantJID.userhost()})
6e3a06b4dd36 plugin xep-0045: added roomUserJoined and roomUserLeft signals
Goffi <goffi@goffi.org>
parents: 73
diff changeset
164 user_data={'entity':user.entity or '', 'affiliation':user.affiliation, 'role':user.role}
6e3a06b4dd36 plugin xep-0045: added roomUserJoined and roomUserLeft signals
Goffi <goffi@goffi.org>
parents: 73
diff changeset
165 self.host.bridge.roomUserJoined(room.roomIdentifier, room.service, user.nick, user_data, self.parent.profile)
6e3a06b4dd36 plugin xep-0045: added roomUserJoined and roomUserLeft signals
Goffi <goffi@goffi.org>
parents: 73
diff changeset
166
6e3a06b4dd36 plugin xep-0045: added roomUserJoined and roomUserLeft signals
Goffi <goffi@goffi.org>
parents: 73
diff changeset
167 def userLeftRoom(self, room, user):
6e3a06b4dd36 plugin xep-0045: added roomUserJoined and roomUserLeft signals
Goffi <goffi@goffi.org>
parents: 73
diff changeset
168 debug (_("user %(nick)s left room (%(room_id)s)") % {'nick':user.nick, 'room_id':room.occupantJID.userhost()})
6e3a06b4dd36 plugin xep-0045: added roomUserJoined and roomUserLeft signals
Goffi <goffi@goffi.org>
parents: 73
diff changeset
169 user_data={'entity':user.entity or '', 'affiliation':user.affiliation, 'role':user.role}
6e3a06b4dd36 plugin xep-0045: added roomUserJoined and roomUserLeft signals
Goffi <goffi@goffi.org>
parents: 73
diff changeset
170 self.host.bridge.roomUserLeft(room.roomIdentifier, room.service, user.nick, user_data, self.parent.profile)
72
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
171
77
1ae680f9682e wix: MUC groupchat management + short nick shown in chat window instead of full jid when possible
Goffi <goffi@goffi.org>
parents: 76
diff changeset
172 def userUpdatedStatus(self, room, user, show, status):
1ae680f9682e wix: MUC groupchat management + short nick shown in chat window instead of full jid when possible
Goffi <goffi@goffi.org>
parents: 76
diff changeset
173 print("FIXME: MUC status not managed yet")
1ae680f9682e wix: MUC groupchat management + short nick shown in chat window instead of full jid when possible
Goffi <goffi@goffi.org>
parents: 76
diff changeset
174 #FIXME: gof
1ae680f9682e wix: MUC groupchat management + short nick shown in chat window instead of full jid when possible
Goffi <goffi@goffi.org>
parents: 76
diff changeset
175
76
8becde8a967c MUC: added subject management
Goffi <goffi@goffi.org>
parents: 75
diff changeset
176 def receivedSubject(self, room, subject):
8becde8a967c MUC: added subject management
Goffi <goffi@goffi.org>
parents: 75
diff changeset
177 debug (_("New subject for room (%(room_id)s): %(subject)s") % {'room_id':room.occupantJID.userhost(),'subject':subject})
78
ace2af8abc5a Added method to know which MUC are joined, and which subjects were received.
Goffi <goffi@goffi.org>
parents: 77
diff changeset
178 room_jid = room.roomIdentifier+'@'+room.service
ace2af8abc5a Added method to know which MUC are joined, and which subjects were received.
Goffi <goffi@goffi.org>
parents: 77
diff changeset
179 self.rec_subjects[room_jid] = (room.roomIdentifier, room.service, subject)
76
8becde8a967c MUC: added subject management
Goffi <goffi@goffi.org>
parents: 75
diff changeset
180 self.host.bridge.roomNewSubject(room.roomIdentifier, room.service, subject, self.parent.profile)
8becde8a967c MUC: added subject management
Goffi <goffi@goffi.org>
parents: 75
diff changeset
181
72
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
182 #def connectionInitialized(self):
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
183 #pass
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
184
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
185 #def getDiscoInfo(self, requestor, target, nodeIdentifier=''):
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
186 #return [disco.DiscoFeature(NS_VCARD)]
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
187
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
188 #def getDiscoItems(self, requestor, target, nodeIdentifier=''):
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
189 #return []
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
190