/** This file is a part of rexy's matrix client Copyright (C) 2019 rexy712 This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. You should have received a copy of the GNU Affero General Public License along with this program. If not, see . */ #ifndef MATRIX_UPLOAD_INFO_HPP #define MATRIX_UPLOAD_INFO_HPP #include "raii/rjp_string.hpp" #include "raii/string.hpp" #include "raii/binary.hpp" #include //size_t namespace matrix{ class client; struct file_details{ raii::binary data; raii::string name; }; struct image_details : public file_details{ int width, height; raii::string mimetype; }; struct video_details : public image_details{}; struct audio_details : public file_details{ raii::string mimetype; }; class uploaded_file { friend class matrix::client; protected: raii::rjp_string m_fileurl = {}; raii::string m_filename = {}; raii::string m_mimetype = {}; size_t m_filesize = 0; public: constexpr uploaded_file(void) = default; uploaded_file(const uploaded_file&) = default; uploaded_file(uploaded_file&&) = default; ~uploaded_file(void) = default; uploaded_file& operator=(const uploaded_file&) = default; uploaded_file& operator=(uploaded_file&&) = default; constexpr operator bool(void)const{return m_fileurl;} const raii::string& mimetype(void)const{return m_mimetype;} const raii::string& name(void)const{return m_filename;} const raii::rjp_string& url(void)const{return m_fileurl;} constexpr size_t size(void)const{return m_filesize;} }; class thumbnail_info { friend class matrix::client; protected: raii::rjp_string m_url; raii::string m_mimetype; size_t m_width = 0; size_t m_height = 0; size_t m_size = 0; public: constexpr thumbnail_info(void) = default; thumbnail_info(const thumbnail_info&) = default; thumbnail_info(thumbnail_info&&) = default; ~thumbnail_info(void) = default; thumbnail_info& operator=(const thumbnail_info&) = default; thumbnail_info& operator=(thumbnail_info&&) = default; constexpr operator bool(void)const{return m_url;} constexpr size_t width(void)const{return m_width;} constexpr size_t height(void)const{return m_height;} constexpr size_t size(void)const{return m_size;} const raii::rjp_string& url(void)const{return m_url;} const raii::string& mimetype(void)const{return m_mimetype;} }; class uploaded_image : public uploaded_file { friend class matrix::client; protected: size_t m_width = 0; size_t m_height = 0; thumbnail_info m_thumb; public: constexpr uploaded_image(void) = default; uploaded_image(const uploaded_image&) = default; uploaded_image(uploaded_image&&) = default; ~uploaded_image(void) = default; uploaded_image& operator=(const uploaded_image&) = default; uploaded_image& operator=(uploaded_image&&) = default; /*uploaded_image& operator=(const uploaded_file& f){ uploaded_file::operator=(f); return *this; } uploaded_image& operator=(uploaded_file&& f){ uploaded_file::operator=(std::move(f)); return *this; }*/ using uploaded_file::operator=; constexpr size_t width(void)const{return m_width;} constexpr size_t height(void)const{return m_height;} constexpr auto thumb_width(void)const{return m_thumb.width();} constexpr auto thumb_height(void)const{return m_thumb.height();} constexpr auto thumb_size(void)const{return m_thumb.size();} decltype(auto) thumb_url(void)const{return m_thumb.url();} decltype(auto) thumb_mimetype(void)const{return m_thumb.mimetype();} }; struct uploaded_video : public uploaded_image{ friend class matrix::client; uploaded_video& operator=(const uploaded_file& f){ uploaded_image::operator=(f); return *this; } uploaded_video& operator=(uploaded_file&& f){ uploaded_image::operator=(std::move(f)); return *this; } }; struct uploaded_audio : public uploaded_file{ friend class matrix::client; using uploaded_file::operator=; }; } #endif