Member since Feb 2003 ·
4449 posts · Location: Germany
Group memberships: Administrators, Members
here is a MucManager helper class for MatriX vnext with the requested functionality.
Please let me know if this helps.
using System;
using System.Threading;
using System.Threading.Tasks;
using Matrix;
using Matrix.Xml;
using Matrix.Xmpp.Client;
using Matrix.Xmpp;
using Matrix.Xmpp.Muc;
using Matrix.Xmpp.Muc.Owner;
using Matrix.Xmpp.XData;
public class MucManager {
public MucManager(XmppClient xmppClient)
{
XmppClient = xmppClient;
}
public XmppClient XmppClient { get; internal set; }
public async Task<Iq> RequestRoomConfigurationAsync(Jid room)
{
var iq
= new OwnerIq
{ Type
= IqType
.Get, To
= room
};
return await XmppClient.SendIqAsync(iq);
}
public async Task<Iq> SubmitRoomConfigurationAsync(Jid room, Data xdata)
{
var iq
= new OwnerIq
{ Type
= IqType
.Set, To
= room, OwnerQuery
= { XData
= xdata
} };
return await XmppClient.SendIqAsync(iq);
}
public async Task<XmppXElement> EnterRoomAsync(Jid jid, string nick)
{
var createRoomStanza = CreateEnterRoomStanza(jid, nick, null, false, null);
Func<XmppXElement, bool> predicate = e =>
e.OfType<Presence>()
&& e
.Cast<Presence
>().From.Equals(jid,
new BareJidComparer
());
return await XmppClient.SendAsync(createRoomStanza, predicate, 10000, CancellationToken.None);
}
public async Task<XmppXElement> ExitRoomAsync(Jid jid, string nick)
{
var exitRoomStanza = CreateExitRoomStanza(jid, nick);
Func<XmppXElement, bool> predicate = e =>
e.OfType<Presence>()
&& e
.Cast<Presence
>().From.Equals(jid,
new BareJidComparer
());
return await XmppClient.SendAsync(exitRoomStanza, predicate, 10000, CancellationToken.None);
}
public Presence CreateEnterRoomStanza(Jid room, string nickname, string password = null, bool disableHistory = false, History history = null)
{
var to
= new Jid
(room
.ToString())
{
Resource = nickname
};
{
To = to
};
if (password != null)
x.Password = password;
if (disableHistory)
{
var hist
= new History
{ MaxCharacters
= 0 };
x.History = hist;
}
if (history != null)
x.History = history;
pres.Add(x);
return pres;
}
public Presence CreateExitRoomStanza(Jid room, string nickname)
{
var to
= new Jid
(room
.ToString())
{
Resource = nickname
};
{
To = to,
Type = PresenceType.Unavailable
};
return pres;
}
}
Alex
This post was edited on 2017-08-09, 00:53 by
Alex.