Skip to content
This repository was archived by the owner on Aug 20, 2024. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 42 additions & 5 deletions prpl/attachments.c
Original file line number Diff line number Diff line change
Expand Up @@ -544,13 +544,10 @@ struct chime_im {
ChimeContact *peer;
};

static void chime_send_init(PurpleXfer *xfer)
static void init_upload(PurpleXfer *xfer, struct purple_chime *pc, ChimeObject *obj)
{
purple_debug_info("chime", "Starting to handle upload of file '%s'\n", xfer->local_filename);

struct purple_chime *pc = purple_connection_get_protocol_data(xfer->account->gc);
struct chime_im *im = g_hash_table_lookup(pc->ims_by_email, xfer->who);

g_return_if_fail(CHIME_IS_CONNECTION(pc->cxn));
ChimeConnectionPrivate *priv = CHIME_CONNECTION_GET_PRIVATE(pc->cxn);

Expand All @@ -566,7 +563,7 @@ static void chime_send_init(PurpleXfer *xfer)
}
AttachmentUpload *data = g_new0(AttachmentUpload, 1);
data->conn = pc->cxn;
data->obj = im->m.obj;
data->obj = obj;
data->content = file_contents;
data->content_length = length;
get_mime_type(xfer->local_filename, &data->content_type);
Expand All @@ -578,6 +575,25 @@ static void chime_send_init(PurpleXfer *xfer)
request_upload_url(pc->cxn, priv->messaging_url, xfer);
}

static void chime_send_init(PurpleXfer *xfer)
{
purple_debug_info("chime", "Starting to handle upload of file '%s'\n", xfer->local_filename);

struct purple_chime *pc = purple_connection_get_protocol_data(xfer->account->gc);
struct chime_im *im = g_hash_table_lookup(pc->ims_by_email, xfer->who);

init_upload(xfer, pc, im->m.obj);
}

static void chime_send_init_chat(PurpleXfer *xfer)
{
purple_debug_info("chime", "Starting to handle upload of file '%s'\n", xfer->local_filename);
ChimeObject *obj = (ChimeObject*)xfer->data;
struct purple_chime *pc = purple_connection_get_protocol_data(xfer->account->gc);

init_upload(xfer, pc, obj);
}

static void chime_send_start(PurpleXfer *xfer)
{
purple_debug_info("chime", "chime_send_start\n");
Expand Down Expand Up @@ -615,3 +631,24 @@ void chime_send_file(PurpleConnection *gc, const char *who, const char *filename
purple_xfer_request(xfer);
}
}

void chime_send_file_chat(PurpleConnection *gc, ChimeObject *obj, const char *who, const char *filename)
{
purple_debug_info("chime", "chime_send_file_chat(who=%s, file=%s\n", who, filename);

PurpleXfer *xfer;
xfer = purple_xfer_new(gc->account, PURPLE_XFER_SEND, who);
if (xfer) {
purple_xfer_set_init_fnc(xfer, chime_send_init_chat);
purple_xfer_set_start_fnc(xfer, chime_send_start);
purple_xfer_set_cancel_send_fnc(xfer, chime_send_cancel);
}

xfer->data = obj;

if (filename) {
purple_xfer_request_accepted(xfer, filename);
} else {
purple_xfer_request(xfer);
}
}
34 changes: 34 additions & 0 deletions prpl/chat.c
Original file line number Diff line number Diff line change
Expand Up @@ -1250,6 +1250,36 @@ static void leave_room(PurpleBuddy *buddy, gpointer _chat)
chime_connection_remove_room_member_async(cxn, room, me, NULL, leave_room_cb, chat);
}

static void send_file(PurpleBuddy *buddy, gpointer *_pchat)
{
purple_debug_info("chime", "send_file\n");
PurpleChat *pchat = (PurpleChat*)_pchat;
purple_debug_info("chime", "room\n");
if (!pchat->components)
return;

const gchar *roomid = g_hash_table_lookup(pchat->components, (char *)"RoomId");
if (!roomid)
return;

purple_debug_info("chime", "Chat menu for %s\n", roomid);

PurpleConnection *conn = pchat->account->gc;
if (!conn)
return;

struct purple_chime *pc = purple_connection_get_protocol_data(conn);
ChimeRoom *room = chime_connection_room_by_id(pc->cxn, roomid);
if (!room)
return;

struct chime_chat *chat = g_hash_table_lookup(pc->chats_by_room, room);
if (!chat)
return;
purple_debug_info("chime", "Has chat\n");
chime_send_file_chat(conn, chat->m.obj, roomid, NULL);
}

GList *chime_purple_chat_menu(PurpleChat *pchat)
{

Expand All @@ -1276,6 +1306,10 @@ GList *chime_purple_chat_menu(PurpleChat *pchat)
return NULL;

GList *items = NULL;
items = g_list_append(items,
purple_menu_action_new(_("Send file"),
PURPLE_CALLBACK(send_file), pchat, NULL));

if (chat->call) {
items = g_list_append(items,
purple_menu_action_new(_("Show participants"),
Expand Down
1 change: 1 addition & 0 deletions prpl/chime.h
Original file line number Diff line number Diff line change
Expand Up @@ -173,5 +173,6 @@ ChimeAttachment *extract_attachment(JsonNode *record);

void download_attachment(ChimeConnection *cxn, ChimeAttachment *att, AttachmentContext *ctx);
void chime_send_file(PurpleConnection *gc, const char *who, const char *filename);
void chime_send_file_chat(PurpleConnection *gc, ChimeObject *obj, const char *who, const char *filename);

#endif /* __CHIME_H__ */