void
skypeweb_do_all_the_things(SkypeWebAccount *sa)
{
	if (!sa->username) {
		skypeweb_get_self_details(sa);
	} else
	if (sa->registration_token) {
		skypeweb_get_self_details(sa);
		
		if (sa->authcheck_timeout) 
			purple_timeout_remove(sa->authcheck_timeout);
		skypeweb_check_authrequests(sa);
		sa->authcheck_timeout = purple_timeout_add_seconds(120, (GSourceFunc)skypeweb_check_authrequests, sa);
		purple_connection_set_state(sa->pc, PURPLE_CONNECTION_CONNECTED);

		skypeweb_get_friend_list(sa);
		skypeweb_poll(sa);
		
		skype_web_get_offline_history(sa);

		skypeweb_set_status(sa->account, purple_account_get_active_status(sa->account));
	} else {
		//Too soon!
		skypeweb_get_registration_token(sa);
	}
}
Beispiel #2
0
static gboolean
purple_sound_play_required(const PurpleAccount *account)
{
	gint pref_status = purple_prefs_get_int("/purple/sound/while_status");

	if (pref_status == PURPLE_SOUND_STATUS_ALWAYS)
	{
		/* Play sounds: Always */
		return TRUE;
	}

	if (account != NULL)
	{
		PurpleStatus *status = purple_account_get_active_status(account);

		if (purple_status_is_online(status))
		{
			gboolean available = purple_status_is_available(status);
			return (( available && pref_status == PURPLE_SOUND_STATUS_AVAILABLE) ||
			        (!available && pref_status == PURPLE_SOUND_STATUS_AWAY));
		}
	}

	/* We get here a couple of ways.  Either the request has been OK'ed
	 * by purple_sound_play_event() and we're here because the UI has
	 * called purple_sound_play_file(), or we're here for something
	 * not related to an account (like testing a sound). */
	return TRUE;
}
Beispiel #3
0
gboolean jabber_chat_change_nick(JabberChat *chat, const char *nick)
{
	xmlnode *presence;
	char *full_jid;
	PurpleAccount *account;
	PurpleStatus *status;
	JabberBuddyState state;
	char *msg;
	int priority;

	if(!chat->muc) {
		purple_conv_chat_write(PURPLE_CONV_CHAT(chat->conv), "",
				_("Nick changing not supported in non-MUC chatrooms"),
				PURPLE_MESSAGE_SYSTEM, time(NULL));
		return FALSE;
	}

	account = purple_connection_get_account(chat->js->gc);
	status = purple_account_get_active_status(account);

	purple_status_to_jabber(status, &state, &msg, &priority);

	presence = jabber_presence_create_js(chat->js, state, msg, priority);
	full_jid = g_strdup_printf("%s@%s/%s", chat->room, chat->server, nick);
	xmlnode_set_attrib(presence, "to", full_jid);
	g_free(full_jid);
	g_free(msg);

	jabber_send(chat->js, presence);
	xmlnode_free(presence);

	return TRUE;
}
guint sipe_backend_status(struct sipe_core_public *sipe_public)
{
	struct sipe_backend_private *purple_private = sipe_public->backend_private;
	PurpleStatus *status = purple_account_get_active_status(purple_private->account);
	if (!status) return(SIPE_ACTIVITY_UNSET);
	return(sipe_purple_token_to_activity(purple_status_get_id(status)));
}
Beispiel #5
0
//gets the text of whatever the user sets the status to. (not necessarily what status is on the server)
//client_text and server_text are freed if it returns false
static gboolean getStatusText(char** client_text, char** server_text, PurpleAccount *account, const char** sid)
{
	PurpleStatus* status;
	PurpleSavedStatus* savedStatus;
	PurpleSavedStatusSub* substat;
	const char* statusMessage;

	status = purple_account_get_active_status(account);
	if (status == NULL)
       	{
		purple_debug_fatal("MusicInfo", "Account with NULL status\n");
		return FALSE;
	}

	*sid = purple_status_get_id(status);
	statusMessage = purple_status_get_attr_string(status, "message");
	if(statusMessage != NULL)
	{
		*server_text = g_strdup(statusMessage);
	}
	else
	{
		*server_text = g_strdup("\0");
	}


	savedStatus = purple_savedstatus_get_current();
	if (savedStatus == NULL) 
	{
		purple_debug_fatal("MusicInfo", "Account with NULL saved status\n");
		g_free(*server_text);
		return FALSE;
	}
	
	statusMessage = NULL;
	if(purple_savedstatus_has_substatuses(savedStatus))
	{
		substat = purple_savedstatus_get_substatus(savedStatus, account);
		if(substat != NULL)
			statusMessage = purple_savedstatus_substatus_get_message(substat);
	}
	
	if(statusMessage == NULL)
	{
		statusMessage = purple_savedstatus_get_message(savedStatus);
	}
		
	if(statusMessage == NULL)
	{
		g_free(*server_text);
		return FALSE;
	}
	
	*client_text = g_strdup(statusMessage);
	return TRUE;
}
static gboolean
should_notify_unavailable (PurpleAccount *account)
{
	PurpleStatus *status;

	if (!purple_prefs_get_bool ("/plugins/gtk/libnotify/only_available"))
		return TRUE;

	status = purple_account_get_active_status (account);

	return purple_status_is_online (status) && purple_status_is_available (status);
}
Beispiel #7
0
void
pn_update_personal_message (MsnSession *session)
{
    PurpleAccount *account;
    PurplePresence *presence;
    gchar *current_media;

    g_return_if_fail (session);

    if (!session->logged_in)
        return;

    account = msn_session_get_user_data (session);
    presence = purple_account_get_presence (account);

    current_media = create_current_media_string (presence);

#ifndef PECAN_USE_PSM
    const gchar *msg;

    msg = purple_account_get_string (account, "personal_message", "");
    pn_set_personal_message (session, (gchar *) msg, current_media);
#else
    PurpleStatus *status;
    const gchar *formatted_msg;

    status = purple_account_get_active_status (account);
    formatted_msg = purple_status_get_attr_string (status, "message");

    if (formatted_msg)
    {
        gchar *msg;
        gchar *tmp;

        tmp = purple_markup_strip_html (formatted_msg);
        msg = g_markup_escape_text (tmp, -1);
        pn_set_personal_message (session, msg, current_media);

        g_free (tmp);
        g_free (msg);
    }
    else
    {
        pn_set_personal_message (session, NULL, current_media);
    }
#endif /* PECAN_USE_PSM */

    if (current_media)
        g_free (current_media);
}
Beispiel #8
0
void pending_reads_send_all (struct tgl_state *TLS) {
  if (! purple_account_get_bool (tls_get_pa (TLS), TGP_KEY_SEND_READ_NOTIFICATIONS,
      TGP_DEFAULT_SEND_READ_NOTIFICATIONS)) {
    debug ("automatic read recipes disabled, not sending recipes");
    return;
  }
  if (! p2tgl_status_is_present (purple_account_get_active_status (tls_get_pa (TLS)))) {
    debug ("user is not present, not sending recipes");
    return;
  }
  debug ("sending all pending recipes");
  g_hash_table_foreach (tls_get_data (TLS)->pending_reads, tgl_do_mark_read_gw, TLS);
  g_hash_table_remove_all (tls_get_data (TLS)->pending_reads);
}
/////////////////////////////////////////////////////////////////////////////
// Determines whether Lock'n'Roll should update the status message when the
//  workstation is locked.  This returns false if the current status is away
//  already, invisible, or offline (fixes bug in 1.0.1)
/////////////////////////////////////////////////////////////////////////////
static gboolean lnr_should_change_message(PurpleAccount *acct)
{
    PurpleStatusType *activeStatusType = NULL;
    activeStatusType = purple_status_get_type(purple_account_get_active_status(acct));
    switch (purple_status_type_get_primitive(activeStatusType))
    {
    case PURPLE_STATUS_AWAY:
    case PURPLE_STATUS_EXTENDED_AWAY:
    case PURPLE_STATUS_UNAVAILABLE:
    case PURPLE_STATUS_INVISIBLE:
    case PURPLE_STATUS_OFFLINE:
        return FALSE;
    default:
        return TRUE;
    }
}
Beispiel #10
0
static gboolean
set_status (PurpleAccount *acnt, const char *loc)
{
   // discover the pidgin saved status in use for this account
   const char *savedmessage = "";
   {
      PurpleSavedStatus *savedstatus = purple_savedstatus_get_current();
      if (savedstatus)
      {
         PurpleSavedStatusSub *savedsubstatus = purple_savedstatus_get_substatus(savedstatus, acnt);
         if (savedsubstatus)
         {
            // use account-specific saved status
            savedmessage = purple_savedstatus_substatus_get_message(savedsubstatus);
         }
         else
         {
            // don't have an account-specific saved status, use the general one
            savedmessage = purple_savedstatus_get_message(savedstatus);
         }
      }
   }

   /* generate status */
   char *msg;
   if (savedmessage) {
      msg = (char *)malloc(strlen(savedmessage)+strlen(loc)+1);
      strcpy(msg, loc);
      strcat(msg, savedmessage);
   }
   else msg = loc;

	PurpleStatus *status = purple_account_get_active_status (acnt);
   GList *attrs = NULL;
   attrs = g_list_append(attrs, "message");
   attrs = g_list_append(attrs, (gpointer)msg);
   purple_status_set_active_with_attrs_list(status, TRUE, attrs);
   g_list_free(attrs);
   trace("setup the account(%s) status: %s", acnt->username, msg);

   if (savedmessage) {
      free(msg);
   }

   return TRUE;
}
Beispiel #11
0
static void
buddy_typing_cb(PurpleAccount *acct, const char *name, void *data) {
  PurpleConversation *gconv;

  if(purple_prefs_get_bool(PREF_STATUS) &&
     ! purple_status_is_available(purple_account_get_active_status(acct))) {
    purple_debug_info("psychic", "not available, doing nothing\n");
    return;
  }

  if(purple_prefs_get_bool(PREF_BUDDIES) &&
     ! purple_find_buddy(acct, name)) {
    purple_debug_info("psychic", "not in blist, doing nothing\n");
    return;
  }

  if(FALSE == purple_privacy_check(acct, name)) {
    purple_debug_info("psychic", "user %s is blocked\n", name);
    return;
  }

  gconv = purple_find_conversation_with_account(PURPLE_CONV_TYPE_IM, name, acct);
  if(! gconv) {
    purple_debug_info("psychic", "no previous conversation exists\n");
    gconv = purple_conversation_new(PURPLE_CONV_TYPE_IM, acct, name);

    if(purple_prefs_get_bool(PREF_RAISE)) {
      purple_conversation_present(gconv);
    }

    if(purple_prefs_get_bool(PREF_NOTICE)) {

      /* This is a quote from Star Wars.  You should probably not
	 translate it literally.  If you can't find a fitting cultural
	 reference in your language, consider translating something
	 like this instead: "You feel a new message coming." */
      purple_conversation_write(gconv, NULL,
			      _("You feel a disturbance in the force..."),
			      PURPLE_MESSAGE_SYSTEM | PURPLE_MESSAGE_NO_LOG | PURPLE_MESSAGE_ACTIVE_ONLY,
			      time(NULL));
    }

    /* Necessary because we may be creating a new conversation window. */
    purple_conv_im_set_typing_state(PURPLE_CONV_IM(gconv), PURPLE_TYPING);
  }
}
Beispiel #12
0
JabberChat *jabber_join_chat(JabberStream *js, const char *room,
                             const char *server, const char *handle,
                             const char *password, GHashTable *data)
{
	JabberChat *chat;

	PurpleConnection *gc;
	PurpleAccount *account;
	PurpleStatus *status;

	xmlnode *presence, *x;
	JabberBuddyState state;
	char *msg;
	int priority;

	char *jid;

	chat = jabber_chat_new(js, room, server, handle, password, data);
	if (chat == NULL)
		return NULL;

	gc = js->gc;
	account = purple_connection_get_account(gc);
	status = purple_account_get_active_status(account);
	purple_status_to_jabber(status, &state, &msg, &priority);

	presence = jabber_presence_create_js(js, state, msg, priority);
	g_free(msg);

	jid = g_strdup_printf("%s@%s/%s", room, server, handle);
	xmlnode_set_attrib(presence, "to", jid);
	g_free(jid);

	x = xmlnode_new_child(presence, "x");
	xmlnode_set_namespace(x, "http://jabber.org/protocol/muc");

	if (password && *password) {
		xmlnode *p = xmlnode_new_child(x, "password");
		xmlnode_insert_data(p, password, -1);
	}

	jabber_send(js, presence);
	xmlnode_free(presence);

	return chat;
}
Beispiel #13
0
static void irc_connected(struct irc_conn *irc, const char *nick)
{
	PurpleConnection *gc;
	PurpleStatus *status;
	PurpleBlistNode *gnode, *cnode, *bnode;

	if ((gc = purple_account_get_connection(irc->account)) == NULL
	    || PURPLE_CONNECTION_IS_CONNECTED(gc))
		return;

	purple_connection_set_display_name(gc, nick);
	purple_connection_set_state(gc, PURPLE_CONNECTED);

	/* If we're away then set our away message */
	status = purple_account_get_active_status(irc->account);
	if (!purple_status_get_type(status) != PURPLE_STATUS_AVAILABLE) {
		PurplePluginProtocolInfo *prpl_info = PURPLE_PLUGIN_PROTOCOL_INFO(gc->prpl);
		prpl_info->set_status(irc->account, status);
	}

	/* this used to be in the core, but it's not now */
	for (gnode = purple_get_blist()->root; gnode; gnode = gnode->next) {
		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(b->account == gc->account) {
					struct irc_buddy *ib = g_new0(struct irc_buddy, 1);
					ib->name = g_strdup(b->name);
					g_hash_table_insert(irc->buddies, ib->name, ib);
				}
			}
		}
	}

	irc_blist_timeout(irc);
	if (!irc->timer)
		irc->timer = purple_timeout_add_seconds(45, (GSourceFunc)irc_blist_timeout, (gpointer)irc);
}
Beispiel #14
0
static void* _background_login(void* data)
{
    qq_account* ac=(qq_account*)data;
    if(!qq_account_valid(ac)) return NULL;
    LwqqClient* lc = ac->qq;
    LwqqErrorCode err;
    //it would raise a invalid ac when wake up from sleep.
    //it would login twice,why? 
    //so what i can do is disable the invalid one.
    if(!lwqq_client_valid(lc)) return NULL;
    const char* status = purple_status_get_id(purple_account_get_active_status(ac->account));

    lwqq_login(lc,lwqq_status_from_str(status), &err);

    if (err == LWQQ_EC_LOGIN_NEED_VC) {
        lc->dispatch(vp_func_pi,(CALLBACK_FUNC)extra_async_opt.need_verify,lc,err);
    }else{
        lc->dispatch(vp_func_pi,(CALLBACK_FUNC)extra_async_opt.login_complete,lc,err);
    }
    return NULL;
}
gboolean sipe_backend_status_changed(struct sipe_core_public *sipe_public,
				     guint activity,
				     const gchar *message)
{
	struct sipe_backend_private *purple_private = sipe_public->backend_private;
	PurpleStatus *status = purple_account_get_active_status(purple_private->account);
	const gchar *status_id = sipe_purple_activity_to_token(activity);
	gboolean changed = TRUE;

	if (g_str_equal(status_id, purple_status_get_id(status)) &&
	    sipe_strequal(message,
			  purple_status_get_attr_string(status,
							SIPE_PURPLE_STATUS_ATTR_ID_MESSAGE)))
	{
		changed = FALSE;
	}

	if (purple_savedstatus_is_idleaway()) {
		changed = FALSE;
	}

	return(changed);
}
Beispiel #16
0
static void msg_received(PurpleAccount *account, char *sender, char *message,
                         PurpleConversation *conv, PurpleMessageFlags flags)
{
    char *topic, *mod, *host, *_port;
    int port;
    PurpleStatus *status;

    topic = (char *) purple_prefs_get_string("/plugins/gtk/"PLUGIN_ID"/topic");
    mod = (char *) purple_prefs_get_string("/plugins/gtk/"PLUGIN_ID"/mod");
    host = (char *) purple_prefs_get_string("/plugins/gtk/"PLUGIN_ID"/host");
    _port = (char *) purple_prefs_get_string("/plugins/gtk/"PLUGIN_ID"/port");
    port = atoi(_port);

    purple_debug_info(PLUGIN_NAME, sender);
    purple_debug_info(PLUGIN_NAME, message);
    purple_debug_info(PLUGIN_NAME, topic);
    purple_debug_info(PLUGIN_NAME, mod);

    status = purple_account_get_active_status(account);
    if (status != NULL && !purple_status_is_avaliable(status)) {
        msg_send(host, port, (const char *) message, topic, mod);
    }
}
std::string get_account_status()
{
    std::string result;
    // :fixme:
    // atm we get the status only for the first account (assuming the status is
    // identical forall active accounts - which may not be true)
    GList *p_accounts = purple_accounts_get_all_active();
    if (p_accounts) {
        PurpleStatus *p_status = purple_account_get_active_status(
          reinterpret_cast<PurpleAccount*>(g_list_first(p_accounts)->data));
        const char *p_status_text = purple_primitive_get_name_from_type(
          purple_status_type_get_primitive(purple_status_get_type(p_status)));
        if (p_status_text) {
            result = p_status_text;
        } else {
            result = "Unknown";
            }
    } else {
        // no active accounts -> offline
        result = "Offline";
    }
    return result;
}
Beispiel #18
0
static void discover_status(PurpleConnection *from, PurpleConnection *to,
                            gpointer userdata) {
  const char *from_username = purple_account_get_username(purple_connection_get_account(from));
  const char *to_username = purple_account_get_username(purple_connection_get_account(to));

  if (purple_blist_find_buddy(purple_connection_get_account(from), to_username)) {
    PurpleStatus *status = purple_account_get_active_status(purple_connection_get_account(to));
    const char *status_id = purple_status_get_id(status);
    const char *message = purple_status_get_attr_string(status, "message");

    if (!strcmp(status_id, NULL_STATUS_ONLINE) ||
        !strcmp(status_id, NULL_STATUS_AWAY) ||
        !strcmp(status_id, NULL_STATUS_OFFLINE)) {
      purple_debug_info("nullprpl", "%s sees that %s is %s: %s\n",
                        from_username, to_username, status_id, message);
      purple_prpl_got_user_status(purple_connection_get_account(from), to_username, status_id,
                                  (message) ? "message" : NULL, message, NULL);
    } else {
      purple_debug_error("nullprpl",
                         "%s's buddy %s has an unknown status: %s, %s",
                         from_username, to_username, status_id, message);
    }
  }
}
Beispiel #19
0
static gboolean
do_signon(gpointer data)
{
	PurpleAccount *account = data;
	PidginAutoRecon *info;
	PurpleStatus *status;

	purple_debug_info("autorecon", "do_signon called\n");
	g_return_val_if_fail(account != NULL, FALSE);
	info = g_hash_table_lookup(auto_reconns, account);

	if (info)
		info->timeout = 0;

	status = purple_account_get_active_status(account);
	if (purple_status_is_online(status))
	{
		purple_debug_info("autorecon", "calling purple_account_connect\n");
		purple_account_connect(account);
		purple_debug_info("autorecon", "done calling purple_account_connect\n");
	}

	return FALSE;
}
static void received_im_msg_cb(PurpleAccount *account, char *who, char *buffer,
    PurpleConversation *conv, PurpleMessageFlags flags, void *data) {
    // A workaround to avoid skipping of the first message as a result on NULL-conv:
    if (conv == NULL) conv = purple_conversation_new(PURPLE_CONV_TYPE_IM,
        account, who); 
    PurpleBuddy *buddy = purple_find_buddy(account, who);
    PurplePresence *presence = purple_buddy_get_presence(buddy);
    msg_metadata_t msg;

    //Get message
    msg.text = purple_markup_strip_html(buffer);
    msg.remote_username = who;

    //LOCAL USER:
    msg.local_alias = purple_account_get_alias(account);
    msg.local_username = (char *) purple_account_get_name_for_display(account);

    //REMOTE USER (Buddy):
    //Get buddy alias
    msg.remote_alias = purple_buddy_get_alias(buddy);
    if(msg.remote_alias == NULL) msg.remote_alias = "";

    //Get buddy group
    PurpleGroup *group = purple_buddy_get_group(buddy);
    //return empty string if not in group
    msg.remote_from_group = group != NULL ? purple_group_get_name(group) : ""; 

    //Get protocol ID
    msg.protocol_id = purple_account_get_protocol_id(account);
    //trim out PROTOCOL_PREFIX (eg.: "prpl-irc" => "irc")
    if(!strncmp(msg.protocol_id,PROTOCOL_PREFIX,strlen(PROTOCOL_PREFIX))) 
        msg.protocol_id += strlen(PROTOCOL_PREFIX); 

    //Get status
    PurpleStatus *status = purple_account_get_active_status(account);
    PurpleStatusType *type = purple_status_get_type(status);
    //remote
    PurpleStatus *r_status = purple_presence_get_active_status(presence);
    PurpleStatusType *r_status_type =	purple_status_get_type(r_status);

    //Get status id
    msg.local_status_id = NULL;
    msg.local_status_id = purple_primitive_get_id_from_type(
        purple_status_type_get_primitive(type));
    //remote
    msg.remote_status_id = NULL;
    msg.remote_status_id = purple_primitive_get_id_from_type(
        purple_status_type_get_primitive(r_status_type));

    //Get status message
    msg.local_status_msg = NULL;
    if (purple_status_type_get_attr(type, "message") != NULL) {
        msg.local_status_msg = purple_status_get_attr_string(status, "message");
    } else {
        PurpleSavedStatus *savedstatus = purple_savedstatus_get_current();
        if(savedstatus)
            msg.local_status_msg = purple_savedstatus_get_message(savedstatus);
    }
    //remote
    msg.remote_status_msg = NULL;
    if (purple_status_type_get_attr(r_status_type, "message") != NULL) {
        msg.remote_status_msg = purple_status_get_attr_string(r_status, "message");
    } else {
        msg.remote_status_msg = "";
    }

    run_lua(conv, msg);
}
Beispiel #21
0
JabberChat *jabber_join_chat(JabberStream *js, const char *room,
                             const char *server, const char *handle,
                             const char *password, GHashTable *data)
{
	JabberChat *chat;

	PurpleConnection *gc;
	PurpleAccount *account;
	PurpleStatus *status;

	xmlnode *presence, *x;
	JabberBuddyState state;
	char *msg;
	int priority;

	char *jid;

	char *history_maxchars;
	char *history_maxstanzas;
	char *history_seconds;
	char *history_since;

	struct tm history_since_datetime;
	const char *history_since_string = NULL;

	chat = jabber_chat_new(js, room, server, handle, password, data);
	if (chat == NULL)
		return NULL;

	gc = js->gc;
	account = purple_connection_get_account(gc);
	status = purple_account_get_active_status(account);
	purple_status_to_jabber(status, &state, &msg, &priority);

	presence = jabber_presence_create_js(js, state, msg, priority);
	g_free(msg);

	jid = g_strdup_printf("%s@%s/%s", room, server, handle);
	xmlnode_set_attrib(presence, "to", jid);
	g_free(jid);

	history_maxchars   = g_hash_table_lookup(data, "history_maxchars");
	history_maxstanzas = g_hash_table_lookup(data, "history_maxstanzas");
	history_seconds    = g_hash_table_lookup(data, "history_seconds");
	history_since      = g_hash_table_lookup(data, "history_since");

	if (history_since) {
		if (purple_str_to_time(history_since, TRUE, &history_since_datetime, NULL, NULL) != 0) {
			history_since_string = purple_utf8_strftime("%Y-%m-%dT%H:%M:%SZ", &history_since_datetime);
		} else {
			history_since_string = NULL;

			purple_debug_error("jabber", "Invalid date format for history_since"
			                             " while requesting history: %s", history_since);
		}
	}

	x = xmlnode_new_child(presence, "x");
	xmlnode_set_namespace(x, "http://jabber.org/protocol/muc");

	if (password && *password) {
		xmlnode *p = xmlnode_new_child(x, "password");
		xmlnode_insert_data(p, password, -1);
	}

	if ((history_maxchars && *history_maxchars)
	    || (history_maxstanzas && *history_maxstanzas)
	    || (history_seconds && *history_seconds)
	    || (history_since_string && *history_since_string)) {

		xmlnode *history = xmlnode_new_child(x, "history");

		if (history_maxchars && *history_maxchars) {
			xmlnode_set_attrib(history, "maxchars", history_maxchars);
		}
		if (history_maxstanzas && *history_maxstanzas) {
			xmlnode_set_attrib(history, "maxstanzas", history_maxstanzas);
		}
		if (history_seconds && *history_seconds) {
			xmlnode_set_attrib(history, "seconds", history_seconds);
		}
		if (history_since_string && *history_since_string) {
			xmlnode_set_attrib(history, "since", history_since_string);
		}
	}

	jabber_send(js, presence);
	xmlnode_free(presence);

	return chat;
}
Beispiel #22
0
static void tgp_msg_display (struct tgl_state *TLS, struct tgp_msg_loading *C) {
  connection_data *conn = TLS->ev_base;
  struct tgl_message *M = C->msg;
  char *text = NULL;
  int flags = 0;

  // only display new messages, ignore updates or deletions
  if ((M->flags & (TGLMF_EMPTY | TGLMF_DELETED)) ||
      !(M->flags & TGLMF_CREATED) ||
      !M->message ||
      tgp_outgoing_msg (TLS, M) ||
      !tgl_get_peer_type (M->to_id)) {
    return;
  }

  if (M->flags & TGLMF_SERVICE) {
    text = format_service_msg (TLS, M);
    flags |= PURPLE_MESSAGE_SYSTEM;
  }
  else if (M->media.type == tgl_message_media_document && M->media.document->flags & TGLDF_STICKER) {
#ifdef HAVE_LIBWEBP
    char *filename = C->data;
    int img = p2tgl_imgstore_add_with_id_webp (filename);
    if (img <= 0) { failure ("Cannot display sticker, adding to imgstore failed"); return; }
    used_images_add (conn, img);
    text = format_img_full (img);
    flags |= PURPLE_MESSAGE_IMAGES;
    g_free (filename);
#else
    char *txt_user = p2tgl_strdup_alias (tgl_peer_get (TLS, M->from_id));
    text = g_strdup_printf ("%s sent a sticker", txt_user);
    flags |= PURPLE_MESSAGE_SYSTEM;
    g_free (txt_user);
#endif
  }
  else if (M->media.type == tgl_message_media_photo ||
          (M->media.type == tgl_message_media_document_encr && M->media.encr_document->flags & TGLDF_IMAGE)) {
    char *filename = C->data;
    int img = p2tgl_imgstore_add_with_id (filename);
    if (img <= 0) {
      failure ("Cannot display picture message, adding to imgstore failed.");
      return;
    }
    used_images_add (conn, img);
    text = format_img_full (img);
    flags |= PURPLE_MESSAGE_IMAGES;
    g_free (filename);
  }
  else if (M->media.type == tgl_message_media_document) {
    char *who = p2tgl_strdup_id (M->from_id);
    if (! tgp_our_msg(TLS, M)) {
      tgprpl_recv_file (conn->gc, who, M->media.document);
    }
    g_free (who);
    return;
  }
  else if (M->media.type == tgl_message_media_document_encr) {
    char *who = p2tgl_strdup_id (M->to_id);
    if (! tgp_our_msg(TLS, M)) {
      tgprpl_recv_encr_file (conn->gc, who, M->media.encr_document);
    }
    g_free (who);
    return;
  }
  else {
    text = format_message (M);
    flags |= PURPLE_MESSAGE_RECV;
  }
  
  if (! text || ! *text) {
    warning ("No text to display");
    return;
  }
  switch (tgl_get_peer_type (M->to_id)) {
    case TGL_PEER_CHAT: {
      if (chat_show (conn->gc, tgl_get_peer_id (M->to_id))) {
        p2tgl_got_chat_in (TLS, M->to_id, M->from_id, text, flags, M->date);
      }
      pending_reads_add (conn->pending_reads, M->to_id);
      break;
    }
    case TGL_PEER_ENCR_CHAT: {
      p2tgl_got_im (TLS, M->to_id, text, flags, M->date);
      pending_reads_add (conn->pending_reads, M->to_id);
      break;
    }
    case TGL_PEER_USER: {
      if (tgp_our_msg (TLS, M)) {
        flags |= PURPLE_MESSAGE_SEND;
        flags &= ~PURPLE_MESSAGE_RECV;
        p2tgl_got_im_combo (TLS, M->to_id, text, flags, M->date);
      } else {
        p2tgl_got_im (TLS, M->from_id, text, flags, M->date);
        pending_reads_add (conn->pending_reads, M->from_id);
      }
      break;
    }
  }
  
  if (p2tgl_status_is_present (purple_account_get_active_status (conn->pa)) && p2tgl_send_notifications(conn->pa)) {
    pending_reads_send_all (conn->pending_reads, conn->TLS);
  }
  
  g_free (text);
}
Beispiel #23
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);
}
static void tgp_msg_display (struct tgl_state *TLS, struct tgp_msg_loading *C) {
  connection_data *conn = TLS->ev_base;
  struct tgl_message *M = C->msg;
  char *text = NULL;
  int flags = 0;
  
  // Filter message updates and deletes, are not created and
  // all messages in general that were already displayed, or shouldn't be displayed
  if ((M->flags & (FLAG_MESSAGE_EMPTY | FLAG_DELETED)) ||
      !(M->flags & FLAG_CREATED) ||
      !M->message ||
      our_msg (TLS, M) ||
      !tgl_get_peer_type (M->to_id)) {
    return;
  }
  
  
  if (M->service) {
    text = format_service_msg (TLS, M);
    flags |= PURPLE_MESSAGE_SYSTEM;
  }
  else if (M->media.type == tgl_message_media_document) {
    char *who = p2tgl_strdup_id (M->from_id);
    if (! out_msg(TLS, M)) {
      tgprpl_recv_file (conn->gc, who, &M->media.document);
    }
    g_free (who);
    return;
  }
  else if (M->media.type == tgl_message_media_document_encr) {
    char *who = p2tgl_strdup_id (M->from_id);
    if (! out_msg(TLS, M)) {
      tgprpl_recv_encr_file (conn->gc, who, &M->media.encr_document);
    }
    g_free (who);
  }
  else if (M->media.type == tgl_message_media_photo) {
    char *filename = C->data;
    int imgStoreId = p2tgl_imgstore_add_with_id (filename);
    if (imgStoreId <= 0) {
      failure ("Cannot display picture message, adding to imgstore failed.");
      return;
    }
    used_images_add (conn, imgStoreId);
    text = format_img_full (imgStoreId);
    flags |= PURPLE_MESSAGE_IMAGES;
  }
  else {
    text = format_message (M);
    flags |= PURPLE_MESSAGE_RECV;
  }
  
  
  if (! text || ! *text) {
    warning ("No text to display");
    return;
  }
  switch (tgl_get_peer_type (M->to_id)) {
    case TGL_PEER_CHAT: {
      if (chat_show (conn->gc, tgl_get_peer_id (M->to_id))) {
        p2tgl_got_chat_in (TLS, M->to_id, M->from_id, text, flags, M->date);
      }
      pending_reads_add (conn->pending_reads, M->to_id);
      break;
    }
    case TGL_PEER_ENCR_CHAT: {
      p2tgl_got_im (TLS, M->to_id, text, flags, M->date);
      pending_reads_add (conn->pending_reads, M->to_id);
      break;
    }
    case TGL_PEER_USER: {
      if (out_msg (TLS, M)) {
        flags |= PURPLE_MESSAGE_SEND;
        flags &= ~PURPLE_MESSAGE_RECV;
        p2tgl_got_im_combo (TLS, M->to_id, text, flags, M->date);
      } else {
        p2tgl_got_im (TLS, M->from_id, text, flags, M->date);
        pending_reads_add (conn->pending_reads, M->from_id);
      }
      break;
    }
  }
  
  
  if (p2tgl_status_is_present (purple_account_get_active_status (conn->pa))) {
    pending_reads_send_all (conn->pending_reads, conn->TLS);
  }

  
  g_free (text);
}
Beispiel #25
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 #26
0
void QuetzalAccount::handleSignedOn()
{
	setStatusChanged(purple_account_get_active_status(m_account));
	if (PURPLE_PLUGIN_PROTOCOL_INFO(m_account->gc->prpl)->chat_info)
		resetGroupChatManager(new QuetzalJoinChatManager(this));
}
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);
}