def subscribe(self, topic, catchup):
        if topic == "addressbook":
            self.do_db_subscribe(topic, "addressbook",
                                 self.deliver_addressbook_event)
            if catchup:
                self.do_catchup("addressbook", self.deliver_addressbook_event)

        elif topic == "messages":
            self.do_db_subscribe(topic, "inbound_messages",
                                 self.deliver_inbound_message_event)
            self.do_db_subscribe(topic, "outbound_messages",
                                 self.deliver_outbound_message_event)
            if catchup:
                self.do_catchup("inbound_messages",
                                self.deliver_inbound_message_event)
                self.do_catchup("outbound_messages",
                                self.deliver_outbound_message_event)

        elif topic == "mailboxes":
            self.do_db_subscribe(topic, "mailboxes",
                                 self.deliver_mailbox_event)
            if catchup:
                self.do_catchup("mailboxes", self.deliver_mailbox_event)
                # send this after any DB row, so the frontend doesn't
                # show and then immediately hide the warning box
                c = self.db.execute("SELECT * FROM agent_profile")
                row = c.fetchone()
                adv_local = bool(row["advertise_local_mailbox"])
                local_url = None
                if adv_local:
                    local_url = self.agent.mailbox_server.baseurl # XXX
                self.deliver_local_mailbox_event(adv_local, local_url)

        else:
            raise ValueError("unknown subscription topic %s" % topic)
dataset/ETHPy150Open warner/petmail/petmail/web.py/EventChannel.subscribe/original