Fixed connecting/disconnecting.
This commit is contained in:
parent
f7b086d38d
commit
7c81c9dcfc
@ -628,43 +628,47 @@ tox_weechat_cmd_tox(void *data, struct t_gui_buffer *buffer,
|
|||||||
return WEECHAT_RC_OK;
|
return WEECHAT_RC_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (argc == 3 && (weechat_strcasecmp(argv[1], "connect") == 0))
|
else if (argc >= 3 && (weechat_strcasecmp(argv[1], "connect") == 0))
|
||||||
{
|
{
|
||||||
char *name = argv[2];
|
for (int i = 2; i < argc; ++i)
|
||||||
|
|
||||||
struct t_tox_weechat_identity *identity = tox_weechat_identity_name_search(name);
|
|
||||||
if (!identity)
|
|
||||||
{
|
{
|
||||||
weechat_printf(NULL,
|
char *name = argv[i];
|
||||||
"%s%s: Identity \"%s\" does not exist.",
|
struct t_tox_weechat_identity *identity = tox_weechat_identity_name_search(name);
|
||||||
weechat_prefix("error"),
|
if (!identity)
|
||||||
weechat_plugin->name,
|
{
|
||||||
name);
|
weechat_printf(NULL,
|
||||||
}
|
"%s%s: Identity \"%s\" does not exist.",
|
||||||
else
|
weechat_prefix("error"),
|
||||||
{
|
weechat_plugin->name,
|
||||||
tox_weechat_identity_connect(identity);
|
name);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
tox_weechat_identity_connect(identity);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return WEECHAT_RC_OK;
|
return WEECHAT_RC_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (argc == 3 && (weechat_strcasecmp(argv[1], "disconnect") == 0))
|
else if (argc >= 3 && (weechat_strcasecmp(argv[1], "disconnect") == 0))
|
||||||
{
|
{
|
||||||
char *name = argv[2];
|
for (int i = 2; i < argc; ++i)
|
||||||
|
|
||||||
struct t_tox_weechat_identity *identity = tox_weechat_identity_name_search(name);
|
|
||||||
if (!identity)
|
|
||||||
{
|
{
|
||||||
weechat_printf(NULL,
|
char *name = argv[i];
|
||||||
"%s%s: Identity \"%s\" does not exist.",
|
struct t_tox_weechat_identity *identity = tox_weechat_identity_name_search(name);
|
||||||
weechat_prefix("error"),
|
if (!identity)
|
||||||
weechat_plugin->name,
|
{
|
||||||
name);
|
weechat_printf(NULL,
|
||||||
}
|
"%s%s: Identity \"%s\" does not exist.",
|
||||||
else
|
weechat_prefix("error"),
|
||||||
{
|
weechat_plugin->name,
|
||||||
tox_weechat_identity_disconnect(identity);
|
name);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
tox_weechat_identity_disconnect(identity);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return WEECHAT_RC_OK;
|
return WEECHAT_RC_OK;
|
||||||
@ -740,8 +744,8 @@ tox_weechat_commands_init()
|
|||||||
"list"
|
"list"
|
||||||
" || create <name>"
|
" || create <name>"
|
||||||
" || delete <name> -yes|-keepdata"
|
" || delete <name> -yes|-keepdata"
|
||||||
" || connect <name>"
|
" || connect [<name>...]"
|
||||||
" || disconnect <name>",
|
" || disconnect [<name>...]",
|
||||||
" list: list all Tox identity\n"
|
" list: list all Tox identity\n"
|
||||||
" create: create a new Tox identity\n"
|
" create: create a new Tox identity\n"
|
||||||
" delete: delete a Tox identity; requires either "
|
" delete: delete a Tox identity; requires either "
|
||||||
@ -752,7 +756,7 @@ tox_weechat_commands_init()
|
|||||||
"list"
|
"list"
|
||||||
" || create"
|
" || create"
|
||||||
" || delete %(tox_identities) -yes|-keepdata"
|
" || delete %(tox_identities) -yes|-keepdata"
|
||||||
" || connect %(tox_disconnected_identities)"
|
" || connect %(tox_disconnected_identities)|%*"
|
||||||
" || disconnect %(tox_connected_identities)",
|
" || disconnect %(tox_connected_identities)|%*",
|
||||||
tox_weechat_cmd_tox, NULL);
|
tox_weechat_cmd_tox, NULL);
|
||||||
}
|
}
|
||||||
|
@ -39,10 +39,7 @@ bar_item_away(void *data,
|
|||||||
{
|
{
|
||||||
struct t_tox_weechat_identity *identity = tox_weechat_identity_for_buffer(buffer);
|
struct t_tox_weechat_identity *identity = tox_weechat_identity_for_buffer(buffer);
|
||||||
|
|
||||||
if (!identity)
|
if (!identity || !(identity->tox))
|
||||||
return NULL;
|
|
||||||
|
|
||||||
if (identity->tox == NULL || identity->tox_online == false)
|
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
char *status = NULL;;
|
char *status = NULL;;
|
||||||
@ -68,7 +65,7 @@ bar_item_input_prompt(void *data,
|
|||||||
{
|
{
|
||||||
struct t_tox_weechat_identity *identity = tox_weechat_identity_for_buffer(buffer);
|
struct t_tox_weechat_identity *identity = tox_weechat_identity_for_buffer(buffer);
|
||||||
|
|
||||||
if (identity->tox == NULL || identity->tox_online == false)
|
if (!identity || !(identity->tox))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
return tox_weechat_get_self_name_nt(identity->tox);
|
return tox_weechat_get_self_name_nt(identity->tox);
|
||||||
@ -88,11 +85,14 @@ bar_item_buffer_plugin(void *data, struct t_gui_bar_item *item,
|
|||||||
const char *identity_name = identity->name;
|
const char *identity_name = identity->name;
|
||||||
|
|
||||||
snprintf(string, sizeof(string),
|
snprintf(string, sizeof(string),
|
||||||
"%s%s/%s%s",
|
"%s%s/%s%s%s/%s%s",
|
||||||
plugin_name,
|
plugin_name,
|
||||||
weechat_color("bar_delim"),
|
weechat_color("bar_delim"),
|
||||||
weechat_color("bar_fg"),
|
weechat_color("bar_fg"),
|
||||||
identity_name);
|
identity_name,
|
||||||
|
weechat_color("bar_delim"),
|
||||||
|
weechat_color("bar_fg"),
|
||||||
|
identity->tox_online ? "online" : "offline");
|
||||||
|
|
||||||
return strdup(string);
|
return strdup(string);
|
||||||
}
|
}
|
||||||
|
@ -175,6 +175,14 @@ tox_weechat_bootstrap_tox(Tox *tox, const char *address, uint16_t port, const ch
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
tox_weechat_bootstrap_random_node(Tox *tox)
|
||||||
|
{
|
||||||
|
int i = rand() % tox_weechat_bootstrap_count;
|
||||||
|
tox_weechat_bootstrap_tox(tox, tox_weechat_bootstrap_addresses[i],
|
||||||
|
tox_weechat_bootstrap_ports[i],
|
||||||
|
tox_weechat_bootstrap_keys[i]);
|
||||||
|
}
|
||||||
|
|
||||||
struct t_tox_weechat_identity *
|
struct t_tox_weechat_identity *
|
||||||
tox_weechat_identity_new(const char *name)
|
tox_weechat_identity_new(const char *name)
|
||||||
@ -207,15 +215,6 @@ tox_weechat_identity_new(const char *name)
|
|||||||
return identity;
|
return identity;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
|
||||||
tox_weechat_bootstrap_random_node(Tox *tox)
|
|
||||||
{
|
|
||||||
int i = rand() % tox_weechat_bootstrap_count;
|
|
||||||
tox_weechat_bootstrap_tox(tox, tox_weechat_bootstrap_addresses[i],
|
|
||||||
tox_weechat_bootstrap_ports[i],
|
|
||||||
tox_weechat_bootstrap_keys[i]);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
void
|
||||||
tox_weechat_identity_connect(struct t_tox_weechat_identity *identity)
|
tox_weechat_identity_connect(struct t_tox_weechat_identity *identity)
|
||||||
{
|
{
|
||||||
@ -230,6 +229,12 @@ tox_weechat_identity_connect(struct t_tox_weechat_identity *identity)
|
|||||||
tox_weechat_identity_buffer_close_callback, identity);
|
tox_weechat_identity_buffer_close_callback, identity);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
weechat_printf(identity->buffer,
|
||||||
|
"%s%s: identity %s connecting",
|
||||||
|
weechat_prefix("network"),
|
||||||
|
weechat_plugin->name,
|
||||||
|
identity->name);
|
||||||
|
|
||||||
// create Tox
|
// create Tox
|
||||||
identity->tox = tox_new(NULL);
|
identity->tox = tox_new(NULL);
|
||||||
|
|
||||||
@ -302,10 +307,12 @@ tox_weechat_identity_disconnect(struct t_tox_weechat_identity *identity)
|
|||||||
free(path);
|
free(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
tox_weechat_identity_set_online_status(identity, false);
|
|
||||||
|
|
||||||
// stop Tox timer
|
// stop Tox timer
|
||||||
weechat_unhook(identity->tox_do_timer);
|
weechat_unhook(identity->tox_do_timer);
|
||||||
|
|
||||||
|
// have to refresh and hide bar items even if we were already offline
|
||||||
|
tox_weechat_identity_refresh_online_status(identity);
|
||||||
|
tox_weechat_identity_set_online_status(identity, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@ -320,32 +327,40 @@ tox_weechat_identity_autoconnect()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
tox_weechat_identity_refresh_online_status(struct t_tox_weechat_identity *identity)
|
||||||
|
{
|
||||||
|
weechat_bar_item_update("buffer_plugin");
|
||||||
|
weechat_bar_item_update("input_prompt");
|
||||||
|
weechat_bar_item_update("away");
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
tox_weechat_identity_set_online_status(struct t_tox_weechat_identity *identity,
|
tox_weechat_identity_set_online_status(struct t_tox_weechat_identity *identity,
|
||||||
bool online)
|
bool online)
|
||||||
{
|
{
|
||||||
identity->tox_online = identity->tox && online;
|
if (identity->tox_online ^ online)
|
||||||
|
|
||||||
weechat_bar_item_update("input_prompt");
|
|
||||||
weechat_bar_item_update("away");
|
|
||||||
|
|
||||||
struct t_gui_buffer *buffer = identity->buffer ?: NULL;
|
|
||||||
|
|
||||||
if (identity->tox_online)
|
|
||||||
{
|
{
|
||||||
weechat_printf(buffer,
|
identity->tox_online = online;
|
||||||
"%s%s: identity %s connected",
|
tox_weechat_identity_refresh_online_status(identity);
|
||||||
weechat_prefix("network"),
|
|
||||||
weechat_plugin->name,
|
struct t_gui_buffer *buffer = identity->buffer ?: NULL;
|
||||||
identity->name);
|
if (identity->tox_online)
|
||||||
}
|
{
|
||||||
else
|
weechat_printf(buffer,
|
||||||
{
|
"%s%s: identity %s connected",
|
||||||
weechat_printf(buffer,
|
weechat_prefix("network"),
|
||||||
"%s%s: identity %s disconnected",
|
weechat_plugin->name,
|
||||||
weechat_prefix("network"),
|
identity->name);
|
||||||
weechat_plugin->name,
|
}
|
||||||
identity->name);
|
else
|
||||||
|
{
|
||||||
|
weechat_printf(buffer,
|
||||||
|
"%s%s: identity %s disconnected",
|
||||||
|
weechat_prefix("network"),
|
||||||
|
weechat_plugin->name,
|
||||||
|
identity->name);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -70,6 +70,9 @@ tox_weechat_identity_disconnect(struct t_tox_weechat_identity *identity);
|
|||||||
void
|
void
|
||||||
tox_weechat_identity_autoconnect();
|
tox_weechat_identity_autoconnect();
|
||||||
|
|
||||||
|
void
|
||||||
|
tox_weechat_identity_refresh_online_status(struct t_tox_weechat_identity *identity);
|
||||||
|
|
||||||
void
|
void
|
||||||
tox_weechat_identity_set_online_status(struct t_tox_weechat_identity *identity,
|
tox_weechat_identity_set_online_status(struct t_tox_weechat_identity *identity,
|
||||||
bool online);
|
bool online);
|
||||||
|
@ -45,10 +45,7 @@ tox_weechat_do_timer_cb(void *data,
|
|||||||
|
|
||||||
// check connection status
|
// check connection status
|
||||||
int connected = tox_isconnected(identity->tox);
|
int connected = tox_isconnected(identity->tox);
|
||||||
if (connected ^ identity->tox_online)
|
tox_weechat_identity_set_online_status(identity, connected);
|
||||||
{
|
|
||||||
tox_weechat_identity_set_online_status(identity, connected);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return WEECHAT_RC_OK;
|
return WEECHAT_RC_OK;
|
||||||
|
Loading…
Reference in New Issue
Block a user