Esempio n. 1
0
        protected override Task HandleInternalAsync(SharpMTProto.Schema.IMessage responseMessage)
        {
            var body = responseMessage.Body;

            Console.WriteLine("handle Internal async " + ObjectDumper.Dump(responseMessage));

            var updatesTooLong         = body as UpdatesTooLong;
            var updateShortMessage     = body as UpdateShortMessage;
            var updateShortChatMessage = body as UpdateShortChatMessage;
            var updateShort            = body as UpdateShort;
            var updatesCombined        = body as UpdatesCombined;
            var updates = body as Updates;
            var updateShortSentMessage = body as UpdateShortSentMessage;
            var updateContactLink      = body as UpdateContactLink;


            if (updatesTooLong != null)
            {
                RaiseOnUpdateTooLong();
            }

            var updateList = new List <object>();
            var state      = new State();

            if (updateShort != null)
            {
                state.Date = updateShort.Date;
                updateList.Add(updateShort.Update);
            }
            else if (updateShortMessage != null)
            {
                state.Date = updateShortMessage.Date;
                state.Pts  = updateShortMessage.Pts;
                updateList.Add(updateShortMessage);
            }
            else if (updateShortChatMessage != null)
            {
                state.Date = updateShortChatMessage.Date;
                state.Pts  = updateShortChatMessage.Pts;
                updateList.Add(updateShortChatMessage);
            }
            else if (updatesCombined != null)
            {
                state.Date = updatesCombined.Date;
                state.Seq  = updatesCombined.Seq;
                updateList.AddRange(updatesCombined.Users);
                updateList.AddRange(updatesCombined.Chats);
                updateList.AddRange(updatesCombined.Updates);
            }
            else if (updates != null)
            {
                state.Date = updates.Date;
                state.Seq  = updates.Seq;
                updateList.AddRange(updates.Users);
                updateList.AddRange(updates.Chats);
                updateList.AddRange(updates.UpdatesProperty);
            }
            else if (updateShortSentMessage != null)
            {
                state.Date = updateShortSentMessage.Date;
                state.Pts  = updateShortSentMessage.Pts;
                updateList.Add(updateShortSentMessage);
            }

            foreach (var update in updateList)
            {
                var newMessage                 = update as UpdateNewMessage;
                var deleteMessages             = update as UpdateDeleteMessages;
                var encryptedMessages          = update as UpdateNewEncryptedMessage;
                var readHistoryInbox           = update as UpdateReadHistoryInbox;
                var readHistoryOutBox          = update as UpdateReadHistoryOutbox;
                var updateWebPage              = update as UpdateWebPage;
                var updateReadMessagesContents = update as UpdateReadMessagesContents;
                var updateEditMessage          = update as UpdateEditMessage;
                var updateChannelTooLong       = update as UpdateChannelTooLong;
                var updateNewChannelMessage    = update as UpdateNewChannelMessage;
                var updateDeleteChannelMessage = update as UpdateDeleteChannelMessages;
                var updateEditChannelMessage   = update as UpdateEditChannelMessage;


                if (newMessage != null)
                {
                    state.Pts = newMessage.Pts;
                }
                else if (deleteMessages != null)
                {
                    state.Pts = deleteMessages.Pts;
                }
                else if (encryptedMessages != null)
                {
                    state.Qts = encryptedMessages.Qts;
                }
                else if (readHistoryInbox != null)
                {
                    state.Pts = readHistoryInbox.Pts;
                }
                else if (readHistoryOutBox != null)
                {
                    state.Pts = readHistoryOutBox.Pts;
                }
                else if (updateWebPage != null)
                {
                    state.Pts = updateWebPage.Pts;
                }
                else if (updateReadMessagesContents != null)
                {
                    state.Pts = updateReadMessagesContents.Pts;
                }
                else if (updateEditMessage != null)
                {
                    state.Pts = updateEditMessage.Pts;
                }
                else if (updateChannelTooLong != null)
                {
                    //state.Pts = updateChannelTooLong.Pts;
                }
                else if (updateNewChannelMessage != null)
                {
                    //for some wierd reason the PTS is a very small value
                    //state.Pts = updateNewChannelMessage.Pts;
                }
                else if (updateDeleteChannelMessage != null)
                {
                    //state.Pts = updateDeleteChannelMessage.Pts;
                }
                else if (updateEditChannelMessage != null)
                {
                    //state.Pts = updateEditChannelMessage.Pts;
                }
            }

            RaiseOnUpdateState(state);

            //TODO: GZIP

            //TODO: remove
            //Console.WriteLine(ObjectDumper.Dump(body));

            RaiseOnUpdate(updateList);

            return(TaskConstants.Completed);
        }
Esempio n. 2
0
        protected override Task HandleInternalAsync(SharpMTProto.Schema.IMessage responseMessage)
        {
            var body = responseMessage.Body;

            var updatesTooLong         = body as UpdatesTooLong;
            var updateShortMessage     = body as UpdateShortMessage;
            var updateShortChatMessage = body as UpdateShortChatMessage;
            var updateShort            = body as UpdateShort;
            var updatesCombined        = body as UpdatesCombined;
            var updates = body as Updates;

            if (updatesTooLong != null)
            {
                RaiseOnUpdateTooLong();
            }

            var updateList = new List <object>();
            var state      = new State();

            if (updateShort != null)
            {
                state.Date = updateShort.Date;
                updateList.Add(updateShort.Update);
            }
            else if (updateShortMessage != null)
            {
                state.Date = updateShortMessage.Date;
                state.Pts  = updateShortMessage.Pts;
                state.Seq  = updateShortMessage.Seq;
                updateList.Add(updateShortMessage);
            }
            else if (updateShortChatMessage != null)
            {
                state.Date = updateShortChatMessage.Date;
                state.Pts  = updateShortChatMessage.Pts;
                state.Seq  = updateShortChatMessage.Seq;
                updateList.Add(updateShortChatMessage);
            }
            else if (updatesCombined != null)
            {
                state.Date = updatesCombined.Date;
                state.Seq  = updatesCombined.Seq;
                updateList.AddRange(updatesCombined.Updates);
                updateList.AddRange(updatesCombined.Users);
                updateList.AddRange(updatesCombined.Chats);
            }
            else if (updates != null)
            {
                state.Date = updates.Date;
                state.Seq  = updates.Seq;
                updateList.AddRange(updates.UpdatesProperty);
                updateList.AddRange(updates.Users);
                updateList.AddRange(updates.Chats);
            }

            foreach (var update in updateList)
            {
                var newMessage        = update as UpdateNewMessage;
                var readMessages      = update as UpdateReadMessages;
                var deleteMessages    = update as UpdateDeleteMessages;
                var restoreMessages   = update as UpdateRestoreMessages;
                var encryptedMessages = update as UpdateNewEncryptedMessage;

                if (newMessage != null)
                {
                    state.Pts = newMessage.Pts;
                }
                else if (readMessages != null)
                {
                    state.Pts = readMessages.Pts;
                }
                else if (deleteMessages != null)
                {
                    state.Pts = deleteMessages.Pts;
                }
                else if (restoreMessages != null)
                {
                    state.Pts = restoreMessages.Pts;
                }
                else if (encryptedMessages != null)
                {
                    state.Qts = encryptedMessages.Qts;
                }
            }

            RaiseOnUpdateState(state);

            //TODO: GZIP

            //TODO: remove
            //Console.WriteLine(ObjectDumper.Dump(body));

            RaiseOnUpdate(updateList);

            return(TaskConstants.Completed);
        }