Handle incoming images
This commit is contained in:
@@ -1,11 +1,12 @@
|
||||
#include <connection.h>
|
||||
#include <debug.h>
|
||||
#include <eventloop.h>
|
||||
#include <imgstore.h>
|
||||
#include <util.h>
|
||||
|
||||
#include <string.h>
|
||||
#include <pthread.h>
|
||||
#include <inttypes.h>
|
||||
#include <pthread.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "delta-connection.h"
|
||||
#include "libdelta.h"
|
||||
@@ -420,7 +421,7 @@ delta_recv_im(DeltaConnectionData *conn, uint32_t msg_id)
|
||||
g_assert(pc != NULL);
|
||||
|
||||
dc_msg_t* msg = dc_get_msg(mailbox, msg_id);
|
||||
|
||||
int viewtype = dc_msg_get_viewtype(msg);
|
||||
time_t timestamp = dc_msg_get_timestamp(msg);
|
||||
char *text = dc_msg_get_text(msg);
|
||||
uint32_t contact_id = dc_msg_get_from_id(msg);
|
||||
@@ -432,8 +433,49 @@ delta_recv_im(DeltaConnectionData *conn, uint32_t msg_id)
|
||||
}
|
||||
|
||||
char *who = dc_contact_get_addr(contact);
|
||||
int flags = PURPLE_MESSAGE_RECV;
|
||||
|
||||
serv_got_im(pc, who, text, PURPLE_MESSAGE_RECV | PURPLE_MESSAGE_RAW, timestamp);
|
||||
switch(viewtype) {
|
||||
case DC_MSG_GIF:
|
||||
case DC_MSG_IMAGE:
|
||||
flags = flags | PURPLE_MESSAGE_IMAGES;
|
||||
break;
|
||||
case DC_MSG_TEXT:
|
||||
flags = flags | PURPLE_MESSAGE_RAW;
|
||||
break;
|
||||
case DC_MSG_VIDEO: // Pidgin only supports these as files for download
|
||||
case DC_MSG_FILE:
|
||||
case DC_MSG_AUDIO: // Sound to play
|
||||
case DC_MSG_VOICE:
|
||||
break;
|
||||
default:
|
||||
purple_debug_info(PLUGIN_ID, "Message %d: unknown message type: %d\n", msg_id, viewtype);
|
||||
}
|
||||
|
||||
int image_id = 0;
|
||||
|
||||
if ((flags & PURPLE_MESSAGE_IMAGES) > 0) {
|
||||
char *filename = dc_msg_get_file(msg);
|
||||
gchar *data;
|
||||
gsize length;
|
||||
GError *err = NULL;
|
||||
|
||||
g_file_get_contents(filename, &data, &length, &err);
|
||||
if (err != NULL) {
|
||||
purple_debug_info(PLUGIN_ID, "Failed to read image %s: %s\n", filename, err->message);
|
||||
g_error_free(err);
|
||||
goto out;
|
||||
}
|
||||
|
||||
image_id = purple_imgstore_add_with_id(data, length, filename);
|
||||
text = g_strdup_printf("<img id='%d'>", image_id);
|
||||
}
|
||||
|
||||
serv_got_im(pc, who, text, flags, timestamp);
|
||||
|
||||
if (image_id > 0) {
|
||||
purple_imgstore_unref_by_id(image_id);
|
||||
}
|
||||
|
||||
dc_markseen_msgs(mailbox, &msg_id, 1);
|
||||
g_free(who);
|
||||
|
Reference in New Issue
Block a user