Skip to content
This repository was archived by the owner on Aug 20, 2024. It is now read-only.

Commit 8895e17

Browse files
committed
Add attachment upload support for chats
On Pidgin a file can be uploaded through `Conversation->More->Send File` menu.
1 parent ceee47d commit 8895e17

File tree

3 files changed

+77
-5
lines changed

3 files changed

+77
-5
lines changed

prpl/attachments.c

Lines changed: 42 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -544,13 +544,10 @@ struct chime_im {
544544
ChimeContact *peer;
545545
};
546546

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

551-
struct purple_chime *pc = purple_connection_get_protocol_data(xfer->account->gc);
552-
struct chime_im *im = g_hash_table_lookup(pc->ims_by_email, xfer->who);
553-
554551
g_return_if_fail(CHIME_IS_CONNECTION(pc->cxn));
555552
ChimeConnectionPrivate *priv = CHIME_CONNECTION_GET_PRIVATE(pc->cxn);
556553

@@ -566,7 +563,7 @@ static void chime_send_init(PurpleXfer *xfer)
566563
}
567564
AttachmentUpload *data = g_new0(AttachmentUpload, 1);
568565
data->conn = pc->cxn;
569-
data->obj = im->m.obj;
566+
data->obj = obj;
570567
data->content = file_contents;
571568
data->content_length = length;
572569
get_mime_type(xfer->local_filename, &data->content_type);
@@ -578,6 +575,25 @@ static void chime_send_init(PurpleXfer *xfer)
578575
request_upload_url(pc->cxn, priv->messaging_url, xfer);
579576
}
580577

578+
static void chime_send_init(PurpleXfer *xfer)
579+
{
580+
purple_debug_info("chime", "Starting to handle upload of file '%s'\n", xfer->local_filename);
581+
582+
struct purple_chime *pc = purple_connection_get_protocol_data(xfer->account->gc);
583+
struct chime_im *im = g_hash_table_lookup(pc->ims_by_email, xfer->who);
584+
585+
init_upload(xfer, pc, im->m.obj);
586+
}
587+
588+
static void chime_send_init_chat(PurpleXfer *xfer)
589+
{
590+
purple_debug_info("chime", "Starting to handle upload of file '%s'\n", xfer->local_filename);
591+
ChimeObject *obj = (ChimeObject*)xfer->data;
592+
struct purple_chime *pc = purple_connection_get_protocol_data(xfer->account->gc);
593+
594+
init_upload(xfer, pc, obj);
595+
}
596+
581597
static void chime_send_start(PurpleXfer *xfer)
582598
{
583599
purple_debug_info("chime", "chime_send_start\n");
@@ -615,3 +631,24 @@ void chime_send_file(PurpleConnection *gc, const char *who, const char *filename
615631
purple_xfer_request(xfer);
616632
}
617633
}
634+
635+
void chime_send_file_chat(PurpleConnection *gc, ChimeObject *obj, const char *who, const char *filename)
636+
{
637+
purple_debug_info("chime", "chime_send_file_chat(who=%s, file=%s\n", who, filename);
638+
639+
PurpleXfer *xfer;
640+
xfer = purple_xfer_new(gc->account, PURPLE_XFER_SEND, who);
641+
if (xfer) {
642+
purple_xfer_set_init_fnc(xfer, chime_send_init_chat);
643+
purple_xfer_set_start_fnc(xfer, chime_send_start);
644+
purple_xfer_set_cancel_send_fnc(xfer, chime_send_cancel);
645+
}
646+
647+
xfer->data = obj;
648+
649+
if (filename) {
650+
purple_xfer_request_accepted(xfer, filename);
651+
} else {
652+
purple_xfer_request(xfer);
653+
}
654+
}

prpl/chat.c

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1250,6 +1250,36 @@ static void leave_room(PurpleBuddy *buddy, gpointer _chat)
12501250
chime_connection_remove_room_member_async(cxn, room, me, NULL, leave_room_cb, chat);
12511251
}
12521252

1253+
static void send_file(PurpleBuddy *buddy, gpointer *_pchat)
1254+
{
1255+
purple_debug_info("chime", "send_file\n");
1256+
PurpleChat *pchat = (PurpleChat*)_pchat;
1257+
purple_debug_info("chime", "room\n");
1258+
if (!pchat->components)
1259+
return;
1260+
1261+
const gchar *roomid = g_hash_table_lookup(pchat->components, (char *)"RoomId");
1262+
if (!roomid)
1263+
return;
1264+
1265+
purple_debug_info("chime", "Chat menu for %s\n", roomid);
1266+
1267+
PurpleConnection *conn = pchat->account->gc;
1268+
if (!conn)
1269+
return;
1270+
1271+
struct purple_chime *pc = purple_connection_get_protocol_data(conn);
1272+
ChimeRoom *room = chime_connection_room_by_id(pc->cxn, roomid);
1273+
if (!room)
1274+
return;
1275+
1276+
struct chime_chat *chat = g_hash_table_lookup(pc->chats_by_room, room);
1277+
if (!chat)
1278+
return;
1279+
purple_debug_info("chime", "Has chat\n");
1280+
chime_send_file_chat(conn, chat->m.obj, roomid, NULL);
1281+
}
1282+
12531283
GList *chime_purple_chat_menu(PurpleChat *pchat)
12541284
{
12551285

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

12781308
GList *items = NULL;
1309+
items = g_list_append(items,
1310+
purple_menu_action_new(_("Send file"),
1311+
PURPLE_CALLBACK(send_file), pchat, NULL));
1312+
12791313
if (chat->call) {
12801314
items = g_list_append(items,
12811315
purple_menu_action_new(_("Show participants"),

prpl/chime.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,5 +173,6 @@ ChimeAttachment *extract_attachment(JsonNode *record);
173173

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

177178
#endif /* __CHIME_H__ */

0 commit comments

Comments
 (0)