Support for history retrieval threshold
Include option to define the maximum amount of days, for which the history should be fetched. Introduce 14 days as default, to reduce performance issues or crashes when the user hasn't been using telegram-purple for a long time.
This commit is contained in:
parent
b67c4115ff
commit
c375ed1df0
3 changed files with 35 additions and 5 deletions
|
@ -390,8 +390,9 @@ void on_ready (struct tgl_state *TLS) {
|
|||
purple_blist_add_group (tggroup, NULL);
|
||||
}
|
||||
|
||||
debug ("seq = %d, pts = %d", TLS->seq, TLS->pts);
|
||||
tgl_do_get_difference (TLS, 0, 0, 0);
|
||||
debug ("seq = %d, pts = %d, date = %d", TLS->seq, TLS->pts, TLS->date);
|
||||
tgl_do_get_difference (TLS, purple_account_get_bool (conn->pa, "history-sync-all", FALSE),
|
||||
NULL, NULL);
|
||||
tgl_do_get_dialog_list (TLS, 0, 0);
|
||||
tgl_do_update_contact_list (TLS, 0, 0);
|
||||
}
|
||||
|
@ -830,10 +831,20 @@ static void tgprpl_init (PurplePlugin *plugin) {
|
|||
opt = purple_account_option_list_new("Accept Secret Chats", "accept-secret-chats", verification_values);
|
||||
prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, opt);
|
||||
|
||||
opt = purple_account_option_int_new ("Split oversized messages in up to (N) chunks.", "max-msg-split-count",
|
||||
TGP_DEFAULT_MAX_MSG_SPLIT_COUNT);
|
||||
opt = purple_account_option_int_new ("Split oversized messages in up to (N) chunks.",
|
||||
"max-msg-split-count",
|
||||
TGP_DEFAULT_MAX_MSG_SPLIT_COUNT);
|
||||
prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, opt);
|
||||
|
||||
opt = purple_account_option_int_new ("Don't fetch messages older than (N) days.\n"
|
||||
"Set 0 for unlimited.",
|
||||
"history-retrieve-days",
|
||||
TGP_DEFAULT_HISTORY_RETRIEVAL_THRESHOLD);
|
||||
prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, opt);
|
||||
|
||||
opt = purple_account_option_bool_new ("Fetch past history on first login.\n"
|
||||
"Can be very slow on big histories.",
|
||||
"history-sync-all", FALSE);
|
||||
_telegram_protocol = plugin;
|
||||
}
|
||||
|
||||
|
|
|
@ -38,6 +38,8 @@
|
|||
|
||||
#define TGP_MAX_MSG_SIZE 4096
|
||||
#define TGP_DEFAULT_MAX_MSG_SPLIT_COUNT 4
|
||||
#define TGP_DEFAULT_HISTORY_RETRIEVAL_THRESHOLD 14
|
||||
|
||||
void on_chat_get_info (struct tgl_state *TLS, void *extra, int success, struct tgl_chat *C);
|
||||
void on_ready (struct tgl_state *TLS);
|
||||
extern const char *pk_path;
|
||||
|
|
19
tgp-msg.c
19
tgp-msg.c
|
@ -168,7 +168,7 @@ static void tgp_msg_send_done (struct tgl_state *TLS, void *callback_extra, int
|
|||
static int tgp_msg_send_split (struct tgl_state *TLS, const char *message, tgl_peer_id_t to) {
|
||||
connection_data *data = TLS->ev_base;
|
||||
int max = purple_account_get_int (data->pa, "max-msg-split-count",
|
||||
TGP_DEFAULT_HISTORY_RETRIEVAL_THRESHOLD);
|
||||
TGP_DEFAULT_MAX_MSG_SPLIT_COUNT);
|
||||
if (max < 1) {
|
||||
max = 1;
|
||||
}
|
||||
|
@ -346,6 +346,18 @@ static void tgp_msg_display (struct tgl_state *TLS, struct tgp_msg_loading *C) {
|
|||
g_free (text);
|
||||
}
|
||||
|
||||
static time_t tgp_msg_oldest_relevant_ts (struct tgl_state *TLS) {
|
||||
connection_data *conn = TLS->ev_base;
|
||||
time_t now;
|
||||
time (&now);
|
||||
int daysAgo = purple_account_get_int (conn->pa, "history-retrieve-days",
|
||||
TGP_DEFAULT_HISTORY_RETRIEVAL_THRESHOLD);
|
||||
if (daysAgo == 0) {
|
||||
return 0;
|
||||
}
|
||||
return now - 24 * 3600 * (time_t)daysAgo;
|
||||
}
|
||||
|
||||
static void tgp_msg_process_ready (struct tgl_state *TLS)
|
||||
{
|
||||
connection_data *conn = TLS->ev_base;
|
||||
|
@ -373,6 +385,11 @@ void tgp_msg_recv (struct tgl_state *TLS, struct tgl_message *M)
|
|||
connection_data *conn = TLS->ev_base;
|
||||
struct tgp_msg_loading *C = tgp_msg_loading_init (TRUE, M);
|
||||
|
||||
if (M->date != 0 && M->date < tgp_msg_oldest_relevant_ts (TLS)) {
|
||||
debug ("Message from %d on %d too old, ignored.", tgl_get_peer_id (M->from_id), M->date);
|
||||
return;
|
||||
}
|
||||
|
||||
if (M->media.type == tgl_message_media_photo) {
|
||||
C->done = FALSE;
|
||||
tgl_do_load_photo (TLS, &M->media.photo, tgp_msg_on_loaded_photo, C);
|
||||
|
|
Loading…
Add table
Reference in a new issue