diff --git a/json-tg.c b/json-tg.c index a58e70a..8395d6d 100644 --- a/json-tg.c +++ b/json-tg.c @@ -233,6 +233,41 @@ json_t *json_pack_media (struct tgl_message_media *M) { case tgl_message_media_video: case tgl_message_media_document_encr: assert (json_object_set (res, "type", json_string ("document")) >= 0); + if (M->type == tgl_message_media_document){ + assert (M->document); + if (M->document->flags & TGLDF_IMAGE) { + assert (json_object_set (res, "media", json_string ("image")) >= 0); + } else if (M->document->flags & TGLDF_AUDIO) { + assert (json_object_set (res, "media", json_string ("audio")) >= 0); + } else if (M->document->flags & TGLDF_VIDEO) { + assert (json_object_set (res, "media", json_string ("video")) >= 0); + } else if (M->document->flags & TGLDF_STICKER) { + assert (json_object_set (res, "media", json_string ("sticker")) >= 0); + } else { + assert (json_object_set (res, "media", json_string ("document")) >= 0); + } + if (M->document->caption && strlen (M->document->caption)) { + assert (json_object_set (res, "dcaption", json_string (M->document->caption)) >= 0); + } + + if (M->document->mime_type) { + assert (json_object_set (res, "mime", json_string (M->document->mime_type)) >= 0); + } + + if (M->document->w && M->document->h) { + assert (json_object_set (res, "width", json_integer (M->document->w)) >= 0); + assert (json_object_set (res, "height", json_integer (M->document->h)) >= 0); + } + + if (M->document->duration) { + assert (json_object_set (res, "duration", json_integer (M->document->duration)) >= 0); + } + assert (json_object_set (res, "size", json_integer (M->document->size)) >= 0); + + if (M->caption) { + assert (json_object_set (res, "caption", json_string (M->caption)) >= 0); + } + } break; case tgl_message_media_unsupported: assert (json_object_set (res, "type", json_string ("unsupported")) >= 0);