Ejemplo n.º 1
0
        public void AddComments()
        {
            var broadcast = With as TLBroadcastChat;

            if (broadcast == null)
            {
                return;
            }

            var broadcastPeer = new TLPeerBroadcast {
                Id = broadcast.Id
            };

            var count = new Random().Next(1, 5);

            var group = new TLMessageGroup
            {
                Count = new TLInt(count),
                Date  = TLUtils.DateToUniversalTimeTLInt(MTProtoService.ClientTicksDelta, DateTime.Now),
                MaxId = new TLInt(int.MaxValue),
                MinId = new TLInt(0)
            };

            var action = new TLMessageActionMessageGroup
            {
                Group = group
            };

            var serviceMessage = new TLMessageService17
            {
                FromId = new TLInt(StateService.CurrentUserId),
                ToId   = broadcastPeer,
                Status = MessageStatus.Confirmed,
                Out    = new TLBool {
                    Value = true
                },
                Date     = TLUtils.DateToUniversalTimeTLInt(MTProtoService.ClientTicksDelta, DateTime.Now),
                RandomId = TLLong.Random(),
                Action   = action
            };

            serviceMessage.SetUnread(TLBool.False);

            Items.Insert(0, serviceMessage);
            CacheService.SyncMessage(serviceMessage, broadcastPeer,
                                     message =>
            {
            });
        }
        public override void Create()
        {
            if (string.IsNullOrEmpty(Title))
            {
                MessageBox.Show(AppResources.PleaseEnterGroupSubject, AppResources.Error, MessageBoxButton.OK);
                return;
            }

            var participants = new TLVector <TLInputUserBase>();

            foreach (var item in SelectedUsers)
            {
                participants.Add(item.ToInputUser());
            }

            if (participants.Count == 0)
            {
                MessageBox.Show(AppResources.PleaseChooseAtLeastOneParticipant, AppResources.Error, MessageBoxButton.OK);
                return;
            }

            var broadcastChat = new TLBroadcastChat
            {
                Id             = TLInt.Random(),
                Photo          = new TLChatPhotoEmpty(),
                Title          = new TLString(Title),
                ParticipantIds = new TLVector <TLInt> {
                    Items = SelectedUsers.Select(x => x.Id).ToList()
                }
            };

            CacheService.SyncBroadcast(broadcastChat, result =>
            {
                var broadcastPeer = new TLPeerBroadcast {
                    Id = broadcastChat.Id
                };
                var serviceMessage = new TLMessageService17
                {
                    FromId = new TLInt(StateService.CurrentUserId),
                    ToId   = broadcastPeer,
                    Status = MessageStatus.Confirmed,
                    Out    = new TLBool {
                        Value = true
                    },
                    Date = TLUtils.DateToUniversalTimeTLInt(MTProtoService.ClientTicksDelta, DateTime.Now),
                    //IsAnimated = true,
                    RandomId = TLLong.Random(),
                    Action   = new TLMessageActionChatCreate
                    {
                        Title = broadcastChat.Title,
                        Users = broadcastChat.ParticipantIds
                    }
                };
                serviceMessage.SetUnread(new TLBool(false));

                CacheService.SyncMessage(serviceMessage,
                                         message =>
                {
                    StateService.With            = broadcastChat;
                    StateService.RemoveBackEntry = true;
                    NavigationService.UriFor <DialogDetailsViewModel>().Navigate();
                });
            });
        }
Ejemplo n.º 3
0
        public override void Create()
        {
            if (IsWorking)
            {
                return;
            }
            if (_newChannel == null)
            {
                return;
            }

            var participants = new TLVector <TLInputUserBase>();

            foreach (var item in SelectedUsers)
            {
                participants.Add(item.ToInputUser());
            }
            participants.Add(new TLInputUserContact {
                UserId = new TLInt(StateService.CurrentUserId)
            });

            if (participants.Count == 0)
            {
                MessageBox.Show(AppResources.PleaseChooseAtLeastOneParticipant, AppResources.Error, MessageBoxButton.OK);
                return;
            }

            _newChannel.ParticipantIds = new TLVector <TLInt> {
                Items = SelectedUsers.Select(x => x.Id).ToList()
            };

#if LAYER_40
            IsWorking = true;
            MTProtoService.InviteToChannelAsync(_newChannel.ToInputChannel(), participants,
                                                result => Execute.BeginOnUIThread(() =>
            {
                IsWorking = false;

                StateService.With = _newChannel;
                StateService.RemoveBackEntries = true;
                NavigationService.UriFor <DialogDetailsViewModel>().Navigate();
            }),
                                                error => Execute.BeginOnUIThread(() =>
            {
                IsWorking = false;
                Execute.ShowDebugMessage("channels.inviteToChannel error " + error);
            }));
#else
            CacheService.SyncBroadcast(_newChannel, result =>
            {
                var broadcastPeer = new TLPeerBroadcast {
                    Id = _newChannel.Id
                };
                var serviceMessage = new TLMessageService17
                {
                    FromId = new TLInt(StateService.CurrentUserId),
                    ToId   = broadcastPeer,
                    Status = MessageStatus.Confirmed,
                    Out    = TLBool.True,
                    Date   = TLUtils.DateToUniversalTimeTLInt(MTProtoService.ClientTicksDelta, DateTime.Now),
                    //IsAnimated = true,
                    RandomId = TLLong.Random(),
                    Action   = new TLMessageActionChannelCreate
                    {
                        Title = _newChannel.Title,
                    }
                };
                serviceMessage.SetUnread(TLBool.False);

                CacheService.SyncMessage(serviceMessage, broadcastPeer,
                                         message =>
                {
                    if (_newChannel.Photo is TLChatPhoto)
                    {
                        var serviceMessage2 = new TLMessageService17
                        {
                            FromId = new TLInt(StateService.CurrentUserId),
                            ToId   = broadcastPeer,
                            Status = MessageStatus.Confirmed,
                            Out    = TLBool.True,
                            Date   = TLUtils.DateToUniversalTimeTLInt(MTProtoService.ClientTicksDelta, DateTime.Now),
                            //IsAnimated = true,
                            RandomId = TLLong.Random(),
                            Action   = new TLMessageActionChatEditPhoto
                            {
                                Photo = _newChannel.Photo,
                            }
                        };
                        serviceMessage2.SetUnread(TLBool.False);

                        CacheService.SyncMessage(serviceMessage2, broadcastPeer, message2 =>
                        {
                            StateService.With = _newChannel;
                            StateService.RemoveBackEntries = true;
                            NavigationService.UriFor <DialogDetailsViewModel>().Navigate();
                        });
                        return;
                    }
                    StateService.With = _newChannel;
                    StateService.RemoveBackEntries = true;
                    NavigationService.UriFor <DialogDetailsViewModel>().Navigate();
                });
            });
#endif
        }