Exemplo n.º 1
0
        public override Vcard GetVCard(Jid jid)
        {
            ASCContext.SetCurrentTenant(jid.Server);

            jid = new Jid(jid.Bare.ToLowerInvariant());
            var ui = ASCContext.UserManager.GetUserByUserName(jid.User);

            if (ui != null)
            {
                var vcard = (Vcard)cache.Get(jid.ToString());
                if (vcard != null)
                {
                    return(vcard);
                }

                vcard             = new Vcard();
                vcard.Name        = new Name(ui.LastName, ui.FirstName, null);
                vcard.Fullname    = UserFormatter.GetUserName(ui);
                vcard.Nickname    = ui.UserName;
                vcard.Description = ui.Notes;
                if (ui.BirthDate != null)
                {
                    vcard.Birthday = ui.BirthDate.Value;
                }
                vcard.JabberId = jid;
                if (ui.Sex.HasValue)
                {
                    vcard.Gender = ui.Sex.Value ? Gender.MALE : Gender.FEMALE;
                }

                var index = ui.Contacts.FindIndex(c => string.Compare(c, "phone", true) == 0) + 1;
                if (0 < index && index < ui.Contacts.Count)
                {
                    vcard.AddTelephoneNumber(new Telephone(TelephoneLocation.WORK, TelephoneType.NUMBER, ui.Contacts[index]));
                }
                vcard.AddEmailAddress(new Email(EmailType.INTERNET, ui.Email, true));

                var tenant      = ASCContext.GetCurrentTenant();
                var departments = string.Join(", ", CoreContext.UserManager.GetUserGroups(ui.ID).Select(d => HttpUtility.HtmlEncode(d.Name)).ToArray());
                if (tenant != null)
                {
                    vcard.Organization = new Organization(tenant.Name, departments);
                }
                vcard.Title = ui.Title;

                var image = PreparePhoto(ASCContext.UserManager.GetUserPhoto(ui.ID, Guid.Empty));
                if (image != null)
                {
                    vcard.Photo = new Photo(image, ImageFormat.Png);
                    image.Dispose();
                }

                cache.Insert(jid.ToString(), vcard, CACHE_TIMEOUT);
                return(vcard);
            }
            else
            {
                return(base.GetVCard(jid));
            }
        }
Exemplo n.º 2
0
        public Dictionary <string, byte> GetAllStates(int tenantId, string from)
        {
            var states = new Dictionary <string, byte>();

            try
            {
                _log.Debug("Get All States");
                var userJid = GetJid(from, tenantId);
                ASCContext.SetCurrentTenant(userJid.Server);

                foreach (var user in ASCContext.UserManager.GetUsers().Where(u => !u.IsMe()))
                {
                    userJid = GetJid(user.UserName, tenantId);
                    var session = _xmppServer.SessionManager.GetAvailableSession(userJid.BareJid);
                    if (session != null && session.Presence != null && session.Presence.Type != PresenceType.unavailable)
                    {
                        states.Add(userJid.User, SignalRHelper.GetState(session.Presence.Show, session.Presence.Type));
                    }
                }
            }
            catch (Exception e)
            {
                _log.Error(e);
            }
            return(states);
        }
Exemplo n.º 3
0
 public override void SetVCard(Jid jid, Vcard vcard)
 {
     ASCContext.SetCurrentTenant(jid.Server);
     if (ASCContext.UserManager.IsUserNameExists(jid.User))
     {
         throw new JabberException(ErrorCode.Forbidden);
     }
     base.SetVCard(jid, vcard);
 }
Exemplo n.º 4
0
        public override void RemoveRosterItem(Jid rosterJid, Jid itemJid)
        {
            ASCContext.SetCurrentTenant(rosterJid.Server);
            if (IsASCRosterItem(rosterJid, itemJid))
            {
                throw new JabberException(ErrorCode.Forbidden);
            }

            base.RemoveRosterItem(rosterJid, itemJid);
        }
Exemplo n.º 5
0
        public User GetUser(Jid jid)
        {
            ASCContext.SetCurrentTenant(jid.Server);
            var u = ASCContext.UserManager.GetUserByUserName(jid.User);

            if (Constants.LostUser.Equals(u) || u.Status == EmployeeStatus.Terminated)
            {
                return(null);
            }
            return(ToUser(u, jid.Server));
        }
Exemplo n.º 6
0
        public override UserRosterItem SaveRosterItem(Jid rosterJid, UserRosterItem item)
        {
            if (item == null)
            {
                throw new ArgumentNullException("item");
            }

            ASCContext.SetCurrentTenant(rosterJid.Server);
            if (IsASCRosterItem(rosterJid, item.Jid))
            {
                throw new JabberException(ErrorCode.Forbidden);
            }

            return(base.SaveRosterItem(rosterJid, item));
        }
Exemplo n.º 7
0
 public override UserRosterItem GetRosterItem(Jid rosterJid, Jid itemJid)
 {
     try
     {
         ASCContext.SetCurrentTenant(rosterJid.Server);
         var u = ASCContext.UserManager.GetUserByUserName(itemJid.User);
         return(!string.IsNullOrEmpty(u.UserName) ?
                ToUserRosterItem(u, itemJid.Server) :
                base.GetRosterItem(rosterJid, itemJid));
     }
     catch (Exception e)
     {
         throw new JabberException("Could not get roster item.", e);
     }
 }
Exemplo n.º 8
0
 public override List <UserRosterItem> GetRosterItems(Jid rosterJid)
 {
     try
     {
         ASCContext.SetCurrentTenant(rosterJid.Server);
         var items = GetASCRosterItems(rosterJid);
         items.AddRange(base.GetRosterItems(rosterJid));
         SortRoster(items);
         return(items);
     }
     catch (Exception e)
     {
         throw new JabberException("Could not get roster items.", e);
     }
 }
Exemplo n.º 9
0
        public ICollection <User> GetUsers(string domain)
        {
            ASCContext.SetCurrentTenant(domain);
            var users = new List <User>();

            foreach (var ui in ASCContext.UserManager.GetUsers())
            {
                var u = ToUser(ui, domain);
                if (u != null)
                {
                    users.Add(u);
                }
            }
            return(users);
        }