Add support for setting a new Affiliation in a muc (#266)

* Added support for setting a new Affiliation in a muc

* small changes

* fix parameter order
This commit is contained in:
David Plassmann 2018-01-09 01:06:32 +01:00 committed by fiaxh
parent 2e041e2984
commit 5d6cf9d8d5
3 changed files with 23 additions and 8 deletions

View file

@ -83,6 +83,11 @@ public class MucManager : StreamInteractionModule, Object {
if (stream != null) stream.get_module(Xep.Muc.Module.IDENTITY).kick(stream, jid.bare_jid.to_string(), nick); if (stream != null) stream.get_module(Xep.Muc.Module.IDENTITY).kick(stream, jid.bare_jid.to_string(), nick);
} }
public void change_affiliation(Account account, Jid jid, string nick, string role) {
Core.XmppStream? stream = stream_interactor.get_stream(account);
if (stream != null) stream.get_module(Xep.Muc.Module.IDENTITY).change_affiliation(stream, jid.bare_jid.to_string(), nick, role);
}
public bool kick_possible(Account account, Jid occupant) { public bool kick_possible(Account account, Jid occupant) {
Core.XmppStream? stream = stream_interactor.get_stream(account); Core.XmppStream? stream = stream_interactor.get_stream(account);
if (stream != null) return stream.get_module(Xep.Muc.Module.IDENTITY).kick_possible(stream, occupant.to_string()); if (stream != null) return stream.get_module(Xep.Muc.Module.IDENTITY).kick_possible(stream, occupant.to_string());

View file

@ -76,6 +76,10 @@ public class View : Box {
case "/kick": case "/kick":
stream_interactor.get_module(MucManager.IDENTITY).kick(conversation.account, conversation.counterpart, token[1]); stream_interactor.get_module(MucManager.IDENTITY).kick(conversation.account, conversation.counterpart, token[1]);
return; return;
case "/affiliate":
string[] user_role = token[1].split(" ", 2);
stream_interactor.get_module(MucManager.IDENTITY).change_affiliation(conversation.account, conversation.counterpart, user_role[0].strip(), user_role[1].strip());
return;
case "/nick": case "/nick":
stream_interactor.get_module(MucManager.IDENTITY).change_nick(conversation.account, conversation.counterpart, token[1]); stream_interactor.get_module(MucManager.IDENTITY).change_nick(conversation.account, conversation.counterpart, token[1]);
return; return;

View file

@ -142,6 +142,20 @@ public class Module : XmppStreamModule {
return true; return true;
} }
public void change_role(XmppStream stream, string jid, string nick, string new_role) {
StanzaNode query = new StanzaNode.build("query", NS_URI_ADMIN).add_self_xmlns();
query.put_node(new StanzaNode.build("item", NS_URI_ADMIN).put_attribute("nick", nick, NS_URI_ADMIN).put_attribute("role", new_role, NS_URI_ADMIN));
Iq.Stanza iq = new Iq.Stanza.set(query) { to=jid };
stream.get_module(Iq.Module.IDENTITY).send_iq(stream, iq);
}
public void change_affiliation(XmppStream stream, string jid, string nick, string new_affiliation) {
StanzaNode query = new StanzaNode.build("query", NS_URI_ADMIN).add_self_xmlns();
query.put_node(new StanzaNode.build("item", NS_URI_ADMIN).put_attribute("nick", nick, NS_URI_ADMIN).put_attribute("affiliation", new_affiliation, NS_URI_ADMIN));
Iq.Stanza iq = new Iq.Stanza.set(query) { to=jid };
stream.get_module(Iq.Module.IDENTITY).send_iq(stream, iq);
}
public delegate void OnConfigFormResult(XmppStream stream, string jid, DataForms.DataForm data_form); public delegate void OnConfigFormResult(XmppStream stream, string jid, DataForms.DataForm data_form);
public void get_config_form(XmppStream stream, string jid, owned OnConfigFormResult listener) { public void get_config_form(XmppStream stream, string jid, owned OnConfigFormResult listener) {
Iq.Stanza get_iq = new Iq.Stanza.get(new StanzaNode.build("query", NS_URI_OWNER).add_self_xmlns()) { to=jid }; Iq.Stanza get_iq = new Iq.Stanza.get(new StanzaNode.build("query", NS_URI_OWNER).add_self_xmlns()) { to=jid };
@ -187,14 +201,6 @@ public class Module : XmppStreamModule {
public override string get_ns() { return NS_URI; } public override string get_ns() { return NS_URI; }
public override string get_id() { return IDENTITY.id; } public override string get_id() { return IDENTITY.id; }
private void change_role(XmppStream stream, string jid, string nick, string new_role) {
StanzaNode query = new StanzaNode.build("query", NS_URI_ADMIN).add_self_xmlns();
query.put_node(new StanzaNode.build("item", NS_URI_ADMIN).put_attribute("nick", nick, NS_URI_ADMIN).put_attribute("role", new_role, NS_URI_ADMIN));
Iq.Stanza iq = new Iq.Stanza.set(query);
iq.to = jid;
stream.get_module(Iq.Module.IDENTITY).send_iq(stream, iq);
}
private void on_received_message(XmppStream stream, Message.Stanza message) { private void on_received_message(XmppStream stream, Message.Stanza message) {
if (message.type_ == Message.Stanza.TYPE_GROUPCHAT) { if (message.type_ == Message.Stanza.TYPE_GROUPCHAT) {
StanzaNode? subject_node = message.stanza.get_subnode("subject"); StanzaNode? subject_node = message.stanza.get_subnode("subject");