예제 #1
0
        public IObservable <Message> LoadMessage(long chatId, long messageId)
        {
            var scope = new MessageLoaderScope(_agent);

            return(scope.GetMessage(chatId, messageId)
                   .SelectSeq(m => MapToMessage(scope, m))
                   .Finally(() =>
            {
                scope.Dispose();
            }));
        }
예제 #2
0
        public IObservable <Message> LoadPinnedMessage(Chat chat)
        {
            var scope = new MessageLoaderScope(_agent);

            return(GetPinnedMessage(chat.ChatData)
                   .Where(m => m != null)
                   .SelectSeq(m => MapToMessage(scope, m))
                   .Finally(() =>
            {
                scope.Dispose();
            }));
        }
예제 #3
0
        public IObservable <Message> LoadMessages(
            Aggregate feed,
            AggregateLoadingState state)
        {
            var scope = new MessageLoaderScope(_agent);

            return(LoadAggregateMessages(feed, state)
                   .SelectSeq(m => MapToMessage(scope, m))
                   .Finally(() =>
            {
                scope.Dispose();
            }));
        }
예제 #4
0
        private IObservable <Message> MapToMessage(
            MessageLoaderScope scope,
            TdApi.Message msg,
            bool fetchReply = true)
        {
            return(Observable.Return(new Message
            {
                MessageData = msg
            })
                   .SelectSeq(message =>
            {
                // get chat data
                return scope.GetChat(msg.ChatId)
                .Select(chat =>
                {
                    message.ChatData = chat;
                    return message;
                });
            })
                   .SelectSeq(message =>
            {
                // get user data
                if (message.MessageData.SenderUserId != 0)
                {
                    return scope.GetUser(message.MessageData.SenderUserId)
                    .Select(user =>
                    {
                        message.UserData = user;
                        return message;
                    });
                }

                return Observable.Return(message);
            })
                   .SelectSeq(message =>
            {
                // get reply data
                if (fetchReply && message.MessageData.ReplyToMessageId != 0)
                {
                    return scope.GetMessage(message.MessageData.ChatId, message.MessageData.ReplyToMessageId)
                    .SelectSeq(m => MapToMessage(scope, m, false))
                    .Select(reply =>
                    {
                        message.ReplyMessage = reply;
                        return message;
                    });
                }

                return Observable.Return(message);
            }));
        }
예제 #5
0
        public IObservable <Message> LoadPrevMessages(
            Chat chat,
            long fromMessageId,
            int limit)
        {
            var scope = new MessageLoaderScope(_agent);

            return(GetMessages(chat.ChatData, fromMessageId, limit, 0)
                   .SelectSeq(m => MapToMessage(scope, m))
                   .Finally(() =>
            {
                scope.Dispose();
            }));
        }