Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
Leave.cs
1using System.Text;
2using System.Threading.Tasks;
4
6{
11 {
15 public Leave()
16 : base()
17 {
18 }
19
23 public override string Name => "Leave";
24
32 public override async Task Execute(ChatState State, string[] Arguments, string OrgMessage, ResponseCallbackHandler ResponseCallback)
33 {
34 if (Gateway.MucClient is null)
35 {
36 await ResponseCallback("Multi-User Chat disabled.", string.Empty);
37 return;
38 }
39
40 Enter.ParseRoom(Arguments[0], out string RoomId, out string Domain);
41
42 if (!XmppServerModule.Instance.TryGetNickName(RoomId, Domain, out string NickName))
43 {
44 await ResponseCallback("Not occupant of room.", string.Empty);
45 return;
46 }
47
48 await Gateway.MucClient.LeaveRoom(RoomId, Domain, NickName, async (Sender, e) =>
49 {
50 if (e.Ok)
51 {
52 StringBuilder sb = new StringBuilder();
53
54 sb.Append("Left room `");
55 sb.Append(e.RoomId);
56 sb.Append('@');
57 sb.Append(e.Domain);
58 sb.Append("`.");
59
60 await ResponseCallback(sb.ToString(), string.Empty);
61 }
62 else
63 await ResponseCallback(string.IsNullOrEmpty(e.ErrorText) ? "Unable to leave room." : e.ErrorText, string.Empty);
64
65 }, null);
66
67 await XmppServerModule.Instance.LeaveRoom(RoomId, Domain);
68 }
69
73 public override string ParameterName => "ROOM";
74
78 public override string[] HelpParagraphs => new string[] { "Leaves a Multi-User Chat Room named `ROOM`." };
79 }
80}
Static class managing the runtime environment of the IoT Gateway.
Definition: Gateway.cs:126
static MultiUserChatClient MucClient
XMPP Multi-User Chat Protocol (MUC) Client.
Definition: Gateway.cs:3267
An administrative command taking one parameter.
Asks the broker to enter a room.
Definition: Enter.cs:13
Asks the broker to leave a room.
Definition: Leave.cs:11
override string Name
Command name
Definition: Leave.cs:23
Leave()
Asks the broker to leave a room.
Definition: Leave.cs:15
override async Task Execute(ChatState State, string[] Arguments, string OrgMessage, ResponseCallbackHandler ResponseCallback)
Executes the command.
Definition: Leave.cs:32
override string[] HelpParagraphs
Markdown description of syntax.
Definition: Leave.cs:78
override string ParameterName
Name of parameter.
Definition: Leave.cs:73
Service Module hosting the XMPP broker and its components.
delegate Task< string > ResponseCallbackHandler(string Markdown, string MessageId)
Delegate for response callback handler methods.