mirror of
https://github.com/profanity-im/profanity.git
synced 2024-11-03 19:37:16 -05:00
Implemented setting affiliation and listing affiliations
This commit is contained in:
parent
719dbfaacc
commit
0b78a9a57e
@ -1246,13 +1246,8 @@ cmd_init(void)
|
||||
autocomplete_add(room_ac, "destroy");
|
||||
autocomplete_add(room_ac, "config");
|
||||
autocomplete_add(room_ac, "info");
|
||||
autocomplete_add(room_ac, "moderators");
|
||||
autocomplete_add(room_ac, "participants");
|
||||
autocomplete_add(room_ac, "visitors");
|
||||
autocomplete_add(room_ac, "owners");
|
||||
autocomplete_add(room_ac, "admins");
|
||||
autocomplete_add(room_ac, "members");
|
||||
autocomplete_add(room_ac, "outcasts");
|
||||
autocomplete_add(room_ac, "role");
|
||||
autocomplete_add(room_ac, "affiliation");
|
||||
|
||||
form_ac = autocomplete_new();
|
||||
autocomplete_add(form_ac, "submit");
|
||||
|
@ -2126,18 +2126,8 @@ cmd_room(gchar **args, struct cmd_help_t help)
|
||||
if ((g_strcmp0(args[0], "accept") != 0) &&
|
||||
(g_strcmp0(args[0], "destroy") != 0) &&
|
||||
(g_strcmp0(args[0], "config") != 0) &&
|
||||
|
||||
// roles
|
||||
(g_strcmp0(args[0], "moderators") != 0) &&
|
||||
(g_strcmp0(args[0], "participants") != 0) &&
|
||||
(g_strcmp0(args[0], "visitors") != 0) &&
|
||||
|
||||
// affiliations
|
||||
(g_strcmp0(args[0], "owners") != 0) &&
|
||||
(g_strcmp0(args[0], "admins") != 0) &&
|
||||
(g_strcmp0(args[0], "members") != 0) &&
|
||||
(g_strcmp0(args[0], "outcasts") != 0) &&
|
||||
|
||||
(g_strcmp0(args[0], "role") != 0) &&
|
||||
(g_strcmp0(args[0], "affiliation") != 0) &&
|
||||
(g_strcmp0(args[0], "info") != 0)) {
|
||||
cons_show("Usage: %s", help.usage);
|
||||
return TRUE;
|
||||
@ -2158,48 +2148,45 @@ cmd_room(gchar **args, struct cmd_help_t help)
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
if (g_strcmp0(args[0], "owners") == 0) {
|
||||
if ((g_strcmp0(args[1], "add") == 0) || (g_strcmp0(args[1], "remove") == 0)) {
|
||||
char *nick = args[2];
|
||||
if (!nick) {
|
||||
cons_show("Usage: %s", help.usage);
|
||||
return TRUE;
|
||||
}
|
||||
Occupant *occupant = muc_roster_item(room, nick);
|
||||
if (!occupant) {
|
||||
win_save_vprint(window, '!', NULL, 0, 0, "", "Could not find occupant: ", nick);
|
||||
return TRUE;
|
||||
}
|
||||
if (!occupant->jid) {
|
||||
win_save_vprint(window, '!', NULL, 0, 0, "", "Could not find JID for occupant: ", nick);
|
||||
return TRUE;
|
||||
}
|
||||
Jid *jidp = jid_create(occupant->jid);
|
||||
if (!jidp->barejid) {
|
||||
win_save_vprint(window, '!', NULL, 0, 0, "", "Could not find bare JID for occupant:", nick);
|
||||
jid_destroy(jidp);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
char *reason = args[3];
|
||||
if (g_strcmp0(args[1], "add") == 0) {
|
||||
if (occupant->affiliation == MUC_AFFILIATION_OWNER) {
|
||||
win_save_vprint(window, '!', NULL, 0, 0, "", "%s already has owner affiliation", nick);
|
||||
} else {
|
||||
iq_room_owner_add(room, jidp->barejid, reason);
|
||||
}
|
||||
} else {
|
||||
if (occupant->affiliation != MUC_AFFILIATION_OWNER) {
|
||||
const char *affiliation_str = muc_occupant_affiliation_str(occupant);
|
||||
win_save_vprint(window, '!', NULL, 0, 0, "",
|
||||
"%s does not have owner affiliation, current affiliation:", nick, affiliation_str);
|
||||
} else {
|
||||
iq_room_owner_remove(room, jidp->barejid, reason);
|
||||
}
|
||||
}
|
||||
jid_destroy(jidp);
|
||||
if (g_strcmp0(args[0], "affiliation") == 0) {
|
||||
char *cmd = args[1];
|
||||
if (cmd == NULL) {
|
||||
cons_show("Usage: %s", help.usage);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
char *affiliation = args[2];
|
||||
if ((g_strcmp0(affiliation, "owner") != 0) &&
|
||||
(g_strcmp0(affiliation, "admin") != 0) &&
|
||||
(g_strcmp0(affiliation, "member") != 0) &&
|
||||
(g_strcmp0(affiliation, "outcast") != 0) &&
|
||||
(g_strcmp0(affiliation, "none") != 0)) {
|
||||
cons_show("Usage: %s", help.usage);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
if (g_strcmp0(cmd, "list") == 0) {
|
||||
iq_room_affiliation_list(room, affiliation);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
if (g_strcmp0(cmd, "set") == 0) {
|
||||
char *jid = args[3];
|
||||
if (jid == NULL) {
|
||||
cons_show("Usage: %s", help.usage);
|
||||
return TRUE;
|
||||
} else {
|
||||
char *reason = args[4];
|
||||
iq_room_affiliation_set(room, jid, affiliation, reason);
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
if (g_strcmp0(args[0], "role") == 0) {
|
||||
cons_show("/room role...");
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
@ -276,21 +276,22 @@ _iq_room_config_cancel(const char * const room_jid)
|
||||
}
|
||||
|
||||
static void
|
||||
_iq_room_owner_add(const char * const room, const char * const jid, const char * const reason)
|
||||
_iq_room_affiliation_list(const char * const room, const char * const affiliation)
|
||||
{
|
||||
xmpp_conn_t * const conn = connection_get_conn();
|
||||
xmpp_ctx_t * const ctx = connection_get_ctx();
|
||||
xmpp_stanza_t *iq = stanza_create_room_owner_add_iq(ctx, room, jid, reason);
|
||||
xmpp_stanza_t *iq = stanza_create_room_affiliation_list_iq(ctx, room, affiliation);
|
||||
xmpp_send(conn, iq);
|
||||
xmpp_stanza_release(iq);
|
||||
}
|
||||
|
||||
static void
|
||||
_iq_room_owner_remove(const char * const room, const char * const jid, const char * const reason)
|
||||
_iq_room_affiliation_set(const char * const room, const char * const jid, const char * const affiliation,
|
||||
const char * const reason)
|
||||
{
|
||||
xmpp_conn_t * const conn = connection_get_conn();
|
||||
xmpp_ctx_t * const ctx = connection_get_ctx();
|
||||
xmpp_stanza_t *iq = stanza_create_room_owner_remove_iq(ctx, room, jid, reason);
|
||||
xmpp_stanza_t *iq = stanza_create_room_affiliation_set_iq(ctx, room, jid, affiliation, reason);
|
||||
xmpp_send(conn, iq);
|
||||
xmpp_stanza_release(iq);
|
||||
}
|
||||
@ -997,6 +998,6 @@ iq_init_module(void)
|
||||
iq_submit_room_config = _iq_submit_room_config;
|
||||
iq_send_caps_request = _iq_send_caps_request;
|
||||
iq_room_info_request = _iq_room_info_request;
|
||||
iq_room_owner_add = _iq_room_owner_add;
|
||||
iq_room_owner_remove = _iq_room_owner_remove;
|
||||
iq_room_affiliation_set = _iq_room_affiliation_set;
|
||||
iq_room_affiliation_list = _iq_room_affiliation_list;
|
||||
}
|
||||
|
@ -529,14 +529,13 @@ stanza_create_room_config_cancel_iq(xmpp_ctx_t *ctx, const char * const room_jid
|
||||
}
|
||||
|
||||
xmpp_stanza_t *
|
||||
stanza_create_room_owner_add_iq(xmpp_ctx_t *ctx, const char * const room, const char * const jid,
|
||||
const char * const reason)
|
||||
stanza_create_room_affiliation_list_iq(xmpp_ctx_t *ctx, const char * const room, const char * const affiliation)
|
||||
{
|
||||
xmpp_stanza_t *iq = xmpp_stanza_new(ctx);
|
||||
xmpp_stanza_set_name(iq, STANZA_NAME_IQ);
|
||||
xmpp_stanza_set_type(iq, STANZA_TYPE_SET);
|
||||
xmpp_stanza_set_type(iq, STANZA_TYPE_GET);
|
||||
xmpp_stanza_set_attribute(iq, STANZA_ATTR_TO, room);
|
||||
char *id = create_unique_id("owner_add");
|
||||
char *id = create_unique_id("affiliation_get");
|
||||
xmpp_stanza_set_id(iq, id);
|
||||
free(id);
|
||||
|
||||
@ -546,20 +545,7 @@ stanza_create_room_owner_add_iq(xmpp_ctx_t *ctx, const char * const room, const
|
||||
|
||||
xmpp_stanza_t *item = xmpp_stanza_new(ctx);
|
||||
xmpp_stanza_set_name(item, STANZA_NAME_ITEM);
|
||||
xmpp_stanza_set_attribute(item, "affiliation", "owner");
|
||||
xmpp_stanza_set_attribute(item, STANZA_ATTR_JID, jid);
|
||||
|
||||
if (reason) {
|
||||
xmpp_stanza_t *reason_st = xmpp_stanza_new(ctx);
|
||||
xmpp_stanza_set_name(reason_st, STANZA_NAME_REASON);
|
||||
xmpp_stanza_t *reason_text = xmpp_stanza_new(ctx);
|
||||
xmpp_stanza_set_text(reason_text, reason);
|
||||
xmpp_stanza_add_child(reason_st, reason_text);
|
||||
xmpp_stanza_release(reason_text);
|
||||
|
||||
xmpp_stanza_add_child(item, reason_st);
|
||||
xmpp_stanza_release(reason_st);
|
||||
}
|
||||
xmpp_stanza_set_attribute(item, "affiliation", affiliation);
|
||||
|
||||
xmpp_stanza_add_child(query, item);
|
||||
xmpp_stanza_release(item);
|
||||
@ -570,14 +556,14 @@ stanza_create_room_owner_add_iq(xmpp_ctx_t *ctx, const char * const room, const
|
||||
}
|
||||
|
||||
xmpp_stanza_t *
|
||||
stanza_create_room_owner_remove_iq(xmpp_ctx_t *ctx, const char * const room, const char * const jid,
|
||||
const char * const reason)
|
||||
stanza_create_room_affiliation_set_iq(xmpp_ctx_t *ctx, const char * const room, const char * const jid,
|
||||
const char * const affiliation, const char * const reason)
|
||||
{
|
||||
xmpp_stanza_t *iq = xmpp_stanza_new(ctx);
|
||||
xmpp_stanza_set_name(iq, STANZA_NAME_IQ);
|
||||
xmpp_stanza_set_type(iq, STANZA_TYPE_SET);
|
||||
xmpp_stanza_set_attribute(iq, STANZA_ATTR_TO, room);
|
||||
char *id = create_unique_id("owner_remove");
|
||||
char *id = create_unique_id("affiliation_set");
|
||||
xmpp_stanza_set_id(iq, id);
|
||||
free(id);
|
||||
|
||||
@ -587,7 +573,7 @@ stanza_create_room_owner_remove_iq(xmpp_ctx_t *ctx, const char * const room, con
|
||||
|
||||
xmpp_stanza_t *item = xmpp_stanza_new(ctx);
|
||||
xmpp_stanza_set_name(item, STANZA_NAME_ITEM);
|
||||
xmpp_stanza_set_attribute(item, "affiliation", "admin");
|
||||
xmpp_stanza_set_attribute(item, "affiliation", affiliation);
|
||||
xmpp_stanza_set_attribute(item, STANZA_ATTR_JID, jid);
|
||||
|
||||
if (reason) {
|
||||
|
@ -205,10 +205,10 @@ xmpp_stanza_t* stanza_create_room_config_cancel_iq(xmpp_ctx_t *ctx,
|
||||
const char * const room_jid);
|
||||
xmpp_stanza_t* stanza_create_room_config_submit_iq(xmpp_ctx_t *ctx,
|
||||
const char * const room, DataForm *form);
|
||||
xmpp_stanza_t* stanza_create_room_owner_add_iq(xmpp_ctx_t *ctx, const char * const room, const char * const jid,
|
||||
const char * const reason);
|
||||
xmpp_stanza_t* stanza_create_room_owner_remove_iq(xmpp_ctx_t *ctx, const char * const room, const char * const jid,
|
||||
const char * const reason);
|
||||
xmpp_stanza_t* stanza_create_room_affiliation_list_iq(xmpp_ctx_t *ctx, const char * const room,
|
||||
const char * const affiliation);
|
||||
xmpp_stanza_t* stanza_create_room_affiliation_set_iq(xmpp_ctx_t *ctx, const char * const room, const char * const jid,
|
||||
const char * const affiliation, const char * const reason);
|
||||
|
||||
int stanza_get_idle_time(xmpp_stanza_t * const stanza);
|
||||
char * stanza_get_caps_str(xmpp_stanza_t * const stanza);
|
||||
|
@ -192,8 +192,9 @@ void (*iq_send_ping)(const char * const target);
|
||||
void (*iq_send_caps_request)(const char * const to, const char * const id,
|
||||
const char * const node, const char * const ver);
|
||||
void (*iq_room_info_request)(gchar *room);
|
||||
void (*iq_room_owner_add)(const char * const room, const char * const jid, const char * const reason);
|
||||
void (*iq_room_owner_remove)(const char * const room, const char * const jid, const char * const reason);
|
||||
void (*iq_room_affiliation_list)(const char * const room, const char * const affiliation);
|
||||
void (*iq_room_affiliation_set)(const char * const room, const char * const jid, const char * const affiliation,
|
||||
const char * const reason);
|
||||
|
||||
// caps functions
|
||||
Capabilities* (*caps_lookup)(const char * const jid);
|
||||
|
Loading…
Reference in New Issue
Block a user