comparison src/server/server.py @ 716:3b91225b457a

server + browser side: blogging refactoring (draft), huge commit sorry: /!\ everything is not working yet, group blog is not working for now - adaptation to backend changes - frontend commons part of blog have been moved to QuickFrontend - (editors) button "WYSIWYG edition" renamed to "preview" - (editors) Shift + [ENTER] is now used to send a text message, [ENTER] to finish a ligne normally - (editors) fixed modifiers handling - global simplification, resulting of the refactoring - with backend refactoring, we are now using PEP again, XEP-0277 compatibility is restored \o/
author Goffi <goffi@goffi.org>
date Sun, 16 Aug 2015 01:51:12 +0200
parents df8cb7bedfbf
children 5745b5e6586a
comparison
equal deleted inserted replaced
715:b2465423c76e 716:3b91225b457a
148 def __init__(self, sat_host): 148 def __init__(self, sat_host):
149 jsonrpc.JSONRPC.__init__(self) 149 jsonrpc.JSONRPC.__init__(self)
150 self.sat_host = sat_host 150 self.sat_host = sat_host
151 151
152 def asyncBridgeCall(self, method_name, *args, **kwargs): 152 def asyncBridgeCall(self, method_name, *args, **kwargs):
153 """Call an asynchrone bridge method and return a deferred 153 """Call an asynchronous bridge method and return a deferred
154
154 @param method_name: name of the method as a unicode 155 @param method_name: name of the method as a unicode
155 @return: a deferred which trigger the result 156 @return: a deferred which trigger the result
156 157
157 """ 158 """
158 d = defer.Deferred() 159 d = defer.Deferred()
256 def jsonrpc_sendMessage(self, to_jid, msg, subject, type_, options={}): 257 def jsonrpc_sendMessage(self, to_jid, msg, subject, type_, options={}):
257 """send message""" 258 """send message"""
258 profile = ISATSession(self.session).profile 259 profile = ISATSession(self.session).profile
259 return self.asyncBridgeCall("sendMessage", to_jid, msg, subject, type_, options, profile) 260 return self.asyncBridgeCall("sendMessage", to_jid, msg, subject, type_, options, profile)
260 261
261 def jsonrpc_sendMblog(self, type_, dest, text, extra={}): 262 ## PubSub ##
262 """ Send microblog message 263
263 @param type_ (unicode): one of "PUBLIC", "GROUP" 264 def jsonrpc_psDeleteNode(self, service, node):
264 @param dest (tuple(unicode)): recipient groups (ignored for "PUBLIC") 265 """Delete a whole node
265 @param text (unicode): microblog's text 266
266 """ 267 @param service (unicode): service jid
267 profile = ISATSession(self.session).profile 268 @param node (unicode): node to delete
268 extra['allow_comments'] = 'True' 269 """
269 270 profile = ISATSession(self.session).profile
270 if not type_: # auto-detect 271 return self.asyncBridgeCall("psDeleteNode", service, node, profile)
271 type_ = "PUBLIC" if dest == [] else "GROUP" 272
272 273 # def jsonrpc_psRetractItem(self, service, node, item, notify):
273 if type_ in ("PUBLIC", "GROUP") and text: 274 # """Delete a whole node
274 if type_ == "PUBLIC": 275
275 #This text if for the public microblog 276 # @param service (unicode): service jid
276 log.debug("sending public blog") 277 # @param node (unicode): node to delete
277 return self.sat_host.bridge.sendGroupBlog("PUBLIC", (), text, extra, profile) 278 # @param items (iterable): id of item to retract
278 else: 279 # @param notify (bool): True if notification is required
279 log.debug("sending group blog") 280 # """
280 dest = dest if isinstance(dest, list) else [dest] 281 # profile = ISATSession(self.session).profile
281 return self.sat_host.bridge.sendGroupBlog("GROUP", dest, text, extra, profile) 282 # return self.asyncBridgeCall("psRetractItem", service, node, item, notify, profile)
282 else: 283
283 raise Exception("Invalid data") 284 # def jsonrpc_psRetractItems(self, service, node, items, notify):
284 285 # """Delete a whole node
285 def jsonrpc_deleteMblog(self, pub_data, comments): 286
286 """Delete a microblog node 287 # @param service (unicode): service jid
287 @param pub_data: a tuple (service, comment node identifier, item identifier) 288 # @param node (unicode): node to delete
288 @param comments: comments node identifier (for main item) or False 289 # @param items (iterable): ids of items to retract
289 """ 290 # @param notify (bool): True if notification is required
290 profile = ISATSession(self.session).profile 291 # """
291 return self.sat_host.bridge.deleteGroupBlog(pub_data, comments if comments else '', profile) 292 # profile = ISATSession(self.session).profile
292 293 # return self.asyncBridgeCall("psRetractItems", service, node, items, notify, profile)
293 def jsonrpc_updateMblog(self, pub_data, comments, message, extra={}): 294
294 """Modify a microblog node 295 ## microblogging ##
295 @param pub_data: a tuple (service, comment node identifier, item identifier) 296
296 @param comments: comments node identifier (for main item) or False 297 def jsonrpc_mbSend(self, service, node, mb_data):
297 @param message: new message 298 """Send microblog data
298 @param extra: dict which option name as key, which can be: 299
299 - allow_comments: True to accept an other level of comments, False else (default: False) 300 @param service (unicode): service jid or empty string to use profile's microblog
300 - rich: if present, contain rich text in currently selected syntax 301 @param node (unicode): publishing node, or empty string to use microblog node
301 """ 302 @param mb_data(dict): microblog data
302 profile = ISATSession(self.session).profile 303 @return: a deferred
303 if comments: 304 """
304 extra['allow_comments'] = 'True' 305 profile = ISATSession(self.session).profile
305 return self.sat_host.bridge.updateGroupBlog(pub_data, comments if comments else '', message, extra, profile) 306 return self.asyncBridgeCall("mbSend", service, node, mb_data, profile)
306 307
307 def jsonrpc_sendMblogComment(self, node, text, extra={}): 308 def jsonrpc_mbRetract(self, service, node, items):
308 """ Send microblog message 309 """Delete a whole node
309 @param node: url of the comments node 310
310 @param text: comment 311 @param service (unicode): service jid, empty string for PEP
311 """ 312 @param node (unicode): node to delete, empty string for default node
312 profile = ISATSession(self.session).profile 313 @param items (iterable): ids of items to retract
313 if node and text: 314 """
314 return self.sat_host.bridge.sendGroupBlogComment(node, text, extra, profile) 315 profile = ISATSession(self.session).profile
315 else: 316 return self.asyncBridgeCall("mbRetract", service, node, items, profile)
316 raise Exception("Invalid data") 317
317 318 def jsonrpc_mbGetLast(self, service_jid, node, max_items, extra):
318 def jsonrpc_getMblogs(self, publisher_jid, item_ids, max_items=C.RSM_MAX_ITEMS): 319 """Get last microblogs from publisher_jid
319 """Get specified microblogs posted by a contact 320
320 @param publisher_jid: jid of the publisher 321 @param service_jid (unicode): pubsub service, usually publisher jid
321 @param item_ids: list of microblogs items IDs 322 @param node(unicode): mblogs node, or empty string to get the defaut one
322 @return list of microblog data (dict)""" 323 @param max_items (int): maximum number of item to get or C.NO_LIMIT to get everything
323 profile = ISATSession(self.session).profile 324 @param rsm (dict): TODO
324 d = self.asyncBridgeCall("getGroupBlogs", publisher_jid, item_ids, {'max_': unicode(max_items)}, False, profile) 325 @return: a deferred couple with the list of items and metadatas.
325 return d 326 """
326 327 profile = ISATSession(self.session).profile
327 def jsonrpc_getMblogsWithComments(self, publisher_jid, item_ids, max_comments=C.RSM_MAX_COMMENTS): 328 return self.asyncBridgeCall("mbGetLast", service_jid, node, max_items, extra, profile)
328 """Get specified microblogs posted by a contact and their comments 329
329 @param publisher_jid: jid of the publisher 330 def jsonrpc_mbGetFromMany(self, publishers_type, publishers, max_items, extra):
330 @param item_ids: list of microblogs items IDs 331 """Get many blog nodes at once
331 @return list of couple (microblog data, list of microblog data)"""
332 profile = ISATSession(self.session).profile
333 d = self.asyncBridgeCall("getGroupBlogsWithComments", publisher_jid, item_ids, {}, max_comments, profile)
334 return d
335
336 def jsonrpc_getMassiveMblogs(self, publishers_type, publishers, rsm=None):
337 """Get lasts microblogs posted by several contacts at once
338 332
339 @param publishers_type (unicode): one of "ALL", "GROUP", "JID" 333 @param publishers_type (unicode): one of "ALL", "GROUP", "JID"
340 @param publishers (tuple(unicode)): tuple of publishers (empty list for all, list of groups or list of jids) 334 @param publishers (tuple(unicode)): tuple of publishers (empty list for all, list of groups or list of jids)
341 @param rsm (dict): TODO 335 @param max_items (int): maximum number of item to get or C.NO_LIMIT to get everything
342 @return: dict{unicode: list[dict]) 336 @param extra (dict): TODO
343 key: publisher's jid 337 @return (str): RT Deferred session id
344 value: list of microblog data (dict) 338 """
345 """ 339 profile = ISATSession(self.session).profile
346 profile = ISATSession(self.session).profile 340 return self.sat_host.bridge.mbGetFromMany(publishers_type, publishers, max_items, extra, profile)
347 if rsm is None: 341
348 rsm = {'max_': unicode(C.RSM_MAX_ITEMS)} 342 def jsonrpc_mbGetFromManyRTResult(self, rt_session):
349 d = self.asyncBridgeCall("getMassiveGroupBlogs", publishers_type, publishers, rsm, profile) 343 """Get results from RealTime mbGetFromMany session
350 self.sat_host.bridge.massiveSubscribeGroupBlogs(publishers_type, publishers, profile) 344
351 return d 345 @param rt_session (str): RT Deferred session id
352 346 """
353 def jsonrpc_getMblogComments(self, service, node, rsm=None): 347 profile = ISATSession(self.session).profile
354 """Get all comments of given node 348 return self.asyncBridgeCall("mbGetFromManyRTResult", rt_session, profile)
355 @param service: jid of the service hosting the node 349
356 @param node: comments node 350 def jsonrpc_mbGetFromManyWithComments(self, publishers_type, publishers, max_items, max_comments, rsm_dict, rsm_comments_dict):
357 """ 351 """Helper method to get the microblogs and their comments in one shot
358 profile = ISATSession(self.session).profile 352
359 if rsm is None: 353 @param publishers_type (str): type of the list of publishers (one of "GROUP" or "JID" or "ALL")
360 rsm = {'max_': unicode(C.RSM_MAX_COMMENTS)} 354 @param publishers (list): list of publishers, according to publishers_type (list of groups or list of jids)
361 d = self.asyncBridgeCall("getGroupBlogComments", service, node, rsm, profile) 355 @param max_items (int): optional limit on the number of retrieved items.
362 return d 356 @param max_comments (int): maximum number of comments to retrieve
357 @param rsm_dict (dict): RSM data for initial items only
358 @param rsm_comments_dict (dict): RSM data for comments only
359 @param profile_key: profile key
360 @return (str): RT Deferred session id
361 """
362 profile = ISATSession(self.session).profile
363 return self.sat_host.bridge.mbGetFromManyWithComments(publishers_type, publishers, max_items, max_comments, rsm_dict, rsm_comments_dict, profile)
364
365 def jsonrpc_mbGetFromManyWithCommentsRTResult(self, rt_session):
366 """Get results from RealTime mbGetFromManyWithComments session
367
368 @param rt_session (str): RT Deferred session id
369 """
370 profile = ISATSession(self.session).profile
371 return self.asyncBridgeCall("mbGetFromManyWithCommentsRTResult", rt_session, profile)
372
373
374 # def jsonrpc_sendMblog(self, type_, dest, text, extra={}):
375 # """ Send microblog message
376 # @param type_ (unicode): one of "PUBLIC", "GROUP"
377 # @param dest (tuple(unicode)): recipient groups (ignored for "PUBLIC")
378 # @param text (unicode): microblog's text
379 # """
380 # profile = ISATSession(self.session).profile
381 # extra['allow_comments'] = 'True'
382
383 # if not type_: # auto-detect
384 # type_ = "PUBLIC" if dest == [] else "GROUP"
385
386 # if type_ in ("PUBLIC", "GROUP") and text:
387 # if type_ == "PUBLIC":
388 # #This text if for the public microblog
389 # log.debug("sending public blog")
390 # return self.sat_host.bridge.sendGroupBlog("PUBLIC", (), text, extra, profile)
391 # else:
392 # log.debug("sending group blog")
393 # dest = dest if isinstance(dest, list) else [dest]
394 # return self.sat_host.bridge.sendGroupBlog("GROUP", dest, text, extra, profile)
395 # else:
396 # raise Exception("Invalid data")
397
398 # def jsonrpc_deleteMblog(self, pub_data, comments):
399 # """Delete a microblog node
400 # @param pub_data: a tuple (service, comment node identifier, item identifier)
401 # @param comments: comments node identifier (for main item) or False
402 # """
403 # profile = ISATSession(self.session).profile
404 # return self.sat_host.bridge.deleteGroupBlog(pub_data, comments if comments else '', profile)
405
406 # def jsonrpc_updateMblog(self, pub_data, comments, message, extra={}):
407 # """Modify a microblog node
408 # @param pub_data: a tuple (service, comment node identifier, item identifier)
409 # @param comments: comments node identifier (for main item) or False
410 # @param message: new message
411 # @param extra: dict which option name as key, which can be:
412 # - allow_comments: True to accept an other level of comments, False else (default: False)
413 # - rich: if present, contain rich text in currently selected syntax
414 # """
415 # profile = ISATSession(self.session).profile
416 # if comments:
417 # extra['allow_comments'] = 'True'
418 # return self.sat_host.bridge.updateGroupBlog(pub_data, comments if comments else '', message, extra, profile)
419
420 # def jsonrpc_sendMblogComment(self, node, text, extra={}):
421 # """ Send microblog message
422 # @param node: url of the comments node
423 # @param text: comment
424 # """
425 # profile = ISATSession(self.session).profile
426 # if node and text:
427 # return self.sat_host.bridge.sendGroupBlogComment(node, text, extra, profile)
428 # else:
429 # raise Exception("Invalid data")
430
431 # def jsonrpc_getMblogs(self, publisher_jid, item_ids, max_items=C.RSM_MAX_ITEMS):
432 # """Get specified microblogs posted by a contact
433 # @param publisher_jid: jid of the publisher
434 # @param item_ids: list of microblogs items IDs
435 # @return list of microblog data (dict)"""
436 # profile = ISATSession(self.session).profile
437 # d = self.asyncBridgeCall("getGroupBlogs", publisher_jid, item_ids, {'max_': unicode(max_items)}, False, profile)
438 # return d
439
440 # def jsonrpc_getMblogsWithComments(self, publisher_jid, item_ids, max_comments=C.RSM_MAX_COMMENTS):
441 # """Get specified microblogs posted by a contact and their comments
442 # @param publisher_jid: jid of the publisher
443 # @param item_ids: list of microblogs items IDs
444 # @return list of couple (microblog data, list of microblog data)"""
445 # profile = ISATSession(self.session).profile
446 # d = self.asyncBridgeCall("getGroupBlogsWithComments", publisher_jid, item_ids, {}, max_comments, profile)
447 # return d
448
449 # def jsonrpc_getMassiveMblogs(self, publishers_type, publishers, rsm=None):
450 # """Get lasts microblogs posted by several contacts at once
451
452 # @param publishers_type (unicode): one of "ALL", "GROUP", "JID"
453 # @param publishers (tuple(unicode)): tuple of publishers (empty list for all, list of groups or list of jids)
454 # @param rsm (dict): TODO
455 # @return: dict{unicode: list[dict])
456 # key: publisher's jid
457 # value: list of microblog data (dict)
458 # """
459 # profile = ISATSession(self.session).profile
460 # if rsm is None:
461 # rsm = {'max_': unicode(C.RSM_MAX_ITEMS)}
462 # d = self.asyncBridgeCall("getMassiveGroupBlogs", publishers_type, publishers, rsm, profile)
463 # self.sat_host.bridge.massiveSubscribeGroupBlogs(publishers_type, publishers, profile)
464 # return d
465
466 # def jsonrpc_getMblogComments(self, service, node, rsm=None):
467 # """Get all comments of given node
468 # @param service: jid of the service hosting the node
469 # @param node: comments node
470 # """
471 # profile = ISATSession(self.session).profile
472 # if rsm is None:
473 # rsm = {'max_': unicode(C.RSM_MAX_COMMENTS)}
474 # d = self.asyncBridgeCall("getGroupBlogComments", service, node, rsm, profile)
475 # return d
363 476
364 def jsonrpc_getPresenceStatuses(self): 477 def jsonrpc_getPresenceStatuses(self):
365 """Get Presence information for connected contacts""" 478 """Get Presence information for connected contacts"""
366 profile = ISATSession(self.session).profile 479 profile = ISATSession(self.session).profile
367 return self.sat_host.bridge.getPresenceStatuses(profile) 480 return self.sat_host.bridge.getPresenceStatuses(profile)
1097 self.bridge.register("actionResult", self.action_handler.actionResultCb) 1210 self.bridge.register("actionResult", self.action_handler.actionResultCb)
1098 #core 1211 #core
1099 for signal_name in ['presenceUpdate', 'newMessage', 'subscribe', 'contactDeleted', 'newContact', 'entityDataUpdated', 'askConfirmation', 'newAlert', 'paramUpdate']: 1212 for signal_name in ['presenceUpdate', 'newMessage', 'subscribe', 'contactDeleted', 'newContact', 'entityDataUpdated', 'askConfirmation', 'newAlert', 'paramUpdate']:
1100 self.bridge.register(signal_name, self.signal_handler.getGenericCb(signal_name)) 1213 self.bridge.register(signal_name, self.signal_handler.getGenericCb(signal_name))
1101 #plugins 1214 #plugins
1102 for signal_name in ['personalEvent', 'roomJoined', 'roomUserJoined', 'roomUserLeft', 'tarotGameStarted', 'tarotGameNew', 'tarotGameChooseContrat', 1215 for signal_name in ['psEvent', 'roomJoined', 'roomUserJoined', 'roomUserLeft', 'tarotGameStarted', 'tarotGameNew', 'tarotGameChooseContrat',
1103 'tarotGameShowCards', 'tarotGameInvalidCards', 'tarotGameCardsPlayed', 'tarotGameYourTurn', 'tarotGameScore', 'tarotGamePlayers', 1216 'tarotGameShowCards', 'tarotGameInvalidCards', 'tarotGameCardsPlayed', 'tarotGameYourTurn', 'tarotGameScore', 'tarotGamePlayers',
1104 'radiocolStarted', 'radiocolPreload', 'radiocolPlay', 'radiocolNoUpload', 'radiocolUploadOk', 'radiocolSongRejected', 'radiocolPlayers', 1217 'radiocolStarted', 'radiocolPreload', 'radiocolPlay', 'radiocolNoUpload', 'radiocolUploadOk', 'radiocolSongRejected', 'radiocolPlayers',
1105 'roomLeft', 'roomUserChangedNick', 'chatStateReceived']: 1218 'roomLeft', 'roomUserChangedNick', 'chatStateReceived']:
1106 self.bridge.register(signal_name, self.signal_handler.getGenericCb(signal_name), "plugin") 1219 self.bridge.register(signal_name, self.signal_handler.getGenericCb(signal_name), "plugin")
1107 self.media_dir = self.bridge.getConfig('', 'media_dir') 1220 self.media_dir = self.bridge.getConfig('', 'media_dir')