private void OnUpdateUserStatus(string userId, FriendsController.UserStatus newStatus)
    {
        var model = new FriendEntry.Model();

        FriendEntryBase entry = view.friendsList.GetEntry(userId) ?? view.friendRequestsList.GetEntry(userId);

        if (entry != null)
        {
            model = entry.model;
        }

        model.status = newStatus.presence;
        model.coords = newStatus.position;

        if (newStatus.realm != null)
        {
            model.realm           = $"{newStatus.realm.serverName.ToUpperFirst()} {newStatus.realm.layer.ToUpperFirst()}";
            model.realmServerName = newStatus.realm.serverName;
            model.realmLayerName  = newStatus.realm.layer;
        }
        else
        {
            model.realm           = string.Empty;
            model.realmServerName = string.Empty;
            model.realmLayerName  = string.Empty;
        }

        view.friendsList.UpdateEntry(userId, model);
        view.friendRequestsList.UpdateEntry(userId, model);
    }
Пример #2
0
    public void BePopulatedCorrectly()
    {
        var model1 = new FriendEntry.Model()
        {
            userName = "******", avatarImage = Texture2D.whiteTexture
        };
        var model2 = new FriendEntry.Model()
        {
            userName = "******", avatarImage = Texture2D.blackTexture
        };

        entry.userId = "userId1";
        entry.Populate(model1);
        entry.SetReceived(true);

        Assert.AreEqual(model1.userName, entry.playerNameText.text);
        Assert.AreEqual(model1.avatarImage, entry.playerImage.texture);

        Assert.IsFalse(entry.cancelButton.gameObject.activeSelf);
        Assert.IsTrue(entry.acceptButton.gameObject.activeSelf);
        Assert.IsTrue(entry.rejectButton.gameObject.activeSelf);

        entry.userId = "userId2";
        entry.Populate(model2);
        entry.SetReceived(false);

        Assert.AreEqual(model2.userName, entry.playerNameText.text);
        Assert.AreEqual(model2.avatarImage, entry.playerImage.texture);

        Assert.IsTrue(entry.cancelButton.gameObject.activeSelf);
        Assert.IsFalse(entry.acceptButton.gameObject.activeSelf);
        Assert.IsFalse(entry.rejectButton.gameObject.activeSelf);
    }
    public bool UpdateEntry(string userId, FriendEntry.Model model, bool?isReceived = null)
    {
        if (!base.UpdateEntry(userId, model))
        {
            return(false);
        }

        var entry = entries[userId] as FriendRequestEntry;

        if (isReceived.HasValue)
        {
            entry.SetReceived(isReceived.Value);

            if (isReceived.Value)
            {
                receivedRequestsList.Add(userId, entry);
            }
            else
            {
                sentRequestsList.Add(userId, entry);
            }
        }

        return(true);
    }
    void RequestCreateFriendEntry(string id, string name, PresenceStatus status = PresenceStatus.ONLINE)
    {
        var model1 = new FriendEntry.Model()
        {
            status   = status,
            userName = name,
        };

        controller.view.friendsList.CreateOrUpdateEntryDeferred(id, model1);
    }
Пример #5
0
    FriendRequestEntry CreateFriendRequestEntry(string id, string name, bool isReceived)
    {
        var model1 = new FriendEntry.Model()
        {
            userName = name,
        };

        controller.view.friendRequestsList.CreateOrUpdateEntry(id, model1, isReceived);

        return(controller.view.friendRequestsList.GetEntry(id) as FriendRequestEntry);
    }
Пример #6
0
    FriendEntry CreateFriendEntry(string id, string name, PresenceStatus status = PresenceStatus.ONLINE)
    {
        var model1 = new FriendEntry.Model()
        {
            status   = status,
            userName = name,
        };

        controller.view.friendsList.CreateOrUpdateEntry(id, model1);

        return(controller.view.friendsList.GetEntry(id) as FriendEntry);
    }
Пример #7
0
    public void SendProperEventWhenOnCancelledIsPressed()
    {
        var model = new FriendEntry.Model()
        {
        };

        entry.userId = "userId-1";
        entry.Populate(model);
        bool buttonPressed = false;

        entry.OnCancelled += (x) => { if (x == entry)
                                      {
                                          buttonPressed = true;
                                      }
        };
        entry.cancelButton.onClick.Invoke();
        Assert.IsTrue(buttonPressed);
    }
Пример #8
0
    public void BePopulatedCorrectly()
    {
        FriendEntry.Model model = new FriendEntry.Model()
        {
            coords          = Vector2.one,
            avatarImage     = Texture2D.whiteTexture,
            realm           = "realm-test",
            realmServerName = "realm-test",
            realmLayerName  = "realm-layer-test",
            status          = PresenceStatus.ONLINE,
            userName        = "******"
        };

        entry.userId = "userId-1";
        entry.Populate(model);

        Assert.AreEqual(model.userName, entry.playerNameText.text);
        Assert.AreEqual(entry.playerImage.texture, Texture2D.whiteTexture);
    }
Пример #9
0
    public void BePopulatedCorrectly()
    {
        Sprite testSprite1 = Sprite.Create(Texture2D.whiteTexture, Rect.zero, Vector2.zero);
        Sprite testSprite2 = Sprite.Create(Texture2D.blackTexture, Rect.zero, Vector2.zero);
        var    model1      = new FriendEntry.Model()
        {
            userName = "******", avatarImage = testSprite1
        };
        var model2 = new FriendEntry.Model()
        {
            userName = "******", avatarImage = testSprite2
        };

        entry.userId = "userId1";
        entry.Populate(model1);
        entry.SetReceived(true);

        Assert.AreEqual(model1.userName, entry.playerNameText.text);
        Assert.AreEqual(model1.avatarImage, entry.playerImage.sprite);

        Assert.IsFalse(entry.cancelButton.gameObject.activeSelf);
        Assert.IsTrue(entry.acceptButton.gameObject.activeSelf);
        Assert.IsTrue(entry.rejectButton.gameObject.activeSelf);

        entry.userId = "userId2";
        entry.Populate(model2);
        entry.SetReceived(false);

        Assert.AreEqual(model2.userName, entry.playerNameText.text);
        Assert.AreEqual(model2.avatarImage, entry.playerImage.sprite);

        Assert.IsTrue(entry.cancelButton.gameObject.activeSelf);
        Assert.IsFalse(entry.acceptButton.gameObject.activeSelf);
        Assert.IsFalse(entry.rejectButton.gameObject.activeSelf);

        Object.Destroy(testSprite1);
        Object.Destroy(testSprite2);
    }
Пример #10
0
    public void BePopulatedCorrectly()
    {
        Sprite testSprite = Sprite.Create(Texture2D.whiteTexture, Rect.zero, Vector2.zero);

        FriendEntry.Model model = new FriendEntry.Model()
        {
            coords          = Vector2.one,
            avatarImage     = testSprite,
            realm           = "realm-test",
            realmServerName = "realm-test",
            realmLayerName  = "realm-layer-test",
            status          = PresenceStatus.ONLINE,
            userName        = "******"
        };

        entry.userId = "userId-1";
        entry.Populate(model);

        Assert.AreEqual(model.userName, entry.playerNameText.text);
        Assert.AreEqual(entry.playerImage.sprite, testSprite);

        Object.Destroy(testSprite);
    }
    private void OnUpdateFriendship(string userId, FriendshipAction friendshipAction)
    {
        var userProfile = UserProfileController.userProfilesCatalog.Get(userId);

        if (userProfile == null)
        {
            Debug.LogError($"UserProfile is null for {userId}! ... friendshipAction {friendshipAction}");
            return;
        }

        var friendEntryModel = new FriendEntry.Model();

        FriendEntryBase entry = view.friendsList.GetEntry(userId) ?? view.friendRequestsList.GetEntry(userId);

        if (entry != null)
        {
            friendEntryModel = entry.model;
        }

        friendEntryModel.userName    = userProfile.userName;
        friendEntryModel.avatarImage = userProfile.faceSnapshot;

        userProfile.OnFaceSnapshotReadyEvent -= friendEntryModel.OnSpriteUpdate;
        userProfile.OnFaceSnapshotReadyEvent += friendEntryModel.OnSpriteUpdate;

        if (ownUserProfile != null && ownUserProfile.blocked != null)
        {
            friendEntryModel.blocked = ownUserProfile.blocked.Contains(userId);
        }

        switch (friendshipAction)
        {
        case FriendshipAction.NONE:
            userProfile.OnFaceSnapshotReadyEvent -= friendEntryModel.OnSpriteUpdate;
            view.friendRequestsList.RemoveEntry(userId);
            view.friendsList.RemoveEntry(userId);
            break;

        case FriendshipAction.APPROVED:
            view.friendRequestsList.RemoveEntry(userId);
            view.friendsList.CreateOrUpdateEntryDeferred(userId, friendEntryModel);
            break;

        case FriendshipAction.REJECTED:
            userProfile.OnFaceSnapshotReadyEvent -= friendEntryModel.OnSpriteUpdate;
            view.friendRequestsList.RemoveEntry(userId);
            break;

        case FriendshipAction.CANCELLED:
            userProfile.OnFaceSnapshotReadyEvent -= friendEntryModel.OnSpriteUpdate;
            view.friendRequestsList.RemoveEntry(userId);
            break;

        case FriendshipAction.REQUESTED_FROM:
            view.friendRequestsList.CreateOrUpdateEntry(userId, friendEntryModel, true);
            break;

        case FriendshipAction.REQUESTED_TO:
            view.friendRequestsList.CreateOrUpdateEntry(userId, friendEntryModel, false);
            break;

        case FriendshipAction.DELETED:
            userProfile.OnFaceSnapshotReadyEvent -= friendEntryModel.OnSpriteUpdate;
            view.friendRequestsList.RemoveEntry(userId);
            view.friendsList.RemoveEntry(userId);
            break;
        }

        UpdateNotificationsCounter();
    }
Пример #12
0
 public void CreateOrUpdateEntry(string userId, FriendEntry.Model model, bool isReceived)
 {
     CreateEntry(userId);
     UpdateEntry(userId, model, isReceived);
 }