Commit 911e6e83 authored by Richard Bayerle's avatar Richard Bayerle
Browse files

Add 'disable' for 'IM's to API and new commands UI

parent 75dd8b98
......@@ -58,6 +58,7 @@ void lurch_api_id_list_handler(PurpleAccount * acc_p, void (*cb)(int32_t err, GL
id_list = omemo_devicelist_get_id_list(dl_p);
//TODO: somehow make clear which is the own ID, maybe sort the list so that the own ID is always the first?
//TODO: then probably merge this with "id show", no one needs two of those
cb(ret_val, id_list, user_data_p);
......@@ -86,6 +87,25 @@ void lurch_api_enable_im_handler(PurpleAccount * acc_p, const char * contact_bar
g_free(db_fn_omemo);
}
void lurch_api_disable_im_handler(PurpleAccount * acc_p, const char * contact_bare_jid, void (*cb)(int32_t err, void * user_data_p), void * user_data_p) {
int32_t ret_val = 0;
char * uname = (void *) 0;
char * db_fn_omemo = (void *) 0;
uname = lurch_util_uname_strip(purple_account_get_username(acc_p));
db_fn_omemo = lurch_util_uname_get_db_fn(uname, LURCH_DB_NAME_OMEMO);
ret_val = omemo_storage_chatlist_save(contact_bare_jid, db_fn_omemo);
if (ret_val) {
purple_debug_error(MODULE_NAME, "Failed to add %s to the blacklist in OMEMO DB %s.", contact_bare_jid, db_fn_omemo);
}
cb(ret_val, user_data_p);
g_free(uname);
g_free(db_fn_omemo);
}
typedef enum {
LURCH_API_HANDLER_ACC_CB_DATA = 0,
LURCH_API_HANDLER_ACC_JID_CB_DATA
......@@ -95,23 +115,26 @@ typedef enum {
* When adding a new signal: increase this number and add the name, handler function, and handler function type
* to the respective array.
*/
#define NUM_OF_SIGNALS 3
#define NUM_OF_SIGNALS 4
const char * signal_names[NUM_OF_SIGNALS] = {
"lurch-id-show",
"lurch-id-list",
"lurch-enable-im"
"lurch-enable-im",
"lurch-disable-im"
};
const void * signal_handlers[NUM_OF_SIGNALS] = {
lurch_api_id_show_handler,
lurch_api_id_list_handler,
lurch_api_enable_im_handler
lurch_api_enable_im_handler,
lurch_api_disable_im_handler
};
const lurch_api_handler_t signal_handler_types[NUM_OF_SIGNALS] = {
LURCH_API_HANDLER_ACC_CB_DATA,
LURCH_API_HANDLER_ACC_CB_DATA,
LURCH_API_HANDLER_ACC_JID_CB_DATA,
LURCH_API_HANDLER_ACC_JID_CB_DATA
};
......
......@@ -8,4 +8,27 @@ void lurch_api_init();
/**
* Unregisters the signals and disconnects the signal handlers.
*/
void lurch_api_unload();
\ No newline at end of file
void lurch_api_unload();
/**
* USAGE
*
* Some functions users might be interested in can be called via libpurple signals.
* Thus, the libpurple commands interface uses these as well and lurch_cmd_ui.c is therefore full of examples.
* Generally, the workflow is as follows:
*
* - Find the signal you need and check the handler function's parameters.
* Generally, you will need to pass the user's PurpleAccount, a callback, and the data to be passed to the callback.
* For some functions, the conversation partner's or chat's JID is also required.
*
* - Write the callback function needed by the handler.
* The first parameter is an error value. It is generally the return value from the called functions.
* If it is non-zero, an error occured somewhere and there should be more information in the debug log.
* Otherwise, the call succeeded and the following parameters will be set.
* The last parameter is the data given when emitting the signal.
*
* - Emit the signal using the plugin system handle as the instance and pass the necessary data.
* If you do it wrong, there will be no compiler errors and the pointers are gibberish, so take care.
* You can easily get the plugin system handle anywhere by calling purple_plugins_get_handle().
*/
\ No newline at end of file
......@@ -90,6 +90,18 @@ void lurch_enable_print(int32_t err, void * user_data_p) {
lurch_cmd_print(conv_p, "Successfully enabled OMEMO.");
}
void lurch_disable_print(int32_t err, void * user_data_p) {
PurpleConversation * conv_p = (PurpleConversation *) user_data_p;
if (err) {
lurch_cmd_print_err(conv_p, "Failed to disable OMEMO for this conversation.");
return;
}
purple_conversation_autoset_title(conv_p);
lurch_cmd_print(conv_p, "Successfully disabled OMEMO.");
}
static void lurch_cmd_id(PurpleConversation * conv_p, const char * arg) {
PurpleAccount * acc_p = purple_conversation_get_account(conv_p);
......@@ -118,7 +130,7 @@ static void lurch_cmd_disable(PurpleConversation * conv_p) {
char * conv_bare_jid = jabber_get_bare_jid(purple_conversation_get_name(conv_p));
if (conv_type == PURPLE_CONV_TYPE_IM) {
purple_signal_emit(purple_plugins_get_handle(), "lurch-disable-im", purple_conversation_get_account(conv_p), conv_bare_jid, lurch_disable_print, conv_p);
}
g_free(conv_bare_jid);
......@@ -136,6 +148,7 @@ PurpleCmdRet lurch_cmd_func_v2(PurpleConversation * conv_p,
} else if (!g_strcmp0(command, "enable")) {
lurch_cmd_enable(conv_p);
} else if (!g_strcmp0(command, "disable")) {
lurch_cmd_disable(conv_p);
} else if (!g_strcmp0(command, "id")) {
lurch_cmd_id(conv_p, args[1]);
} else {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment