Exemplo n.º 1
0
        private void UpdateLiveLocations(Action <TLMessagesBase> callback, Action <TLRPCError> faultCallback = null)
        {
            MTProtoService.GetRecentLocationsAsync(Peer, new TLInt(int.MaxValue), new TLInt(0),
                                                   result => Execute.BeginOnUIThread(() =>
            {
                if (LiveLocationBadge != null)
                {
                    LiveLocationBadge.UpdateLiveLocations(result.Messages);
                }

                callback.SafeInvoke(result);
            }),
                                                   faultCallback);
        }
        public void Handle(TLUpdateEditMessage update)
        {
            var message = update.Message as TLMessageCommon;

            if (message == null)
            {
                return;
            }

            var editMessage = false;

            var user = With as TLUserBase;
            var chat = With as TLChatBase;

            if (user != null &&
                message.ToId is TLPeerUser &&
                !message.Out.Value &&
                user.Id.Value == message.FromId.Value)
            {
                editMessage = true;
            }
            else if (user != null &&
                     message.ToId is TLPeerUser &&
                     message.Out.Value &&
                     user.Id.Value == message.ToId.Id.Value)
            {
                editMessage = true;
            }
            else if (chat != null &&
                     message.ToId is TLPeerChat &&
                     chat.Id.Value == message.ToId.Id.Value)
            {
                editMessage = true;
            }

            if (editMessage)
            {
                Execute.BeginOnUIThread(() =>
                {
                    var item = Items.FirstOrDefault(x => x.Index == update.Message.Index) as TLMessageCommon;
                    if (item == null)
                    {
                        return;
                    }

                    if (item != message)
                    {
                        item.Edit(message);
                    }

                    message       = item;
                    var item48    = item as TLMessage48;
                    var message48 = message as TLMessage48;
                    if (message48 != null && item48 != null)
                    {
                        message48.Entities = item48.Entities;
                    }
                    var message31 = message as TLMessage48;
                    if (message31 != null)
                    {
                        var mediaGeoLive = message31.Media as TLMessageMediaGeoLive;
                        if (mediaGeoLive != null)
                        {
                            mediaGeoLive.EditDate = message31.EditDate;
                            mediaGeoLive.Date     = message31.Date;
                            mediaGeoLive.NotifyOfPropertyChange(() => mediaGeoLive.Geo);
                            mediaGeoLive.NotifyOfPropertyChange(() => mediaGeoLive.EditDate);
                            mediaGeoLive.NotifyOfPropertyChange(() => mediaGeoLive.Active);

                            message31.NotifyOfPropertyChange(() => message31.Message);
                            message31.NotifyOfPropertyChange(() => message31.ReplyMarkup);

                            if (LocationPicker != null)
                            {
                                LocationPicker.UpdateLiveLocation(message31);
                            }
                            if (LiveLocationBadge != null)
                            {
                                LiveLocationBadge.UpdateLiveLocation(message31);
                            }

                            return;
                        }

                        message31.NotifyOfPropertyChange(() => message31.Message);
                        message31.NotifyOfPropertyChange(() => message31.Media);
                        message31.NotifyOfPropertyChange(() => message31.ReplyMarkup);

                        var mediaGame = message31.Media as TLMessageMediaGame;
                        if (mediaGame != null)
                        {
                            mediaGame.NotifyOfPropertyChange(() => mediaGame.Message);
                            mediaGame.NotifyOfPropertyChange(() => mediaGame.MessageVisibility);
                            mediaGame.NotifyOfPropertyChange(() => mediaGame.DescriptionVisibility);
                        }
                    }

                    var messageService = item as TLMessageService;
                    if (messageService != null)
                    {
                        var actionGameScore = messageService.Action as TLMessageActionGameScore;
                        if (actionGameScore != null)
                        {
                            messageService.NotifyOfPropertyChange(() => messageService.Self);
                        }
                    }
                });
            }
        }
        public void Handle(TLUpdateEditChannelMessage update)
        {
            var channel = With as TLChannel;

            if (channel == null)
            {
                return;
            }

            var message = update.Message as TLMessage31;

            if (message == null || !(message.ToId is TLPeerChannel))
            {
                return;
            }

            if (channel.Id.Value == message.ToId.Id.Value)
            {
                Execute.BeginOnUIThread(() =>
                {
                    var item = Items.FirstOrDefault(x => x.Index == update.Message.Index) as TLMessage31;
                    if (item == null)
                    {
                        return;
                    }

                    if (item != message)
                    {
                        item.Edit(message);
                    }

                    message       = item;
                    var item48    = item as TLMessage48;
                    var message48 = message as TLMessage48;
                    if (message48 != null && item48 != null)
                    {
                        message48.Entities = item48.Entities;
                    }
                    var message31 = message as TLMessage48;
                    if (message31 != null)
                    {
                        var mediaGeoLive = message31.Media as TLMessageMediaGeoLive;
                        if (mediaGeoLive != null)
                        {
                            mediaGeoLive.EditDate = message31.EditDate;
                            mediaGeoLive.Date     = message31.Date;
                            mediaGeoLive.NotifyOfPropertyChange(() => mediaGeoLive.Geo);
                            mediaGeoLive.NotifyOfPropertyChange(() => mediaGeoLive.EditDate);
                            mediaGeoLive.NotifyOfPropertyChange(() => mediaGeoLive.Active);

                            message31.NotifyOfPropertyChange(() => message31.Message);
                            message31.NotifyOfPropertyChange(() => message31.ReplyMarkup);

                            if (LocationPicker != null)
                            {
                                LocationPicker.UpdateLiveLocation(message31);
                            }
                            if (LiveLocationBadge != null)
                            {
                                LiveLocationBadge.UpdateLiveLocation(message31);
                            }

                            return;
                        }

                        message31.NotifyOfPropertyChange(() => message31.Message);
                        message31.NotifyOfPropertyChange(() => message31.Media);
                        message31.NotifyOfPropertyChange(() => message31.ReplyMarkup);

                        var mediaGame = message31.Media as TLMessageMediaGame;
                        if (mediaGame != null)
                        {
                            mediaGame.NotifyOfPropertyChange(() => mediaGame.Message);
                            mediaGame.NotifyOfPropertyChange(() => mediaGame.MessageVisibility);
                            mediaGame.NotifyOfPropertyChange(() => mediaGame.DescriptionVisibility);
                        }
                    }
                });
            }
        }