示例#1
0
 def post(self, registry_id):
     user = self.get_current_user()
     message = self.get_argument('message')
     channel_chat = model.channel_name(user, registry_id)
     channel_notify = registry_id
     
     if channel_chat:
         msg = msg_chat(user, message)
        
         
         model.REDIS_PUBSUB.publish(channel_chat, msg)
         model.REDIS_PUBSUB.lpush(channel_chat, msg)
         log.model.log(user, u'escreveu no chat de', objeto=registry_id, tipo="chat", news=False)
         
         # publica no canal de notificações somente se a conversa não é em comunidade e o usuário com quem eu falo não está no chat
         if ":" in channel_chat and (channel_chat not in model.USUARIOS_NO_CHAT or registry_id not in model.USUARIOS_NO_CHAT[channel_chat]):            
             model.REDIS_PUBSUB.publish(channel_notify, msg)
             model.REDIS_PUBSUB.lpush(channel_notify, msg)
           
             # Armazena no couchdb a notificação que será enviada por email pela thread
             self._notification = model.NotificationChat().retrieve(registry_id)
             if self._notification:
                 self._notification.registros.append(msg)
                 self._notification.save()
                 
             else:
                 self._reg = core.model.Member().retrieve(registry_id)
                 self._notification = model.NotificationChat()
                 self._notification.email = self._reg.email
                 self._notification.name = self._reg.name
                 self._notification.registros = [msg]
                 self._notification.save(id=registry_id)
示例#2
0
 def open(self, registry_id):
     user = self.get_current_user()
     #print "open: ", user, "-", registry_id
     self._channel_chat =  model.channel_name(user, registry_id)
     self._channel_notify = registry_id
     #print "MessagesUpdate, open, channel_chat = ", self._channel_chat
     self.listen()
     
     # acrescenta mensagem de entrada se o canal for de uma comunidade
     if self._channel_chat and ":" not in self._channel_chat:
         model.REDIS_PUBSUB.publish(self._channel_chat, msg_chat(user, "Entrou no Chat."))
         model.REDIS_PUBSUB.lpush(self._channel_chat, msg_chat(user, "Entrou no Chat."))
示例#3
0
    def get(self, registry_id):
        self._user = self.get_current_user()
        self._registry_id = registry_id

        if self._user==self._registry_id:
            self.redirect("/chat")
            return
        
        channel = model.channel_name(self._user, registry_id)
        
        if channel:
            self.retrieve_messages(model.REDIS.lrange(channel, 0, NUM_MAX_CHAT_MSGS))
            
        else:
            self.render("home.html", NOMEPAG='chat', \
                        MSG=u"Acesso negado a este Chat.", \
                        REGISTRY_ID=registry_id)