Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
RemoveRosterItem.cs
1using System;
3using System.Threading.Tasks;
4using System.Xml;
5using Waher.Content;
12using Waher.Script;
15
17{
22 {
27 : base("Xmpp/RemoveRosterItem",
28 new KeyValuePair<Type, Expression>(typeof(Dictionary<string, object>), new Expression(jsonPattern)),
29 new KeyValuePair<Type, Expression>(typeof(XmlDocument), new Expression(xmlPattern)))
30 {
31 }
32
33 private static readonly string jsonPattern = Resources.LoadResourceAsText(typeof(RemoveRosterItem).Namespace + ".JSON.RemoveRosterItem.req");
34 private static readonly string xmlPattern = Resources.LoadResourceAsText(typeof(RemoveRosterItem).Namespace + ".XML.RemoveRosterItem.req");
35
44 public override async Task POST(HttpRequest Request, HttpResponse Response, Dictionary<string, IElement> Parameters)
45 {
47 string BareJid = (string)Parameters["PBareJid"].AssociatedObjectValue;
48
49 if (string.IsNullOrEmpty(BareJid))
50 throw new BadRequestException("Empty Bare JID.");
51
52 if (!IsValidBareJID(BareJid))
53 throw new BadRequestException("Invalid Bare JID.");
54
55 if (XmppServerModule.Server is null)
56 {
58
59 if (Client is null)
60 {
61 if (Types.TryGetModuleParameter("XMPP", out XmppClient Client2))
62 Client = Client2;
63 }
64
65 if (Client is null)
66 throw new ServiceUnavailableException("XMPP Client not available.");
67
68 Networking.XMPP.RosterItem Item = Client[BareJid]
69 ?? throw new NotFoundException("Roster item not found.");
70
71 await Client.RemoveRosterItem(BareJid);
72
73 await Response.Return(new NamedDictionary<string, object>("RosterItem", AgentNamespace)
74 {
75 { "bareJid", Item.BareJid },
76 { "pendingSubscription", Item.PendingSubscription == PendingSubscription.Subscribe },
77 { "status", Item.State },
78 { "name", Item.Name },
79 { "Groups", Item.Groups }
80 });
81 }
82 else
83 {
84 PersistenceLayer PersistenceLayer = XmppServerModule.PersistenceLayer ?? new PersistenceLayer();
85 IRosterItem Item = await PersistenceLayer.GetRosterItem(User.UserName, BareJid)
86 ?? throw new NotFoundException("Roster item not found.");
87
88 await PersistenceLayer.RemoveRosterItem(User.UserName, BareJid);
89
90 await Response.Return(new NamedDictionary<string, object>("RosterItem", AgentNamespace)
91 {
92 { "bareJid", Item.BareJid.Value },
93 { "pendingSubscription", Item.PendingSubscription },
94 { "status", Item.Subscription },
95 { "name", Item.Name },
96 { "Groups", Item.Groups }
97 });
98 }
99 }
100 }
101}
A Named dictionary is a dictionary, with a local name and a namespace. Use it to return content that ...
Static class managing the runtime environment of the IoT Gateway.
Definition: Gateway.cs:147
static XmppClient XmppClient
XMPP Client connection of gateway.
Definition: Gateway.cs:4038
The request could not be understood by the server due to malformed syntax. The client SHOULD NOT repe...
Represents an HTTP request.
Definition: HttpRequest.cs:22
Represets a response of an HTTP client request.
Definition: HttpResponse.cs:23
Task Return(Exception ex)
Returns an error to the client.
The server has not found anything matching the Request-URI. No indication is given of whether the con...
The server is currently unable to handle the request due to a temporary overloading or maintenance of...
Maintains information about an item in the roster.
Definition: RosterItem.cs:75
Manages an XMPP client connection. Implements XMPP, as defined in https://tools.ietf....
Definition: XmppClient.cs:58
Task RemoveRosterItem(string BareJID)
Removes an item from the roster.
Definition: XmppClient.cs:4680
Static class managing loading of resources stored as embedded resources or in content files.
Definition: Resources.cs:13
static string LoadResourceAsText(string ResourceName)
Loads a text resource from an embedded resource.
Definition: Resources.cs:55
Static class that dynamically manages types and interfaces available in the runtime environment.
Definition: Types.cs:15
static bool TryGetModuleParameter(string Name, out object Value)
Tries to get a module parameter value.
Definition: Types.cs:607
Class managing a script expression.
Definition: Expression.cs:41
async Task< IRosterItem > GetRosterItem(CaseInsensitiveString UserName, CaseInsensitiveString Jid)
Gets a roster item for an account.
async Task< bool > RemoveRosterItem(CaseInsensitiveString UserName, CaseInsensitiveString Jid)
Removes a roster item.
static AccountUser AssertUserAuthenticated(HttpRequest Request)
Makes sure the request is made by an authenticated API user.
const string AgentNamespace
https://waher.se/Schema/BrokerAgent.xsd
Abstract base class for XMPP resources.
static bool IsValidBareJID(string JID)
Checks if a string is a valid Bare JID.
Removes a specific item from the account's roster.
RemoveRosterItem()
Removes a specific item from the account's roster.
override async Task POST(HttpRequest Request, HttpResponse Response, Dictionary< string, IElement > Parameters)
Executes the POST method on the resource.
Service Module hosting the XMPP broker and its components.
Interface for roster items.
Definition: IRosterItem.cs:43