<s> import logging <EOL> from google . appengine . api import xmpp <EOL> from django . core . urlresolvers import reverse <EOL> from . import models <EOL> from . import decorators as deco <EOL> from . responses import HttpTextResponse <EOL> def get_chat_status ( account ) : <EOL> try : <EOL> presence = xmpp . get_presence ( account . email ) <EOL> return '<STR_LIT>' if presence else '<STR_LIT>' <EOL> except Exception as err : <EOL> logging . error ( '<STR_LIT>' , err ) <EOL> return '<STR_LIT>' % err <EOL> @ deco . require_methods ( '<STR_LIT:POST>' ) <EOL> def incoming_chat ( request ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> msg = xmpp . Message ( request . POST ) <EOL> except xmpp . InvalidMessageError , err : <EOL> logging . warn ( '<STR_LIT>' % err ) <EOL> return HttpTextResponse ( '<STR_LIT>' ) <EOL> sts = msg . reply ( '<STR_LIT>' ) <EOL> logging . debug ( '<STR_LIT>' , sts ) <EOL> return HttpTextResponse ( '<STR_LIT>' ) <EOL> def must_invite ( account ) : <EOL> logging . info ( '<STR_LIT>' , account . email ) <EOL> try : <EOL> xmpp . send_invite ( account . email ) <EOL> except Exception : <EOL> logging . error ( '<STR_LIT>' , account . email ) <EOL> def notify_issue ( request , issue , message ) : <EOL> """<STR_LIT>""" <EOL> iid = issue . key . id ( ) <EOL> emails = set ( ) <EOL> emails . add ( issue . owner . email ( ) ) <EOL> if issue . reviewers : <EOL> emails . update ( issue . reviewers ) <EOL> if request . user : <EOL> emails . discard ( request . user . email ( ) ) <EOL> accounts = models . Account . get_multiple_accounts_by_email ( emails ) <EOL> jids = [ ] <EOL> for account in accounts . itervalues ( ) : <EOL> logging . debug ( '<STR_LIT>' , account . email , account . notify_by_chat ) <EOL> if account . notify_by_chat : <EOL> jids . append ( account . email ) <EOL> if not jids : <EOL> logging . debug ( '<STR_LIT>' , iid ) <EOL> return True <EOL> jids_str = '<STR_LIT:U+002CU+0020>' . join ( jids ) <EOL> logging . debug ( '<STR_LIT>' , iid , jids_str ) <EOL> sender = '<STR_LIT:?>' <EOL> if models . Account . current_user_account : <EOL> sender = models . Account . current_user_account . nickname <EOL> elif request . user : <EOL> sender = request . user . email ( ) <EOL> message = '<STR_LIT>' % ( message , <EOL> sender , <EOL> issue . subject , <EOL> request . build_absolute_uri ( <EOL> reverse ( '<STR_LIT>' , <EOL> args = [ iid ] ) ) ) <EOL> try : <EOL> sts = xmpp . send_message ( jids , message ) <EOL> except Exception , err : <EOL> logging . exception ( '<STR_LIT>' , <EOL> err , iid , jids_str ) <EOL> return False <EOL> else : <EOL> if sts == [ xmpp . NO_ERROR ] * len ( jids ) : <EOL> logging . info ( '<STR_LIT>' , iid , jids_str ) <EOL> return True <EOL> else : <EOL> logging . error ( '<STR_LIT>' , <EOL> sts , iid , jids_str ) <EOL> return False </s>
