Ejemplo n.º 1
0
 def encrypted_media(mxc, body, key, hash,  iv, homeserver=None):
     """Render a mxc media URI of an encrypted file."""
     http_url = Api.encrypted_mxc_to_plumb(
         mxc,
         key,
         hash,
         iv,
         homeserver
     )
     url = http_url if http_url else mxc
     description = "{}".format(body) if body else "file"
     return Render._media(url, description)
Ejemplo n.º 2
0
    def render(self):
        # type: () -> str
        assert self.content_uri

        if self.encrypt:
            http_url = Api.encrypted_mxc_to_plumb(
                self.content_uri, self.file_keys["key"]["k"],
                self.file_keys["hashes"]["sha256"], self.file_keys["iv"])
            url = http_url if http_url else self.content_uri

            description = "{}".format(self.file_name)
            return ("{del_color}<{ncolor}{desc}{del_color}>{ncolor} "
                    "{del_color}[{ncolor}{url}{del_color}]{ncolor}").format(
                        del_color=W.color("chat_delimiters"),
                        ncolor=W.color("reset"),
                        desc=description,
                        url=url)

        http_url = Api.mxc_to_http(self.content_uri)
        description = ("/{}".format(self.file_name) if self.file_name else "")
        return "{url}{desc}".format(url=http_url, desc=description)