public void CommandWhoIs(CommandModel cmd)
{
Jid jid;
if (cmd.DataArray.Length < 2) {
if ((cmd.DataArray.Length == 1)
&& (cmd.Chat is PersonChatModel)) {
jid = (cmd.Chat as PersonChatModel).Person.ID;
} else {
NotEnoughParameters(cmd);
return;
}
} else {
jid = GetJidFromNickname(cmd.DataArray[1]);
}
XmppPersonModel person;
var builder = CreateMessageBuilder();
if (!Contacts.TryGetValue(jid.Bare, out person)) {
builder.AppendErrorText(_("Could not find contact {0}"), jid);
Session.AddMessageToFrontend(cmd, builder.ToMessage());
return;
}
if (!String.IsNullOrEmpty(jid.Resource)) {
if (person.Resources.Count > 1) {
builder.AppendText(_("Contact {0} has {1} known resources"), jid.Bare, person.Resources.Count);
}
XmppResourceModel res;
if (!person.Resources.TryGetValue(jid.Resource??"", out res)) {
builder.AppendErrorText(_("{0} is not a known resource"), jid.Resource);
Session.AddMessageToFrontend(cmd, builder.ToMessage());
return;
}
printResource(builder, res);
Session.AddMessageToFrontend(cmd, builder.ToMessage());
return;
}
builder.AppendText(_("Contact's JID: {0}"), person.Jid);
builder.AppendText("\n");
switch (person.Subscription) {
case SubscriptionType.both:
builder.AppendText(_("You have a mutual subscription with this contact"));
break;
case SubscriptionType.none:
builder.AppendText(_("You have no subscription with this contact and this contact is not subscribed to you"));
break;
case SubscriptionType.to:
builder.AppendText(_("You are subscribed to this contact, but the contact is not subscribed to you"));
break;
case SubscriptionType.from:
builder.AppendText(_("You are not subscribed to this contact, but the contact is subscribed to you"));
break;
case SubscriptionType.remove:
#if LOG4NET
_Logger.Debug("a contact with SubscriptionType remove has been found");
#endif
break;
}
int i = 0;
foreach(var res in person.Resources) {
builder.AppendText("\nResource({0}):", i);
printResource(builder, res.Value);
i++;
}
Session.AddMessageToFrontend(cmd, builder.ToMessage());
}