Draft: Image pasting from clipboard, attaching MIME type information to allow previewable images and more
The goal of this MR is twofold:
- Allow pasting images #824
- Attach MIME type to outgoing messages #880 (needs to be changed in libcmatrix)
However, a larger amount of various fixes and improvements has also made it in. I can split those off into a different MR to ease review, if desired.
After digging a bit in the relevant parts of the codebase (ChattyFile, ChattyAttachment, ChattyAttachmentBar, ...) I have formulated a plan of attack.
ChattyFile
problems:
- currently only handles
GFiles - in most cases (except
chatty_filew_new_full(): needs to do a bunch of {a,}sync stuff before it can be considered "ready for use"
solution: needs to become a bit smarter:
-
needs to work with the clipboard -
use properties for mime-type, height, width etc, so that e.g. ChattyAttachmentdoes not need to deal with this -
implement GInitable(andGAsyncInitable) instead of emulating it. (Currently we retrieve e.g.GFileInfoand bail on error, see e.g.chatty_file_new_for_path ()) After initialization is done, all relevant properties should have sensible values, or: even better, checked against provided expected values (in the case ofchatt_file_new_full()) -
Regarding constructors: I've opted /currently/ to have chatty_file_new_full()not do any initialization/validation. The underlying assumption being perhaps, that if you use_new_full()you've checked that e.g. it actually refers to a valid file - I may yet reconsider and have it useg_initable_new()(where all the checks happen) instead ofg_object_new()for both consistencies sake as well as the added validations performed, which would also allow us to: -
Have more checks in place: expected size, mime-type, ... (another reasaon for g_initable_new() -
might need to add chatty_file_save_to_file(const char *path)for e.g. clipboard contents as otherwise theChattyHistorywill not be able to load older files (probably only relevant for MMS and perhaps XMPP, TODO need to check the libcmatrix side as well) -
tag all tasks -
Needs tests added! -
Do we maybe want to keep the GdkPixbuf around that we create for images? memory consumption? allow unloading?
potential constructors
sort of
ChattyFile *chatty_file_new_finish (GAsyncResult *res,
GError **error);
void chatty_file_new_for_cm_event (gpointer cm_event,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data);
void chatty_file_new_for_clipboard (GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data);
void chatty_file_new_for_path (const char *path,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data);
ChattyFile *chatty_file_new_for_path_sync (const char *path);
ChattyFile *chatty_file_new_full (const char *file_name,
const char *url,
const char *path,
const char *mime_type,
gpointer data, // maybe GBytes?, however we had size already, so ...
gsize size, // I think both would still be fine, we can use that to error out
int width,
int height,
int duration);
ChattyAttachment
-
Switch from GFiletoChattyFile -
Move thumbnail creation/retrievable logic to ChattyFile(probably sensible) Looking at it some more. Or perhaps chatty-media.c which has a similar ish
ChattyAttachmentBar
-
Allow multiple attachments for matrix: We can just send multiple messages with one attachment each (follow-up material)
ChattyMessageBar
-
when pasting anything other than text/plaincreate a newChattyFileand add it toChattyAttachmentBar
ChattyMaChat
-
needs libcmatrix with new API -
needs to adapt in `chatty_ma_chat_message_send_async()
Edited by Evangelos Ribeiro Tzaras