Beispiel #1
0
        private async Task LoginUser(LoginData data)
        {
            var response = await IdeaBagApi.Instance.LoginAsync(data);

            if (response.Payload != null)
            {
                Global.AuthUser(response.Payload);

                var expirationDate = DateTime.Now.AddMilliseconds(response.Payload.ExpiresInMillis);
                PreferenceManager.Instance.AddEntry("expiresIn", JsonConvert.SerializeObject(expirationDate));

                OnUserLoggedIn?.Invoke(this, response.Payload.Email);
                Dismiss();
            }
            else
            {
                Snackbar.Make(loadingCircle, response.ErrorMessage, Snackbar.LengthLong).Show();
            }
        }
Beispiel #2
0
        /// <summary>
        /// Handles incoming <see cref="UserUpdatePacket"/>s.
        /// </summary>
        /// <param name="connectionId">Original connection ID</param>
        /// <param name="packet">Incoming <see cref="UserUpdatePacket"/></param>
        private void userUpdatePacketHandler(string connectionId, UserUpdatePacket packet)
        {
            User user = packet.User;

            lock (userStoreLock)
            {
                // Check if the user does not already exist
                if (!userStore.Users.ContainsKey(user.Uuid))
                {
                    // Add the user
                    userStore.Users.Add(user.Uuid, user);

                    // Raise the user created event and return
                    OnUserCreated?.Invoke(this, new UserCreatedEventArgs(user.Uuid, user.LoggedIn, user.DisplayName));
                    return;
                }

                // Hold on to the existing copy for later
                User existingUser = userStore.Users[user.Uuid];

                // Replace the user with the new copy
                userStore.Users[user.Uuid] = user;

                // Compare the user's login states and raise an event if they differ
                if (user.LoggedIn != existingUser.LoggedIn)
                {
                    if (user.LoggedIn)
                    {
                        OnUserLoggedIn?.Invoke(this, new UserLoginStateChangedEventArgs(user.Uuid, false, true));
                    }
                    else
                    {
                        OnUserLoggedOut?.Invoke(this, new UserLoginStateChangedEventArgs(user.Uuid, true, false));
                    }
                }

                // Compare the user's display name and raise an event if they differ
                if (user.DisplayName != existingUser.DisplayName)
                {
                    OnUserDisplayNameChanged?.Invoke(this, new UserDisplayNameChangedEventArgs(user.Uuid, existingUser.DisplayName, user.DisplayName));
                }
            }
        }
 public static void RaiseOnUserLoggedIn(User user) =>
 OnUserLoggedIn?.Invoke(user);