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); }
void tox_OnFriendMessageReceived(object sender, ToxEventArgs.FriendMessageEventArgs e) { //get the name associated with the friendnumber string name = tox.GetFriendName(e.FriendNumber); Package receivedPackage = JsonConvert.DeserializeObject <Package>(e.Message); if (receivedPackage.currentCount == 0) { if (receivedPackage.totalCount == 1) { newReqReceived(receivedPackage, e.FriendNumber); return; } mPackageCache.Add(receivedPackage.uuid, receivedPackage); } else if (receivedPackage.currentCount != receivedPackage.totalCount - 1) { mPackageCache[receivedPackage.uuid].content += receivedPackage.content; } else if (receivedPackage.currentCount == receivedPackage.totalCount - 1) { newReqReceived(receivedPackage, e.FriendNumber); } }
public FriendListEntryViewModel(Tox tox, uint friendNumber) { //var publicKey = tox.GetFriendPublicKey(friendNumber); var status = tox.Events().Friends.StatusChanged .Where(x => x.FriendNumber == friendNumber) .Select(x => x.Status); status.Select(x => x == ToxUserStatus.Away) .ToPropertyEx(this, x => x.IsAway); status.Select(x => x == ToxUserStatus.Busy) .ToPropertyEx(this, x => x.IsBusy); tox.Events().Friends.NameChanged .Where(x => x.FriendNumber == friendNumber) .Select(x => x.Name) .StartWith(tox.GetFriendName(friendNumber, out _)) .ToPropertyEx(this, x => x.Name); tox.Events().Friends.StatusMessageChanged .Where(x => x.FriendNumber == friendNumber) .Select(x => x.StatusMessage) .StartWith(tox.GetFriendStatusMessage(friendNumber, out _)) .ToPropertyEx(this, x => x.StatusMessage); this.Remove = ReactiveCommand.Create(() => friendNumber); this.Conversation = new FriendConversationViewModel(tox, friendNumber); }
public FriendConversationViewModel(Tox tox, uint friendNumber) { var messages = new SourceList <MessageViewModel>(); messages.Connect() .AutoRefresh(x => x.Read) .Filter(x => !x.Read) .AsObservableList() .CountChanged .ToPropertyEx(this, x => x.UnreadCount); this.SendMessage = ReactiveCommand.Create <string>(msg => { if (!string.IsNullOrWhiteSpace(msg)) { _ = tox.SendMessage(friendNumber, msg, ToxMessageType.Message, out _); messages.Add(new MessageViewModel("Me", msg, DateTime.Now.Ticks)); } }); ReadOnlyObservableCollection <MessageViewModel> msgs; messages.Connect() .Bind(out msgs) .Subscribe(); this.Messages = msgs; this.SendTypedMessage = ReactiveCommand.Create(() => { var msg = this.InputMessage; this.InputMessage = string.Empty; return(msg); }, this.WhenAnyValue(x => x.InputMessage, (string s) => !string.IsNullOrWhiteSpace(s))); this.WhenAnyValue(x => x.InputMessage) .Select(msg => !string.IsNullOrWhiteSpace(msg)) .Where(x => x) .Do(x => tox.SetTypingStatus(friendNumber, true, out _)) .Throttle(TimeSpan.FromMilliseconds(500)) .Subscribe(x => tox.SetTypingStatus(friendNumber, false, out _)); tox.Events().Friends .Message .Where(x => x.FriendNumber == friendNumber && x.MessageType == ToxMessageType.Message) .Select(x => x.Message) .Subscribe(msg => messages.Add(new MessageViewModel(tox.GetFriendName(friendNumber, out _), msg, DateTime.Now.Ticks))); this.WhenAnyObservable(x => x.SendTypedMessage) .InvokeCommand(this, x => x.SendMessage); }
private void Tox_OnFriendConnectionStatusChanged(object sender, ToxEventArgs.FriendConnectionStatusEventArgs e) { Debugging.Write(string.Format("Friend {0} connnection status changed to: {1}", _tox.GetFriendName(e.FriendNumber), e.Status)); }