From d9cb6885ab741ba69a966109cb05e26692143ce0 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Fri, 2 Oct 2020 16:27:59 +0200 Subject: Matrix: add video/regular file upload --- plugins/Matrix.hpp | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) (limited to 'plugins') diff --git a/plugins/Matrix.hpp b/plugins/Matrix.hpp index 36b8072..bbf35db 100644 --- a/plugins/Matrix.hpp +++ b/plugins/Matrix.hpp @@ -1,5 +1,6 @@ #pragma once +#include "../include/FileAnalyzer.hpp" #include "Plugin.hpp" #include #include @@ -31,13 +32,6 @@ namespace QuickMedia { MessageType type; }; - struct MessageInfo { - int size = 0; - int w = 0; - int h = 0; - const char* mimetype = nullptr; - }; - struct RoomData { std::string id; // Each room has its own list of user data, even if multiple rooms has the same user @@ -59,6 +53,14 @@ namespace QuickMedia { AFTER }; + struct UploadInfo { + ContentType content_type; + size_t file_size; + std::optional dimensions; + std::optional duration_seconds; + std::string content_uri; + }; + using RoomSyncMessages = std::unordered_map>>; class Matrix : public Plugin { @@ -81,14 +83,13 @@ namespace QuickMedia { // |url| should only be set when uploading media. // TODO: Make api better. - PluginResult post_message(const std::string &room_id, const std::string &body, const std::string &url = "", MessageType msgtype = MessageType::TEXT, MessageInfo *info = nullptr); + PluginResult post_message(const std::string &room_id, const std::string &body, const std::optional &file_info, const std::optional &thumbnail_info); // |relates_to| is from |BodyItem.userdata| and is of type |Message*| PluginResult post_reply(const std::string &room_id, const std::string &body, void *relates_to); // |relates_to| is from |BodyItem.userdata| and is of type |Message*| PluginResult post_edit(const std::string &room_id, const std::string &body, void *relates_to); - // TODO: Make this work for all image types and videos and regular files - PluginResult post_file(const std::string &room_id, const std::string &filepath); + PluginResult post_file(const std::string &room_id, const std::string &filepath, std::string &err_msg); PluginResult login(const std::string &username, const std::string &password, const std::string &homeserver, std::string &err_msg); PluginResult logout(); @@ -106,12 +107,16 @@ namespace QuickMedia { bool was_message_posted_by_me(const std::string &room_id, void *message) const; std::string message_get_author_displayname(RoomData *room_data, Message *message) const; + + // Cached + PluginResult get_config(int *upload_size); private: PluginResult sync_response_to_body_items(const Json::Value &root, RoomSyncMessages &room_messages); PluginResult get_previous_room_messages(const std::string &room_id, RoomData *room_data); void events_add_user_info(const Json::Value &events_json, RoomData *room_data); void events_add_messages(const Json::Value &events_json, RoomData *room_data, MessageDirection message_dir, RoomSyncMessages *room_messages, bool has_unread_notifications); void events_set_room_name(const Json::Value &events_json, RoomData *room_data); + PluginResult upload_file(const std::string &room_id, const std::string &filepath, UploadInfo &file_info, UploadInfo &thumbnail_info, std::string &err_msg); std::shared_ptr get_edited_message_original_message(RoomData *room_data, std::shared_ptr message); private: @@ -120,6 +125,7 @@ namespace QuickMedia { std::string username; std::string access_token; std::string homeserver; + std::optional upload_limit; std::string next_batch; }; } \ No newline at end of file -- cgit v1.2.3