Exemple #1
0
    def post(self, board, thread):
        # FIXME: move subscribe crap somewhere out

        key = "updatetime-thread-%s-%d" % (board, thread)
        person_cookie = self.get_secure_cookie("person", True)
        person = person_cookie.get("update", str(uuid()))

        # FIXME: tt sucks, temporary workarround
        while len(person + key) % 4:
            person += "="

        person_cookie["update"] = person

        watchers = memcache.get(key) or []

        nwatchers = util.watchers_clean(watchers, person)
        nwatchers.insert(0, (time(), person))

        memcache.set(key, nwatchers, time=self.WATCH_TIME)

        token = memcache.get(person + key)

        if not token:
            token = channel.create_channel(person + key)
            memcache.set(person + key, token)

        post_level = util.post_level(self.request.remote_addr)

        rb = rainbow.make_rainbow(self.request.remote_addr, board, thread)

        util.watchers_send(watchers, key, {"evt": "enter", "rainbow": rb})

        return json_response({"token": token, "post_quota": post_level, "watcher_time": self.WATCH_TIME})
Exemple #2
0
  def post(self, board, thread):
    # FIXME: move subscribe crap somewhere out

    rb = rainbow.make_rainbow(self.request.remote_addr, board, thread)
    person_cookie = self.get_secure_cookie("person", True, max_age=MONTH*12)
    person = person_cookie.get("update", str(uuid()))

    person_cookie['update'] = person

    subid = "%s/%s/%s/%d" %(rb, person, board, thread, )


    token = memcache.get(subid)

    if not token:
      token = channel.create_channel(subid)
      memcache.set(subid, token)

    try:
        query = 'thread:%d board:%s' %(thread, board)

        matcher.subscribe(util.Post, query, subid,
        topic='post',
        lease_duration_sec=self.WATCH_TIME)
    except OverQuotaError:
        logging.error("subscribe failed")
        token = None

    post_level = util.post_level(self.request.remote_addr)

    """
    if self.NEWFAG and \
      not person_cookie.get("postcount") > self.OLDFAG and \
      (board, thread) not in self.NEWFAG:
          post_level = "err"
    """


    return json_response( 
        {
          "token" : token,
          "post_quota" : post_level,
          "watcher_time" : self.WATCH_TIME,
        }
    )