def video_widget_intercept(self, message): 'Reroutes messages from video widgets.' video_buddy = self._video_buddy_for_message(message) if video_buddy is None: return False elif video_buddy is True: return True body = get_message_body(message) log.info('intercepted video widget message') log.info_s('message is %r', body) if body: buddy = video_buddy.buddy() if buddy is None: log.critical('got video widget message, but linked buddy is gone') log.critical('buddy info was %r', video_buddy) return True convo = buddy.protocol.convo_for(buddy) if convo.received_message(buddy, body): Conversation.incoming_message(convo) return True # TODO: typing notifications?
def video_widget_intercept(self, message): 'Reroutes messages from video widgets.' video_buddy = self._video_buddy_for_message(message) if video_buddy is None: return False elif video_buddy is True: return True body = get_message_body(message) log.info('intercepted video widget message') log.info_s('message is %r', body) if body: buddy = video_buddy.buddy() if buddy is None: log.critical( 'got video widget message, but linked buddy is gone') log.critical('buddy info was %r', video_buddy) return True convo = buddy.protocol.convo_for(buddy) if convo.received_message(buddy, body): Conversation.incoming_message(convo) return True # TODO: typing notifications?
def conditional_messages_handler(self, stanza): # bind profile.account_manager.all_accounts and sys.REVISION to the conditional_messages function from common import profile import sys ret = conditional_messages(stanza, revision = sys.REVISION) if ret in (None, True): #None = not a conditional message, True = filtered for cause return ret log.critical('got a conditional message. accttypes = %r', ret) if ret == []: #no account types, no reason to filter it here. return None accttypes = ret message = stanza from_jid = message.get_from() log.critical('from_jid = %r', from_jid) if from_jid != 'digsby.org': return None buddy = self.get_buddy(from_jid) body = get_message_body(message) log.critical('body = %r', body) if not body: #no message return timestamp = get_message_timestamp(message) if not timestamp: timestamp = datetime.datetime.utcnow() content_type = 'text/html' #delay call based on accounts having shown up, then: messageobj = common.message.Message(buddy = buddy, message = body, timestamp = timestamp, content_type = content_type) import hooks def do_acct_math(*a, **k): has_accts = set(a.protocol for a in self.profile.all_accounts) if (has_accts & set(accttypes)): #user has accounts we're targeting log.critical('sending message obj to hook') hooks.notify('digsby.server.announcement', messageobj) else: log.critical('filtering conditional message for no accounts in common') log.critical('one shot next') if not hook_util.OneShotHook(self.profile, 'digsby.accounts.released.async')(do_acct_math, if_not_fired=True): log.critical('no one shot, calling now') do_acct_math() return True
def _video_buddy_for_message(self, message): 'Returns a video buddy info for a message object.' _from = message.get_from() # Video widgets are always on the guest server. if _from.domain != 'guest.digsby.org': return log.info('not a video widget: domain is %r', _from.domain) # Video widgets' resources always start with "video." resource = _from.resource if not resource.startswith('video.'): return log.info("resource does not start with video: %s", resource) else: # strip off the video. part resource = resource[6:] # Do we have a matching resource ID for a video widget? video_chat = self.video_chats.get(resource, None) if video_chat is None: log.info( 'ignoring video widget message--no video chat open client side (resource=%s)' % resource) return True # set the JID in the video chat object so it can forward messages to the widget as well video_chat.widget_jid = _from video_buddy = video_chat.buddy_info if video_buddy is None: log.info( 'ignoring message from unknown video widget: JID=%s, message=%r', _from, get_message_body(message)) return None return video_buddy
def _video_buddy_for_message(self, message): 'Returns a video buddy info for a message object.' _from = message.get_from() # Video widgets are always on the guest server. if _from.domain != 'guest.digsby.org': return log.info('not a video widget: domain is %r', _from.domain) # Video widgets' resources always start with "video." resource = _from.resource if not resource.startswith('video.'): return log.info("resource does not start with video: %s", resource) else: # strip off the video. part resource = resource[6:] # Do we have a matching resource ID for a video widget? video_chat = self.video_chats.get(resource, None) if video_chat is None: log.info('ignoring video widget message--no video chat open client side (resource=%s)' % resource) return True # set the JID in the video chat object so it can forward messages to the widget as well video_chat.widget_jid = _from video_buddy = video_chat.buddy_info if video_buddy is None: log.info('ignoring message from unknown video widget: JID=%s, message=%r', _from, get_message_body(message)) return None return video_buddy
def conditional_messages_handler(self, stanza): # bind profile.account_manager.all_accounts and sys.REVISION to the conditional_messages function from common import profile import sys ret = conditional_messages(stanza, revision=sys.REVISION) if ret in ( None, True ): #None = not a conditional message, True = filtered for cause return ret log.critical('got a conditional message. accttypes = %r', ret) if ret == []: #no account types, no reason to filter it here. return None accttypes = ret message = stanza from_jid = message.get_from() log.critical('from_jid = %r', from_jid) if from_jid != 'digsby.org': return None buddy = self.get_buddy(from_jid) body = get_message_body(message) log.critical('body = %r', body) if not body: #no message return timestamp = get_message_timestamp(message) if not timestamp: timestamp = datetime.datetime.utcnow() content_type = 'text/html' #delay call based on accounts having shown up, then: messageobj = common.message.Message(buddy=buddy, message=body, timestamp=timestamp, content_type=content_type) import hooks def do_acct_math(*a, **k): has_accts = set(a.protocol for a in self.profile.all_accounts) if (has_accts & set(accttypes)): #user has accounts we're targeting log.critical('sending message obj to hook') hooks.notify('digsby.server.announcement', messageobj) else: log.critical( 'filtering conditional message for no accounts in common') log.critical('one shot next') if not hook_util.OneShotHook(self.profile, 'digsby.accounts.released.async')( do_acct_math, if_not_fired=True): log.critical('no one shot, calling now') do_acct_math() return True