Skip to content

Commit

Permalink
Fix downloads of documents with audio / video flag
Browse files Browse the repository at this point in the history
Instead of using the document attributes, use the InputMedia type to
determine the download type in tgl_do_load_document. This fixes an
FILE_ID_INVALID error in certain cases when sending a video or audio
file as regular document.
  • Loading branch information
majn committed Aug 9, 2015
1 parent 5cc7e87 commit 71ba543
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 14 deletions.
35 changes: 26 additions & 9 deletions queries.c
Original file line number Diff line number Diff line change
Expand Up @@ -2476,23 +2476,16 @@ void tgl_do_load_document_thumb (struct tgl_state *TLS, struct tgl_document *vid
tgl_do_load_photo_size (TLS, &video->thumb, callback, callback_extra);
}

void tgl_do_load_document (struct tgl_state *TLS, struct tgl_document *V, void (*callback)(struct tgl_state *TLS, void *callback_extra, int success, const char *filename), void *callback_extra) {
static void _tgl_do_load_document (struct tgl_state *TLS, struct tgl_document *V, struct download *D, void (*callback)(struct tgl_state *TLS, void *callback_extra, int success, const char *filename), void *callback_extra) {
assert (V);
struct download *D = talloc0 (sizeof (*D));
D->offset = 0;
D->size = V->size;
D->id = V->id;
D->access_hash = V->access_hash;
D->dc = V->dc_id;
D->name = 0;
D->fd = -1;
if (V->flags & TGLDF_VIDEO) {
D->type = CODE_input_video_file_location;
} else if (V->flags & TGLDF_AUDIO) {
D->type = CODE_input_audio_file_location;
} else {
D->type = CODE_input_document_file_location;
}

if (V->mime_type) {
char *r = tg_extension_by_mime (V->mime_type);
if (r) {
Expand All @@ -2502,6 +2495,30 @@ void tgl_do_load_document (struct tgl_state *TLS, struct tgl_document *V, void (
load_next_part (TLS, D, callback, callback_extra);
}

void tgl_do_load_document (struct tgl_state *TLS, struct tgl_document *V, void (*callback)(struct tgl_state *TLS, void *callback_extra, int success, const char *filename), void *callback_extra) {

struct download *D = talloc0 (sizeof (*D));
D->type = CODE_input_document_file_location;

_tgl_do_load_document (TLS, V, D, callback, callback_extra);
}

void tgl_do_load_video (struct tgl_state *TLS, struct tgl_document *V, void (*callback)(struct tgl_state *TLS, void *callback_extra, int success, const char *filename), void *callback_extra) {

struct download *D = talloc0 (sizeof (*D));
D->type = CODE_input_video_file_location;

_tgl_do_load_document (TLS, V, D, callback, callback_extra);
}

void tgl_do_load_audio (struct tgl_state *TLS, struct tgl_document *V, void (*callback)(struct tgl_state *TLS, void *callback_extra, int success, const char *filename), void *callback_extra) {

struct download *D = talloc0 (sizeof (*D));
D->type = CODE_input_audio_file_location;

_tgl_do_load_document (TLS, V, D, callback, callback_extra);
}

void tgl_do_load_encr_document (struct tgl_state *TLS, struct tgl_encr_document *V, void (*callback)(struct tgl_state *TLS, void *callback_extra, int success, const char *filename), void *callback_extra) {
assert (V);
struct download *D = talloc0 (sizeof (*D));
Expand Down
6 changes: 4 additions & 2 deletions structures.c
Original file line number Diff line number Diff line change
Expand Up @@ -956,12 +956,12 @@ void tglf_fetch_message_media_new (struct tgl_state *TLS, struct tgl_message_med
break;
case CODE_message_media_video:
case CODE_message_media_video_l27:
M->type = tgl_message_media_document;
M->type = tgl_message_media_video;
M->document = tglf_fetch_alloc_video_new (TLS, DS_MM->video);
M->caption = DS_STR_DUP (DS_MM->caption);
break;
case CODE_message_media_audio:
M->type = tgl_message_media_document;
M->type = tgl_message_media_audio;
M->document = tglf_fetch_alloc_audio_new (TLS, DS_MM->audio);
break;
case CODE_message_media_document:
Expand Down Expand Up @@ -1763,6 +1763,8 @@ void tgls_free_message_media (struct tgl_state *TLS, struct tgl_message_media *M
tfree_str (M->last_name);
return;
case tgl_message_media_document:
case tgl_message_media_video:
case tgl_message_media_audio:
tgls_free_document (TLS, M->document);
return;
case tgl_message_media_unsupported:
Expand Down
6 changes: 3 additions & 3 deletions tgl-layout.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,6 @@ struct tgl_dc {
enum tgl_message_media_type {
tgl_message_media_none,
tgl_message_media_photo,
//tgl_message_media_video,
//tgl_message_media_audio,
tgl_message_media_document,
tgl_message_media_geo,
tgl_message_media_contact,
Expand All @@ -147,7 +145,9 @@ enum tgl_message_media_type {
//tgl_message_media_audio_encr,
tgl_message_media_document_encr,
tgl_message_media_webpage,
tgl_message_media_venue
tgl_message_media_venue,
tgl_message_media_video,
tgl_message_media_audio
};

enum tgl_message_action_type {
Expand Down
3 changes: 3 additions & 0 deletions tgl.h
Original file line number Diff line number Diff line change
Expand Up @@ -568,6 +568,9 @@ void tgl_do_load_photo (struct tgl_state *TLS, struct tgl_photo *photo, void (*c
void tgl_do_load_encr_document (struct tgl_state *TLS, struct tgl_encr_document *V, void (*callback)(struct tgl_state *TLS, void *callback_extra, int success, const char *file_name), void *callback_extra);
void tgl_do_load_document (struct tgl_state *TLS, struct tgl_document *V, void (*callback)(struct tgl_state *TLS, void *callback_extra, int success, const char *file_name), void *callback_extra);
void tgl_do_load_document_thumb (struct tgl_state *TLS, struct tgl_document *video, void (*callback)(struct tgl_state *TLS, void *callback_extra, int success, const char *file_name), void *callback_extra);
void tgl_do_load_video (struct tgl_state *TLS, struct tgl_document *V, void (*callback)(struct tgl_state *TLS, void *callback_extra, int success, const char *filename), void *callback_extra);
void tgl_do_load_audio (struct tgl_state *TLS, struct tgl_document *V, void (*callback)(struct tgl_state *TLS, void *callback_extra, int success, const char *filename), void *callback_extra);


// loads file by location. Use only for small files!
void tgl_do_load_file_location (struct tgl_state *TLS, struct tgl_file_location *FL, void (*callback)(struct tgl_state *TLS, void *callback_extra, int success, const char *file_name), void *callback_extra);
Expand Down

0 comments on commit 71ba543

Please sign in to comment.