changeset 177:0339b4abe290 multiaccounts

- fixed a problem that preferences per conversation die when its name of PurpleConversation changed. - fixed a problem that some getting messages were lost from API with multiaccounts of Twitter.
author mikanbako <maoutwo@gmail.com>
date Sun, 03 Aug 2008 12:15:09 +0900
parents 7affa10c1f0e
children 1265988dc2bf
files pidgin-twitter.c pidgin-twitter.h
diffstat 2 files changed, 55 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/pidgin-twitter.c	Sat Aug 02 22:09:41 2008 +0900
+++ b/pidgin-twitter.c	Sun Aug 03 12:15:09 2008 +0900
@@ -29,6 +29,7 @@
 static gboolean suppress_oops = FALSE;
 static GHashTable *icon_hash[3]; /* twitter, wassr, identica. */
 static GHashTable *conv_hash = NULL;
+static GHashTable *last_id_hash = NULL;
 static GList *statuseslist = NULL;
 static GList *postedlist = NULL;
 static gchar *wassr_post = NULL;
@@ -471,8 +472,9 @@
 {
     xmlDocPtr doc;
     xmlNode *nptr, *nptr2;
-    static guint lastid = 0;
+    guint lastid = 0;
     PurpleConversation *conv;
+    PurpleAccount *account;
     GList *stp;
     const gchar *start;
     PurpleMessageFlags msg_flags;
@@ -482,6 +484,14 @@
     conv = (PurpleConversation *)user_data;
     if(!conv)
         return;
+    account = purple_conversation_get_account(conv);
+
+    /* If the key is not found, lastid is 0. */
+    /* The format of this key depends on supporting Twitter's API only. */
+    lastid = GPOINTER_TO_UINT(
+                      g_hash_table_lookup(
+                             last_id_hash,
+                             purple_account_get_username(account)));
 
     /* skip to the beginning of xml */
     start = strstr(url_text, "<?xml");
@@ -537,6 +547,9 @@
          stp->data = NULL;
      }
 
+     g_hash_table_insert(last_id_hash,
+                         g_strdup(purple_account_get_username(account)),
+                         GUINT_TO_POINTER(lastid));
      statuseslist = g_list_remove_all(statuseslist, NULL);
 }
 
@@ -1493,6 +1506,21 @@
     return is_identica_account(account, name);
 }
 
+static const char*
+get_service_name(PurpleAccount *account, const char *conv_name)
+{
+    /* Do not change those names. */
+    /* Because they are used for the preferences per conversation. */
+    if(is_twitter_account(account, conv_name))
+        return "twitter";
+    if(is_wassr_account(account, conv_name))
+        return "wassr";
+    if(is_identica_account(account, conv_name))
+        return "identica";
+
+    return "unknown";
+}
+
 static gint
 get_service_type(PurpleConversation *conv)
 {
@@ -2481,7 +2509,7 @@
 
     conv_hash = g_hash_table_new_full(g_direct_hash, g_direct_equal,
                                               NULL, NULL);
-
+    last_id_hash = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL);
 
     /* attach counter to the existing twitter window */
     if(purple_prefs_get_bool(OPT_COUNTER)) {
@@ -2571,6 +2599,7 @@
     }
 
     g_hash_table_destroy(conv_hash);
+    g_hash_table_destroy(last_id_hash);
 
     /* detach from twitter window */
     detach_from_window();
@@ -3261,9 +3290,11 @@
 }
 
 static gchar*
-create_key_with_service_account(const char *conv_name, const char *key)
+create_key_with_service_account(PurpleAccount *account,
+                                const char *conv_name,
+                                const char *key)
 {
-    return g_strdup_printf("%s:%s", key, conv_name);
+    return g_strdup_printf("%s:%s", key, get_service_name(account, conv_name));
 }
 
 static void
@@ -3272,7 +3303,9 @@
                            const char *key,
                            const char *value)
 {
-    gchar *key_with_account = create_key_with_service_account(conv_name, key);
+    gchar *key_with_account = create_key_with_service_account(account,
+                                                              conv_name,
+                                                              key);
 
     purple_account_set_string(account, key_with_account, value);
     g_free(key_with_account);
@@ -3284,7 +3317,9 @@
                            const char *key,
                            const char *default_value)
 {
-    gchar *key_with_account = create_key_with_service_account(conv_name, key);
+    gchar *key_with_account = create_key_with_service_account(account,
+                                                              conv_name,
+                                                              key);
     const char *value = purple_account_get_string(account,
                                                   key_with_account,
                                                   default_value);
@@ -3300,7 +3335,9 @@
                         const char *key,
                         int value)
 {
-    gchar *key_with_account = create_key_with_service_account(conv_name, key);
+    gchar *key_with_account = create_key_with_service_account(account,
+                                                              conv_name,
+                                                              key);
 
     purple_account_set_int(account, key_with_account, value);
     g_free(key_with_account);
@@ -3312,7 +3349,9 @@
                         const char *key,
                         int default_value)
 {
-    gchar *key_with_account = create_key_with_service_account(conv_name, key);
+    gchar *key_with_account = create_key_with_service_account(account,
+                                                              conv_name,
+                                                              key);
     int value = purple_account_get_int(account,
                                        key_with_account,
                                        default_value);
@@ -3328,7 +3367,9 @@
                          const char *key,
                          gboolean value)
 {
-    gchar *key_with_account = create_key_with_service_account(conv_name, key);
+    gchar *key_with_account = create_key_with_service_account(account,
+                                                              conv_name,
+                                                              key);
 
     purple_account_set_bool(account, key_with_account, value);
     g_free(key_with_account);
@@ -3340,7 +3381,9 @@
                          const char *key,
                          gboolean default_value)
 {
-    gchar *key_with_account = create_key_with_service_account(conv_name, key);
+    gchar *key_with_account = create_key_with_service_account(account,
+                                                              conv_name,
+                                                              key);
     gboolean value = purple_account_get_bool(account,
                                              key_with_account,
                                              default_value);
--- a/pidgin-twitter.h	Sat Aug 02 22:09:41 2008 +0900
+++ b/pidgin-twitter.h	Sun Aug 03 12:15:09 2008 +0900
@@ -216,6 +216,7 @@
 static void init_plugin(PurplePlugin *plugin);
 static void remove_marks_func(gpointer key, gpointer value, gpointer user_data);
 static void cancel_fetch_func(gpointer key, gpointer value, gpointer user_data);
+static const char *get_service_name(PurpleAccount *account, const char *conv_name);
 static gint get_service_type(PurpleConversation *conv);
 static GdkPixbuf *make_scaled_pixbuf(const gchar *url_text, gsize len);
 static void open_account_preference_window(GtkWidget *called_widged, gpointer gtkconv_ptr);
@@ -228,7 +229,7 @@
 static void account_preference_bool_toggled_cb(GtkToggleButton *togglebutton, gpointer conv_ptr);
 static void account_preference_interval_changed(PurpleAccount *account, const char *conv_name);
 static void account_preference_spin_changed_cb(GtkSpinButton *spinbutton, gpointer conv_ptr);
-static gchar* create_key_with_service_account(const char *conv_name, const char *key);
+static gchar* create_key_with_service_account(PurpleAccount *account, const char *conv_name, const char *key);
 static void service_account_set_string(PurpleAccount *account, const char *conv_name, const char *key, const char *value);
 static const char* service_account_get_string(PurpleAccount *account, const char *conv_name, const char *key, const char *default_value);
 static void service_account_set_int(PurpleAccount *account, const char *conv_name, const char *key, gboolean value);