diff --git a/Makefile.in b/Makefile.in
index c7222ae..84cd60d 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -23,7 +23,7 @@ PLUGIN_OBJECTS=${OBJ}/tgp-net.o ${OBJ}/tgp-timers.o ${OBJ}/msglog.o ${OBJ}/teleg
ALL_OBJS=${PLUGIN_OBJECTS}
ifdef MSGFMT_PATH
-LOCALES=$(patsubst %.po, %.mo, $(wildcard po/*.po))
+LOCALES=$(addprefix po/,$(addsuffix .mo,$(shell cat po/LINGUAS)))
endif
.SUFFIXES:
diff --git a/README.md b/README.md
index 400fe4a..dc032f3 100644
--- a/README.md
+++ b/README.md
@@ -4,25 +4,34 @@ Telegram-Purple Unofficial (Beta)
Telegram-purple is a Libpurple protocol plugin that adds support for the Telegram messenger.
I keep getting many questions about this plugin in my E-mail, so I've created a
-[telegram group chat](https://telegram.me/joinchat/01fb53f301b67d3c7a5532908dfa9a89) for
+[telegram group chat](https://goo.gl/bhmM7N) for
telegram-purple related discussions or questions.
OS Support
----------
-This plugin is tested and works on **Linux** and **OS X**. As of right now, **Windows is not supported** although there's a plan to port it in the near future.
+This plugin is tested and works on **Linux** and **OS X**. Right now the Windows port is **still under development and needs some testing**, check out the discussion for the [pull request](https://github.com/majn/telegram-purple/pull/149) for additional info.
-1.2.2
+1.2.3
-----
- - fix some licensing issues by not depending on OpenSSL any longer (thanks Ben!)
- - add tons of translations (thanks to anyone helping!)
- - fix issue that caused empty files
- - fix pidgin not reconnecting after hibernation
- - fix adium not reconnecting after hibernation
- - fix secret chat fingerprint not being displayed after restart
- - fix secret chat name not being displayed after restart
+- Build: Allow compilation on Windows (#52 Thanks Rob!)
+- Build: Drop dependency on LodePNG (Thanks Ben!)
+- Build: Gettext is now optional
+- Fix issue that prevented to send messages to deleted users in certain cases (#174)
+- Fix own user being added to the buddy list in certain cases
+- Fix that read recipes of own messages are being displayed (#139)
+- Fix encoding inconsistencies with Unicode characters (#177)
+- Fix auto-joining for chats (#179)
+- Fix client not reconnecting anymore under certain circumstances (#173)
+- Fix crash on compat-verification (PullRequest #183)
+
+- Remove pointless "create chat" confirmation dialogue
+- Improve logging messages
+- Always send read recipes when the user is typing or sending a message
+- Improve translation and user messages (#139)
+- Use native password prompts (Adium)
Build
-----
@@ -237,13 +246,31 @@ You can also write your own conversion tool if you prefer. The format is really
If you are interested in developing a non-OpenSSL-licensed converter, look into [insane-triangle-banana](https://github.com/BenWiederhake/insane-triangle-banana).
+
+FAQ
+---
+
+- I receive pictures in a chat, but they aren't showing up
+ * A: Make sure that you don't have a plugin like "Conversation Colors" that strips HTML from messages and removes the pictures.
+
#### Group chat
Telegram group chat for telegram-purple or libtgl related discussions or questions:
- - https://telegram.me/joinchat/01fb53f301b67d3c7a5532908dfa9a89
+ - https://goo.gl/bhmM7N
+Submitting Bug Reports
+----------------------
+
+**IMPORTANT**: if you report bugs PLEASE make sure to always **include as much information as possible**. This should always include **at least the telegram-purple version and (if possible) commit**, where you got telegram-purple from (Source build, package repository, etc.), the Pidgin version (if you use a different messenger please state that too!) and your OS Version.
+
+If you describe some issue please be as precise as possible. Descriptions like "XY doesn't work" will not help me. Describe what you are doing what kind of issue you are experiencing: "If I click on X, Y happens, but instead I would expect Z to happen".
+
+For error reports please include the application logs. To get Pidgin to print a log, [start it from command line, specifying the -d option](https://developer.pidgin.im/wiki/GetABacktrace#TheEasyWay). **ATTENTION**: This log will contain personal information like your phone number, message content or contact or chat names. If you plan on uploading it somewhere public mask those entries in the log.
+
+Bug reports regarding crashes should include a backtrace if possible, there is extended documentation available on [how to get a backtrace for crashes](https://developer.pidgin.im/wiki/GetABacktrace)
+
Empathy / libtelepathy
----------------------
diff --git a/configure b/configure
index 85b5804..5abe643 100755
--- a/configure
+++ b/configure
@@ -1,6 +1,6 @@
#! /bin/sh
# Guess values for system-dependent variables and create Makefiles.
-# Generated by GNU Autoconf 2.69 for telegram-purple 1.2.2.
+# Generated by GNU Autoconf 2.69 for telegram-purple 1.2.3.
#
#
# Copyright (C) 1992-1996, 1998-2012 Free Software Foundation, Inc.
@@ -577,8 +577,8 @@ MAKEFLAGS=
# Identity of this package.
PACKAGE_NAME='telegram-purple'
PACKAGE_TARNAME='telegram-purple'
-PACKAGE_VERSION='1.2.2'
-PACKAGE_STRING='telegram-purple 1.2.2'
+PACKAGE_VERSION='1.2.3'
+PACKAGE_STRING='telegram-purple 1.2.3'
PACKAGE_BUGREPORT=''
PACKAGE_URL=''
@@ -1244,7 +1244,7 @@ if test "$ac_init_help" = "long"; then
# Omit some internal or obsolete options to make the list less imposing.
# This message is too long to be a string in the A/UX 3.1 sh.
cat <<_ACEOF
-\`configure' configures telegram-purple 1.2.2 to adapt to many kinds of systems.
+\`configure' configures telegram-purple 1.2.3 to adapt to many kinds of systems.
Usage: $0 [OPTION]... [VAR=VALUE]...
@@ -1305,7 +1305,7 @@ fi
if test -n "$ac_init_help"; then
case $ac_init_help in
- short | recursive ) echo "Configuration of telegram-purple 1.2.2:";;
+ short | recursive ) echo "Configuration of telegram-purple 1.2.3:";;
esac
cat <<\_ACEOF
@@ -1412,7 +1412,7 @@ fi
test -n "$ac_init_help" && exit $ac_status
if $ac_init_version; then
cat <<\_ACEOF
-telegram-purple configure 1.2.2
+telegram-purple configure 1.2.3
generated by GNU Autoconf 2.69
Copyright (C) 2012 Free Software Foundation, Inc.
@@ -1831,7 +1831,7 @@ cat >config.log <<_ACEOF
This file contains any messages produced by compilers while
running configure, to aid debugging if configure makes a mistake.
-It was created by telegram-purple $as_me 1.2.2, which was
+It was created by telegram-purple $as_me 1.2.3, which was
generated by GNU Autoconf 2.69. Invocation command line was
$ $0 $@
@@ -4869,7 +4869,7 @@ cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
# report actual input values of CONFIG_FILES etc. instead of their
# values after options handling.
ac_log="
-This file was extended by telegram-purple $as_me 1.2.2, which was
+This file was extended by telegram-purple $as_me 1.2.3, which was
generated by GNU Autoconf 2.69. Invocation command line was
CONFIG_FILES = $CONFIG_FILES
@@ -4931,7 +4931,7 @@ _ACEOF
cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
ac_cs_config="`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`"
ac_cs_version="\\
-telegram-purple config.status 1.2.2
+telegram-purple config.status 1.2.3
configured by $0, generated by GNU Autoconf 2.69,
with options \\"\$ac_cs_config\\"
@@ -5641,3 +5641,6 @@ if test -n "$ac_unrecognized_opts" && test "$enable_option_checking" != no; then
$as_echo "$as_me: WARNING: unrecognized options: $ac_unrecognized_opts" >&2;}
fi
+
+rm -f tgl/Makefile
+
diff --git a/configure.ac b/configure.ac
index 2c2ad9e..ca9b9ac 100644
--- a/configure.ac
+++ b/configure.ac
@@ -2,7 +2,7 @@
# Process this file with autoconf to produce a configure script.
AC_PREREQ([2.69])
-AC_INIT([telegram-purple], [1.2.2])
+AC_INIT([telegram-purple], [1.2.3])
AC_CONFIG_SRCDIR([config.h.in])
AC_CONFIG_HEADERS([config.h])
@@ -69,3 +69,6 @@ AC_DEFINE_UNQUOTED(GETTEXT_PACKAGE, ["$GETTEXT_PACKAGE"], [Define the gettext pa
AC_CONFIG_FILES([Makefile])
AC_OUTPUT
+
+rm -f tgl/Makefile
+
diff --git a/telegram-adium/TelegramAccount.m b/telegram-adium/TelegramAccount.m
index 21fa14a..e9dbc4c 100644
--- a/telegram-adium/TelegramAccount.m
+++ b/telegram-adium/TelegramAccount.m
@@ -103,19 +103,6 @@
intValue]);
}
-/**!
- * @brief Returns the name passed to new_purple_buddy, when adding a new contact
- *
- * This function is called when creating a new contact from the purple GUI.
- */
-- (NSString *)_UIDForAddingObject:(AIListContact *)object
-{
- // The contact UID in Adium was encoded with decomposoed unicode codepoints (see http://unicode.org/reports/tr15/).
- // Since libtgl and libpurple (and apparently the rest of the world) encode with composed code points, the name
- // needs to be converted to the composed format to prevent inequality in binary string comparison.
- return [object.UID precomposedStringWithCanonicalMapping];
-}
-
#pragma mark Action Menu
-(NSMenu*)actionMenuForChat:(AIChat*)chat
{
@@ -164,7 +151,7 @@
AIChat *chat = adium.interfaceController.activeChat;
if (chat) {
const char *name = [chat.name UTF8String];
- tgl_peer_t *P = tgl_peer_get_by_name (conn->TLS, name);
+ tgl_peer_t *P = tgp_blist_lookup_peer_get (conn->TLS, name);
if (P) {
leave_and_delete_chat (conn->TLS, P);
}
@@ -207,7 +194,7 @@
connection_data *conn = purple_connection_get_protocol_data (purple_conversation_get_gc (conv));
const char *name = purple_conversation_get_name (conv);
- tgl_peer_t *P = tgl_peer_get_by_name (conn->TLS, purple_conversation_get_title (conv));
+ tgl_peer_t *P = tgp_blist_lookup_peer_get (conn->TLS, purple_conversation_get_title (conv));
if (P) {
return [NSMutableDictionary dictionaryWithObjectsAndKeys:
[NSString stringWithFormat:@"%d", tgl_get_peer_id(P->id)], @"id",
diff --git a/telegram-adium/telegram-adium.xcodeproj/xcuserdata/matj.xcuserdatad/xcschemes/telegram-adium.xcscheme b/telegram-adium/telegram-adium.xcodeproj/xcuserdata/matj.xcuserdatad/xcschemes/telegram-adium.xcscheme
index 5b295fd..3b69798 100644
--- a/telegram-adium/telegram-adium.xcodeproj/xcuserdata/matj.xcuserdatad/xcschemes/telegram-adium.xcscheme
+++ b/telegram-adium/telegram-adium.xcodeproj/xcuserdata/matj.xcuserdatad/xcschemes/telegram-adium.xcscheme
@@ -23,21 +23,24 @@
+ shouldUseLaunchSchemeArgsEnv = "YES">
+
+
CFBundlePackageType
BNDL
CFBundleShortVersionString
- 1.2.1
+ 1.2.3
CFBundleSignature
AdIM
CFBundleVersion
diff --git a/telegram-base.c b/telegram-base.c
index 060f61b..90f9185 100644
--- a/telegram-base.c
+++ b/telegram-base.c
@@ -477,9 +477,10 @@ void tgp_create_group_chat_by_usernames (struct tgl_state *TLS, const char *titl
for (i = 0; i < num_users; i++) if (str_not_empty (users[i])) {
tgl_peer_t *P = NULL;
if (use_print_names) {
+ // used by Adium autocompletion that is based on print_names
P = tgl_peer_get_by_name (TLS, users[i]);
} else {
- P = tgp_blist_peer_find (TLS, users[i]);
+ P = tgp_blist_lookup_peer_get (TLS, users[i]);
}
if (P && tgl_get_peer_id (P->id) != tgl_get_peer_id (TLS->our_id)) {
debug ("Adding %s: %d", P->print_name, tgl_get_peer_id (P->id));
diff --git a/telegram-purple.c b/telegram-purple.c
index 5dd3ed4..d8a3289 100644
--- a/telegram-purple.c
+++ b/telegram-purple.c
@@ -87,43 +87,53 @@ static void update_user_handler (struct tgl_state *TLS, struct tgl_user *user, u
// own user object, do not add that user to the buddy list but make the ID known to the name lookup and
// set the print name as the name to be displayed in IM chats instead of the login name (the phone number)
purple_connection_set_display_name (tls_get_conn (TLS), user->print_name);
- tgp_blist_peer_add_purple_name (TLS, user->id, user->print_name);
+ tgp_blist_lookup_add (TLS, user->id, user->print_name);
return;
}
if (flags & TGL_UPDATE_CREATED) {
- // new user was allocated, fetch the corresponding buddy from the buddy list
+ // user was allocated, fetch the corresponding buddy from the buddy list
PurpleBuddy *buddy = tgp_blist_buddy_find (TLS, user->id);
debug ("new user %s allocated (%s)", user->print_name, print_flags_user (user->flags));
- // the buddy doesn't exist, if it is stored in the legacy naming format find and migrate it. This
- // should only happen when making the switch from a version < 1.2.2 to a version >= 1.2.2
- if (! buddy) {
- char *id = g_strdup_printf ("%d", tgl_get_peer_id (user->id));
- buddy = purple_find_buddy (tls_get_pa (TLS), id);
- g_free (id);
+ if (user->flags & TGLUF_DELETED) {
if (buddy) {
- debug ("migrating buddy from old name %s to %s", purple_buddy_get_name (buddy), user->print_name);
- buddy = tgp_blist_buddy_migrate (TLS, buddy, user);
- if (user->photo_id) {
- tgl_do_get_user_info (TLS, user->id, 0, on_user_get_info, get_user_info_data_new (0, user->id));
- }
+ info ("user %d was deleted, removing from buddy list ...", tgl_get_peer_id (user->id));
+ purple_blist_remove_buddy (buddy);
}
- }
-
- // changing the username would mean dropping the history. The first print name that is known to the blist
- // will remain the permanent name for this user, all future name changes will just change the user alias.
- if (buddy) {
- tgp_blist_peer_add_purple_name (TLS, user->id, purple_buddy_get_name (buddy));
- if (user->print_name && strcmp (user->print_name, purple_buddy_get_name (buddy))) {
- purple_blist_alias_buddy (buddy, user->print_name);
- }
- p2tgl_prpl_got_user_status (TLS, user->id, &user->status);
} else {
- tgp_blist_peer_add_purple_name (TLS, user->id, user->print_name);
+ g_return_if_fail(user->print_name);
+
+ if (! buddy) {
+ // if the buddy is still stored in the legacy naming format find and migrate it. This
+ // should only happen when making the switch from a version < 1.2.2 to a version >= 1.2.2
+ char *id = g_strdup_printf ("%d", tgl_get_peer_id (user->id));
+ buddy = purple_find_buddy (tls_get_pa (TLS), id);
+ g_free (id);
+
+ if (buddy) {
+ info ("migrating buddy from old name %s to %s", purple_buddy_get_name (buddy), user->print_name);
+ buddy = tgp_blist_buddy_migrate (TLS, buddy, user);
+ if (user->photo_id) {
+ tgl_do_get_user_info (TLS, user->id, 0, on_user_get_info, get_user_info_data_new (0, user->id));
+ }
+ }
+
+ // the id isn't known to the lookup yet since the user is not in the buddy list. Add the id to the
+ // lookup to allow sending messages to this user based on the purple name.
+ tgp_blist_lookup_add (TLS, user->id, user->print_name);
+
+ } else {
+ // Keep the users name up-to-date. Changing the actual user name would imply making the history
+ // inacessible, therefore name changes should only affect the alias.
+ if (strcmp (purple_buddy_get_alias (buddy), user->print_name)) {
+ serv_got_alias (tls_get_conn (TLS), purple_buddy_get_name (buddy), user->print_name);
+ }
+ p2tgl_prpl_got_user_status (TLS, user->id, &user->status);
+ }
}
} else {
- // peer was altered in some way
+ // peer was not created, but altered in some way
_update_buddy (TLS, (tgl_peer_t *)user, flags);
}
}
@@ -136,13 +146,13 @@ static void update_channel_handler (struct tgl_state *TLS, struct tgl_channel *C
PurpleBuddy *buddy = tgp_blist_buddy_find (TLS, C->id);
debug ("channel allocated '%s' (%s)", C->title, print_flags_channel (C->flags));
if (buddy) {
- tgp_blist_peer_add_purple_name (TLS, C->id, purple_buddy_get_name (buddy));
+ tgp_blist_lookup_add (TLS, C->id, purple_buddy_get_name (buddy));
if (C->title && strcmp (C->title, purple_buddy_get_name (buddy))) {
purple_blist_alias_buddy (buddy, C->title);
}
purple_prpl_got_user_status (tls_get_pa (TLS), purple_buddy_get_name (buddy), "available", NULL);
} else {
- tgp_blist_peer_add_purple_name (TLS, C->id, C->title);
+ tgp_blist_lookup_add (TLS, C->id, C->title);
}
} else {
if (flags & TGL_UPDATE_FLAGS) {
@@ -165,20 +175,21 @@ static void update_secret_chat_handler (struct tgl_state *TLS, struct tgl_secret
PurpleBuddy *buddy = tgp_blist_buddy_find (TLS, U->id);
if (flags & TGL_UPDATE_CREATED) {
- tgp_blist_peer_add_purple_name (TLS, U->id, U->print_name);
+ tgp_blist_lookup_add (TLS, U->id, U->print_name);
} else {
if (flags & TGL_UPDATE_WORKING) {
write_secret_chat_file (TLS);
if (U->state == sc_ok) {
- tgp_msg_special_out (TLS , _("Secret chat ready.") , U->id , TRUE);
+ tgp_msg_special_out (TLS , _("Secret chat ready.") , U->id, PURPLE_MESSAGE_NO_LOG | PURPLE_MESSAGE_SYSTEM);
}
}
if (buddy) {
if (flags & TGL_UPDATE_DELETED) {
U->state = sc_deleted;
write_secret_chat_file (TLS);
- tgp_msg_special_out (TLS , _("Secret chat terminated.") , U->id , FALSE);
- purple_prpl_got_user_status (tls_get_pa (TLS), tgp_blist_peer_get_purple_name (TLS, U->id), "offline", NULL);
+
+ tgp_msg_special_out (TLS , _("Secret chat terminated.") , U->id, PURPLE_MESSAGE_SYSTEM);
+ purple_prpl_got_user_status (tls_get_pa (TLS), tgp_blist_lookup_purple_name (TLS, U->id), "offline", NULL);
purple_blist_remove_buddy (buddy);
} else {
_update_buddy (TLS, (tgl_peer_t *)U, flags);
@@ -192,7 +203,7 @@ static void update_secret_chat_handler (struct tgl_state *TLS, struct tgl_secret
purple_blist_add_buddy (buddy, NULL, tgp_blist_group_init (_("Telegram")), NULL);
purple_blist_alias_buddy (buddy, U->print_name);
}
- purple_prpl_got_user_status (tls_get_pa (TLS), tgp_blist_peer_get_purple_name (TLS, U->id), "mobile", NULL);
+ purple_prpl_got_user_status (tls_get_pa (TLS), tgp_blist_lookup_purple_name (TLS, U->id), "mobile", NULL);
}
if (flags & TGL_UPDATE_REQUESTED) {
@@ -210,11 +221,9 @@ static void update_chat_handler (struct tgl_state *TLS, struct tgl_chat *chat, u
if (flags & TGL_UPDATE_CREATED) {
debug ("new chat '%s' allocated (%s)", chat->title, print_flags_peer (chat->flags));
- tgp_blist_peer_add_purple_name (TLS, chat->id, chat->print_title);
- }
- if (! (flags & TGL_UPDATE_CREATED)) {
+ tgp_blist_lookup_add (TLS, chat->id, chat->print_title);
+ } else {
PurpleChat *ch = tgp_blist_chat_find (TLS, chat->id);
-
if (flags & TGL_UPDATE_TITLE && ch) {
purple_blist_alias_chat (ch, chat->print_title);
}
@@ -234,9 +243,9 @@ static void update_message_handler (struct tgl_state *TLS, struct tgl_message *M
}
static void update_user_typing (struct tgl_state *TLS, struct tgl_user *U, enum tgl_typing_status status) {
- g_return_if_fail (tgp_blist_peer_get_purple_name (TLS, U->id));
+ g_return_if_fail (tgp_blist_lookup_purple_name (TLS, U->id));
if (status == tgl_typing_typing) {
- serv_got_typing (tls_get_conn (TLS), tgp_blist_peer_get_purple_name (TLS, U->id), 2, PURPLE_TYPING);
+ serv_got_typing (tls_get_conn (TLS), tgp_blist_lookup_purple_name (TLS, U->id), 2, PURPLE_TYPING);
}
}
@@ -247,14 +256,11 @@ static void update_marked_read (struct tgl_state *TLS, int num, struct tgl_messa
int i;
for (i = 0; i < num; i++) {
if (list[i]) {
- tgl_peer_id_t to_id;
- if (tgl_get_peer_type (list[i]->to_id) == TGL_PEER_USER &&
- tgl_get_peer_id (list[i]->to_id) == tgl_get_peer_id (TLS->our_id)) {
- to_id = list[i]->from_id;
- } else {
- to_id = list[i]->to_id;
+ // only display the read recipes for messages that we sent ourselves
+ if (tgl_get_peer_id (list[i]->from_id) == tgl_get_peer_id (TLS->our_id)) {
+ debug ("update_mark_read to=%d", tgl_get_peer_id (list[i]->to_id));
+ tgp_msg_special_out (TLS , _("Message marked as read."), list[i]->to_id, PURPLE_MESSAGE_SYSTEM);
}
- tgp_msg_special_out (TLS , _("Message marked as read.") , to_id , TRUE);
}
}
}
@@ -278,7 +284,7 @@ static void on_userpic_loaded (struct tgl_state *TLS, void *extra, int success,
p2tgl_buddy_icons_set_for_user (tls_get_pa (TLS), P->id, filename);
if (dld->get_user_info_data->show_info == 1) {
- purple_notify_userinfo (tls_get_conn (TLS), tgp_blist_peer_get_purple_name (TLS, P->id),
+ purple_notify_userinfo (tls_get_conn (TLS), tgp_blist_lookup_purple_name (TLS, P->id),
p2tgl_notify_peer_info_new (TLS, P), NULL, NULL);
}
}
@@ -331,7 +337,7 @@ static void on_get_dialog_list_done (struct tgl_state *TLS, void *extra, int suc
PurpleBuddy *buddy = tgp_blist_buddy_find (TLS, UC->id);
if (! buddy) {
info ("%s is in the dialogue list but not in the buddy list, add the user",
- tgp_blist_peer_get_purple_name (TLS, UC->id));
+ tgp_blist_lookup_purple_name (TLS, UC->id));
buddy = tgp_blist_buddy_new (TLS, UC);
purple_blist_add_buddy (buddy, NULL, tgp_blist_group_init (_("Telegram")), NULL);
if (UC->user.photo_id) {
@@ -348,7 +354,7 @@ static void on_get_dialog_list_done (struct tgl_state *TLS, void *extra, int suc
PurpleChat *PC = tgp_blist_chat_find (TLS, UC->id);
if (!PC) {
PC = p2tgl_chat_new (TLS, &UC->chat);
- purple_blist_add_chat (PC, NULL, NULL);
+ purple_blist_add_chat (PC, tgp_blist_group_init ("Telegram Chats"), NULL);
}
}
} else if (tgl_get_peer_type (UC->id) == TGL_PEER_CHANNEL) {
@@ -360,7 +366,7 @@ static void on_get_dialog_list_done (struct tgl_state *TLS, void *extra, int suc
purple_blist_add_buddy (buddy, NULL, tgp_blist_group_init (_("Telegram Channels")), NULL);
tgl_do_get_channel_info (TLS, UC->id, FALSE, channel_load_photo, NULL);
}
- purple_prpl_got_user_status (tls_get_pa (TLS), tgp_blist_peer_get_purple_name (TLS, UC->id), "available",
+ purple_prpl_got_user_status (tls_get_pa (TLS), tgp_blist_lookup_purple_name (TLS, UC->id), "available",
NULL);
}
}
@@ -381,7 +387,7 @@ void on_user_get_info (struct tgl_state *TLS, void *info_data, int success, stru
if (!U->photo || U->photo->sizes_num == 0) {
// No profile pic to load, display it right away
if (user_info_data->show_info) {
- purple_notify_userinfo (tls_get_conn (TLS), tgp_blist_peer_get_purple_name (TLS, P->id),
+ purple_notify_userinfo (tls_get_conn (TLS), tgp_blist_lookup_purple_name (TLS, P->id),
p2tgl_notify_peer_info_new (TLS, P), NULL, NULL);
}
g_free (user_info_data);
@@ -474,7 +480,7 @@ static void export_chat_link_checked_gw (PurpleBlistNode *node, gpointer data) {
}
void export_chat_link_checked (struct tgl_state *TLS, const char *name) {
- tgl_peer_t *C = tgl_peer_get_by_name (TLS, name);
+ tgl_peer_t *C = tgp_blist_lookup_peer_get (TLS, name);
if (! C) {
failure ("Chat \"%s\" not found, not exporting link.", name);
return;
@@ -566,7 +572,9 @@ static void update_on_logged_in (struct tgl_state *TLS) {
debug ("state: seq = %d, pts = %d, date = %d", TLS->seq, TLS->pts, TLS->date);
purple_connection_set_state (tls_get_conn (TLS), PURPLE_CONNECTED);
+
purple_blist_add_account (tls_get_pa (TLS));
+ tgp_blist_lookup_init (TLS);
// It is important to load secret chats exactly at this point during login, cause if it was done earlier,
// the update function wouldn't find existing chats and create duplicate entries. If it was done later, eventual
@@ -692,7 +700,7 @@ static int tgprpl_send_im (PurpleConnection *gc, const char *who, const char *me
// Make sure that to only send messages to an existing peer by searching it in the peer tree, to give immediate
// feedback by returning an error-code in case the peer doesn't exist.
- tgl_peer_t *peer = tgp_blist_peer_find (gc_get_tls (gc), who);
+ tgl_peer_t *peer = tgp_blist_lookup_peer_get (gc_get_tls (gc), who);
if (peer) {
// give a proper error message when attempting to send to a secret chat that is not usable
if (tgl_get_peer_type (peer->id) == TGL_PEER_ENCR_CHAT && peer->encr_chat.state != sc_ok) {
@@ -722,7 +730,7 @@ static int tgprpl_send_im (PurpleConnection *gc, const char *who, const char *me
static unsigned int tgprpl_send_typing (PurpleConnection *gc, const char *who, PurpleTypingState typing) {
debug ("tgprpl_send_typing()");
- tgl_peer_t *peer = tgp_blist_peer_find (gc_get_tls (gc), who);
+ tgl_peer_t *peer = tgp_blist_lookup_peer_get (gc_get_tls (gc), who);
if (peer) {
tgl_do_send_typing (gc_get_tls (gc), peer->id, typing == PURPLE_TYPING ? tgl_typing_typing : tgl_typing_cancel,
0, 0);
@@ -740,14 +748,14 @@ static void channel_show_info (struct tgl_state *TLS, void *extra, int success,
}
tgl_peer_t *P = tgl_peer_get (TLS, C->id);
g_return_if_fail (P);
- purple_notify_userinfo (tls_get_conn (TLS), tgp_blist_peer_get_purple_name (TLS, P->id),
+ purple_notify_userinfo (tls_get_conn (TLS), tgp_blist_lookup_purple_name (TLS, P->id),
p2tgl_notify_peer_info_new (TLS, P), NULL, NULL);
}
static void tgprpl_get_info (PurpleConnection *gc, const char *who) {
debug ("tgprpl_get_info()");
-
- tgl_peer_t *peer = tgp_blist_peer_find (gc_get_data (gc)->TLS, who);
+
+ tgl_peer_t *peer = tgp_blist_lookup_peer_get (gc_get_data (gc)->TLS, who);
if (peer) {
if (tgl_get_peer_type (peer->id) == TGL_PEER_ENCR_CHAT) {
tgl_peer_t *parent_peer = tgp_encr_chat_get_partner (gc_get_tls (gc), &peer->encr_chat);
@@ -765,7 +773,6 @@ static void tgprpl_get_info (PurpleConnection *gc, const char *who) {
static void tgprpl_set_status (PurpleAccount *acct, PurpleStatus *status) {
debug ("tgprpl_set_status(%s)", purple_status_get_name (status));
- debug ("tgprpl_set_status(currstatus=%s)", purple_status_get_name (purple_account_get_active_status (acct)));
pending_reads_send_all (pa_get_data (acct)->TLS);
}
@@ -796,14 +803,13 @@ static void tgprpl_remove_buddy (PurpleConnection *gc, PurpleBuddy *buddy, Purpl
static void tgprpl_chat_invite (PurpleConnection *gc, int id, const char *message, const char *who) {
debug ("tgprpl_chat_invite()");
tgl_peer_t *chat = tgl_peer_get (gc_get_tls (gc), TGL_MK_CHAT (id));
- tgl_peer_t *user = tgp_blist_peer_find (gc_get_tls (gc), who);
+ tgl_peer_t *user = tgp_blist_lookup_peer_get (gc_get_tls (gc), who);
if (! chat || ! user) {
purple_notify_error (_telegram_protocol, _("Cannot invite buddy to chat"), _("Cannot invite buddy to chat"),
_("Specified user does not exist."));
return;
}
-
tgl_do_add_user_to_chat (gc_get_tls (gc), chat->id, user->id, 0, tgp_notify_on_error_gw, chat);
}
@@ -936,9 +942,9 @@ static void tgprpl_init (PurplePlugin *plugin) {
// Messaging
GList *verification_values = NULL;
- ADD_VALUE(verification_values, _("ask"), "ask");
ADD_VALUE(verification_values, _("always"), "always");
ADD_VALUE(verification_values, _("never"), "never");
+ ADD_VALUE(verification_values, _("ask"), "ask");
opt = purple_account_option_list_new (_("Accept secret chats"),
TGP_KEY_ACCEPT_SECRET_CHATS, verification_values);
diff --git a/tgp-2prpl.c b/tgp-2prpl.c
index f0e7793..b21a170 100644
--- a/tgp-2prpl.c
+++ b/tgp-2prpl.c
@@ -65,7 +65,7 @@ int p2tgl_status_is_present (PurpleStatus *status) {
void p2tgl_got_chat_in (struct tgl_state *TLS, tgl_peer_id_t chat, tgl_peer_id_t who, const char *message, int flags,
time_t when) {
- serv_got_chat_in (tls_get_conn (TLS), tgl_get_peer_id (chat), tgp_blist_peer_get_purple_name (TLS, who), flags,
+ serv_got_chat_in (tls_get_conn (TLS), tgl_get_peer_id (chat), tgp_blist_lookup_purple_name (TLS, who), flags,
message, when);
}
@@ -90,14 +90,14 @@ void p2tgl_got_im_combo (struct tgl_state *TLS, tgl_peer_id_t who, const char *m
PurpleConversation *conv = p2tgl_find_conversation_with_account (TLS, who);
if (!conv) {
conv = purple_conversation_new (PURPLE_CONV_TYPE_IM, tls_get_pa (TLS),
- tgp_blist_peer_get_purple_name (TLS, who));
+ tgp_blist_lookup_purple_name (TLS, who));
}
- purple_conv_im_write (purple_conversation_get_im_data (conv), tgp_blist_peer_get_purple_name (TLS, who),
- msg, PURPLE_MESSAGE_SEND, when);
+ purple_conv_im_write (purple_conversation_get_im_data (conv), tgp_blist_lookup_purple_name (TLS, who),
+ msg, PURPLE_MESSAGE_SEND, when);
return;
}
#endif
- serv_got_im (conn->gc, tgp_blist_peer_get_purple_name (TLS, who), msg, flags, when);
+ serv_got_im (conn->gc, tgp_blist_lookup_purple_name (TLS, who), msg, flags, when);
}
PurpleConversation *p2tgl_find_conversation_with_account (struct tgl_state *TLS, tgl_peer_id_t peer) {
@@ -105,7 +105,7 @@ PurpleConversation *p2tgl_find_conversation_with_account (struct tgl_state *TLS,
if (tgl_get_peer_type (peer) == TGL_PEER_CHAT) {
type = PURPLE_CONV_TYPE_CHAT;
}
- PurpleConversation *conv = purple_find_conversation_with_account (type, tgp_blist_peer_get_purple_name (TLS, peer),
+ PurpleConversation *conv = purple_find_conversation_with_account (type, tgp_blist_lookup_purple_name (TLS, peer),
tls_get_pa (TLS));
return conv;
}
@@ -114,23 +114,23 @@ void p2tgl_prpl_got_user_status (struct tgl_state *TLS, tgl_peer_id_t user, stru
connection_data *data = TLS->ev_base;
if (status->online == 1) {
- purple_prpl_got_user_status (tls_get_pa (TLS), tgp_blist_peer_get_purple_name (TLS, user), "available", NULL);
+ purple_prpl_got_user_status (tls_get_pa (TLS), tgp_blist_lookup_purple_name (TLS, user), "available", NULL);
} else {
debug ("%d: when=%d", tgl_get_peer_id (user), status->when);
if (tgp_time_n_days_ago (
purple_account_get_int (data->pa, "inactive-days-offline", TGP_DEFAULT_INACTIVE_DAYS_OFFLINE)) > status->when && status->when) {
debug ("offline");
- purple_prpl_got_user_status (tls_get_pa (TLS), tgp_blist_peer_get_purple_name (TLS, user), "offline", NULL);
+ purple_prpl_got_user_status (tls_get_pa (TLS), tgp_blist_lookup_purple_name (TLS, user), "offline", NULL);
} else {
debug ("mobile");
- purple_prpl_got_user_status (tls_get_pa (TLS), tgp_blist_peer_get_purple_name (TLS, user), "mobile", NULL);
+ purple_prpl_got_user_status (tls_get_pa (TLS), tgp_blist_lookup_purple_name (TLS, user), "mobile", NULL);
}
}
}
void p2tgl_conv_add_user (struct tgl_state *TLS, PurpleConversation *conv, int user, char *message, int flags,
int new_arrival) {
- const char *name = tgp_blist_peer_get_purple_name (TLS, TGL_MK_USER (user));
+ const char *name = tgp_blist_lookup_purple_name (TLS, TGL_MK_USER (user));
g_return_if_fail (name);
purple_conv_chat_add_user (purple_conversation_get_chat_data (conv), name, message, flags, new_arrival);
}
@@ -342,6 +342,6 @@ void p2tgl_buddy_icons_set_for_user (PurpleAccount *pa, tgl_peer_id_t id, const
size_t len;
GError *err = NULL;
g_file_get_contents (filename, &data, &len, &err);
- purple_buddy_icons_set_for_user (pa, tgp_blist_peer_get_purple_name (pa_get_data (pa)->TLS, id), data, len, NULL);
+ purple_buddy_icons_set_for_user (pa, tgp_blist_lookup_purple_name (pa_get_data (pa)->TLS, id), data, len, NULL);
}
diff --git a/tgp-blist.c b/tgp-blist.c
index 0cfb697..ec0fefe 100644
--- a/tgp-blist.c
+++ b/tgp-blist.c
@@ -18,38 +18,82 @@
#include "telegram-purple.h"
-const char *tgp_blist_peer_get_purple_name (struct tgl_state *TLS, tgl_peer_id_t id) {
- const char *name = g_hash_table_lookup (tls_get_data (TLS)->id_to_purple_name, GINT_TO_POINTER(tgl_get_peer_id (id)));
- if (! name) {
- g_warn_if_reached();
- return NULL;
+// utilities
+
+PurpleBlistNode *tgp_blist_iterate (struct tgl_state *TLS,
+ int (* callback) (PurpleBlistNode *node, void *extra), void *extra) {
+ PurpleBlistNode *node = purple_blist_get_root ();
+ while (node) {
+ if ((PURPLE_BLIST_NODE_IS_BUDDY(node) && purple_buddy_get_account ((PurpleBuddy *)node) == tls_get_pa (TLS))
+ || (PURPLE_BLIST_NODE_IS_CHAT(node) && purple_chat_get_account ((PurpleChat *)node) == tls_get_pa (TLS))) {
+ if (callback (node, extra)) {
+ return node;
+ }
+ }
+ node = purple_blist_node_next (node, FALSE);
}
+ return NULL;
+}
+
+// lookup
+
+const char *tgp_blist_lookup_purple_name (struct tgl_state *TLS, tgl_peer_id_t id) {
+ const char *name = g_hash_table_lookup (tls_get_data (TLS)->id_to_purple_name,
+ GINT_TO_POINTER(tgl_get_peer_id (id)));
+ g_warn_if_fail(name);
return name;
}
-void tgp_blist_peer_add_purple_name (struct tgl_state *TLS, tgl_peer_id_t id, const char *purple_name) {
+void tgp_blist_lookup_add (struct tgl_state *TLS, tgl_peer_id_t id, const char *purple_name) {
+
+ // to avoid issues with differences in string normalization, always store in composed form this helps to avoid
+ // issues with clients like Adium, that will store strings in decomposed format by default
+ const char *name = g_utf8_normalize (purple_name, -1, G_NORMALIZE_DEFAULT_COMPOSE);
+
g_hash_table_replace (tls_get_data (TLS)->id_to_purple_name, GINT_TO_POINTER(tgl_get_peer_id (id)),
- g_strdup (purple_name));
+ g_strdup (name));
+ g_hash_table_replace (tls_get_data (TLS)->purple_name_to_id, g_strdup (name),
+ g_memdup (&id, sizeof(tgl_peer_id_t)));
}
-tgl_peer_t *tgp_blist_peer_find (struct tgl_state *TLS, const char *purple_name) {
- // buddies will keep the name they had when they were first added to the user list. The print_name of the peer
- // may have changed since then, therefore the ID stored in the buddy is used to fetch the user name.
- PurpleBuddy *buddy = purple_find_buddy (tls_get_pa (TLS), purple_name);
- if (! buddy) {
- // foreign users are not in the buddy list by default, therefore the name used by libpurple and the
- // print name is always identical
- return tgl_peer_get_by_name (TLS, purple_name);
- }
- if (! tgp_blist_buddy_has_id (buddy)) {
- g_warn_if_reached ();
- return NULL;
- }
- return tgl_peer_get (TLS, tgp_blist_buddy_get_id (buddy));
+static tgl_peer_id_t *tgp_blist_lookup_get_id (struct tgl_state *TLS, const char *purple_name) {
+ return g_hash_table_lookup (tls_get_data (TLS)->purple_name_to_id,
+ g_utf8_normalize (purple_name, -1, G_NORMALIZE_DEFAULT_COMPOSE));
}
+tgl_peer_t *tgp_blist_lookup_peer_get (struct tgl_state *TLS, const char *purple_name) {
+ tgl_peer_id_t *id = tgp_blist_lookup_get_id (TLS, purple_name);
+ g_return_val_if_fail(id, NULL);
+ return tgl_peer_get (TLS, *id);
+}
+
+static int tgp_blist_lookup_init_cb (PurpleBlistNode *node, void *extra) {
+ if (PURPLE_BLIST_NODE_IS_BUDDY(node)) {
+ PurpleBuddy *buddy = (PurpleBuddy *) node;
+ if (tgl_get_peer_type (tgp_blist_buddy_get_id (buddy)) != TGL_PEER_UNKNOWN) {
+ tgp_blist_lookup_add (pbn_get_data (node)->TLS, tgp_blist_buddy_get_id (buddy),
+ purple_buddy_get_name (buddy));
+ }
+ }
+ if (PURPLE_BLIST_NODE_IS_CHAT(node)) {
+ PurpleChat *chat = (PurpleChat *) node;
+ if (tgp_chat_has_id (chat)) {
+ tgp_blist_lookup_add (pbn_get_data (node)->TLS, tgp_chat_get_id (chat),
+ purple_chat_get_name (chat));
+ }
+ }
+ return FALSE;
+}
+
+void tgp_blist_lookup_init (struct tgl_state *TLS) {
+ info ("loading known ids from buddy list ...");
+ tgp_blist_iterate (TLS, tgp_blist_lookup_init_cb, 0);
+}
+
+// buddies
+
PurpleBuddy *tgp_blist_buddy_new (struct tgl_state *TLS, tgl_peer_t *user) {
- PurpleBuddy *buddy = purple_buddy_new (tls_get_pa (TLS), tgp_blist_peer_get_purple_name (TLS, user->id), NULL);
+ PurpleBuddy *buddy = purple_buddy_new (tls_get_pa (TLS), tgp_blist_lookup_purple_name (TLS, user->id), NULL);
tgp_blist_buddy_set_id (buddy, user->id);
return buddy;
}
@@ -84,9 +128,7 @@ tgl_peer_id_t tgp_blist_buddy_get_id (PurpleBuddy *buddy) {
} else if (type == TGL_PEER_CHANNEL) {
return TGL_MK_CHANNEL (id);
} else {
- assert (FALSE);
- // avoid compiler errors for missing return value
- return TGL_MK_USER(0);
+ return tgl_set_peer_id (TGL_PEER_UNKNOWN, 0);
}
}
@@ -98,40 +140,34 @@ tgl_peer_t *tgp_blist_buddy_get_peer (PurpleBuddy *buddy) {
return tgl_peer_get (pbn_get_data (&buddy->node)->TLS, tgp_blist_buddy_get_id (buddy));
}
+static int tgp_blist_buddy_find_cb (PurpleBlistNode *node, void *extra) {
+ return PURPLE_BLIST_NODE_IS_BUDDY(node)
+ && purple_blist_node_get_int (node, TGP_BUDDY_KEY_PEER_ID) == GPOINTER_TO_INT(extra);
+}
+
PurpleBuddy *tgp_blist_buddy_find (struct tgl_state *TLS, tgl_peer_id_t user) {
- PurpleBlistNode *node = purple_blist_get_root ();
- while (node) {
- if (PURPLE_BLIST_NODE_IS_BUDDY(node)) {
- PurpleBuddy *buddy = PURPLE_BUDDY(node);
- if (purple_buddy_get_account (buddy) == tls_get_pa (TLS)) {
- if (purple_blist_node_get_int (node, TGP_BUDDY_KEY_PEER_ID) == tgl_get_peer_id (user)) {
- assert (tgl_get_peer_type (user) == purple_blist_node_get_int (node, TGP_BUDDY_KEY_PEER_TYPE));
- return buddy;
- }
- }
+ return (PurpleBuddy *) tgp_blist_iterate (TLS, tgp_blist_buddy_find_cb, GINT_TO_POINTER(tgl_get_peer_id (user)));
+}
+
+// chats
+
+static int tgp_blist_chat_find_cb (PurpleBlistNode *node, void *extra) {
+ if (PURPLE_BLIST_NODE_IS_CHAT(node)) {
+ PurpleChat *chat = PURPLE_CHAT(node);
+ const char *id = g_hash_table_lookup (purple_chat_get_components (chat), "id");
+ if (id && *id && atoi (id) == GPOINTER_TO_INT(extra)) {
+ return TRUE;
}
- node = purple_blist_node_next (node, FALSE);
}
- return NULL;
+ return FALSE;
}
PurpleChat *tgp_blist_chat_find (struct tgl_state *TLS, tgl_peer_id_t user) {
- PurpleBlistNode *node = purple_blist_get_root ();
- while (node) {
- if (PURPLE_BLIST_NODE_IS_CHAT(node)) {
- PurpleChat *chat = PURPLE_CHAT(node);
- if (purple_chat_get_account (chat) == tls_get_pa (TLS)) {
- const char *id = g_hash_table_lookup (purple_chat_get_components (chat), "id");
- if (id && *id && atoi (id) == tgl_get_peer_id (user)) {
- return chat;
- }
- }
- }
- node = purple_blist_node_next (node, FALSE);
- }
- return NULL;
+ return (PurpleChat *) tgp_blist_iterate (TLS, tgp_blist_chat_find_cb, GINT_TO_POINTER(tgl_get_peer_id (user)));
}
+// groups
+
PurpleGroup *tgp_blist_group_init (const char *name) {
PurpleGroup *grp = purple_find_group (name);
if (! grp) {
@@ -142,8 +178,11 @@ PurpleGroup *tgp_blist_group_init (const char *name) {
}
+// names
+
char *tgp_blist_create_print_name (struct tgl_state *TLS, tgl_peer_id_t id, const char *a1, const char *a2,
const char *a3, const char *a4) {
+
// libtgl passes 0 for all unused strings, therefore the last passed string will always be followed
// by a NULL-termination as expected
gchar *name = g_strjoin (" ", a1, a2, a3, a4, NULL);
@@ -161,13 +200,14 @@ char *tgp_blist_create_print_name (struct tgl_state *TLS, tgl_peer_id_t id, cons
with the old BlistNode. */
int i = 0;
gchar *n = NULL;
- tgl_peer_t *B = tgp_blist_peer_find (TLS, name);
- while (B && tgl_get_peer_id (B->id) != tgl_get_peer_id (id)) {
+ tgl_peer_id_t *id2 = tgp_blist_lookup_get_id (TLS, name);
+ while (id2 && tgl_get_peer_id (*id2) != tgl_get_peer_id (id)) {
if (n) {
g_free (n);
}
n = g_strdup_printf ("%s #%d", name, ++ i);
- B = tgp_blist_peer_find (TLS, n);
+ debug ("resolving duplicate for %s, assigning: %s", name, n);
+ id2 = tgp_blist_lookup_get_id (TLS, n);
}
if (n) {
g_free (name);
diff --git a/tgp-blist.h b/tgp-blist.h
index 5495310..67f0a70 100644
--- a/tgp-blist.h
+++ b/tgp-blist.h
@@ -36,9 +36,10 @@
which unfortunately doesn't work when a user isn't in the buddy list, or in Adium group chats.
Because of that, this plugin now uses the unique print names provided by libtgl as username instead. */
-const char *tgp_blist_peer_get_purple_name (struct tgl_state *TLS, tgl_peer_id_t id);
-void tgp_blist_peer_add_purple_name (struct tgl_state *TLS, tgl_peer_id_t id, const char *purple_name);
-tgl_peer_t *tgp_blist_peer_find (struct tgl_state *TLS, const char *purple_name);
+const char *tgp_blist_lookup_purple_name (struct tgl_state *TLS, tgl_peer_id_t id);
+void tgp_blist_lookup_add (struct tgl_state *TLS, tgl_peer_id_t id, const char *purple_name);
+tgl_peer_t *tgp_blist_lookup_peer_get (struct tgl_state *TLS, const char *purple_name);
+void tgp_blist_lookup_init (struct tgl_state *TLS);
/* To make this new approach robust to names changes, it is necessary to store the user ID in each
blist node to allow reliable buddy list look-ups by user ids. */
diff --git a/tgp-chat.c b/tgp-chat.c
index 234a570..1a29343 100644
--- a/tgp-chat.c
+++ b/tgp-chat.c
@@ -87,7 +87,7 @@ static void tgp_chat_add_all_users (struct tgl_state *TLS, PurpleConversation *c
int i = 0;
for (; i < C->user_list_size; i++) {
struct tgl_chat_user *uid = (C->user_list + i);
- const char *name = tgp_blist_peer_get_purple_name (TLS, TGL_MK_USER(uid->user_id));
+ const char *name = tgp_blist_lookup_purple_name (TLS, TGL_MK_USER(uid->user_id));
if (! name) {
g_warn_if_reached();
continue;
@@ -100,26 +100,29 @@ static void tgp_chat_add_all_users (struct tgl_state *TLS, PurpleConversation *c
g_list_free (flags);
}
-void tgp_chat_users_update (struct tgl_state *TLS, struct tgl_chat *C) {
- PurpleConversation *pc = purple_find_chat (tls_get_conn (TLS), tgl_get_peer_id (C->id));
- if (pc) {
- purple_conv_chat_clear_users (purple_conversation_get_chat_data (pc));
- tgp_chat_add_all_users (TLS, pc, C);
- }
-}
-
PurpleConversation *tgp_chat_show (struct tgl_state *TLS, struct tgl_chat *C) {
- PurpleConversation *convo = purple_find_chat (tls_get_conn (TLS), tgl_get_peer_id (C->id));
- PurpleConvChat *chat = purple_conversation_get_chat_data (convo);
+ PurpleConvChat *chat = NULL;
- if (! convo || (chat && purple_conv_chat_has_left (chat))) {
- convo = serv_got_joined_chat (tls_get_conn (TLS), tgl_get_peer_id (C->id), C->print_title);
- tgp_chat_users_update (TLS, C);
+ // check if chat is already shown
+ PurpleConversation *conv = purple_find_chat (tls_get_conn (TLS), tgl_get_peer_id (C->id));
+ if (conv) {
+ chat = purple_conversation_get_chat_data (conv);
+ if (chat && ! purple_conv_chat_has_left (chat)) {
+ return conv;
+ }
}
- return convo;
+
+ // join the chat now
+ conv = serv_got_joined_chat (tls_get_conn (TLS), tgl_get_peer_id (C->id), C->print_title);
+ g_return_val_if_fail(conv, NULL);
+
+ purple_conv_chat_clear_users (purple_conversation_get_chat_data (conv));
+ tgp_chat_add_all_users (TLS, conv, C);
+
+ return conv;
}
-GList *tgprpl_chat_join_info (PurpleConnection * gc) {
+GList *tgprpl_chat_join_info (PurpleConnection *gc) {
struct proto_chat_entry *pce;
pce = g_new0 (struct proto_chat_entry, 1);
pce->label = _("Subject:");
diff --git a/tgp-chat.h b/tgp-chat.h
index 4171189..cb9f4d3 100644
--- a/tgp-chat.h
+++ b/tgp-chat.h
@@ -30,7 +30,6 @@ int tgp_chat_has_id (PurpleChat *C);
void tgp_chat_on_loaded_chat_full (struct tgl_state *TLS, struct tgl_chat *C);
PurpleConversation *tgp_chat_show (struct tgl_state *TLS, struct tgl_chat *C);
-void tgp_chat_users_update (struct tgl_state *TLS, struct tgl_chat *C);
char *tgprpl_get_chat_name (GHashTable *data);
void tgprpl_chat_join (PurpleConnection *gc, GHashTable *data);
diff --git a/tgp-ft.c b/tgp-ft.c
index e33a62f..08cbc36 100644
--- a/tgp-ft.c
+++ b/tgp-ft.c
@@ -160,7 +160,7 @@ static void tgprpl_xfer_recv_init (PurpleXfer *X) {
purple_xfer_start (X, -1, NULL, 0);
const char *who = purple_xfer_get_remote_user (X);
- P = tgp_blist_peer_find (TLS, who);
+ P = tgp_blist_lookup_peer_get (TLS, who);
if (P) {
switch (M->media.type) {
case tgl_message_media_document:
@@ -202,7 +202,7 @@ static void tgprpl_xfer_send_init (PurpleXfer *X) {
who = purple_xfer_get_remote_user (X);
debug ("xfer_on_init (file=%s, local=%s, who=%s)", file, localfile, who);
- P = tgp_blist_peer_find (data->conn->TLS, who);
+ P = tgp_blist_lookup_peer_get (data->conn->TLS, who);
g_return_if_fail (P);
if (tgl_get_peer_type (P->id) == TGL_PEER_ENCR_CHAT) {
diff --git a/tgp-msg.c b/tgp-msg.c
index 4e67926..a1d9ad9 100644
--- a/tgp-msg.c
+++ b/tgp-msg.c
@@ -107,7 +107,7 @@ static char *format_service_msg (struct tgl_state *TLS, struct tgl_message *M) {
PurpleConversation *conv = tgp_chat_show (TLS, &chatPeer->chat);
if (conv) {
char *alias = peer->print_name;
- const char *aliasLeft = tgp_blist_peer_get_purple_name (TLS, TGL_MK_USER (M->action.user));
+ const char *aliasLeft = tgp_blist_lookup_purple_name (TLS, TGL_MK_USER (M->action.user));
if (tgl_get_peer_id (M->from_id) != tgl_get_peer_id (peer->id)) {
txt = g_strdup_printf (_("%2$s deleted user %1$s."), alias, txt_user);
@@ -164,7 +164,7 @@ static char *format_service_msg (struct tgl_state *TLS, struct tgl_message *M) {
PurpleBuddy *buddy = tgp_blist_buddy_new (TLS, fromPeer);
purple_blist_add_buddy (buddy, NULL, tgp_blist_group_init (_("Telegram Channels")), NULL);
tgl_do_get_channel_info (TLS, fromPeer->id, FALSE, channel_load_photo, NULL);
- purple_prpl_got_user_status (tls_get_pa (TLS), tgp_blist_peer_get_purple_name (TLS, fromPeer->id),
+ purple_prpl_got_user_status (tls_get_pa (TLS), tgp_blist_lookup_purple_name (TLS, fromPeer->id),
"available", NULL);
break;
}
@@ -260,7 +260,7 @@ void tgp_msg_special_out (struct tgl_state *TLS, const char *msg, tgl_peer_id_t
// Regular IM conversations will not display specialized message flags like PURPLE_MESSAGE_ERROR or
// PURPLE_MESSAGE_SYSTEM correctly when using serv_got_in, therefore it is necessary to use the underlying
// conversation directly.
- const char *name = tgp_blist_peer_get_purple_name (TLS, to_id);
+ const char *name = tgp_blist_lookup_purple_name (TLS, to_id);
PurpleConversation *conv = p2tgl_find_conversation_with_account (TLS, to_id);
g_return_if_fail (name);
if (! conv) {
@@ -286,6 +286,7 @@ int tgp_msg_send (struct tgl_state *TLS, const char *message, tgl_peer_id_t to)
// search for outgoing embedded image tags and send them
gchar *img = NULL;
gchar *stripped = NULL;
+ debug ("tgp_msg_send='%s'", message);
if ((img = g_strrstr (message, "
data, &flags);
} else {
if (! tgp_our_msg(TLS, M)) {
- tgprpl_recv_file (conn->gc, tgp_blist_peer_get_purple_name (TLS, M->from_id), M);
+ tgprpl_recv_file (conn->gc, tgp_blist_lookup_purple_name (TLS, M->from_id), M);
}
return;
}
@@ -479,7 +480,7 @@ static void tgp_msg_display (struct tgl_state *TLS, struct tgp_msg_loading *C) {
case tgl_message_media_video:
case tgl_message_media_audio: {
if (! tgp_our_msg(TLS, M)) {
- tgprpl_recv_file (conn->gc, tgp_blist_peer_get_purple_name (TLS, M->from_id), M);
+ tgprpl_recv_file (conn->gc, tgp_blist_lookup_purple_name (TLS, M->from_id), M);
}
}
break;
@@ -493,7 +494,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_peer_get_purple_name (TLS, M->to_id), M);
+ tgprpl_recv_file (conn->gc, tgp_blist_lookup_purple_name (TLS, M->to_id), M);
}
return;
}
diff --git a/tgp-request.c b/tgp-request.c
index a7a2f9f..0519318 100644
--- a/tgp-request.c
+++ b/tgp-request.c
@@ -78,7 +78,8 @@ static void request_name_code_entered (struct request_values_data *data, PurpleR
} else {
request_name (data->TLS, data->callback, data->arg);
}
- for (int j = 0; j < 3; ++j) {
+ int j;
+ for (j = 0; j < 3; ++j) {
g_free (names[j]);
}
free (data);
@@ -196,7 +197,7 @@ void request_create_chat (struct tgl_state *TLS, const char *subject) {
purple_request_fields_add_group (fields, group);
purple_request_fields (tls_get_conn (TLS), _("Create group chat"), _("Invite users"), NULL, fields, _("OK"),
G_CALLBACK(create_group_chat_cb), _("Cancel"), G_CALLBACK(cancel_group_chat_cb), tls_get_pa (TLS), NULL, NULL,
- request_values_data_init (TLS, NULL, (void *) subject, 0));
+ request_values_data_init (TLS, NULL, (void *) g_strdup (subject), 0));
}
static void request_cur_and_new_password_ok (struct request_values_data *data, PurpleRequestFields* fields) {
diff --git a/tgp-structs.c b/tgp-structs.c
index edcf01b..59e9f1a 100644
--- a/tgp-structs.c
+++ b/tgp-structs.c
@@ -103,6 +103,7 @@ connection_data *connection_data_init (struct tgl_state *TLS, PurpleConnection *
conn->pending_reads = g_hash_table_new_full (g_direct_hash, g_direct_equal, NULL, g_free);
conn->pending_chat_info = g_hash_table_new (g_direct_hash, g_direct_equal);
conn->id_to_purple_name = g_hash_table_new_full (g_direct_hash, g_direct_equal, NULL, g_free);
+ conn->purple_name_to_id = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
return conn;
}
@@ -118,6 +119,7 @@ void *connection_data_free (connection_data *conn) {
g_hash_table_destroy (conn->pending_reads);
g_hash_table_destroy (conn->pending_chat_info);
g_hash_table_destroy (conn->id_to_purple_name);
+ g_hash_table_destroy (conn->purple_name_to_id);
tgprpl_xfer_free_all (conn);
g_free (conn->TLS->base_path);
tgl_free_all (conn->TLS);
diff --git a/tgp-structs.h b/tgp-structs.h
index c90d991..ecf68e4 100644
--- a/tgp-structs.h
+++ b/tgp-structs.h
@@ -45,6 +45,7 @@ typedef struct {
PurpleRoomlist *roomlist;
GHashTable *pending_chat_info;
GHashTable *id_to_purple_name;
+ GHashTable *purple_name_to_id;
GList *pending_joins;
int dialogues_ready;
} connection_data;