Exemplo n.º 1
0
        public FriendListViewModel(Tox tox)
        {
            var friends = new SourceList <uint>();

            foreach (var friend in tox.Friends)
            {
                friends.Add(friend);
                tox.AddFriendNoRequest(tox.GetFriendPublicKey(friend, out _), out _);
            }

            this.Add = ReactiveCommand.Create <uint>(friendNumber =>
            {
                friends.Add(friendNumber);
            });

            ReadOnlyObservableCollection <FriendListEntryViewModel> entries;

            friends.Connect()
            .Transform(number => new FriendListEntryViewModel(tox, number))
            .Bind(out entries)
            .Subscribe();

            this.Friends = entries;

            this.Friends.ToObservableChangeSet()
            .MergeMany(x => x.Remove)
            .Subscribe(number =>
            {
                if (tox.DeleteFriend(number, out _))
                {
                    friends.Remove(number);
                }
            });
        }
Exemplo n.º 2
0
 void tox_OnFriendRequestReceived(object sender, ToxEventArgs.FriendRequestEventArgs e)
 {
     //automatically accept every friend request we receive
     tox.AddFriendNoRequest(e.PublicKey);
     Console.WriteLine("From Server " + httpPort + " ");
     Console.WriteLine("Received friend req: " + e.PublicKey);
 }
Exemplo n.º 3
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();
        }
Exemplo n.º 4
0
 private void Tox_OnFriendRequestReceived(object sender, ToxEventArgs.FriendRequestEventArgs e)
 {
     Tox.AddFriendNoRequest(e.PublicKey);
 }
Exemplo n.º 5
0
 private void tox_OnFriendRequest(object sender, ToxEventArgs.FriendRequestEventArgs e)
 {
     //automatically accept every friend request we receive
     tox.AddFriendNoRequest(new ToxKey(ToxKeyType.Public, e.Id));
 }