1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-12-04 14:46:46 -05:00

Add plugin get_barejid_from_roster function

This commit is contained in:
Dustin Lagoy 2021-04-29 13:50:57 -04:00
parent 802442fffc
commit 2350a94c44
8 changed files with 53 additions and 0 deletions

View File

@ -144,6 +144,12 @@ Retrieve the nickname for a given barejid if it is in the roster.
*/
char* prof_get_name_from_roster(const char *barejid);
/**
Retrieve the barejid for a given nickname if it is in the roster.
@return the users barejid e.g. "eddie@server.tld", or NULLL if the nickname is not in the roster.
*/
char* prof_get_barejid_from_roster(const char *name);
/**
Retrieve nicknames of all occupants in a chat room, when in a chat room window.
@return nicknames of all occupants in the current room or an empty list if not in a chat room window.

View File

@ -262,6 +262,15 @@ def get_name_from_roster(barejid):
pass
def get_barejid_from_roster(name):
"""Retrieve the barejid for a given nickname if it is in the roster.
:return: the users barejid e.g. "eddie@server.tld", or ``None`` if the nickname is not in the roster.
:rtype: str
"""
pass
def get_current_occupants():
"""Retrieve nicknames of all occupants in a chat room, when in a chat room window.

View File

@ -246,6 +246,12 @@ api_get_name_from_roster(const char* barejid)
return roster_get_display_name(barejid);
}
char*
api_get_barejid_from_roster(const char* name)
{
return roster_barejid_from_name(name);
}
char**
api_get_current_occupants(void)
{

View File

@ -50,6 +50,7 @@ char* api_get_current_muc(void);
gboolean api_current_win_is_console(void);
char* api_get_current_nick(void);
char* api_get_name_from_roster(const char* barejid);
char* api_get_barejid_from_roster(const char* name);
char** api_get_current_occupants(void);
char* api_get_room_nick(const char* barejid);

View File

@ -201,6 +201,12 @@ c_api_get_name_from_roster(const char* barejid)
return api_get_name_from_roster(barejid);
}
static char*
c_api_get_barejid_from_roster(const char* name)
{
return api_get_barejid_from_roster(name);
}
static char**
c_api_get_current_occupants(void)
{
@ -490,6 +496,7 @@ c_api_init(void)
prof_current_win_is_console = c_api_current_win_is_console;
prof_get_current_nick = c_api_get_current_nick;
prof_get_name_from_roster = c_api_get_name_from_roster;
prof_get_barejid_from_roster = c_api_get_barejid_from_roster;
prof_get_current_occupants = c_api_get_current_occupants;
prof_get_room_nick = c_api_get_room_nick;
prof_log_debug = c_api_log_debug;

View File

@ -65,6 +65,7 @@ char* (*prof_get_current_muc)(void) = NULL;
int (*prof_current_win_is_console)(void) = NULL;
char* (*prof_get_current_nick)(void) = NULL;
char* (*prof_get_name_from_roster)(const char *barejid) = NULL;
char* (*prof_get_barejid_from_roster)(const char *name) = NULL;
char** (*prof_get_current_occupants)(void) = NULL;
char* (*prof_get_room_nick)(const char *barejid) = NULL;

View File

@ -75,6 +75,7 @@ char* (*prof_get_current_muc)(void);
int (*prof_current_win_is_console)(void);
char* (*prof_get_current_nick)(void);
char* (*prof_get_name_from_roster)(const char *barejid);
char* (*prof_get_barejid_from_roster)(const char *name);
char** (*prof_get_current_occupants)(void);
char* (*prof_get_room_nick)(const char *barejid);

View File

@ -462,6 +462,27 @@ python_api_get_name_from_roster(PyObject* self, PyObject* args)
}
}
static PyObject*
python_api_get_barejid_from_roster(PyObject* self, PyObject* args)
{
PyObject* name = NULL;
if (!PyArg_ParseTuple(args, "O", &name)) {
Py_RETURN_NONE;
}
char* name_str = python_str_or_unicode_to_string(name);
allow_python_threads();
char* barejid = roster_barejid_from_name(name_str);
free(name_str);
disable_python_threads();
if (barejid) {
return Py_BuildValue("s", barejid);
} else {
Py_RETURN_NONE;
}
}
static PyObject*
python_api_get_current_occupants(PyObject* self, PyObject* args)
{
@ -1510,6 +1531,7 @@ static PyMethodDef apiMethods[] = {
{ "get_current_muc", python_api_get_current_muc, METH_VARARGS, "Return the jid of the room of the current window." },
{ "get_current_nick", python_api_get_current_nick, METH_VARARGS, "Return nickname in current room." },
{ "get_name_from_roster", python_api_get_name_from_roster, METH_VARARGS, "Return nickname in roster of barejid." },
{ "get_barejid_from_roster", python_api_get_barejid_from_roster, METH_VARARGS, "Return nickname in roster of barejid." },
{ "get_current_occupants", python_api_get_current_occupants, METH_VARARGS, "Return list of occupants in current room." },
{ "current_win_is_console", python_api_current_win_is_console, METH_VARARGS, "Returns whether the current window is the console." },
{ "get_room_nick", python_api_get_room_nick, METH_VARARGS, "Return the nickname used in the specified room, or None if not in the room." },