Update to libtgl v2

This commit is contained in:
mjentsch 2015-05-23 00:18:26 +02:00
parent 6614c25cbc
commit b415bbd3b4
11 changed files with 99 additions and 93 deletions

View file

@ -35,7 +35,7 @@ include ${srcdir}/Makefile.tl-parser
include ${srcdir}/Makefile.tgl
create_dirs: ${DIR_LIST}
create_dirs_and_headers: ${DIR_LIST} ${AUTO}/auto.c ${AUTO}/auto-header.h ${AUTO}/constants.h
create_dirs_and_headers: ${DIR_LIST} ${AUTO}/auto-skip.h ${AUTO}/auto-fetch.h ${AUTO}/auto-store.h ${AUTO}/auto-types.h
${DIR_LIST}:
@test -d $@ || mkdir -p $@

View file

@ -1,27 +1,32 @@
TGL_OBJECTS=${OBJ}/mtproto-common.o ${OBJ}/mtproto-client.o ${OBJ}/queries.o ${OBJ}/structures.o ${OBJ}/binlog.o ${OBJ}/tgl.o ${OBJ}/updates.o ${OBJ}/tg-mime-types.o ${OBJ}/mtproto-utils.o
TGL_OBJECTS=${OBJ}/mtproto-common.o ${OBJ}/mtproto-client.o ${OBJ}/queries.o ${OBJ}/structures.o ${OBJ}/binlog.o ${OBJ}/tgl.o ${OBJ}/updates.o ${OBJ}/tgl-net.o ${OBJ}/tgl-timers.o ${OBJ}/tg-mime-types.o ${OBJ}/mtproto-utils.o
TGL_OBJECTS_AUTO=${OBJ}/auto/auto-skip.o ${OBJ}/auto/auto-fetch.o ${OBJ}/auto/auto-store.o ${OBJ}/auto/auto-autocomplete.o ${OBJ}/auto/auto-types.o ${OBJ}/auto/auto-fetch-ds.o ${OBJ}/auto/auto-free-ds.o ${OBJ}/auto/auto-store-ds.o ${OBJ}/auto/auto-print-ds.o
TLD_OBJECTS=${OBJ}/dump-tl-file.o
GENERATE_OBJECTS=${OBJ}/generate.o
TGL_COMMON_OBJECTS=${OBJ}/tools.o
TGL_OBJ_C=${GENERATE_OBJECTS} ${TGL_COMMON_OBJECTS} ${TGL_OBJECTS} ${TLD_OBJECTS}
ALL_OBJS+=${TGL_OBJ_C}
.SUFFIXES:
.SUFFIXES: .c .h .o
dump-tl: ${EXE}/dump-tl-file
${OBJ}/auto/auto.o ${TGL_OBJECTS}: ${AUTO}/constants.h ${AUTO}/auto-header.h
${TGL_OBJECTS}: ${AUTO}/constants.h ${AUTO}/auto-skip.h ${AUTO}/auto-fetch.h ${AUTO}/auto-store.h ${AUTO}/auto-autocomplete.h ${AUTO}/auto-types.h ${AUTO}/auto-fetch-ds.h ${AUTO}/auto-free-ds.h ${AUTO}/auto-store-ds.h ${AUTO}/auto-print-ds.h
${TGL_OBJ_C}: ${OBJ}/%.o: ${srcdir}/tgl/%.c | create_dirs
${CC} ${INCLUDE} ${COMPILE_FLAGS} -iquote ${srcdir}/tgl -c -MP -MD -MF ${DEP}/$*.d -MQ ${OBJ}/$*.o -o $@ $<
${OBJ}/auto/auto.o: ${AUTO}/auto.c
${CC} ${INCLUDE} ${COMPILE_FLAGS} -iquote ${srcdir}/tgl -c -MP -MD -MF ${DEP}/auto/auto.d -MQ ${OBJ}/auto/auto.o -o $@ $<
${TGL_OBJECTS_AUTO}: ${OBJ}/auto/%.o: ${AUTO}/%.c | create_dirs
${CC} ${INCLUDE} ${COMPILE_FLAGS} -iquote ${srcdir}/tgl -c -MP -MD -MF ${DEP}/$*.d -MQ ${OBJ}/$*.o -o $@ $<
${LIB}/libtgl.a: ${TGL_OBJECTS} ${TGL_COMMON_OBJECTS} ${OBJ}/auto/auto.o
ar ruv $@ $^
#${OBJ}/auto/auto.o: ${AUTO}/auto.c
# ${CC} ${INCLUDE} ${COMPILE_FLAGS} -iquote ${srcdir}/tgl -c -MP -MD -MF ${DEP}/auto/auto.d -MQ ${OBJ}/auto/auto.o -o $@ $<
${LIB}/libtgl.a: ${TGL_OBJECTS} ${TGL_COMMON_OBJECTS} ${TGL_OBJECTS_AUTO}
rm -f $@ && ar ruv $@ $^
${EXE}/generate: ${GENERATE_OBJECTS} ${TGL_COMMON_OBJECTS}
${CC} ${GENERATE_OBJECTS} ${TGL_COMMON_OBJECTS} ${LINK_FLAGS} -o $@
@ -35,11 +40,11 @@ ${AUTO}/scheme.tl: ${srcdir}/tgl/scheme.tl ${srcdir}/tgl/encrypted_scheme.tl ${s
${AUTO}/scheme2.tl: ${AUTO}/scheme.tl ${EXE}/tl-parser
${EXE}/tl-parser -E ${AUTO}/scheme.tl 2> $@ || ( cat $@ && rm $@ && false )
${AUTO}/auto.c: ${AUTO}/scheme.tlo ${EXE}/generate
${EXE}/generate ${AUTO}/scheme.tlo > $@
${AUTO}/auto-%.c: ${AUTO}/scheme.tlo ${EXE}/generate auto/constants.h ${AUTO}/auto-%.h | create_dirs_and_headers
${EXE}/generate -g $(patsubst ${AUTO}/auto-%.c,%,$@) ${AUTO}/scheme.tlo > $@ || rm $@
${AUTO}/auto-header.h: ${AUTO}/scheme.tlo ${EXE}/generate
${EXE}/generate -H ${AUTO}/scheme.tlo > $@
${AUTO}/auto-%.h: ${AUTO}/scheme.tlo ${EXE}/generate
${EXE}/generate -g $(patsubst ${AUTO}/auto-%.h,%-header,$@) ${AUTO}/scheme.tlo > $@ || rm $@
${AUTO}/constants.h: ${AUTO}/scheme2.tl ${srcdir}/tgl/gen_constants_h.awk
awk -f ${srcdir}/tgl/gen_constants_h.awk < $< > $@

View file

@ -97,6 +97,7 @@
C4B4BE351AB5FB5C0064AC17 /* TelegramJoinChatViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TelegramJoinChatViewController.m; sourceTree = "<group>"; };
C4B4BE361AB5FB5C0064AC17 /* TelegramJoinChatViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TelegramJoinChatViewController.h; sourceTree = "<group>"; };
C4B4BE381AB613950064AC17 /* TelegramJoinChatView.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = TelegramJoinChatView.xib; sourceTree = "<group>"; };
C4C8672D1B0A6EFA00C2770C /* auto-types.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "auto-types.h"; path = "../auto/auto-types.h"; sourceTree = "<group>"; };
C4D819011A5C85FE0044CBA9 /* lodepng.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = lodepng.c; sourceTree = "<group>"; };
C4D819021A5C85FE0044CBA9 /* lodepng.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = lodepng.h; sourceTree = "<group>"; };
C4D819041A5C862E0044CBA9 /* tgp-structs.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = "tgp-structs.c"; path = "../tgp-structs.c"; sourceTree = "<group>"; };
@ -232,6 +233,7 @@
C431EB7C1A76C737006521CB /* tgp-chat.h */,
C4E5280F1A8A907200C4B915 /* tgp-ft.c */,
C4E528101A8A907200C4B915 /* tgp-ft.h */,
C4C8672D1B0A6EFA00C2770C /* auto-types.h */,
);
name = "telegram-purple";
sourceTree = "<group>";
@ -446,6 +448,7 @@
"$(PROJECT_DIR)/Frameworks/Adium/libpurple.framework/Headers",
"$(PROJECT_DIR)/Frameworks/Adium/libglib.framework/Headers",
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include,
"$(PROJECT_DIR)/../auto",
);
INFOPLIST_FILE = "telegram-adium/telegram-adium-Info.plist";
INSTALL_PATH = "$(HOME)/Library/Application Support/Adium 2.0/PlugIns/";
@ -481,6 +484,7 @@
"$(PROJECT_DIR)/Frameworks/Adium/libpurple.framework/Headers",
"$(PROJECT_DIR)/Frameworks/Adium/libglib.framework/Headers",
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include,
"$(PROJECT_DIR)/../auto",
);
INFOPLIST_FILE = "telegram-adium/telegram-adium-Info.plist";
INSTALL_PATH = "$(HOME)/Library/Application Support/Adium 2.0/PlugIns/";

View file

@ -28,6 +28,7 @@
#include <tgl.h>
#include <tgl-binlog.h>
#include <tgl-methods-in.h>
#include <glib.h>
#include <request.h>
@ -137,7 +138,7 @@ void write_dc (struct tgl_dc *DC, void *extra) {
assert (write (auth_file_fd, &x, 4) == 4);
}
assert (DC->has_auth);
assert (DC->flags & TGLDCF_LOGGED_IN);
assert (write (auth_file_fd, &DC->port, 4) == 4);
int l = strlen (DC->ip);
@ -181,8 +182,8 @@ void read_dc (struct tgl_state *TLS, int auth_file_fd, int id, unsigned ver) {
assert (read (auth_file_fd, &auth_key_id, 8) == 8);
assert (read (auth_file_fd, auth_key, 256) == 256);
bl_do_dc_option (TLS, id, 2, "DC", l, ip, port);
bl_do_set_auth_key_id (TLS, id, auth_key);
bl_do_dc_option (TLS, id, "DC", 2, ip, l, port);
bl_do_set_auth_key (TLS, id, auth_key);
bl_do_dc_signed (TLS, id);
}
@ -200,16 +201,16 @@ int error_if_val_false (struct tgl_state *TLS, int val, const char *cause, const
void empty_auth_file (struct tgl_state *TLS) {
if (TLS->test_mode) {
bl_do_dc_option (TLS, 1, 0, "", strlen (TG_SERVER_TEST_1), TG_SERVER_TEST_1, 443);
bl_do_dc_option (TLS, 2, 0, "", strlen (TG_SERVER_TEST_2), TG_SERVER_TEST_2, 443);
bl_do_dc_option (TLS, 3, 0, "", strlen (TG_SERVER_TEST_3), TG_SERVER_TEST_3, 443);
bl_do_dc_option (TLS, 1, "", 0, TG_SERVER_TEST_1, strlen (TG_SERVER_TEST_1), 443);
bl_do_dc_option (TLS, 2, "", 0, TG_SERVER_TEST_2, strlen (TG_SERVER_TEST_2), 443);
bl_do_dc_option (TLS, 3, "", 0, TG_SERVER_TEST_3, strlen (TG_SERVER_TEST_3), 443);
bl_do_set_working_dc (TLS, TG_SERVER_TEST_DEFAULT);
} else {
bl_do_dc_option (TLS, 1, 0, "", strlen (TG_SERVER_1), TG_SERVER_1, 443);
bl_do_dc_option (TLS, 2, 0, "", strlen (TG_SERVER_2), TG_SERVER_2, 443);
bl_do_dc_option (TLS, 3, 0, "", strlen (TG_SERVER_3), TG_SERVER_3, 443);
bl_do_dc_option (TLS, 4, 0, "", strlen (TG_SERVER_4), TG_SERVER_4, 443);
bl_do_dc_option (TLS, 5, 0, "", strlen (TG_SERVER_5), TG_SERVER_5, 443);
bl_do_dc_option (TLS, 1, "", 0, TG_SERVER_1, strlen (TG_SERVER_1), 443);
bl_do_dc_option (TLS, 2, "", 0, TG_SERVER_2, strlen (TG_SERVER_2), 443);
bl_do_dc_option (TLS, 3, "", 0, TG_SERVER_3, strlen (TG_SERVER_3), 443);
bl_do_dc_option (TLS, 4, "", 0, TG_SERVER_4, strlen (TG_SERVER_4), 443);
bl_do_dc_option (TLS, 5, "", 0, TG_SERVER_5, strlen (TG_SERVER_5), 443);
bl_do_set_working_dc (TLS, TG_SERVER_DEFAULT);
}
}
@ -333,6 +334,8 @@ void read_secret_chat (struct tgl_state *TLS, int fd, int v) {
assert (read (fd, &key, 256) == 256);
if (v >= 2) {
assert (read (fd, sha, 20) == 20);
} else {
SHA1 ((void *)key, 256, sha);
}
int in_seq_no = 0, out_seq_no = 0, last_in_seq_no = 0;
if (v >= 1) {
@ -340,25 +343,10 @@ void read_secret_chat (struct tgl_state *TLS, int fd, int v) {
assert (read (fd, &last_in_seq_no, 4) == 4);
assert (read (fd, &out_seq_no, 4) == 4);
}
bl_do_encr_chat_create (TLS, id, user_id, admin_id, s, l);
struct tgl_secret_chat *P = (void *)tgl_peer_get (TLS, TGL_MK_ENCR_CHAT (id));
assert (P && (P->flags & FLAG_CREATED));
bl_do_encr_chat_set_date (TLS, P, date);
bl_do_encr_chat_set_ttl (TLS, P, ttl);
bl_do_encr_chat_set_layer (TLS ,P, layer);
bl_do_encr_chat_set_state (TLS, P, state);
bl_do_encr_chat_set_key (TLS, P, key, key_fingerprint);
if (v >= 2) {
bl_do_encr_chat_set_sha (TLS, P, sha);
} else {
SHA1 ((void *)key, 256, sha);
bl_do_encr_chat_set_sha (TLS, P, sha);
}
if (v >= 1) {
bl_do_encr_chat_set_seq (TLS, P, in_seq_no, last_in_seq_no, out_seq_no);
}
bl_do_encr_chat_set_access_hash (TLS, P, access_hash);
bl_do_encr_chat_new(TLS, id, &access_hash, &date, &admin_id, &user_id, &admin_id,
key, NULL, &state, &ttl, &layer, &in_seq_no, &last_in_seq_no,
&out_seq_no, &key_fingerprint, TGLECF_CREATE | TGLECF_CREATED);
}
void read_secret_chat_file (struct tgl_state *TLS) {
@ -432,7 +420,7 @@ void telegram_export_authorization (struct tgl_state *TLS) {
int i;
for (i = 0; i <= TLS->max_dc_num; i++) if (TLS->DC_list[i] && !tgl_signed_dc (TLS, TLS->DC_list[i])) {
debug ("tgl_do_export_auth(%d)", i);
tgl_do_export_auth (TLS, i, export_auth_callback, (void*)(long)TLS->DC_list[i]);
tgl_do_export_auth (TLS, i, export_auth_callback, (void*)(long)TLS->DC_list[i]);
return;
}
write_auth_file (TLS);
@ -463,7 +451,9 @@ void request_code_entered (gpointer data, const gchar *code) {
struct tgl_state *TLS = data;
connection_data *conn = TLS->ev_base;
char const *username = purple_account_get_username(conn->pa);
tgl_do_send_code_result (TLS, username, conn->hash, code, code_receive_result, 0) ;
tgl_do_send_code_result (TLS, username, (int)strlen (username), conn->hash,
(int)strlen (conn->hash), code, (int)strlen (code),
code_receive_result, 0);
}
static void request_code_canceled (gpointer data) {
@ -486,8 +476,11 @@ static void request_name_code_entered (PurpleConnection* gc, PurpleRequestFields
request_name_and_code (TLS);
return;
}
tgl_do_send_code_result_auth (TLS, username, conn->hash, code, first, last, code_auth_receive_result, NULL);
tgl_do_send_code_result_auth(TLS, username, (int)strlen(username), conn->hash,
(int)strlen (conn->hash), code, (int)strlen (code), first,
(int)strlen (first), last, (int)strlen (last),
code_auth_receive_result, NULL);
}
static void request_code (struct tgl_state *TLS) {
@ -600,7 +593,7 @@ static void telegram_send_sms (struct tgl_state *TLS) {
}
connection_data *conn = TLS->ev_base;
char const *username = purple_account_get_username(conn->pa);
tgl_do_send_code (TLS, username, sign_in_callback, 0);
tgl_do_send_code (TLS, username, (int) strlen(username), sign_in_callback, NULL);
}
static int all_authorized (struct tgl_state *TLS) {

View file

@ -59,6 +59,7 @@
#include <tgl.h>
#include <tgl-binlog.h>
#include <tools.h>
#include <tgl-methods-in.h>
#include "tgp-structs.h"
#include "tgp-2prpl.h"
#include "tgp-net.h"
@ -261,7 +262,7 @@ static void on_contact_added (struct tgl_state *TLS,void *callback_extra, int su
}
}
static void on_userpic_loaded (struct tgl_state *TLS, void *extra, int success, char *filename) {
static void on_userpic_loaded (struct tgl_state *TLS, void *extra, int success, const char *filename) {
connection_data *conn = TLS->ev_base;
struct download_desc *dld = extra;
@ -299,8 +300,8 @@ void on_user_get_info (struct tgl_state *TLS, void *info_data, int success, stru
warning ("on_user_get_info not successfull, aborting...");
return;
}
if (U->photo.sizes_num == 0) {
if (!U->photo || U->photo->sizes_num == 0) {
// No profile pic to load, display it right away
if (user_info_data->show_info) {
PurpleNotifyUserInfo *info = p2tgl_notify_peer_info_new (TLS, P);
@ -312,7 +313,7 @@ void on_user_get_info (struct tgl_state *TLS, void *info_data, int success, stru
struct download_desc *dld = malloc (sizeof(struct download_desc));
dld->data = U;
dld->get_user_info_data = info_data;
tgl_do_load_photo (TLS, &U->photo, on_userpic_loaded, dld);
tgl_do_load_photo (TLS, U->photo, on_userpic_loaded, dld);
}
}
@ -342,11 +343,11 @@ void on_ready (struct tgl_state *TLS) {
tggroup = purple_group_new ("Telegram");
purple_blist_add_group (tggroup, NULL);
}
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_get_dialog_list (TLS, 0, 0, NULL, NULL);
tgl_do_update_contact_list (TLS, 0, 0);
}

2
tgl

@ -1 +1 @@
Subproject commit 5e36b2bc84f47656eb82bb0039dadb4c5133c996
Subproject commit b3dcce35110f5c995366318c2886065287815d09

View file

@ -30,7 +30,7 @@
static void tgprpl_xfer_free_data (struct tgp_xfer_send_data *data);
static void tgprpl_xfer_recv_on_finished (struct tgl_state *TLS, void *_data, int success, char *filename) {
static void tgprpl_xfer_recv_on_finished (struct tgl_state *TLS, void *_data, int success, const char *filename) {
debug ("tgprpl_xfer_recv_on_finished()");
struct tgp_xfer_send_data *data = _data;
@ -43,7 +43,7 @@ static void tgprpl_xfer_recv_on_finished (struct tgl_state *TLS, void *_data, in
}
g_unlink (purple_xfer_get_local_filename (data->xfer));
g_rename (filename, purple_xfer_get_local_filename(data->xfer));
g_rename (filename, purple_xfer_get_local_filename (data->xfer));
} else {
failure ("ERROR xfer failed");
@ -154,7 +154,8 @@ static void tgprpl_xfer_send_init (PurpleXfer *X) {
tgl_peer_t *P = find_peer_by_name (data->conn->TLS, who);
if (P) {
tgl_do_send_document (data->conn->TLS, -2, P->id, (char*)localfile, tgprpl_xfer_on_finished, data);
tgl_do_send_document (data->conn->TLS, P->id, (char*) localfile, NULL,
0, TGL_SEND_MSG_FLAG_DOCUMENT_AUTO, tgprpl_xfer_on_finished, data);
}
data->timer = purple_timeout_add (100, tgprpl_xfer_upload_progress, X);

View file

@ -36,7 +36,7 @@
static void tgp_msg_err_out (struct tgl_state *TLS, const char *error, tgl_peer_id_t to);
static char *format_service_msg (struct tgl_state *TLS, struct tgl_message *M) {
assert (M && M->service);
assert (M && M->flags & TGLMF_SERVICE);
char *txt_user = NULL;
char *txt_action = NULL;
char *txt = NULL;
@ -128,9 +128,6 @@ static char *format_document_desc (char *type, char *caption, gint64 size) {
static char *format_message (struct tgl_message *M) {
switch (M->media.type) {
case tgl_message_media_photo_encr:
return format_document_desc ("ENCRYPTED PHOTO", "(not yet supported)", M->media.encr_photo.size);
break;
case tgl_message_media_contact:
return g_strdup_printf ("<b>%s %s</b><br>%s", M->media.first_name, M->media.last_name, M->media.phone);
break;
@ -163,10 +160,12 @@ static gboolean tgp_msg_send_schedule_cb (gpointer data) {
connection_data *conn = data;
conn->out_timer = 0;
struct tgp_msg_sending *D = NULL;
while ((D = g_queue_peek_head (conn->out_messages))) {
g_queue_pop_head (conn->out_messages);
tgl_do_send_message (D->TLS, D->to, D->msg, (int)strlen (D->msg), tgp_msg_send_done, NULL);
// TODO: option for disable_msg_preview
tgl_do_send_message(D->TLS, D->to, D->msg, (int)strlen (D->msg), 0, tgp_msg_send_done, NULL);
tgp_msg_sending_free (D);
}
return FALSE;
@ -235,18 +234,20 @@ int tgp_msg_send (struct tgl_state *TLS, const char *message, tgl_peer_id_t to)
gconstpointer data = purple_imgstore_get_data (psi);
g_file_set_contents (tmp, data, purple_imgstore_get_size (psi), &err);
if (! err) {
tgl_do_send_document (TLS, -2, to, tmp, tgp_msg_send_done, NULL);
stripped = purple_markup_strip_html (message);
tgl_do_send_document (TLS, to, tmp, stripped, (int)strlen (stripped), TGL_SEND_MSG_FLAG_DOCUMENT_AUTO,
tgp_msg_send_done, NULL);
g_free (stripped);
return 1;
} else {
failure ("Cannot store image, temp directory not available: %s\n", err->message);
g_error_free (err);
return 0;
}
}
}
// send remaining text as additional plaintext message
stripped = purple_markup_strip_html (message);
int ret = tgp_msg_send_split (TLS, stripped, to);
g_free (stripped);
return ret;
// no image id found in image
return 0;
}
#ifndef __ADIUM_
@ -280,33 +281,32 @@ static void tgp_msg_display (struct tgl_state *TLS, struct tgp_msg_loading *C) {
struct tgl_message *M = C->msg;
char *text = NULL;
int flags = 0;
// Filter message updates and deletes, are not created and
// all messages in general that were already displayed, or shouldn't be displayed
if ((M->flags & (FLAG_MESSAGE_EMPTY | FLAG_DELETED)) ||
!(M->flags & FLAG_CREATED) ||
// only display new messages, ignore updates or deletions
if ((M->flags & (TGLMF_EMPTY | TGLMF_DELETED)) ||
!(M->flags & TGLMF_CREATED) ||
!M->message ||
our_msg (TLS, M) ||
tgp_outgoing_msg (TLS, M) ||
!tgl_get_peer_type (M->to_id)) {
return;
}
if (M->service) {
if (M->flags & TGLMF_SERVICE) {
text = format_service_msg (TLS, M);
flags |= PURPLE_MESSAGE_SYSTEM;
}
else if (M->media.type == tgl_message_media_document) {
char *who = p2tgl_strdup_id (M->from_id);
if (! out_msg(TLS, M)) {
tgprpl_recv_file (conn->gc, who, &M->media.document);
if (! tgp_our_msg(TLS, M)) {
tgprpl_recv_file (conn->gc, who, M->media.document);
}
g_free (who);
return;
}
else if (M->media.type == tgl_message_media_document_encr) {
char *who = p2tgl_strdup_id (M->from_id);
if (! out_msg(TLS, M)) {
tgprpl_recv_encr_file (conn->gc, who, &M->media.encr_document);
if (! tgp_our_msg(TLS, M)) {
tgprpl_recv_encr_file (conn->gc, who, M->media.encr_document);
}
g_free (who);
}
@ -344,7 +344,7 @@ static void tgp_msg_display (struct tgl_state *TLS, struct tgp_msg_loading *C) {
break;
}
case TGL_PEER_USER: {
if (out_msg (TLS, M)) {
if (tgp_our_msg (TLS, M)) {
flags |= PURPLE_MESSAGE_SEND;
flags &= ~PURPLE_MESSAGE_RECV;
p2tgl_got_im_combo (TLS, M->to_id, text, flags, M->date);
@ -384,9 +384,9 @@ static void tgp_msg_process_in_ready (struct tgl_state *TLS) {
}
}
static void tgp_msg_on_loaded_photo (struct tgl_state *TLS, void *extra, int success, char *filename) {
static void tgp_msg_on_loaded_photo (struct tgl_state *TLS, void *extra, int success, const char *filename) {
struct tgp_msg_loading *C = extra;
C->data = filename;
C->data = (void *)filename;
C->done = TRUE;
tgp_msg_process_in_ready (TLS);
}
@ -401,7 +401,7 @@ void tgp_msg_recv (struct tgl_state *TLS, struct tgl_message *M) {
}
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);
tgl_do_load_photo (TLS, M->media.photo, tgp_msg_on_loaded_photo, C);
}
if (M->media.type == tgl_message_media_geo) {
// TODO: load geo thumbnail

View file

@ -46,6 +46,8 @@
#include "telegram-base.h"
#include <tgl.h>
#include <tgl-inner.h>
#include <tools.h>
#include <mtproto-client.h>
#include <glib.h>
#include <eventloop.h>

View file

@ -68,12 +68,12 @@ int str_not_empty (const char *string) {
return string && string[0] != '\0';
}
int our_msg (struct tgl_state *TLS, struct tgl_message *M) {
return (M->flags & FLAG_SESSION_OUTBOUND) != 0;
int tgp_outgoing_msg (struct tgl_state *TLS, struct tgl_message *M) {
return (M->flags & TGLMF_OUT);
}
int out_msg (struct tgl_state *TLS, struct tgl_message *M) {
return M->out;
int tgp_our_msg (struct tgl_state *TLS, struct tgl_message *M) {
return TLS->our_id == tgl_get_peer_id(M->from_id);
}
tgl_peer_t *find_peer_by_name (struct tgl_state *TLS, const char *who) {

View file

@ -34,12 +34,12 @@ tgl_peer_t *find_peer_by_name (struct tgl_state *TLS, const char *who);
/**
* Return whether this message was created by our client in this session
*/
int our_msg (struct tgl_state *TLS, struct tgl_message *M);
int tgp_outgoing_msg (struct tgl_state *TLS, struct tgl_message *M);
/**
* Return whether this message was created by the current user.
* Return whether this message was created by the current user
*/
int out_msg (struct tgl_state *TLS, struct tgl_message *M);
int tgp_our_msg (struct tgl_state *TLS, struct tgl_message *M);
const char *format_time (time_t date);
char *format_img_full (int imgstore);