コード例 #1
0
        /// <summary>
        /// Accepts a party invite.
        /// </summary>
        /// <param name="xmppClient">The <see cref="XMPPClient"/> to accept the invite for.</param>
        /// <exception cref="InvalidOperationException">Thrown if the invite is expired.</exception>
        public async Task Accept(XMPPClient xmppClient)
        {
            // If the expiry time has passed, this means the invite has expired.
            if (DateTime.Compare(DateTime.UtcNow, ExpiresAt) > 0)
            {
                IsExpired = true;
            }

            // If the invite has expired, throw an exception.
            if (IsExpired)
            {
                throw new InvalidOperationException($"Party invite to {PartyId} expired or was already accepted/declined!");
            }

            // If our XMPP client's party is not null, leave it.
            if (xmppClient.CurrentParty != null)
            {
                await PartyService.LeaveParty(xmppClient);
            }

            // Join the party of the invite, and delete the ping.
            await PartyService.JoinParty(xmppClient, this);

            await PartyService.DeletePingById(xmppClient.AuthSession, SentBy);

            // The invite was accepted, so it has now expired.
            IsExpired = true;
        }
コード例 #2
0
        /// <summary>
        /// Declines a party invite.
        /// </summary>
        /// <param name="xmppClient">The <see cref="XMPPClient"/> to decline the invite for.</param>
        /// <exception cref="InvalidOperationException">Thrown if the invite is expired.</exception>
        public async Task Decline(XMPPClient xmppClient)
        {
            // If the expiry time has passed, this means the invite has expired.
            if (DateTime.Compare(DateTime.UtcNow, ExpiresAt) > 0)
            {
                IsExpired = true;
            }

            // If the invite has expired, throw an exception.
            if (IsExpired)
            {
                throw new InvalidOperationException($"Party invite to {PartyId} expired or was already accepted/declined!");
            }

            // Delete the ping.
            await PartyService.DeletePingById(xmppClient.AuthSession, SentBy);

            // The invite was declined, so it has now expired.
            IsExpired = true;
        }