Ejemplo n.º 1
0
        private void AddFriend(int id)
        {
            if (!Tox.FriendExists(id))
            {
                return;
            }

            ContactViewModel contact = new ContactViewModel();

            contact.ID        = id;
            contact.Name      = Tox.GetFriendName(id);
            contact.Subtext   = Tox.GetFriendStatusMessage(id); // TODO: Replace this with last message when we have a conversation with the contact
            contact.Status    = Utilities.GetDetoxStatusByFriendNumber(id, Tox);
            contact.Timestamp = "5m";                           // TODO: Replace this with last messaged

            if (!File.Exists(Utilities.GetAvatarPath(id, Tox)))
            {
                contact.Image = Path.GetFullPath("./defaultpic.png");
            }
            else
            {
                contact.Image = Utilities.GetAvatarPath(id, Tox);
            }

            List.Add(contact);
        }
Ejemplo n.º 2
0
        public void TestToxFriendRequest()
        {
            var    options      = new ToxOptions(true, true);
            var    tox1         = new Tox(options);
            var    tox2         = new Tox(options);
            var    error        = ToxErrorFriendAdd.Ok;
            string message      = "Hey, this is a test friend request.";
            bool   testFinished = false;

            tox1.AddFriend(tox2.Id, message, out error);
            if (error != ToxErrorFriendAdd.Ok)
            {
                Assert.Fail("Failed to add friend: {0}", error);
            }

            tox2.OnFriendRequestReceived += (sender, args) =>
            {
                if (args.Message != message)
                {
                    Assert.Fail("Message received in the friend request is not the same as the one that was sent");
                }

                tox2.AddFriendNoRequest(args.PublicKey, out error);
                if (error != ToxErrorFriendAdd.Ok)
                {
                    Assert.Fail("Failed to add friend (no request): {0}", error);
                }

                if (!tox2.FriendExists(0))
                {
                    Assert.Fail("Friend doesn't exist according to core");
                }

                testFinished = true;
            };

            while (!testFinished && tox1.GetFriendConnectionStatus(0) == ToxConnectionStatus.None)
            {
                int time1 = tox1.Iterate();
                int time2 = tox2.Iterate();

                Thread.Sleep(Math.Min(time1, time2));
            }

            tox1.Dispose();
            tox2.Dispose();
        }