/// <summary> /// Constructs a ProviderUser /// </summary> public ProviderUser() { this.presence = new Presence(PresenceType.Offline); this.relationship = ProviderUserRelationship.Unknown; this.uri = String.Empty; this.accountName = String.Empty; this.alias = String.Empty; this.isMe = false; this.protocol = String.Empty; this.avatarToken = String.Empty; this.mediaCaps = Banter.MediaCapability.None; }
/// <summary> /// Authorize a user to enable chatting /// the user must be in the correct relationship state to authorize /// </summary> public void Authorize(string message) { if (this.relationship != ProviderUserRelationship.ReceivedInvitation) { throw new ApplicationException("User is not in a the correct authorization state"); } // Need to get the account information so we can AddMember // to the correct group Account account = AccountManagement.GetAccountByName(this.accountName); account.AuthorizeUser(true, this.id, message); this.relationship = ProviderUserRelationship.Linked; }
/// <summary> /// Method to revoke an outstanding invitation /// </summary> public void RevokeInvitation() { if (this.relationship != ProviderUserRelationship.SentInvitation) { throw new ApplicationException("User is not in the SentInvitation relationship state"); } // Need to get the account information so we can AddMember // to the correct group Account account = AccountManagement.GetAccountByName(this.accountName); account.RemoveUser(this.id, String.Empty); this.relationship = ProviderUserRelationship.Unknown; ProviderUserManager.RemoveProviderUser(this.uri, this.protocol); }
/// <summary> /// Deny a user who is requesting authorization to chat /// </summary> public void DenyAuthorization(string message) { if (this.relationship != ProviderUserRelationship.ReceivedInvitation) { throw new ApplicationException("User is not in the ReceivedInvitation state"); } // Need to get the account information so we can AddMember // to the correct group Account account = AccountManagement.GetAccountByName(this.accountName); account.AuthorizeUser(false, this.id, message); this.relationship = ProviderUserRelationship.Unknown; ProviderUserManager.RemoveProviderUser(this.uri, this.protocol); }
/// <summary> /// Creates a new ProviderUser and adds them in one atomic operation /// </summary> public static ProviderUser CreateProviderUser(string uri, string protocol, ProviderUserRelationship relationship) { lock (locker) { string key = CreateKey(uri, protocol); if (!ProviderUserManager.Instance.users.ContainsKey(key)) { ProviderUser user = new ProviderUser(); user.Uri = uri; user.Protocol = protocol; user.Relationship = relationship; ProviderUserManager.Instance.users[key] = user; if (ProviderUserAdded != null) { ProviderUserAdded(user); } return(user); } else { throw new ApplicationException("key already exists"); } } }
/// <summary> /// Method to add or update a user to the provider list /// </summary> private ProviderUser AddProviderUser(uint id, string jid, ProviderUserRelationship relationship) { string key = ProviderUserManager.CreateKey (jid, this.protocol); ProviderUser providerUser = null; try { providerUser = ProviderUserManager.GetProviderUser (key); if (providerUser != null) { providerUser.TlpConnection = tlpConnection; providerUser.AccountName = this.Name; providerUser.Protocol = this.Protocol; providerUser.ID = id; providerUser.Relationship = relationship; } } catch (Exception fff) { Logger.Debug ("Failed to get ProviderUser {0}", key); Logger.Debug (fff.Message); } if (providerUser == null) { try { providerUser = ProviderUserManager.CreateProviderUser ( jid, this.protocol, relationship); providerUser.TlpConnection = tlpConnection; providerUser.AccountName = this.Name; providerUser.ID = id; Logger.Debug ("Member: {0} ID: {1} - object created", jid, id); } catch{} } else { Logger.Debug ("Member: {0} ID: {1} - object updated", jid, id); } return providerUser; }
/// <summary> /// Creates a new ProviderUser and adds them in one atomic operation /// </summary> public static ProviderUser CreateProviderUser(string uri, string protocol, ProviderUserRelationship relationship) { lock(locker) { string key = CreateKey (uri, protocol); if (!ProviderUserManager.Instance.users.ContainsKey (key)) { ProviderUser user = new ProviderUser(); user.Uri = uri; user.Protocol = protocol; user.Relationship = relationship; ProviderUserManager.Instance.users[key] = user; if (ProviderUserAdded != null) ProviderUserAdded (user); return user; } else throw new ApplicationException("key already exists"); } }