Пример #1
0
    def notify_session(self, jid, session, type = None):
        # notify session changed (online/state change)
        for hisjid in self._rosters:
            roster = self._rosters[hisjid]
            if (jid in roster.watching()):
                him = self.get_user(hisjid)
                # he can't see you!
                if (not him.CanSee(session._userinfo)):
                    continue
                # you are watching me, so I'll notify you
                Log.debug("notify %s about %s" % (hisjid, session.get_fulljid()))
                elem = None
                if (type == None):
                    show = session.get_show(self.get_user(hisjid))
                    elem = self.E.presence(
                            {'from' : session.get_fulljid(),
                                'to' : hisjid}, 
                            self.E.status(session.get_status()), 
                            self.E.priority(session.get_priority()))
                    if (show != None):
                        elem.append(self.E.show(show))
                else:
                    elem = self.E.presence(
                            {'from' : session.get_fulljid(),
                                'to' : hisjid,
                                'type' : type})

                try:
                    self.transmit(hisjid, elem)
                except Exception as e:
                    Log.error("notify error: %r" % e)
                    Log.error(traceback.format_exc())
Пример #2
0
    def probe(self, conn):
        """Ask everybody this account is subscribed to for a status
        update.  This is used when a client first connects.
        Also fake responses from TERM users"""

        Log.debug("probing friends from %s" % conn.authJID.full)
        roster = self._get(conn)
        elem = conn.E.presence({'from': unicode(conn.authJID), 'type': 'probe'})
        sender = UserManager.UserManager.LoadUser(conn._userid)
        for jid in roster.watching():
            if (jid in self._rosters):
                try:
                    conn.send(jid, elem)
                except Exception as e:
                    Log.error("Exception caught when probing XMPP user %r: %r" % (jid, e))
                    Log.error(traceback.format_exc())
#            if (jid != conn.authJID.bare): # bug somewhere, if they are equal..
            for session_info in self.get_bbs_online(jid):
                if (not sender.CanSee(session_info._userinfo)):
                    continue
                show = session_info.get_show(self.get_user(conn.authJID.bare))
                elem = conn.E.presence(
                    {'from' : '%s/%s' % (jid, session_info.get_res()),
                     'to' : conn.authJID.bare},
                    conn.E.status(session_info.get_status()),
                    conn.E.priority(session_info.get_priority()))
                if (show != None):
                    elem.append(conn.E.show(show))
                try:
                    conn.send(conn.authJID, elem)
                except Exception as e:
                    Log.error("Exception caught when faking response from %s/%s to %r" % (jid, session_info.get_res(), conn.authJID.bare))
                    Log.error(traceback.format_exc())
        Log.debug("probed friends from %s" % conn.authJID.full)
Пример #3
0
    def probe(self, conn):
        """Ask everybody this account is subscribed to for a status
        update.  This is used when a client first connects.
        Also fake responses from TERM users"""

        Log.debug("probing friends from %s" % conn.authJID.full)
        roster = self.get(conn)
        sender = UserManager.UserManager.LoadUser(conn._userid)
        for jid in roster.watching():
            Log.debug("probing %r" % (jid))
            if (jid in self._rosters):
                Log.debug("probing XMPP jid %r" % jid)
                elem = conn.E.presence({'from': unicode(conn.authJID),
                    'type': 'probe'})
                try:
                    conn.send(jid, elem)
                except Exception as e:
                    Log.error("Exception caught when probing XMPP user %r: %r" % (jid, e))
                    Log.error(traceback.format_exc())
#            if (jid != conn.authJID.bare): # bug somewhere, if they are equal..
            for session_info in self.get_bbs_online(jid):
                Log.debug("probing session %s" % session_info.get_res())
                if (not sender.CanSee(session_info._userinfo)):
                    continue
                show = session_info.get_show(self.get_user(conn.authJID.bare))
                sess_elem = conn.E.presence(
                    {'from' : '%s/%s' % (jid, session_info.get_res()),
                     'to' : conn.authJID.bare},
                    conn.E.status(session_info.get_status()),
                    conn.E.priority(session_info.get_priority()))
                if (show != None):
                    sess_elem.append(conn.E.show(show))
                try:
                    conn.send(conn.authJID, sess_elem)
                except Exception as e:
                    Log.error("Exception caught when faking response from %s/%s to %r" % (jid, session_info.get_res(), conn.authJID.bare))
                    Log.error(traceback.format_exc())
        Log.debug("probed friends from %s" % conn.authJID.full)