Tony Olagbaiye 3 years ago
parent 4e2e7d91cc
commit 020da2710e
No known key found for this signature in database
GPG Key ID: 9E2FF3BDEBDFC910

@ -89,13 +89,14 @@
** TODO [#A] Implement essential functionality (milestone v0.2)
* [X] Opening PMs with initial message
* [X] OOB media messages
* [ ] Buffer autoswitch on enter/open
* [ ] Handle open/enter jids with a resource without breaking
* [ ] Allow /close without crashing
* [X] Buffer autoswitch on enter/open
* [X] Handle open/enter jids with a resource without breaking
* [X] Allow /close without crashing
* [ ] [#B] Handle wide errors gracefully
* [ ] [#B] Event-driven MUC entrance
* [ ] MUCs
* [X] Opening (/enter)
* [ ] Leave on /close
* [X] Receiving
* [X] Sending
* [ ] [#B] Edits

@ -352,7 +352,6 @@ void account__disconnect(struct t_account *account, int reconnect)
(void) reconnect;
struct t_channel *ptr_channel;
(void) ptr_channel;
if (account->is_connected)
{
@ -415,7 +414,9 @@ void account__disconnect(struct t_account *account, int reconnect)
account__set_lag (account);
account->monitor = 0;
account->monitor_time = 0;
*/
/*
if (reconnect
&& IRC_SERVER_OPTION_BOOLEAN(account, IRC_SERVER_OPTION_AUTORECONNECT))
account__reconnect_schedule(account);
@ -437,10 +438,8 @@ void account__disconnect(struct t_account *account, int reconnect)
*/
/* send signal "account_disconnected" with account name */
/*
(void) weechat_hook_signal_send("account_disconnected",
(void) weechat_hook_signal_send("xmpp_account_disconnected",
WEECHAT_HOOK_SIGNAL_STRING, account->name);
*/
}
void account__disconnect_all()
@ -516,6 +515,9 @@ int account__connect(struct t_account *account)
connection__connect(account, &account->connection, account_jid(account),
account_password(account), account_tls(account));
(void) weechat_hook_signal_send("xmpp_account_connected",
WEECHAT_HOOK_SIGNAL_STRING, account->name);
return account->is_connected;
}

@ -21,6 +21,9 @@ void buffer__get_account_and_channel(struct t_gui_buffer *buffer,
if (!buffer)
return;
*account = NULL;
*channel = NULL;
/* look for a account or channel using this buffer */
for (ptr_account = accounts; ptr_account;
ptr_account = ptr_account->next_account)
@ -45,8 +48,6 @@ void buffer__get_account_and_channel(struct t_gui_buffer *buffer,
}
}
}
/* no account or channel found */
}
char *buffer__typing_bar_cb(const void *pointer, void *data,
@ -73,7 +74,7 @@ char *buffer__typing_bar_cb(const void *pointer, void *data,
buffer__get_account_and_channel(buffer, &account, &channel);
if (!channel)
return strdup("");
return strndup("", 0);
typecount = 0;
@ -105,7 +106,7 @@ char *buffer__typing_bar_cb(const void *pointer, void *data,
}
else
{
return strdup("");
return strndup("", 0);
}
}
@ -140,25 +141,51 @@ int buffer__close_cb(const void *pointer, void *data,
struct t_account *ptr_account = NULL;
struct t_channel *ptr_channel = NULL;
buffer_plugin = weechat_buffer_get_pointer(buffer, "plugin");
if (buffer_plugin == weechat_plugin)
buffer__get_account_and_channel(buffer,
&ptr_account, &ptr_channel);
(void) pointer;
(void) data;
(void) buffer;
buffer_plugin = weechat_buffer_get_pointer(buffer, "plugin");
if (buffer_plugin != weechat_plugin)
return WEECHAT_RC_OK;
buffer__get_account_and_channel(buffer, &ptr_account, &ptr_channel);
const char* type = weechat_buffer_get_string(buffer, "localvar_type");
if (weechat_strcasecmp(type, "server") == 0)
{
if (ptr_account)
{
if (!ptr_account->disconnected)
{
//command_quit_account(ptr_account, NULL);
account__disconnect(ptr_account, 0);
}
ptr_account->buffer = NULL;
}
}
else if (weechat_strcasecmp(type, "channel") == 0)
{
if (ptr_account && ptr_channel)
{
if (!ptr_account->disconnected)
{
channel__free(ptr_account, ptr_channel);
}
}
}
else if (weechat_strcasecmp(type, "private") == 0)
{
if (ptr_account && ptr_channel)
{
if (!ptr_account->disconnected)
{
channel__free(ptr_account, ptr_channel);
}
}
}
else
{
}
return WEECHAT_RC_OK;
}

@ -101,6 +101,9 @@ struct t_channel_typing *channel__typing_search(struct t_channel *channel,
void channel__add_typing(struct t_channel *channel,
struct t_user *user);
void channel__free(struct t_account *account,
struct t_channel *channel);
void channel__free_all(struct t_account *account);
void channel__update_topic(struct t_channel *channel,

@ -4,6 +4,7 @@
#include <strophe.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <weechat/weechat-plugin.h>
@ -237,6 +238,66 @@ int command__account_connect(int argc, char **argv)
return (connect_ok) ? WEECHAT_RC_OK : WEECHAT_RC_ERROR;
}
int command__disconnect_account(struct t_account *account)
{
if (!account)
return 0;
if (!account->is_connected)
{
weechat_printf(
NULL,
_("%s%s: not connected to account \"%s\"!"),
weechat_prefix("error"), WEECHAT_XMPP_PLUGIN_NAME,
account->name);
}
account__disconnect(account, 0);
return 1;
}
int command__account_disconnect(int argc, char **argv)
{
int i, nb_disconnect, disconnect_ok;
struct t_account *ptr_account;
(void) argc;
(void) argv;
disconnect_ok = 1;
nb_disconnect = 0;
for (i = 2; i < argc; i++)
{
nb_disconnect++;
ptr_account = account__search(argv[i]);
if (ptr_account)
{
if (!command__disconnect_account(ptr_account))
{
disconnect_ok = 0;
}
}
else
{
weechat_printf(
NULL,
_("%s%s: account not found \"%s\" "),
weechat_prefix("error"), WEECHAT_XMPP_PLUGIN_NAME,
argv[i]);
}
}
return (disconnect_ok) ? WEECHAT_RC_OK : WEECHAT_RC_ERROR;
}
int command__account_reconnect(int argc, char **argv)
{
command__account_disconnect(argc, argv);
return command__account_connect(argc, argv);
}
void command__account_delete(int argc, char **argv)
{
struct t_account *account;
@ -316,6 +377,18 @@ int command__account(const void *pointer, void *data,
return WEECHAT_RC_OK;
}
if (weechat_strcasecmp(argv[1], "disconnect") == 0)
{
command__account_disconnect(argc, argv);
return WEECHAT_RC_OK;
}
if (weechat_strcasecmp(argv[1], "reconnect") == 0)
{
command__account_reconnect(argc, argv);
return WEECHAT_RC_OK;
}
if (weechat_strcasecmp(argv[1], "delete") == 0)
{
command__account_delete(argc, argv);
@ -397,6 +470,11 @@ int command__enter(const void *pointer, void *data,
channel__send_message(ptr_account, ptr_channel, jid, text);
}
char buf[16];
int num = weechat_buffer_get_integer(ptr_channel->buffer, "number");
snprintf(buf, sizeof(buf), "/buffer %d", num);
weechat_command(ptr_account->buffer, buf);
}
weechat_string_free_split(jids);
}
@ -432,7 +510,11 @@ int command__open(const void *pointer, void *data,
if (argc > 1)
{
jid = xmpp_jid_bare(ptr_account->context, argv[1]);
int n_jid = 0;
char **jids = weechat_string_split(argv[1], ",", NULL, 0, 0, &n_jid);
for (int i = 0; i < n_jid; i++)
{
jid = xmpp_jid_bare(ptr_account->context, jids[i]);
pres = xmpp_presence_new(ptr_account->context);
xmpp_stanza_set_to(pres, jid);
@ -450,6 +532,13 @@ int command__open(const void *pointer, void *data,
channel__send_message(ptr_account, ptr_channel, jid, text);
}
char buf[16];
int num = weechat_buffer_get_integer(ptr_channel->buffer, "number");
snprintf(buf, sizeof(buf), "/buffer %d", num);
weechat_command(ptr_account->buffer, buf);
}
weechat_string_free_split(jids);
}
return WEECHAT_RC_OK;
@ -517,14 +606,20 @@ void command__init()
N_("list"
" || add <account>"
" || connect <account>"
" || disconnect <account>"
" || reconnect <account>"
" || delete <account>"),
N_(" list: list accounts\n"
" add: add a xmpp account\n"
" connect: connect to a xmpp account\n"
"disconnect: disconnect from a xmpp account\n"
" reconnect: reconnect an xmpp account\n"
" delete: delete a xmpp account\n"),
"list"
" || add %(xmpp_account)"
" || connect %(xmpp_account)"
" || disconnect %(xmpp_account)"
" || reconnect %(xmpp_account)"
" || delete %(xmpp_account)",
&command__account, NULL, NULL);
if (!hook)

Loading…
Cancel
Save