chat_core.py 文件源码

python
阅读 23 收藏 0 点赞 0 评论 0

项目:best-ever-chat 作者: lazymeadow 项目源码 文件源码
def broadcast_image(self, user, image_url, room_id, nsfw_flag=False):
        """
        Broadcast an image message to the given room. Stores the image in the s3 bucket, if available, setting the img
        tag's src to the cache. If s3 is unavailable, the img src is the original url. Images are wrapping in an a tag
        with the original url as the href.
        :param user: user sending the message
        :param image_url: url of the image
        :param room_id: room receiving the message
        """
        image_src_url = retrieve_image_in_s3(image_url, self.bucket)

        new_message = {'user': user,
                       'color': users[user]['color'],
                       'image_url': xhtml_escape(image_url),
                       'image_src_url': xhtml_escape(image_src_url),
                       'nsfw_flag': nsfw_flag,
                       # 'message': "<a href=\"{}\" target=\"_blank\"><img src=\"{}\" /></a>".format(
                       #     xhtml_escape(image_url), xhtml_escape(image_src_url)),
                       'time': time.time(),
                       'room': room_id}
        rooms[room_id]['history'].append(new_message)
        self.broadcast(self.participants, {'type': 'chatMessage',
                                           'data': new_message})
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号