Example #1
0
        public void SetActivatedArgs(IActivatedEventArgs args, INavigationService service)
        {
            _args    = args;
            _service = service = WindowWrapper.Current().NavigationServices.FirstOrDefault();

            UseActivatedArgs(args, service, _protoService.GetAuthorizationState());
        }
Example #2
0
        public async Task ProcessAsync(Dictionary <string, string> data)
        {
            var state = _protoService.GetAuthorizationState();

            if (!(state is AuthorizationStateReady))
            {
                state = await _authorizationStateTask.Task;
            }

            if (!(state is AuthorizationStateReady))
            {
                return;
            }

            if (data.TryGetValue("action", out string action))
            {
                var chat = default(Chat);
                if (data.TryGetValue("from_id", out string from_id) && int.TryParse(from_id, out int fromId))
                {
                    chat = await _protoService.SendAsync(new CreatePrivateChat(fromId, false)) as Chat;
                }
                else if (data.TryGetValue("channel_id", out string channel_id) && int.TryParse(channel_id, out int channelId))
                {
                    chat = await _protoService.SendAsync(new CreateSupergroupChat(channelId, false)) as Chat;
                }
                else if (data.TryGetValue("chat_id", out string chat_id) && int.TryParse(chat_id, out int chatId))
                {
                    chat = await _protoService.SendAsync(new CreateBasicGroupChat(chatId, false)) as Chat;
                }

                if (chat == null)
                {
                    return;
                }

                if (string.Equals(action, "reply", StringComparison.OrdinalIgnoreCase) && data.TryGetValue("input", out string text))
                {
                    var messageText = text.Replace("\r\n", "\n").Replace('\v', '\n').Replace('\r', '\n');
                    var formatted   = Client.Execute(new ParseMarkdown(new FormattedText(messageText, new TextEntity[0]))) as FormattedText;

                    var replyToMsgId = data.ContainsKey("msg_id") ? long.Parse(data["msg_id"]) << 20 : 0;
                    var response     = await _protoService.SendAsync(new SendMessage(chat.Id, replyToMsgId, new MessageSendOptions(false, true, null), null, new InputMessageText(formatted, false, false)));

                    if (chat.Type is ChatTypePrivate)
                    {
                        await _protoService.SendAsync(new ViewMessages(chat.Id, new long[] { chat.LastMessage.Id }, true));
                    }
                }
                else if (string.Equals(action, "markasread", StringComparison.OrdinalIgnoreCase))
                {
                    if (chat.LastMessage == null)
                    {
                        return;
                    }

                    await _protoService.SendAsync(new ViewMessages(chat.Id, new long[] { chat.LastMessage.Id }, true));
                }
            }
        }