Beispiel #1
0
static GntWidget*
create_string_field(PurpleRequestField *field, GntWidget **screenname)
{
	const char *hint = purple_request_field_get_type_hint(field);
	GntWidget *entry = gnt_entry_new(
			purple_request_field_string_get_default_value(field));
	gnt_entry_set_masked(GNT_ENTRY(entry),
			purple_request_field_string_is_masked(field));
	if (hint && purple_str_has_prefix(hint, "screenname")) {
		PurpleBlistNode *node = purple_blist_get_root();
		gboolean offline = purple_str_has_suffix(hint, "all");
		for (; node; node = purple_blist_node_next(node, offline)) {
			if (!PURPLE_BLIST_NODE_IS_BUDDY(node))
				continue;
			gnt_entry_add_suggest(GNT_ENTRY(entry), purple_buddy_get_name((PurpleBuddy*)node));
		}
		gnt_entry_set_always_suggest(GNT_ENTRY(entry), TRUE);
		if (screenname)
			*screenname = entry;
	} else if (hint && !strcmp(hint, "group")) {
		PurpleBlistNode *node;
		for (node = purple_blist_get_root(); node;
				node = purple_blist_node_get_sibling_next(node)) {
			if (PURPLE_BLIST_NODE_IS_GROUP(node))
				gnt_entry_add_suggest(GNT_ENTRY(entry), purple_group_get_name((PurpleGroup *)node));
		}
	}
	return entry;
}
static void
extended_menu_cb(PurpleBlistNode *node, GList **menu, gpointer data)
{
	GList *submenu = NULL, *submenu_1 = NULL, *submenu_2 = NULL;
	PurpleMenuAction *action = NULL;
	PurpleBlistNode *group;
	PurpleMenuAction *action_submenu = NULL, *action_submenu_1 = NULL, *action_submenu_2 = NULL; 
	const gchar *group_name = NULL;

	if (!PURPLE_IS_BUDDY(node))
		return;

   for (group = purple_blist_get_root(); group; group = purple_blist_node_get_sibling_next(group)) {
		if (!PURPLE_IS_GROUP(group))
			continue;
			
		group_name = purple_group_get_name((PurpleGroup *)group);

		action_submenu_1 = purple_menu_action_new(group_name,
		                 PURPLE_CALLBACK(send_buddy_list_cb),
		                 group, NULL); 
		submenu_1 = g_list_append (submenu_1, action_submenu_1);

	}

	for (group = purple_blist_get_root(); group; group = purple_blist_node_get_sibling_next(group)) {
		if (!PURPLE_IS_GROUP(group))
			continue;
			
		group_name = purple_group_get_name((PurpleGroup *)group);

		action_submenu_2 = purple_menu_action_new(group_name,
		                 PURPLE_CALLBACK(send_online_buddy_cb),
		                 group, NULL); 
		submenu_2 = g_list_append (submenu_2, action_submenu_2);

	}

   action_submenu = purple_menu_action_new(_("Group list"), 
		                                PURPLE_CALLBACK(send_group_list_cb), NULL, NULL);
	submenu = g_list_append (submenu, action_submenu);
   action_submenu = purple_menu_action_new(_("Buddy List for"), 
		                                NULL, NULL, submenu_1);
	submenu = g_list_append (submenu, action_submenu);
	action_submenu = purple_menu_action_new(_("Online Buddies for"), 
		                                NULL, NULL, submenu_2);
	submenu = g_list_append (submenu, action_submenu);

	action = purple_menu_action_new(_("Send"), 
		                                NULL, NULL, submenu);
	*menu = g_list_append (*menu, action);
}
Beispiel #3
0
static void buddy_ticker_show(void)
{
	PurpleBlistNode *gnode, *cnode, *bnode;
	PurpleBuddy *b;

	for(gnode = purple_blist_get_root();
	    gnode;
	    gnode = purple_blist_node_get_sibling_next(gnode))
	{
		if(!PURPLE_BLIST_NODE_IS_GROUP(gnode))
			continue;
		for(cnode = purple_blist_node_get_first_child(gnode);
		    cnode;
		    cnode = purple_blist_node_get_sibling_next(cnode))
		{
			if(!PURPLE_BLIST_NODE_IS_CONTACT(cnode))
				continue;
			for(bnode = purple_blist_node_get_first_child(cnode);
			    bnode;
			    bnode = purple_blist_node_get_sibling_next(bnode))
			{
				if(!PURPLE_BLIST_NODE_IS_BUDDY(bnode))
					continue;
				b = (PurpleBuddy *)bnode;
				if(PURPLE_BUDDY_IS_ONLINE(b))
					buddy_ticker_add_buddy(b);
			}
		}
	}
}
Beispiel #4
0
static void waprpl_chat_invite(PurpleConnection *gc, int id, const char *message, const char *name) {
  whatsapp_connection * wconn = purple_connection_get_protocol_data(gc);
  PurpleAccount *account = purple_connection_get_account(gc);
  PurpleConversation *convo = purple_find_chat(gc, id);
  
  PurpleBlistNode* node = purple_blist_get_root();
  GHashTable* hasht = NULL;
  while (node != 0) {
    if (PURPLE_BLIST_NODE_IS_CHAT(node)) {
      PurpleChat * ch = PURPLE_CHAT(node);
      if (purple_chat_get_account(ch) == account) {
        hasht = purple_chat_get_components(ch);
        if (chatid_to_convo(g_hash_table_lookup(hasht, "id")) == id) {
          break;
        }
      }
    }
    node = purple_blist_node_next(node,FALSE);
  }

  char * chat_id = g_hash_table_lookup(hasht, "id");
  if (strstr(name,"@s.whatsapp.net") == 0) name = g_strdup_printf("*****@*****.**",name);
  waAPI_manageparticipant(wconn->waAPI, chat_id, name, "add");
  
  purple_conv_chat_add_user (purple_conversation_get_chat_data(convo), name, "", PURPLE_CBFLAGS_NONE, FALSE);

  waprpl_check_output(gc);
  
  return 1;
}
Beispiel #5
0
static int waprpl_send_chat(PurpleConnection *gc, int id, const char *message, PurpleMessageFlags flags) {
  whatsapp_connection * wconn = purple_connection_get_protocol_data(gc);
  PurpleAccount *account = purple_connection_get_account(gc);
  PurpleConversation *convo = purple_find_chat(gc, id);
  
  PurpleBlistNode* node = purple_blist_get_root();
  GHashTable* hasht = NULL;
  while (node != 0) {
    if (PURPLE_BLIST_NODE_IS_CHAT(node)) {
      PurpleChat * ch = PURPLE_CHAT(node);
      if (purple_chat_get_account(ch) == account) {
        hasht = purple_chat_get_components(ch);
        if (chatid_to_convo(g_hash_table_lookup(hasht, "id")) == id) {
          break;
        }
      }
    }
    node = purple_blist_node_next(node,FALSE);
  }

  char * chat_id = g_hash_table_lookup(hasht, "id");
  waAPI_sendchat(wconn->waAPI,chat_id,message);
  waprpl_check_output(gc);

  serv_got_chat_in(gc, purple_conv_chat_get_id(PURPLE_CONV_CHAT(convo)), purple_connection_get_display_name(gc), PURPLE_MESSAGE_SEND, message, time(NULL));
  purple_conv_im_write(PURPLE_CONV_CHAT(convo), purple_connection_get_display_name(gc), message, PURPLE_MESSAGE_SEND, time(NULL));

  return 1;
}
Beispiel #6
0
BuddyListGroup::GroupContextMenu::GroupContextMenu(
    BuddyListGroup& parent_group_)
: ContextMenu(parent_group_), parent_group(&parent_group_)
{
  appendExtendedMenu();

  appendItem(_("Rename..."), sigc::mem_fun(this,
        &GroupContextMenu::onRename));
  appendItem(_("Delete..."), sigc::mem_fun(this,
        &GroupContextMenu::onRemove));

  if (BUDDYLIST->getGroupSortMode() == BuddyList::GROUP_SORT_BY_USER) {
    /* If the manual sorting is enabled then show a menu item and a submenu
     * for group moving. */
    CppConsUI::MenuWindow *groups = new CppConsUI::MenuWindow(*this, AUTOSIZE,
        AUTOSIZE);

    groups->appendItem(_("-Top-"), sigc::bind(
          sigc::mem_fun(this, &GroupContextMenu::onMoveAfter),
          static_cast<PurpleGroup*>(NULL)));
    for (PurpleBlistNode *node = purple_blist_get_root(); node;
        node = purple_blist_node_get_sibling_next(node)) {
      if (!PURPLE_BLIST_NODE_IS_GROUP(node))
        continue;

      PurpleGroup *group = PURPLE_GROUP(node);
      groups->appendItem(purple_group_get_name(group), sigc::bind(
            sigc::mem_fun(this, &GroupContextMenu::onMoveAfter), group));
    }

    appendSubMenu(_("Move after..."), *groups);
  }
}
Beispiel #7
0
static void
setup_buddy_list_suggestion(GntEntry *entry, gboolean offline)
{
	PurpleBlistNode *node = purple_blist_get_root();
	for (; node; node = purple_blist_node_next(node, offline)) {
		if (!PURPLE_BLIST_NODE_IS_BUDDY(node))
			continue;
		gnt_entry_add_suggest(entry, purple_buddy_get_name((PurpleBuddy*)node));
	}
}
Beispiel #8
0
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) == tg_get_acc (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;
        }
      }
    }
    node = purple_blist_node_next (node, FALSE);
  }
  return NULL;
}
Beispiel #9
0
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) == tg_get_acc (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;
}
Beispiel #10
0
void BuddyList::request_add_buddy(PurpleAccount *account,
    const char *username, const char *group, const char *alias)
{
  if (!CheckAnyAccountConnected())
    return;

  PurpleRequestFields *fields = purple_request_fields_new();
  PurpleRequestFieldGroup *g = purple_request_field_group_new(NULL);

  purple_request_fields_add_group(fields, g);

  PurpleRequestField *f;
  f = purple_request_field_account_new("account", _("Account"), account);
  purple_request_field_group_add_field(g, f);
  f = purple_request_field_string_new("name", _("Buddy name"), username,
      FALSE);
  purple_request_field_group_add_field(g, f);
  f = purple_request_field_string_new("alias", _("Alias"), alias, FALSE);
  purple_request_field_group_add_field(g, f);

  f = purple_request_field_choice_new("group", _("Group"), 0);
  bool add_default_group = true;
  int dval = 0;
  bool dval_set = false;
  for (PurpleBlistNode *i = purple_blist_get_root(); i; i = i->next)
    if (PURPLE_BLIST_NODE_IS_GROUP(i)) {
      const char *cur_name = purple_group_get_name(
          reinterpret_cast<PurpleGroup*>(i));
      purple_request_field_choice_add(f, cur_name);
      if (!dval_set) {
        if (group && !strcmp(group, cur_name)) {
          purple_request_field_choice_set_default_value(f, dval);
          dval_set = true;
        }
        dval++;
      }
      add_default_group = false;
    }
  if (add_default_group)
      purple_request_field_choice_add(f, _("Buddies"));
  purple_request_field_group_add_field(g, f);

  purple_request_fields(NULL, _("Add buddy"), NULL, NULL, fields, _("Add"),
      G_CALLBACK(add_buddy_ok_cb_), CANCEL_BUTTON_TEXT, NULL, NULL, NULL,
      NULL, this);
}
/* void Quit (); */
NS_IMETHODIMP purpleCoreService::Quit()
{
  // This seems to happen when Windows is shutting down, don't know why... :(
  if (!mInitialized)
    return NS_OK;

  // Avoid reentering when called from the unload handler of the buddy list
  if (mQuitting)
    return NS_OK;

  mQuitting = PR_TRUE;

  nsresult rv;
  nsCOMPtr<nsIObserverService> os =
    do_GetService(NS_OBSERVERSERVICE_CONTRACTID, &rv);
  NS_ENSURE_SUCCESS(rv, rv);

  rv = os->RemoveObserver(this, "prpl-quit");
  NS_ENSURE_SUCCESS(rv, rv);

  os->RemoveObserver(this, "idle-time-changed");

  disconnect_blist_signals();

  PurpleBlistNode *gnode;
  for (gnode = purple_blist_get_root(); gnode; gnode = gnode->next) {
    if (!PURPLE_BLIST_NODE_IS_GROUP(gnode))
      continue;
    imITag *tag =
      purpleAccountBuddy::GetTagFromPurpleGroup(PURPLE_GROUP(gnode));
    NS_IF_RELEASE(tag);
  }

  mProxies.Clear();
  mInitialized = PR_FALSE;
  purple_core_quit();
  LOG(("purple_core_quit"));
  purpleSocketWatcher::unInit();
  purpleNetworkObserver::unInit();
  purpleDNS::unInit();
  purpleTimer::unInit();
  purpleGetText::unInit();

  mQuitting = PR_FALSE;
  return NS_OK;
}
Beispiel #12
0
static PurpleChat *blist_find_chat_by_hasht_cond(PurpleConnection *gc,
    int (*fn)(GHashTable *hasht, void *data), void *data) {
  PurpleAccount *account = purple_connection_get_account(gc);
  PurpleBlistNode *node = purple_blist_get_root();
  GHashTable *hasht;
  while (node) {
    if (PURPLE_BLIST_NODE_IS_CHAT(node)) {
      PurpleChat *ch = PURPLE_CHAT(node);
      if (purple_chat_get_account(ch) == account) {
        hasht = purple_chat_get_components(ch);
        if (fn(hasht, data))
          return ch;
      }
    }
    node = purple_blist_node_next(node, 0);
  }
  return NULL;
}
Beispiel #13
0
Contact *QuetzalContactsFactory::addContact(const QString &id, const QVariantMap &data)
{
	QByteArray group = data.value(QLatin1String("group")).toString().toUtf8();
	if (group.isEmpty()) {
		// For compatibility with other implementations
		// Looks like libpurple doesn't support multiple groups
		// Or does it at some unknown way
		group = data.value(QLatin1String("tags")).toStringList().value(0).toUtf8();
	}
	QString name = data.value(QLatin1String("name")).toString();
	
	const char *groupName = group.isEmpty() ? "Buddies" : group.constData();
	PurpleGroup *pg = purple_find_group(groupName);
	if (!pg) {
		pg = purple_group_new(groupName);
		purple_blist_add_group(pg, quetzal_blist_get_last_sibling(purple_blist_get_root()));
	}
	PurpleContact *pc = purple_contact_new();
	purple_blist_add_contact(pc, pg, quetzal_blist_get_last_child(PURPLE_BLIST_NODE(pg)));
	PurpleBuddy *buddy = purple_buddy_new(m_account->purple(), id.toUtf8().constData(),
										  name.toUtf8().constData());
	PurpleBlistNode *node = PURPLE_BLIST_NODE(buddy);
	purple_blist_add_buddy(buddy, pc, pg, quetzal_blist_get_last_child(PURPLE_BLIST_NODE(pc)));
	QMapIterator<QString, QVariant> it(data.value(QLatin1String("quetzal_settings")).toMap());
	while (it.hasNext()) {
		it.next();
		QByteArray key = it.key().toUtf8();
		QVariant::Type type = it.value().type();
		if (type == QVariant::Bool) {
			purple_blist_node_set_bool(node, key.constData(), it.value().toBool());
		} else if (type == QVariant::Int || type == QVariant::UInt
				 || type == QVariant::LongLong || type == QVariant::ULongLong) {
			purple_blist_node_set_int(node, key.constData(), it.value().toInt());
		} else {
			purple_blist_node_set_string(node, key.constData(), it.value().toString().toUtf8());
		}
	}
	QuetzalContact *contact = reinterpret_cast<QuetzalContact*>(node->ui_data);
	contact->update(buddy);
	return contact;
}
Beispiel #14
0
void BuddyList::blist_pref_change(const char *name, PurplePrefType type,
    gconstpointer val)
{
  // blist/* preference changed
  UpdateCachedPreference(name);

  bool groups_only = false;
  if (!strcmp(name, CONF_PREFIX "blist/show_empty_groups"))
    groups_only = true;

  PurpleBlistNode *node = purple_blist_get_root();
  while (node) {
    if (!groups_only || PURPLE_BLIST_NODE_IS_GROUP(node)) {
      BuddyListNode *bnode = reinterpret_cast<BuddyListNode*>(node->ui_data);
      if (bnode)
        bnode->Update();
    }

    node = purple_blist_node_next(node, TRUE);
  }
}
Beispiel #15
0
BuddyListContact::ContactContextMenu::ContactContextMenu(
    BuddyListContact& parent_contact_)
: ContextMenu(parent_contact_), parent_contact(&parent_contact_)
{
  appendExtendedMenu();

  if (parent_contact->isCollapsed())
    appendItem(_("Expand"), sigc::bind(sigc::mem_fun(this,
            &ContactContextMenu::onExpandRequest), true));
  else
    appendItem(_("Collapse"), sigc::bind(sigc::mem_fun(this,
            &ContactContextMenu::onExpandRequest), false));

  appendItem(_("Information..."), sigc::mem_fun(this,
        &ContactContextMenu::onInformation));
  appendItem(_("Alias..."), sigc::mem_fun(this,
        &ContactContextMenu::onChangeAlias));
  appendItem(_("Delete..."), sigc::mem_fun(this,
        &ContactContextMenu::onRemove));

  CppConsUI::MenuWindow *groups = new CppConsUI::MenuWindow(*this, AUTOSIZE,
      AUTOSIZE);

  for (PurpleBlistNode *node = purple_blist_get_root(); node;
      node = purple_blist_node_get_sibling_next(node)) {
    if (!PURPLE_BLIST_NODE_IS_GROUP(node))
      continue;

    PurpleGroup *group = PURPLE_GROUP(node);
    CppConsUI::Button *button = groups->appendItem(
        purple_group_get_name(group), sigc::bind(sigc::mem_fun(this,
            &ContactContextMenu::onMoveTo), group));
    if (purple_contact_get_group(parent_contact->getPurpleContact())
        == group)
      button->grabFocus();
  }

  appendSubMenu(_("Move to..."), *groups);
}
static gboolean
nested_group_can_add_node(PurpleBlistNode *node)
{
	PurpleBlistNode *group;
	int len;

	if (!PURPLE_IS_GROUP(node))
		return default_manager->can_add_node(node);

	if (default_manager->can_add_node(node))
		return TRUE;

	len = strlen(purple_group_get_name(PURPLE_GROUP(node)));
	group = purple_blist_get_root();
	for (; group; group = purple_blist_node_get_sibling_next(group)) {
		if (group == node)
			continue;
		if (strncmp(purple_group_get_name(PURPLE_GROUP(node)),
					purple_group_get_name(PURPLE_GROUP(group)), len) == 0 &&
				default_manager->can_add_node(group))
			return TRUE;
	}
	return FALSE;
}
static void waprpl_process_incoming_events(PurpleConnection * gc)
{
	whatsapp_connection *wconn = purple_connection_get_protocol_data(gc);
	PurpleAccount *acc = purple_connection_get_account(gc);

	switch (waAPI_loginstatus(wconn->waAPI)) {
	case 0:
		purple_connection_update_progress(gc, "Connecting", 0, 4);
		break;
	case 1:
		purple_connection_update_progress(gc, "Sending authorization", 1, 4);
		break;
	case 2:
		purple_connection_update_progress(gc, "Awaiting response", 2, 4);
		break;
	case 3:
		purple_connection_update_progress(gc, "Connection established", 3, 4);
		purple_connection_set_state(gc, PURPLE_CONNECTED);

		if (!wconn->connected)
			waprpl_insert_contacts(gc);

		wconn->connected = 1;

		PurpleAccount *account = purple_connection_get_account(gc);
		PurpleStatus *status = purple_account_get_active_status(account);
		waprpl_set_status(account, status);

		break;
	default:
		break;
	};
	
	/* Groups update */
	if (waAPI_getgroupsupdated(wconn->waAPI)) {

		/* Delete/update the chats that are in our list */
		PurpleBlistNode *node;

		for (node = purple_blist_get_root(); node; node = purple_blist_node_next(node, FALSE)) {
			if (!PURPLE_BLIST_NODE_IS_CHAT(node))
				continue;

			PurpleChat *ch = PURPLE_CHAT(node);
			if (purple_chat_get_account(ch) != acc)
				continue;

			GHashTable *hasht = purple_chat_get_components(ch);
			char *grid = g_hash_table_lookup(hasht, "id");
			char *glist = waAPI_getgroups(wconn->waAPI);
			gchar **gplist = g_strsplit(glist, ",", 0);

			if (str_array_find(gplist, grid) >= 0) {
				/* The group is in the system, update the fields */
				char *sub, *own;
				waAPI_getgroupinfo(wconn->waAPI, grid, &sub, &own, 0);
				g_hash_table_replace(hasht, g_strdup("subject"), g_strdup(sub));
				g_hash_table_replace(hasht, g_strdup("owner"), g_strdup(own));
				purple_blist_alias_chat(ch, g_strdup(sub));
			} else {
				/* The group was deleted */
				PurpleChat *del = (PurpleChat *) node;
				node = purple_blist_node_next(node, FALSE);
				purple_blist_remove_chat(del);
			}

			g_strfreev(gplist);
		}

		/* Add new groups */
		char *glist = waAPI_getgroups(wconn->waAPI);
		gchar **gplist = g_strsplit(glist, ",", 0);
		gchar **p;

		for (p = gplist; *p; p++) {
			gchar *gpid = *p;
			PurpleChat *ch = blist_find_chat_by_id(gc, gpid);
			if (!ch) {
				char *sub, *own;
				waAPI_getgroupinfo(wconn->waAPI, gpid, &sub, &own, 0);
				purple_debug_info("waprpl", "New group found %s %s\n", gpid, sub);

				GHashTable *htable = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free);
				g_hash_table_insert(htable, g_strdup("subject"), g_strdup(sub));
				g_hash_table_insert(htable, g_strdup("id"), g_strdup(gpid));
				g_hash_table_insert(htable, g_strdup("owner"), g_strdup(own));

				ch = purple_chat_new(acc, sub, htable);
				purple_blist_add_chat(ch, NULL, NULL);
			}
			/* Now update the open conversation that may exist */
			char *id = g_hash_table_lookup(purple_chat_get_components(ch), "id");
			int prplid = chatid_to_convo(id);
			PurpleConversation *conv = purple_find_chat(gc, prplid);
			char *subject, *owner, *part;
			if (conv && waAPI_getgroupinfo(wconn->waAPI, id, &subject, &owner, &part))
				conv_add_participants(conv, part, owner);
		}

		g_strfreev(gplist);
	}

	/* Incoming messages. */
	for (;;) {
		int r = waAPI_querynext(wconn->waAPI);

		if (r < 0)
			break;

		switch (r) {
		case 0:
			query_chat_message(gc);
			break;
		case 1:
			query_chat_image(gc);
			break;
		case 2:
			query_chat_location(gc);
			break;
		case 3:
			query_chat_sound(gc);
			break;
		case 4:
			query_chat_video(gc);
			break;
		default:
			/* Unsupported message type. */
			break;
		};
	}

	/* Status changes, typing notices and profile pictures. */
	query_status(gc);
	query_typing(gc);
	query_icon(gc);
}
Beispiel #18
0
static void waprpl_process_incoming_events(PurpleConnection * gc)
{
	whatsapp_connection *wconn = purple_connection_get_protocol_data(gc);
	PurpleAccount *acc = purple_connection_get_account(gc);

	int err;
	do {
		char * reason;
		err = waAPI_geterror(wconn->waAPI, &reason);
		if (err != 0) {
			PurpleConnectionError errcode = PURPLE_CONNECTION_ERROR_OTHER_ERROR;
			if (err == 1)
				errcode = PURPLE_CONNECTION_ERROR_AUTHENTICATION_FAILED;
			purple_connection_error_reason(gc, errcode, reason);
			g_free(reason);
		}
	} while (err != 0);

	switch (waAPI_loginstatus(wconn->waAPI)) {
	case 0:
		purple_connection_update_progress(gc, "Connecting", 0, 4);
		break;
	case 1:
		purple_connection_update_progress(gc, "Sending authorization", 1, 4);
		break;
	case 2:
		purple_connection_update_progress(gc, "Awaiting response", 2, 4);
		break;
	case 3:
		if (!wconn->connected) {
			purple_connection_update_progress(gc, "Connection established", 3, 4);
			purple_connection_set_state(gc, PURPLE_CONNECTED);

			PurpleAccount *account = purple_connection_get_account(gc);
			PurpleStatus *status = purple_account_get_active_status(account);

			waprpl_insert_contacts(gc);
			waprpl_set_status(account, status);

			wconn->connected = 1;
		}
		break;
	default:
		break;
	};
	
	/* Groups update */
	if (waAPI_getgroupsupdated(wconn->waAPI)) {
		purple_debug_info(WHATSAPP_ID, "Receiving update information from my groups\n");

		/* Delete/update the chats that are in our list */
		PurpleBlistNode *node;

		for (node = purple_blist_get_root(); node; node = purple_blist_node_next(node, FALSE)) {
			if (!PURPLE_BLIST_NODE_IS_CHAT(node))
				continue;

			PurpleChat *ch = PURPLE_CHAT(node);
			if (purple_chat_get_account(ch) != acc)
				continue;

			GHashTable *hasht = purple_chat_get_components(ch);
			char *grid = g_hash_table_lookup(hasht, "id");
			char *glist = waAPI_getgroups(wconn->waAPI);
			gchar **gplist = g_strsplit(glist, ",", 0);

			if (str_array_find(gplist, grid) >= 0) {
				/* The group is in the system, update the fields */
				char *sub, *own;
				waAPI_getgroupinfo(wconn->waAPI, grid, &sub, &own, 0);
				g_hash_table_replace(hasht, g_strdup("subject"), sub);
				g_hash_table_replace(hasht, g_strdup("owner"), own);
				purple_blist_alias_chat(ch, sub);
			} else {
				/* The group was deleted */
				PurpleChat *del = (PurpleChat *) node;
				node = purple_blist_node_next(node, FALSE);
				purple_blist_remove_chat(del);
			}

			g_strfreev(gplist);
			g_free(glist);
		}

		/* Add new groups */
		char *glist = waAPI_getgroups(wconn->waAPI);
		gchar **gplist = g_strsplit(glist, ",", 0);
		gchar **p;

		for (p = gplist; *p; p++) {
			gchar *gpid = *p;
			PurpleChat *ch = blist_find_chat_by_id(gc, gpid);
			if (!ch)
				ch = create_chat_group(gpid, wconn, acc);
			
			/* Now update the open conversation that may exist */
			char *id = g_hash_table_lookup(purple_chat_get_components(ch), "id");
			int prplid = chatid_to_convo(id);
			PurpleConversation *conv = purple_find_chat(gc, prplid);
			char *subject, *owner, *part;
			if (conv && waAPI_getgroupinfo(wconn->waAPI, id, &subject, &owner, &part)) {
				conv_add_participants(conv, part, owner);
			}
		}

		g_strfreev(gplist);
		g_free(glist);
	}

	t_message m;
	while (waAPI_querymsg(wconn->waAPI, &m)) {
		switch (m.type) {
		case 0:
			purple_debug_info(WHATSAPP_ID, "Got chat message from %s: %s\n", m.who, m.message);
			conv_add_message(gc, m.who, m.message, m.author, m.t);
			break;
		case 1: {
			purple_debug_info(WHATSAPP_ID, "Got image from %s: %s\n", m.who, m.message);
			int imgid = purple_imgstore_add_with_id(g_memdup(m.image, m.imagelen), m.imagelen, NULL);
			char *msg = g_strdup_printf("<a href=\"%s\"><img id=\"%u\"></a><br/><a href=\"%s\">%s</a>",
				m.url, imgid, m.url, m.url);
			conv_add_message(gc, m.who, msg, m.author, m.t);
			g_free(msg);
			} break;
		case 2: {
			purple_debug_info(WHATSAPP_ID, "Got geomessage from: %s Coordinates (%f %f)\n", 
				m.who, (float)m.lat, (float)m.lng);
			char * lat = dbl2str(m.lat);
			char * lng = dbl2str(m.lng);
			char *msg = g_strdup_printf("<a href=\"http://openstreetmap.org/?lat=%s&lon=%s&zoom=20\">"
				"http://openstreetmap.org/?lat=%s&lon=%s&zoom=20</a>", 
				lat, lng, lat, lng);
			conv_add_message(gc, m.who, msg, m.author, m.t);
			g_free(msg); g_free(lng); g_free(lat);
			} break;
		case 3: {
			purple_debug_info(WHATSAPP_ID, "Got chat sound from %s: %s\n", m.who, m.url);
			char *msg = g_strdup_printf("<a href=\"%s\">%s</a>", m.url, m.url);
			conv_add_message(gc, m.who, msg, m.author, m.t);
			g_free(msg);
			} break;
		case 4: {
			purple_debug_info(WHATSAPP_ID, "Got chat video from %s: %s\n", m.who, m.url);
			char *msg = g_strdup_printf("<a href=\"%s\">%s</a>", m.url, m.url);
			conv_add_message(gc, m.who, msg, m.author, m.t);
			g_free(msg);
			} break;
		case 5: {
			purple_debug_info(WHATSAPP_ID, "Got phone call from %s\n", m.who);
			conv_add_message(gc, m.who, "[Trying to voice-call you]", m.author, m.t);
			} break;
		default:
			purple_debug_info(WHATSAPP_ID, "Got an unrecognized message!\n");
			break;
		};
		g_free(m.who); g_free(m.author); g_free(m.message);
	}

	while (1) {
		int typer;
		char msgid[128];
		if (!waAPI_queryreceivedmsg(wconn->waAPI, msgid, &typer))
			break;

		purple_debug_info(WHATSAPP_ID, "Received message %s type: %d\n", msgid, typer);
		purple_signal_emit(purple_connection_get_prpl(gc), "whatsapp-message-received", gc, msgid, typer);
	}

	/* Status changes, typing notices and profile pictures. */
	query_status(gc);
	query_typing(gc);
	query_icon(gc);
}
Beispiel #19
0
void BuddyList::request_add_chat(PurpleAccount *account, PurpleGroup *group,
    const char *alias, const char *name)
{
  if (!CheckAnyAccountConnected())
    return;

  if (account) {
    PurpleConnection *gc = purple_account_get_connection(account);

    if (!PURPLE_PLUGIN_PROTOCOL_INFO(gc->prpl)->join_chat) {
      LOG->Message(_("This protocol does not support chat rooms."));
      return;
    }
  }
  else {
    // find an account with chat capabilities
    for (GList *l = purple_connections_get_all(); l; l = l->next) {
      PurpleConnection *gc = reinterpret_cast<PurpleConnection*>(l->data);

      if (PURPLE_PLUGIN_PROTOCOL_INFO(gc->prpl)->join_chat) {
        account = purple_connection_get_account(gc);
        break;
      }
    }

    if (!account) {
      LOG->Message(_("You are not currently signed on with any "
            "protocols that have the ability to chat."));
      return;
    }
  }

  PurpleRequestFields *fields = purple_request_fields_new();
  PurpleRequestFieldGroup *g = purple_request_field_group_new(NULL);

  purple_request_fields_add_group(fields, g);

  PurpleRequestField *f;
  f = purple_request_field_account_new("account", _("Account"), account);
  purple_request_field_group_add_field(g, f);
  f = purple_request_field_string_new("name", _("Chat name"), NULL, FALSE);
  purple_request_field_group_add_field(g, f);
  f = purple_request_field_string_new("alias", _("Alias"), NULL, FALSE);
  purple_request_field_group_add_field(g, f);

  f = purple_request_field_choice_new("group", _("Group"), 0);
  bool add_default_group = true;
  int dval = 0;
  bool dval_set = false;
  for (PurpleBlistNode *i = purple_blist_get_root(); i; i = i->next)
    if (PURPLE_BLIST_NODE_IS_GROUP(i)) {
      PurpleGroup *cur_group = reinterpret_cast<PurpleGroup*>(i);
      const char *cur_name = purple_group_get_name(cur_group);
      purple_request_field_choice_add(f, cur_name);
      if (!dval_set) {
        if (group == cur_group) {
          purple_request_field_choice_set_default_value(f, dval);
          dval_set = true;
        }
        dval++;
      }
      add_default_group = false;
    }
  if (add_default_group)
      purple_request_field_choice_add(f, _("Chats"));
  purple_request_field_group_add_field(g, f);

  f = purple_request_field_bool_new("autojoin", _("Auto-join"), FALSE);
  purple_request_field_group_add_field(g, f);

  purple_request_fields(NULL, _("Add chat"), NULL, NULL, fields, _("Add"),
      G_CALLBACK(add_chat_ok_cb_), CANCEL_BUTTON_TEXT, NULL, NULL, NULL, NULL,
      this);
}
Beispiel #20
0
static void
msn_session_sync_users(MsnSession *session)
{
	PurpleBlistNode *gnode, *cnode, *bnode;
	PurpleConnection *gc = purple_account_get_connection(session->account);
	GList *to_remove = NULL;

	g_return_if_fail(gc != NULL);

	/* The core used to use msn_add_buddy to add all buddies before
	 * being logged in. This no longer happens, so we manually iterate
	 * over the whole buddy list to identify sync issues. */

	for (gnode = purple_blist_get_root(); gnode; gnode = gnode->next) {
		PurpleGroup *group = (PurpleGroup *)gnode;
		const char *group_name = group->name;
		if(!PURPLE_BLIST_NODE_IS_GROUP(gnode))
			continue;
		for(cnode = gnode->child; cnode; cnode = cnode->next) {
			if(!PURPLE_BLIST_NODE_IS_CONTACT(cnode))
				continue;
			for(bnode = cnode->child; bnode; bnode = bnode->next) {
				PurpleBuddy *b;
				if(!PURPLE_BLIST_NODE_IS_BUDDY(bnode))
					continue;
				b = (PurpleBuddy *)bnode;
				if(purple_buddy_get_account(b) == purple_connection_get_account(gc)) {
					MsnUser *remote_user;
					gboolean found = FALSE;

					remote_user = msn_userlist_find_user(session->userlist, purple_buddy_get_name(b));

					if ((remote_user != NULL) && (remote_user->list_op & MSN_LIST_FL_OP))
					{
						int group_id;
						GList *l;

						group_id = msn_userlist_find_group_id(remote_user->userlist,
								group_name);

						for (l = remote_user->group_ids; l != NULL; l = l->next)
						{
							if (group_id == GPOINTER_TO_INT(l->data))
							{
								found = TRUE;
								break;
							}
						}

					}

					/* We don't care if they're in a different group, as long as they're on the
					 * list somewhere. If we check for the group, we cause pain, agony and
					 * suffering for people who decide to re-arrange their buddy list elsewhere.
					 */
					if (!found)
					{
						if ((remote_user == NULL) || !(remote_user->list_op & MSN_LIST_FL_OP)) {
							/* The user is not on the server list */
							msn_show_sync_issue(session, purple_buddy_get_name(b), group_name);
						} else {
							/* The user is not in that group on the server list */
							to_remove = g_list_prepend(to_remove, b);
						}
					}
				}
			}
		}
	}

	if (to_remove != NULL) {
		g_list_foreach(to_remove, (GFunc)purple_blist_remove_buddy, NULL);
		g_list_free(to_remove);
	}
}
Beispiel #21
0
static void
msn_session_sync_users(MsnSession *session)
{
	PurpleBlistNode *gnode, *cnode, *bnode;
	PurpleConnection *gc = purple_account_get_connection(session->account);

	g_return_if_fail(gc != NULL);

	/* The core used to use msn_add_buddy to add all buddies before
	 * being logged in. This no longer happens, so we manually iterate
	 * over the whole buddy list to identify sync issues. */

	for (gnode = purple_blist_get_root(); gnode; gnode = gnode->next) {
		PurpleGroup *group = (PurpleGroup *)gnode;
		const char *group_name = group->name;
		if(!PURPLE_BLIST_NODE_IS_GROUP(gnode))
			continue;
		for(cnode = gnode->child; cnode; cnode = cnode->next) {
			if(!PURPLE_BLIST_NODE_IS_CONTACT(cnode))
				continue;
			for(bnode = cnode->child; bnode; bnode = bnode->next) {
				PurpleBuddy *b;
				if(!PURPLE_BLIST_NODE_IS_BUDDY(bnode))
					continue;
				b = (PurpleBuddy *)bnode;
				if(purple_buddy_get_account(b) == purple_connection_get_account(gc)) {
					MsnUser *remote_user;
					gboolean found = FALSE;

					remote_user = msn_userlist_find_user(session->userlist, purple_buddy_get_name(b));

					if ((remote_user != NULL) && (remote_user->list_op & MSN_LIST_FL_OP))
					{
						int group_id;
						GList *l;

						group_id = msn_userlist_find_group_id(remote_user->userlist,
								group_name);

						for (l = remote_user->group_ids; l != NULL; l = l->next)
						{
							if (group_id == GPOINTER_TO_INT(l->data))
							{
								found = TRUE;
								break;
							}
						}

					}

					if (!found)
					{
						/* The user was not on the server list or not in that group
						 * on the server list */
						msn_show_sync_issue(session, purple_buddy_get_name(b), group_name);
					}
				}
			}
		}
	}
}
Beispiel #22
0
static void waprpl_process_incoming_events(PurpleConnection * gc)
{
	whatsapp_connection *wconn = purple_connection_get_protocol_data(gc);
	PurpleAccount *acc = purple_connection_get_account(gc);

	switch (waAPI_loginstatus(wconn->waAPI)) {
	case 0:
		purple_connection_update_progress(gc, "Connecting", 0, 4);
		break;
	case 1:
		purple_connection_update_progress(gc, "Sending authorization", 1, 4);
		break;
	case 2:
		purple_connection_update_progress(gc, "Awaiting response", 2, 4);
		break;
	case 3:
		purple_connection_update_progress(gc, "Connection established", 3, 4);
		purple_connection_set_state(gc, PURPLE_CONNECTED);

		if (!wconn->connected)
			waprpl_insert_contacts(gc);

		wconn->connected = 1;

		PurpleAccount *account = purple_connection_get_account(gc);
		PurpleStatus *status = purple_account_get_active_status(account);
		waprpl_set_status(account, status);

		break;
	default:
		break;
	};

	char *msg, *who, *prev, *url, *author;
	int status;
	int size;
	double lat, lng;
	unsigned long timestamp;
	/* Incoming messages */
	while (1) {
		int r = waAPI_querynext(wconn->waAPI);
		switch (r) {
		case 0:
		if (waAPI_querychat(wconn->waAPI, &who, &msg, &author, &timestamp)) {
			purple_debug_info(WHATSAPP_ID, "Got chat message from %s: %s\n", who, msg);
			conv_add_message(gc, who, msg, author, timestamp);
		}
		break;
		case 1:
		if (waAPI_querychatimage(wconn->waAPI, &who, &prev, &size, &url, &author, &timestamp)) {
			purple_debug_info(WHATSAPP_ID, "Got image from %s: %s\n", who, url);
			int imgid = purple_imgstore_add_with_id(g_memdup(prev, size), size, NULL);

			char *msg = g_strdup_printf("<a href=\"%s\"><img id=\"%u\"></a><br/><a href=\"%s\">%s</a>", url, imgid, url, url);
			conv_add_message(gc, who, msg, author, timestamp);
			g_free(msg);
		}
		break;
		case 2:
		if (waAPI_querychatlocation(wconn->waAPI, &who, &prev, &size, &lat, &lng, &author, &timestamp)) {
			purple_debug_info(WHATSAPP_ID, "Got geomessage from: %s Coordinates (%f %f)\n", who, (float)lat, (float)lng);
			int imgid = purple_imgstore_add_with_id(g_memdup(prev, size), size, NULL);
			char *msg = g_strdup_printf("<a href=\"http://openstreetmap.org/?lat=%f&lon=%f&zoom=16\"><img src=\"%u\"></a>", lat, lng, imgid);
			conv_add_message(gc, who, msg, author, timestamp);
			g_free(msg);
		}
		break;
		case 3:
		if (waAPI_querychatsound(wconn->waAPI, &who, &url, &author, &timestamp)) {
			purple_debug_info(WHATSAPP_ID, "Got chat sound from %s: %s\n", who, url);
			char *msg = g_strdup_printf("<a href=\"%s\">%s</a>", url, url);
			conv_add_message(gc, who, msg, author, timestamp);
			g_free(msg);
		}
		break;
		default: break;
		};
		if (r < 0) break;
	}

	/* User status change */
	while (waAPI_querystatus(wconn->waAPI, &who, &status)) {
		if (status == 1) {
			purple_prpl_got_user_status(acc, who, "available", "message", "", NULL);
		} else {
			purple_prpl_got_user_status(acc, who, "unavailable", "message", "", NULL);
		}
	}
	/* User typing info notify */
	while (waAPI_querytyping(wconn->waAPI, &who, &status)) {
		if (status == 1) {
			purple_debug_info(WHATSAPP_ID, "%s is typing\n", who);
			serv_got_typing(gc, who, 0, PURPLE_TYPING);
		} else {
			purple_debug_info(WHATSAPP_ID, "%s is not typing\n", who);
			serv_got_typing(gc, who, 0, PURPLE_NOT_TYPING);
			serv_got_typing_stopped(gc, who);
		}
	}

	/* User profile picture */
	char *icon, *hash;
	int len;
	while (waAPI_queryicon(wconn->waAPI, &who, &icon, &len, &hash)) {
		purple_buddy_icons_set_for_user(acc, who, g_memdup(icon, len), len, hash);
	}

	/* Groups update */
	if (waAPI_getgroupsupdated(wconn->waAPI)) {

		/* Delete/update the chats that are in our list */
		PurpleBlistNode *node;

		for (node = purple_blist_get_root(); node; node = purple_blist_node_next(node, FALSE)) {
			if (!PURPLE_BLIST_NODE_IS_CHAT(node))
				continue;

			PurpleChat *ch = PURPLE_CHAT(node);
			if (purple_chat_get_account(ch) != acc)
				continue;

			GHashTable *hasht = purple_chat_get_components(ch);
			char *grid = g_hash_table_lookup(hasht, "id");
			char *glist = waAPI_getgroups(wconn->waAPI);
			gchar **gplist = g_strsplit(glist, ",", 0);

			if (str_array_find(gplist, grid) >= 0) {
				/* The group is in the system, update the fields */
				char *sub, *own;
				waAPI_getgroupinfo(wconn->waAPI, grid, &sub, &own, 0);
				g_hash_table_insert(hasht, g_strdup("subject"), g_strdup(sub));
				g_hash_table_insert(hasht, g_strdup("owner"), g_strdup(own));
			} else {
				/* The group was deleted */
				PurpleChat *del = (PurpleChat *) node;
				node = purple_blist_node_next(node, FALSE);
				purple_blist_remove_chat(del);
			}

			g_strfreev(gplist);
		}

		/* Add new groups */
		char *glist = waAPI_getgroups(wconn->waAPI);
		gchar **gplist = g_strsplit(glist, ",", 0);
		gchar **p;

		for (p = gplist; *p; p++) {
			gchar *gpid = *p;
			PurpleChat *ch = blist_find_chat_by_id(gc, gpid);
			if (!ch) {
				char *sub, *own;
				waAPI_getgroupinfo(wconn->waAPI, gpid, &sub, &own, 0);
				purple_debug_info("waprpl", "New group found %s %s\n", gpid, sub);

				GHashTable *htable = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free);
				g_hash_table_insert(htable, g_strdup("subject"), g_strdup(sub));
				g_hash_table_insert(htable, g_strdup("id"), g_strdup(gpid));
				g_hash_table_insert(htable, g_strdup("owner"), g_strdup(own));

				ch = purple_chat_new(acc, sub, htable);
				purple_blist_add_chat(ch, NULL, NULL);
			}
			/* Now update the open conversation that may exist */
			char *id = g_hash_table_lookup(purple_chat_get_components(ch), "id");
			int prplid = chatid_to_convo(id);
			PurpleConversation *conv = purple_find_chat(gc, prplid);
			char *subject, *owner, *part;
			if (conv && waAPI_getgroupinfo(wconn->waAPI, id, &subject, &owner, &part))
				conv_add_participants(conv, part, owner);
		}

		g_strfreev(gplist);
	}
}
Beispiel #23
0
void
_purple_buddy_icons_blist_loaded_cb()
{
	PurpleBlistNode *node = purple_blist_get_root();
	const char *dirname = purple_buddy_icons_get_cache_dir();

	/* Doing this once here saves having to check it inside a loop. */
	if (old_icons_dir != NULL)
	{
		if (!g_file_test(dirname, G_FILE_TEST_IS_DIR))
		{
			purple_debug_info("buddyicon", "Creating icon cache directory.\n");

			if (g_mkdir(dirname, S_IRUSR | S_IWUSR | S_IXUSR) < 0)
			{
				purple_debug_error("buddyicon",
				                   "Unable to create directory %s: %s\n",
				                   dirname, g_strerror(errno));
			}
		}
	}

	while (node != NULL)
	{
		if (PURPLE_BLIST_NODE_IS_BUDDY(node))
		{
			const char *filename;

			filename = purple_blist_node_get_string(node, "buddy_icon");
			if (filename != NULL)
			{
				if (old_icons_dir != NULL)
				{
					migrate_buddy_icon(node,
					                   "buddy_icon",
					                   dirname, filename);
				}
				else
				{
					char *path = g_build_filename(dirname, filename, NULL);
					if (!g_file_test(path, G_FILE_TEST_EXISTS))
					{
						purple_blist_node_remove_setting(node,
						                                 "buddy_icon");
						purple_blist_node_remove_setting(node,
						                                 "icon_checksum");
					}
					else
						ref_filename(filename);
					g_free(path);
				}
			}
		}
		else if (PURPLE_BLIST_NODE_IS_CONTACT(node) ||
		         PURPLE_BLIST_NODE_IS_CHAT(node) ||
		         PURPLE_BLIST_NODE_IS_GROUP(node))
		{
			const char *filename;

			filename = purple_blist_node_get_string(node, "custom_buddy_icon");
			if (filename != NULL)
			{
				if (old_icons_dir != NULL)
				{
					migrate_buddy_icon(node,
					                   "custom_buddy_icon",
					                   dirname, filename);
				}
				else
				{
					char *path = g_build_filename(dirname, filename, NULL);
					if (!g_file_test(path, G_FILE_TEST_EXISTS))
					{
						purple_blist_node_remove_setting(node,
						                                 "custom_buddy_icon");
					}
					else
						ref_filename(filename);
					g_free(path);
				}
			}
		}
		node = purple_blist_node_next(node, TRUE);
	}
}
Beispiel #24
0
static void waprpl_process_incoming_events(PurpleConnection *gc) {
  whatsapp_connection * wconn = purple_connection_get_protocol_data(gc);
  PurpleAccount * acc = purple_connection_get_account(gc);

  switch (waAPI_loginstatus(wconn->waAPI)) {
  case 0:
    purple_connection_update_progress(gc, "Connecting", 0, 4);
    break;
  case 1:
    purple_connection_update_progress(gc, "Sending auth", 1, 4);
    break;
  case 2:
    purple_connection_update_progress(gc, "Waiting response", 2, 4);
    break;
  case 3:
    purple_connection_update_progress(gc, "Connected", 3, 4);
    purple_connection_set_state(gc, PURPLE_CONNECTED);
    
    if (!wconn->connected)
      waprpl_insert_contacts(gc);
      
    wconn->connected = 1;
    break;
  default:
    break;
  };
  
  char * msg, * who, * prev, * url, *author;
  int status; int size;
  double lat,lng;
  // Incoming messages
  while (waAPI_querychat(wconn->waAPI, &who, &msg, &author)) {
    purple_debug_info(WHATSAPP_ID, "Got chat message from %s: %s\n", who,msg);
    
    if (isgroup(who)) {
      // Search fot the combo
      PurpleBlistNode* node = purple_blist_get_root();
      GHashTable* hasht = NULL;
      while (node != 0) {
        if (PURPLE_BLIST_NODE_IS_CHAT(node)) {
          PurpleChat * ch = PURPLE_CHAT(node);
          if (purple_chat_get_account(ch) == acc) {
            hasht = purple_chat_get_components(ch);
            if (strcmp(g_hash_table_lookup(hasht, "id"),who) == 0) {
              break;
            }
          }
        }
        node = purple_blist_node_next(node,FALSE);
      }
      int convo_id = chatid_to_convo(who);
      PurpleConversation *convo = purple_find_chat(gc, convo_id);
      
      // Create a window if it's not open yet
      if (!convo)
        waprpl_chat_join(gc,hasht);
      
      if (convo != NULL) {
        serv_got_chat_in(gc, purple_conv_chat_get_id(PURPLE_CONV_CHAT(convo)), author, PURPLE_MESSAGE_RECV, msg, time(NULL));
      }else{
        printf("Received group message but could not find the group! %s\n",msg);
      }
    }else{
      // Search fot the combo
      PurpleConversation *convo = purple_find_conversation_with_account(PURPLE_CONV_TYPE_IM, who, acc);
      if (!convo)
        convo = purple_conversation_new(PURPLE_CONV_TYPE_IM, acc, who);
      
      serv_got_chat_in(gc, purple_conv_chat_get_id(PURPLE_CONV_IM(convo)), who, PURPLE_MESSAGE_RECV, msg, time(NULL));
      purple_conv_im_write(PURPLE_CONV_IM(convo), who, msg, PURPLE_MESSAGE_RECV, time(NULL));
    }
  }
  while (waAPI_querychatimage(wconn->waAPI, &who, &prev, &size, &url)) {
    printf("Got chat image %s %s\n",who,url);
    purple_debug_info(WHATSAPP_ID, "Got image from %s: %s\n", who,url);
    
    // Search fot the combo
    PurpleConversation *convo = purple_find_conversation_with_account(PURPLE_CONV_TYPE_IM, who, acc);
    if (!convo)
      convo = purple_conversation_new(PURPLE_CONV_TYPE_IM, acc, who);
      
    int imgid = purple_imgstore_add_with_id(g_memdup(prev, size), size, NULL);

    serv_got_chat_in(gc, purple_conv_chat_get_id(PURPLE_CONV_IM(convo)), who, PURPLE_MESSAGE_RECV, msg, time(NULL));
    purple_conv_im_write(PURPLE_CONV_IM(convo), who, g_strdup_printf("<a href=\"%s\"><img id=\"%u\"></a>",url,imgid),
      PURPLE_MESSAGE_RECV | PURPLE_MESSAGE_IMAGES, time(NULL));
  }
  while (waAPI_querychatlocation(wconn->waAPI, &who, &prev, &size, &lat, &lng)) {
    purple_debug_info(WHATSAPP_ID, "Got geomessage from: %s Coordinates (%f %f)\n", who,(float)lat,(float)lng);
    
    // Search fot the combo
    PurpleConversation *convo = purple_find_conversation_with_account(PURPLE_CONV_TYPE_IM, who, acc);
    if (!convo)
      convo = purple_conversation_new(PURPLE_CONV_TYPE_IM, acc, who);
      
    int imgid = purple_imgstore_add_with_id(g_memdup(prev, size), size, NULL);

    serv_got_chat_in(gc, purple_conv_chat_get_id(PURPLE_CONV_IM(convo)), who, PURPLE_MESSAGE_RECV, msg, time(NULL));
    purple_conv_im_write(PURPLE_CONV_IM(convo), who, 
      g_strdup_printf("<a href=\"http://openstreetmap.org/?lat=%f&lon=%f&zoom=16\"><img src=\"%u\"></a>",lat,lng,imgid),
      PURPLE_MESSAGE_RECV | PURPLE_MESSAGE_IMAGES, time(NULL));
  }
  while (waAPI_querychatsound(wconn->waAPI, &who, &url)) {
    purple_debug_info(WHATSAPP_ID, "Got chat sound from %s: %s\n", who,url);
    
    // Search fot the combo
    PurpleConversation *convo = purple_find_conversation_with_account(PURPLE_CONV_TYPE_IM, who, acc);
    if (!convo)
      convo = purple_conversation_new(PURPLE_CONV_TYPE_IM, acc, who);

    serv_got_chat_in(gc, purple_conv_chat_get_id(PURPLE_CONV_IM(convo)), who, PURPLE_MESSAGE_RECV, msg, time(NULL));
    purple_conv_im_write(PURPLE_CONV_IM(convo), who, g_strdup_printf("<a href=\"%s\">%s</a>",url,url),
      PURPLE_MESSAGE_RECV , time(NULL));
  }
  
  // User status change
  while (waAPI_querystatus(wconn->waAPI, &who, &status)) {
    if (status == 1) {
      purple_prpl_got_user_status(acc, who, "available", "message","", NULL);
    }
    else {
      purple_prpl_got_user_status(acc, who, "unavailable", "message","", NULL);
    }
  }
  // User typing info notify
  while (waAPI_querytyping(wconn->waAPI, &who, &status)) {
    if (status == 1) {
      serv_got_typing(gc,who,0,PURPLE_TYPING);
    }
    else {
      serv_got_typing_stopped(gc,who);
    }
  }
  
  // User profile picture
  char * icon, * hash;
  int len;
  while (waAPI_queryicon(wconn->waAPI, &who, &icon, &len, &hash)) {
    purple_buddy_icons_set_for_user(acc,who, g_memdup(icon,len),len, hash);
  }
  
  // Groups update
  if (waAPI_getgroupsupdated(wconn->waAPI)) {
  
    // Delete/update the chats that are in our list
    PurpleBlistNode* node = purple_blist_get_root();
    while (node != 0) {
      if (PURPLE_BLIST_NODE_IS_CHAT(node)) {
        PurpleChat * ch = PURPLE_CHAT(node);
        if (purple_chat_get_account(ch) == acc) {
        
          int found = 0;
          GHashTable *hasht = purple_chat_get_components(ch);
          char * grid = g_hash_table_lookup(hasht, "id");
          char * glist = waAPI_getgroups(wconn->waAPI);
          gchar **gplist = g_strsplit(glist,",",0);
          while (*gplist) {
            if (strcmp(*gplist,grid) == 0) {
              // The group is in the system, update the fields
              char *id,*sub,*own;
              waAPI_getgroupinfo(wconn->waAPI, *gplist, &sub, &own, 0);
              g_hash_table_insert(hasht, g_strdup("subject"), g_strdup(sub));
              g_hash_table_insert(hasht, g_strdup("owner"), g_strdup(own));
              
              found = 1;
              break;
            }
            gplist++;
          }

          // The group was deleted
          if (!found) {
              PurpleBlistNode* del = node;
              node = purple_blist_node_next(node,FALSE);
              purple_blist_remove_chat(del);
          }
          
        }
      }
      node = purple_blist_node_next(node,FALSE);
    }

    // Add new groups
    char * glist = waAPI_getgroups(wconn->waAPI);
    gchar **gplist = g_strsplit(glist,",",0);
    while (*gplist) {
      int found = 0;
      PurpleBlistNode* node = purple_blist_get_root();
      PurpleChat * ch;
      while (node != 0) {
        if (PURPLE_BLIST_NODE_IS_CHAT(node)) {
          ch = PURPLE_CHAT(node);
          if (purple_chat_get_account(ch) == acc) {
            char * grid = g_hash_table_lookup(purple_chat_get_components(ch), "id");
            if (strcmp(*gplist,grid) == 0) {
              found = 1;
              break;
            }
          }
        }
        node = purple_blist_node_next(node,FALSE);
      }

      if (!found) {
        char *sub,*own;
        waAPI_getgroupinfo(wconn->waAPI, *gplist, &sub, &own, 0);
        purple_debug_info("waprpl", "New group found %s %s\n", *gplist,sub);
        
        GHashTable * htable = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free);
        g_hash_table_insert(htable, g_strdup("subject"), g_strdup(sub));
        g_hash_table_insert(htable, g_strdup("id"), g_strdup(*gplist));
        g_hash_table_insert(htable, g_strdup("owner"), g_strdup(own));

        ch = purple_chat_new(acc,sub,htable);
        purple_blist_add_chat(ch,NULL,NULL);
      }
      
      // Now update the open conversation that may exist
      char * id = g_hash_table_lookup(purple_chat_get_components(ch), "id");
      int prplid = chatid_to_convo(id);
      PurpleConversation * conv = purple_find_chat(gc, prplid);
      if (conv) {
        char *subject, *owner, *part;
        if (!waAPI_getgroupinfo(wconn->waAPI, id, &subject, &owner, &part)) return;
        
        purple_conv_chat_clear_users(purple_conversation_get_chat_data(conv));
        gchar **plist = g_strsplit(part,",",0);
        while (*plist) {
          purple_conv_chat_add_user (purple_conversation_get_chat_data(conv),
            *plist,"",PURPLE_CBFLAGS_NONE | (!strcmp(owner,*plist) ? PURPLE_CBFLAGS_FOUNDER : 0),FALSE);
          plist++;
        }
      }
      
      gplist++;
    }
  }
}