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); } }
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); } }
public override Vcard GetVCard(Jid jid, string id = "") { ASCContext.SetCurrentTenant(jid.Server); var tenant = ASCContext.GetCurrentTenant(); if (tenant == null) { return(new Vcard()); } jid = new Jid(jid.Bare.ToLowerInvariant()); var ui = ASCContext.UserManager.GetUserByUserName(jid.User); if (ui != null) { var vcard = cache.Get <Vcard>(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 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; if (id == null || id.IndexOf("tmtalk", StringComparison.OrdinalIgnoreCase) < 0) { var image = PreparePhoto(ASCContext.UserManager.GetUserPhoto(ui.ID)); 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)); } }