Auto-load audio, video and animated messages up to 8mb
Reduce the amount of annoying popup messages for file transfers. Don't do it for Adium, which doesn't support file-links for security reasons. Make the threshold configurable.
This commit is contained in:
parent
921db6bc5c
commit
e73e247444
5 changed files with 68 additions and 11 deletions
|
@ -820,6 +820,11 @@ static void tgprpl_init (PurplePlugin *plugin) {
|
|||
TGP_KEY_HISTORY_RETRIEVAL_THRESHOLD, TGP_DEFAULT_HISTORY_RETRIEVAL_THRESHOLD);
|
||||
prpl_info.protocol_options = g_list_append (prpl_info.protocol_options, opt);
|
||||
|
||||
// Media
|
||||
opt = purple_account_option_int_new (_("Autoload media size (kb)"), TGP_KEY_MEDIA_SIZE,
|
||||
TGP_DEFAULT_MEDIA_SIZE);
|
||||
prpl_info.protocol_options = g_list_append (prpl_info.protocol_options, opt);
|
||||
|
||||
// Chats
|
||||
opt = purple_account_option_bool_new (_("Add all group chats to buddy list"),
|
||||
TGP_KEY_JOIN_GROUP_CHATS, TGP_DEFAULT_JOIN_GROUP_CHATS);
|
||||
|
|
|
@ -67,6 +67,9 @@
|
|||
#define TGP_MAX_MSG_SIZE 4096
|
||||
#define TGP_DEFAULT_MAX_MSG_SPLIT_COUNT 4
|
||||
|
||||
#define TGP_DEFAULT_MEDIA_SIZE 8192
|
||||
#define TGP_KEY_MEDIA_SIZE "media-size-threshold"
|
||||
|
||||
#define TGP_KEY_PASSWORD_TWO_FACTOR "password-two-factor"
|
||||
|
||||
#define TGP_DEFAULT_ACCEPT_SECRET_CHATS "ask"
|
||||
|
|
|
@ -36,6 +36,11 @@ connection_data *tls_get_data (struct tgl_state *TLS) {
|
|||
return TLS->ev_base;
|
||||
}
|
||||
|
||||
int tls_get_media_threshold (struct tgl_state *TLS) {
|
||||
return purple_account_get_int (tls_get_pa (TLS),
|
||||
TGP_KEY_MEDIA_SIZE, TGP_DEFAULT_MEDIA_SIZE) << 10;
|
||||
}
|
||||
|
||||
connection_data *gc_get_data (PurpleConnection *gc) {
|
||||
return purple_connection_get_protocol_data (gc);
|
||||
}
|
||||
|
|
|
@ -27,6 +27,7 @@
|
|||
PurpleAccount *tls_get_pa (struct tgl_state *TLS);
|
||||
PurpleConnection *tls_get_conn (struct tgl_state *TLS);
|
||||
connection_data *tls_get_data (struct tgl_state *TLS);
|
||||
int tls_get_media_threshold (struct tgl_state *TLS);
|
||||
connection_data *gc_get_data (PurpleConnection *gc);
|
||||
connection_data *pa_get_data (PurpleAccount *pa);
|
||||
connection_data *pbn_get_data (PurpleBlistNode *node);
|
||||
|
|
65
tgp-msg.c
65
tgp-msg.c
|
@ -379,6 +379,15 @@ int tgp_msg_send (struct tgl_state *TLS, const char *message, tgl_peer_id_t to)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static char *tgp_msg_file_display (const char *filename, const char *caption) {
|
||||
#ifndef __ADIUM_
|
||||
return g_strdup_printf ("<a href=\"file:///%s\">%s</a>", g_markup_escape_text (filename, -1),
|
||||
g_markup_escape_text (caption, -1));
|
||||
#else
|
||||
return g_strdup_printf ("file:///%s", g_uri_escape_string (filename, NULL, TRUE));
|
||||
#endif
|
||||
}
|
||||
|
||||
static char *tgp_msg_photo_display (struct tgl_state *TLS, const char *filename, int *flags) {
|
||||
connection_data *conn = TLS->ev_base;
|
||||
int img = p2tgl_imgstore_add_with_id (filename);
|
||||
|
@ -416,7 +425,6 @@ static char *tgp_msg_sticker_display (struct tgl_state *TLS, tgl_peer_id_t from,
|
|||
}
|
||||
|
||||
static void tgp_msg_display (struct tgl_state *TLS, struct tgp_msg_loading *C) {
|
||||
connection_data *conn = TLS->ev_base;
|
||||
struct tgl_message *M = C->msg;
|
||||
char *text = NULL;
|
||||
int flags = 0;
|
||||
|
@ -490,21 +498,28 @@ static void tgp_msg_display (struct tgl_state *TLS, struct tgp_msg_loading *C) {
|
|||
if (M->media.document->flags & TGLDF_STICKER) {
|
||||
g_return_if_fail(C->data != NULL);
|
||||
text = tgp_msg_sticker_display (TLS, M->from_id, C->data, &flags);
|
||||
} else if (M->media.document->flags & TGLDF_ANIMATED && C->data) {
|
||||
text = tgp_msg_file_display (C->data, _("[animation]"));
|
||||
} else if (M->media.document->flags & TGLDF_IMAGE) {
|
||||
g_return_if_fail(C->data != NULL);
|
||||
text = tgp_msg_photo_display (TLS, C->data, &flags);
|
||||
} else {
|
||||
if (! tgp_our_msg(TLS, M)) {
|
||||
tgprpl_recv_file (conn->gc, tgp_blist_lookup_purple_name (TLS, M->from_id), M);
|
||||
if (! tgp_our_msg (TLS, M)) {
|
||||
tgprpl_recv_file (tls_get_conn (TLS), tgp_blist_lookup_purple_name (TLS, M->from_id), M);
|
||||
}
|
||||
return;
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
case tgl_message_media_video:
|
||||
case tgl_message_media_audio: {
|
||||
if (! tgp_our_msg(TLS, M)) {
|
||||
tgprpl_recv_file (conn->gc, tgp_blist_lookup_purple_name (TLS, M->from_id), M);
|
||||
if (! tgp_our_msg (TLS, M)) {
|
||||
if (C->data) {
|
||||
text = tgp_msg_file_display (C->data,
|
||||
M->media.type == tgl_message_media_audio ? _("[audio]") : _("[video]"));
|
||||
} else {
|
||||
tgprpl_recv_file (tls_get_conn (TLS), tgp_blist_lookup_purple_name (TLS, M->from_id), M);
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
@ -518,7 +533,7 @@ static void tgp_msg_display (struct tgl_state *TLS, struct tgp_msg_loading *C) {
|
|||
text = tgp_msg_photo_display (TLS, C->data, &flags);
|
||||
} else {
|
||||
if (! tgp_our_msg(TLS, M)) {
|
||||
tgprpl_recv_file (conn->gc, tgp_blist_lookup_purple_name (TLS, M->to_id), M);
|
||||
tgprpl_recv_file (tls_get_conn (TLS), tgp_blist_lookup_purple_name (TLS, M->to_id), M);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
@ -815,15 +830,43 @@ void tgp_msg_recv (struct tgl_state *TLS, struct tgl_message *M, GList *before)
|
|||
}
|
||||
|
||||
// documents that are stickers or images will be displayed just like regular photo messages
|
||||
// and need to be lodaed beforehand
|
||||
// and need to be loaded beforehand
|
||||
case tgl_message_media_document:
|
||||
case tgl_message_media_video:
|
||||
case tgl_message_media_audio:
|
||||
if (M->media.document->flags & TGLDF_STICKER || M->media.document->flags & TGLDF_IMAGE) {
|
||||
if (M->media.document->flags & (TGLDF_STICKER | TGLDF_IMAGE)) {
|
||||
++ C->pending;
|
||||
tgl_do_load_document (TLS, M->media.document, tgp_msg_on_loaded_document, C);
|
||||
} else if (M->media.document->flags & (TGLDF_ANIMATED | TGLDF_VIDEO | TGLDF_AUDIO)) {
|
||||
|
||||
// adium doesn't support file links, autoloading media would mean that it
|
||||
// wouldn't be possible to show a usable link to the user
|
||||
#ifndef __ADIUM_
|
||||
if (M->media.document->size <= tls_get_media_threshold (TLS)) { // 8mb auto loading threshold
|
||||
++ C->pending;
|
||||
if (M->media.document->flags & TGLDF_AUDIO) {
|
||||
tgl_do_load_audio (TLS, M->media.document, tgp_msg_on_loaded_document, C);
|
||||
} else if (M->media.document->flags & TGLDF_VIDEO) {
|
||||
tgl_do_load_video (TLS, M->media.document, tgp_msg_on_loaded_document, C);
|
||||
} else {
|
||||
tgl_do_load_document (TLS, M->media.document, tgp_msg_on_loaded_document, C);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
break;
|
||||
#ifndef __ADIUM_
|
||||
case tgl_message_media_video:
|
||||
if (M->media.document->size <= tls_get_media_threshold (TLS)) {
|
||||
++ C->pending;
|
||||
tgl_do_load_video (TLS, M->media.document, tgp_msg_on_loaded_document, C);
|
||||
}
|
||||
break;
|
||||
case tgl_message_media_audio:
|
||||
if (M->media.document->size <= tls_get_media_threshold (TLS)) {
|
||||
++ C->pending;
|
||||
tgl_do_load_audio (TLS, M->media.document, tgp_msg_on_loaded_document, C);
|
||||
}
|
||||
break;
|
||||
#endif
|
||||
case tgl_message_media_document_encr:
|
||||
if (M->media.encr_document->flags & TGLDF_STICKER || M->media.encr_document->flags & TGLDF_IMAGE) {
|
||||
++ C->pending;
|
||||
|
|
Loading…
Add table
Reference in a new issue