Ejemplo n.º 1
0
        private string NickName()
        {
            SuggestionEventArgs e = new SuggestionEventArgs(string.Empty);

            try
            {
                OnGetNickNameSuggestions?.Invoke(this, e);
            }
            catch (Exception ex)
            {
                Log.Critical(ex);
            }

            string[] Suggestions = e.ToArray();
            string   NickName    = Suggestions.Length > 0 ? Suggestions[0] : (string)Gateway.Domain;

            return(XmppClient.EmbedNickName(NickName));
        }
Ejemplo n.º 2
0
        private Task GetGroups(HttpRequest Request, HttpResponse Response)
        {
            Gateway.AssertUserAuthenticated(Request, this.ConfigPrivilege);

            if (!Request.HasData)
            {
                throw new BadRequestException();
            }

            string StartsWith = Request.DecodeData() as string;

            if (string.IsNullOrEmpty(StartsWith))
            {
                throw new BadRequestException();
            }

            SuggestionEventArgs e = new SuggestionEventArgs(StartsWith.Trim());

            foreach (RosterItem Item in Gateway.XmppClient.Roster)
            {
                foreach (string Group in Item.Groups)
                {
                    e.AddSuggestion(Group);
                }
            }

            try
            {
                OnGetGroupSuggestions?.Invoke(this, e);
            }
            catch (Exception ex)
            {
                Log.Critical(ex);
            }

            StringBuilder sb = new StringBuilder();

            string[] Groups = e.ToArray();
            bool     First  = true;
            int      Nr     = 0;

            sb.Append("{\"groups\":[");

            foreach (string Group in Groups)
            {
                if (First)
                {
                    First = false;
                }
                else
                {
                    sb.Append(',');
                }

                sb.Append('"');
                sb.Append(CommonTypes.JsonStringEncode(Group));
                sb.Append('"');

                Nr++;
            }

            sb.Append("],\"count\":");
            sb.Append(Nr.ToString());
            sb.Append("}");

            Response.ContentType = "application/json";
            return(Response.Write(sb.ToString()));
        }