aboutsummaryrefslogtreecommitdiff
path: root/plugins
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2020-10-02 16:27:59 +0200
committerdec05eba <dec05eba@protonmail.com>2020-10-02 16:27:59 +0200
commitd9cb6885ab741ba69a966109cb05e26692143ce0 (patch)
treee4e356c182011bc389bc895665dab1507ecdb767 /plugins
parent9e68dfad4449d5c0180e252fada6de56b4f405d1 (diff)
Matrix: add video/regular file upload
Diffstat (limited to 'plugins')
-rw-r--r--plugins/Matrix.hpp26
1 files changed, 16 insertions, 10 deletions
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 <unordered_map>
#include <json/value.h>
@@ -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> dimensions;
+ std::optional<double> duration_seconds;
+ std::string content_uri;
+ };
+
using RoomSyncMessages = std::unordered_map<RoomData*, std::vector<std::shared_ptr<Message>>>;
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<UploadInfo> &file_info, const std::optional<UploadInfo> &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<Message> get_edited_message_original_message(RoomData *room_data, std::shared_ptr<Message> message);
private:
@@ -120,6 +125,7 @@ namespace QuickMedia {
std::string username;
std::string access_token;
std::string homeserver;
+ std::optional<int> upload_limit;
std::string next_batch;
};
} \ No newline at end of file