Allow chat prefix char to be set by plugins
This commit is contained in:
@@ -561,3 +561,87 @@ api_chat_unset_titlebar_enctext(const char *const barejid)
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int
|
||||
api_chat_set_incoming_char(const char *const barejid, const char *const ch)
|
||||
{
|
||||
if (ch == NULL) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (strlen(ch) != 1) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (barejid == NULL) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
ProfChatWin *chatwin = wins_get_chat(barejid);
|
||||
if (chatwin == NULL) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
chatwin_set_incoming_char(chatwin, ch);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int
|
||||
api_chat_unset_incoming_char(const char *const barejid)
|
||||
{
|
||||
if (barejid == NULL) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
ProfChatWin *chatwin = wins_get_chat(barejid);
|
||||
if (chatwin == NULL) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
chatwin_unset_incoming_char(chatwin);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int
|
||||
api_chat_set_outgoing_char(const char *const barejid, const char *const ch)
|
||||
{
|
||||
if (ch == NULL) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (strlen(ch) != 1) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (barejid == NULL) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
ProfChatWin *chatwin = wins_get_chat(barejid);
|
||||
if (chatwin == NULL) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
chatwin_set_outgoing_char(chatwin, ch);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int
|
||||
api_chat_unset_outgoing_char(const char *const barejid)
|
||||
{
|
||||
if (barejid == NULL) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
ProfChatWin *chatwin = wins_get_chat(barejid);
|
||||
if (chatwin == NULL) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
chatwin_unset_outgoing_char(chatwin);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -100,5 +100,9 @@ void api_encryption_reset(const char *const barejid);
|
||||
|
||||
int api_chat_set_titlebar_enctext(const char *const barejid, const char *const enctext);
|
||||
int api_chat_unset_titlebar_enctext(const char *const barejid);
|
||||
int api_chat_set_incoming_char(const char *const barejid, const char *const ch);
|
||||
int api_chat_unset_incoming_char(const char *const barejid);
|
||||
int api_chat_set_outgoing_char(const char *const barejid, const char *const ch);
|
||||
int api_chat_unset_outgoing_char(const char *const barejid);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -359,6 +359,30 @@ c_api_chat_unset_titlebar_enctext(const char *barejid)
|
||||
return api_chat_unset_titlebar_enctext(barejid);
|
||||
}
|
||||
|
||||
static int
|
||||
c_api_chat_set_incoming_char(const char *barejid, const char *ch)
|
||||
{
|
||||
return api_chat_set_incoming_char(barejid, ch);
|
||||
}
|
||||
|
||||
static int
|
||||
c_api_chat_unset_incoming_char(const char *barejid)
|
||||
{
|
||||
return api_chat_unset_incoming_char(barejid);
|
||||
}
|
||||
|
||||
static int
|
||||
c_api_chat_set_outgoing_char(const char *barejid, const char *ch)
|
||||
{
|
||||
return api_chat_set_outgoing_char(barejid, ch);
|
||||
}
|
||||
|
||||
static int
|
||||
c_api_chat_unset_outgoing_char(const char *barejid)
|
||||
{
|
||||
return api_chat_unset_outgoing_char(barejid);
|
||||
}
|
||||
|
||||
void
|
||||
c_command_callback(PluginCommand *command, gchar **args)
|
||||
{
|
||||
@@ -429,6 +453,10 @@ c_api_init(void)
|
||||
prof_encryption_reset = c_api_encryption_reset;
|
||||
prof_chat_set_titlebar_enctext = c_api_chat_set_titlebar_enctext;
|
||||
prof_chat_unset_titlebar_enctext = c_api_chat_unset_titlebar_enctext;
|
||||
prof_chat_set_incoming_char = c_api_chat_set_incoming_char;
|
||||
prof_chat_unset_incoming_char = c_api_chat_unset_incoming_char;
|
||||
prof_chat_set_outgoing_char = c_api_chat_set_outgoing_char;
|
||||
prof_chat_unset_outgoing_char = c_api_chat_unset_outgoing_char;
|
||||
}
|
||||
|
||||
static char *
|
||||
|
||||
@@ -97,4 +97,7 @@ void (*prof_encryption_reset)(const char *barejid) = NULL;
|
||||
|
||||
int (*prof_chat_set_titlebar_enctext)(const char *barejid, const char *enctext) = NULL;
|
||||
int (*prof_chat_unset_titlebar_enctext)(const char *barejid) = NULL;
|
||||
|
||||
int (*prof_chat_set_incoming_char)(const char *barejid, const char *ch) = NULL;
|
||||
int (*prof_chat_unset_incoming_char)(const char *barejid) = NULL;
|
||||
int (*prof_chat_set_outgoing_char)(const char *barejid, const char *ch) = NULL;
|
||||
int (*prof_chat_unset_outgoing_char)(const char *barejid) = NULL;
|
||||
|
||||
@@ -109,5 +109,9 @@ void (*prof_encryption_reset)(const char *barejid);
|
||||
|
||||
int (*prof_chat_set_titlebar_enctext)(const char *barejid, const char *enctext);
|
||||
int (*prof_chat_unset_titlebar_enctext)(const char *barejid);
|
||||
int (*prof_chat_set_incoming_char)(const char *barejid, const char *ch);
|
||||
int (*prof_chat_unset_incoming_char)(const char *barejid);
|
||||
int (*prof_chat_set_outgoing_char)(const char *barejid, const char *ch);
|
||||
int (*prof_chat_unset_outgoing_char)(const char *barejid);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1096,6 +1096,100 @@ python_api_chat_unset_titlebar_enctext(PyObject *self, PyObject *args)
|
||||
}
|
||||
}
|
||||
|
||||
static PyObject*
|
||||
python_api_chat_set_incoming_char(PyObject *self, PyObject *args)
|
||||
{
|
||||
PyObject *barejid = NULL;
|
||||
PyObject *ch = NULL;
|
||||
if (!PyArg_ParseTuple(args, "OO", &barejid, &ch)) {
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
char *barejid_str = python_str_or_unicode_to_string(barejid);
|
||||
char *ch_str = python_str_or_unicode_to_string(ch);
|
||||
|
||||
allow_python_threads();
|
||||
int res = api_chat_set_incoming_char(barejid_str, ch_str);
|
||||
free(barejid_str);
|
||||
free(ch_str);
|
||||
disable_python_threads();
|
||||
|
||||
if (res) {
|
||||
return Py_BuildValue("O", Py_True);
|
||||
} else {
|
||||
return Py_BuildValue("O", Py_False);
|
||||
}
|
||||
}
|
||||
|
||||
static PyObject*
|
||||
python_api_chat_unset_incoming_char(PyObject *self, PyObject *args)
|
||||
{
|
||||
PyObject *barejid = NULL;
|
||||
if (!PyArg_ParseTuple(args, "O", &barejid)) {
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
char *barejid_str = python_str_or_unicode_to_string(barejid);
|
||||
|
||||
allow_python_threads();
|
||||
int res = api_chat_unset_incoming_char(barejid_str);
|
||||
free(barejid_str);
|
||||
disable_python_threads();
|
||||
|
||||
if (res) {
|
||||
return Py_BuildValue("O", Py_True);
|
||||
} else {
|
||||
return Py_BuildValue("O", Py_False);
|
||||
}
|
||||
}
|
||||
|
||||
static PyObject*
|
||||
python_api_chat_set_outgoing_char(PyObject *self, PyObject *args)
|
||||
{
|
||||
PyObject *barejid = NULL;
|
||||
PyObject *ch = NULL;
|
||||
if (!PyArg_ParseTuple(args, "OO", &barejid, &ch)) {
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
char *barejid_str = python_str_or_unicode_to_string(barejid);
|
||||
char *ch_str = python_str_or_unicode_to_string(ch);
|
||||
|
||||
allow_python_threads();
|
||||
int res = api_chat_set_outgoing_char(barejid_str, ch_str);
|
||||
free(barejid_str);
|
||||
free(ch_str);
|
||||
disable_python_threads();
|
||||
|
||||
if (res) {
|
||||
return Py_BuildValue("O", Py_True);
|
||||
} else {
|
||||
return Py_BuildValue("O", Py_False);
|
||||
}
|
||||
}
|
||||
|
||||
static PyObject*
|
||||
python_api_chat_unset_outgoing_char(PyObject *self, PyObject *args)
|
||||
{
|
||||
PyObject *barejid = NULL;
|
||||
if (!PyArg_ParseTuple(args, "O", &barejid)) {
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
char *barejid_str = python_str_or_unicode_to_string(barejid);
|
||||
|
||||
allow_python_threads();
|
||||
int res = api_chat_unset_outgoing_char(barejid_str);
|
||||
free(barejid_str);
|
||||
disable_python_threads();
|
||||
|
||||
if (res) {
|
||||
return Py_BuildValue("O", Py_True);
|
||||
} else {
|
||||
return Py_BuildValue("O", Py_False);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
python_command_callback(PluginCommand *command, gchar **args)
|
||||
{
|
||||
@@ -1207,6 +1301,10 @@ static PyMethodDef apiMethods[] = {
|
||||
{ "encryption_reset", python_api_encryption_reset, METH_VARARGS, "End encrypted chat session with barejid, if one exists" },
|
||||
{ "chat_set_titlebar_enctext", python_api_chat_set_titlebar_enctext, METH_VARARGS, "Set the encryption status in the title bar for the specified contact" },
|
||||
{ "chat_unset_titlebar_enctext", python_api_chat_unset_titlebar_enctext, METH_VARARGS, "Reset the encryption status in the title bar for the specified recipient" },
|
||||
{ "chat_set_incoming_char", python_api_chat_set_incoming_char, METH_VARARGS, "Set the incoming message prefix character for specified contact" },
|
||||
{ "chat_unset_incoming_char", python_api_chat_unset_incoming_char, METH_VARARGS, "Reset the incoming message prefix character for specified contact" },
|
||||
{ "chat_set_outgoing_char", python_api_chat_set_outgoing_char, METH_VARARGS, "Set the outgoing message prefix character for specified contact" },
|
||||
{ "chat_unset_outgoing_char", python_api_chat_unset_outgoing_char, METH_VARARGS, "Reset the outgoing message prefix character for specified contact" },
|
||||
{ NULL, NULL, 0, NULL }
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user