Exemplo n.º 1
0
        public void AddTypingUser(int userId, TLSendMessageActionBase action)
        {
            var now    = DateTime.Now;
            var max    = DateTime.MaxValue;
            var typing = new List <Tuple <int, TLSendMessageActionBase> >();

            lock (_typingUsersSyncRoot)
            {
                _typingUsersCache[userId] = new Tuple <DateTime, TLSendMessageActionBase>(TillDate(now, action), action);

                foreach (var current in _typingUsersCache)
                {
                    if (current.Value.Item1 > now)
                    {
                        if (max > current.Value.Item1)
                        {
                            max = current.Value.Item1;
                        }

                        typing.Add(new Tuple <int, TLSendMessageActionBase>(current.Key, current.Value.Item2));
                    }
                }
            }

            if (typing.Count > 0)
            {
                StartTypingTimer((int)(max - now).TotalMilliseconds);
                _typingCallback?.Invoke(typing);
                return;
            }

            _callback?.Invoke();
        }
Exemplo n.º 2
0
        public override TLObject FromBytes(byte[] bytes, ref int position)
        {
            bytes.ThrowExceptionIfIncorrect(ref position, Signature);

            Action = GetObject <TLSendMessageActionBase>(bytes, ref position);

            return(this);
        }
        public void SetTyping(TLSendMessageActionBase action)
        {
            if (_lastTypingTime.HasValue && _lastTypingTime.Value.AddSeconds(_delay) > DateTime.Now)
            {
                return;
            }

            _lastTypingTime = DateTime.Now;
            _protoService.SetTypingAsync(_peer, action, null);
        }
Exemplo n.º 4
0
        private static DateTime TillDate(DateTime now, TLSendMessageActionBase action)
        {
            var playGameAction = action as TLSendMessageGamePlayAction;

            if (playGameAction != null)
            {
                return(now.AddSeconds(10.0));
            }

            return(now.AddSeconds(5.0));
        }
Exemplo n.º 5
0
        public override TLObject FromStream(Stream input)
        {
            Action = GetObject <TLSendMessageActionBase>(input);

            return(this);
        }
Exemplo n.º 6
0
        private void HandleTypingCommon(TLUpdateTypingBase updateTyping, Dictionary <int, TypingTuple> typingCache)
        {
            Execute.BeginOnUIThread(() =>
            {
                var frame = Application.Current.RootVisual as TelegramTransitionFrame;
                if (frame != null)
                {
                    var shellView = frame.Content as ShellView;
                    if (shellView == null)
                    {
                        return;
                    }
                }

                var updateChatUserTyping = updateTyping as TLUpdateChatUserTyping;
                var id = updateChatUserTyping != null ? updateChatUserTyping.ChatId : updateTyping.UserId;
                TypingTuple tuple;
                if (!typingCache.TryGetValue(id.Value, out tuple))
                {
                    for (var i = 0; i < Items.Count; i++)
                    {
                        if (updateChatUserTyping == null &&
                            Items[i].Peer is TLPeerUser &&
                            Items[i].Peer.Id.Value == id.Value ||
                            (updateChatUserTyping != null &&
                             Items[i].Peer is TLPeerChat &&
                             Items[i].Peer.Id.Value == id.Value))
                        {
                            var dialog = Items[i] as TLDialog;
                            if (dialog != null)
                            {
                                tuple = new TypingTuple(dialog, new InputTypingManager(
                                                            users => Execute.BeginOnUIThread(() =>
                                {
                                    dialog.TypingString = GetTypingString(dialog.Peer, users);
                                    dialog.NotifyOfPropertyChange(() => dialog.Self.TypingString);
                                }),
                                                            () => Execute.BeginOnUIThread(() =>
                                {
                                    dialog.TypingString = null;
                                    dialog.NotifyOfPropertyChange(() => dialog.Self.TypingString);
                                })));
                                typingCache[id.Value] = tuple;
                            }
                            break;
                        }
                    }
                }

                if (tuple != null)
                {
                    TLSendMessageActionBase action = null;
                    var typingAction = updateTyping as IUserTypingAction;
                    if (typingAction != null)
                    {
                        action = typingAction.Action;
                    }

                    tuple.Item2.AddTypingUser(updateTyping.UserId.Value, action);
                }
            });
        }