示例#1
0
    def removeContact(self, cjid):
        """Removes the contact from this user's roster. Returns the contact's
        id in the DB.

        cjid -- bare JID or the contact as a string.
        """
        con = DB()
        c = con.cursor()

        # get the contact's id
        c.execute(
            "SELECT jids.id\
                   FROM roster\
                   JOIN jids ON roster.contactid = jids.id\
                   WHERE roster.userid = ? AND jids.jid = ?", (self.uid, cjid))
        res = c.fetchone()
        if res:
            cid = res[0]
        else:
            logging.info("[%s] Contact %s does not exist in roster of %s",
                         self.__class__, cjid, self.jid)
            commitSQLiteTransaction(con, c)
            con.close()
            return False

        # delete the contact from all groups it's in for this user
        c.execute(
            "DELETE FROM rostergroupitems\
                   WHERE rostergroupitems.groupid IN (\
                       SELECT rgs.groupid FROM rostergroups AS rgs\
                       JOIN rostergroupitems AS rgi ON rgi.groupid = rgs.groupid\
                       WHERE rgs.userid = ?\
                    ) AND rostergroupitems.contactid = ?", (self.uid, cid))

        # now delete the roster entry
        c.execute(
            "DELETE FROM roster\
                   WHERE userid = ? AND contactid = ?", (self.uid, cid))

        commitSQLiteTransaction(con, c)

        return cid
示例#2
0
    def removeContact(self, cjid):
        """Removes the contact from this user's roster. Returns the contact's
        id in the DB.

        cjid -- bare JID or the contact as a string.
        """
        con = DB()
        c = con.cursor()

        # get the contact's id
        c.execute("SELECT jids.id\
                   FROM roster\
                   JOIN jids ON roster.contactid = jids.id\
                   WHERE roster.userid = ? AND jids.jid = ?", (self.uid, cjid))
        res = c.fetchone()
        if res:
            cid = res[0]
        else:
            logging.info("[%s] Contact %s does not exist in roster of %s",
                         self.__class__, cjid, self.jid)
            commitSQLiteTransaction(con, c)
            con.close()
            return False

        # delete the contact from all groups it's in for this user
        c.execute("DELETE FROM rostergroupitems\
                   WHERE rostergroupitems.groupid IN (\
                       SELECT rgs.groupid FROM rostergroups AS rgs\
                       JOIN rostergroupitems AS rgi ON rgi.groupid = rgs.groupid\
                       WHERE rgs.userid = ?\
                    ) AND rostergroupitems.contactid = ?", (self.uid, cid))

        # now delete the roster entry
        c.execute("DELETE FROM roster\
                   WHERE userid = ? AND contactid = ?", (self.uid, cid))

        commitSQLiteTransaction(con, c)

        return cid