Exemple #1
0
        public void KickFromChannelAsync(TLChannel channel, TLInputUserBase userId, TLBool kicked, Action <TLUpdatesBase> callback, Action <TLRPCError> faultCallback = null)
        {
            var obj = new TLKickFromChannel {
                Channel = channel.ToInputChannel(), UserId = userId, Kicked = kicked
            };

            const string caption = "channels.kickFromChannel";

            SendInformativeMessage <TLUpdatesBase>(caption, obj,
                                                   result =>
            {
                var multiPts = result as IMultiPts;
                if (multiPts != null)
                {
                    _updatesService.SetState(multiPts, caption);
                }
                else
                {
                    ProcessUpdates(result, null);
                }

                GetFullChannelAsync(channel.ToInputChannel(),
                                    messagesChatFull => callback.SafeInvoke(result),
                                    faultCallback.SafeInvoke);
            },
                                                   faultCallback);
        }
Exemple #2
0
        public async System.Threading.Tasks.Task GetChennals()
        {
            var store   = new FileSessionStore();
            var apiId   = 434408;
            var apiHash = "0bdea67547ee00f2e164a5522174d7dc";
            var client  = new TelegramClient(apiId, apiHash);
            await client.ConnectAsync();

            var dialogs = (TLDialogs)await client.GetUserDialogsAsync();

            foreach (var element in dialogs.Chats)
            {
                if (element is TLChannel)
                {
                    TLChannel chat = element as TLChannel;
                    metroComboBox1.Items.Add(chat.Title);
                }
            }

            for (int a = 0; a < metroComboBox1.Items.Count; a++)
            {
                if (metroComboBox1.Items[a].ToString() == Settings.Default.ChanelTo)
                {
                    metroComboBox1.SelectedIndex = a;
                }
            }
            bunifuMaterialTextbox1.Text = Properties.Settings.Default.BitlyAPI;
        }
        public static async Task MarkMessagesasRead(TLChannel channel, TLMessage firstmessage)
        {
            var ch = new TLInputChannel()
            {
                ChannelId = channel.Id, AccessHash = (long)channel.AccessHash
            };



            try
            {
                int    mID         = firstmessage.Id;
                string TMessage    = firstmessage.Message;
                string TvisitCount = firstmessage.Views.ToString();

                var markAsRead = new TLRequestReadHistory()
                {
                    Channel = ch,
                    // MaxId = -1,
                    MessageId = mID,
                    // Dirty = true,
                    //  MessageId = 356217,
                    // ConfirmReceived = true,
                    //Sequence = dia.unread_count
                };
                var affectedMessages = await _client.SendRequestAsync <bool>(markAsRead);

                Console.WriteLine(mID + ' ' + TMessage + ' ' + TvisitCount + ' ' + affectedMessages);
            }
            catch { }
        }
        /// <summary>
        /// Возвращает код-во людей
        /// </summary>
        /// <param name="channelName"></param>
        /// <returns>Получение кол-во людей (int) в канале  , если что-то пошло не так вернет -1</returns>
        public async Task <Int32> GetCountParticipantsChannelandSuperGroup(String channelName)
        {
            if (client == null)
            {
                return(-1);
            }
            TLAbsDialogs dialogs_temp = await client.GetUserDialogsAsync();

            TLDialogsSlice dialogs = dialogs_temp as TLDialogsSlice;

            TeleSharp.TL.Messages.TLChatFull res = new TeleSharp.TL.Messages.TLChatFull();
            try
            {
                TLChannel channelInfo = (await client.SendRequestAsync <TeleSharp.TL.Contacts.TLResolvedPeer>(
                                             new TeleSharp.TL.Contacts.TLRequestResolveUsername
                {
                    Username = channelName
                }).ConfigureAwait(false)).Chats.Last() as TeleSharp.TL.TLChannel;

                TLRequestGetFullChannel req = new TLRequestGetFullChannel()
                {
                    Channel = new TLInputChannel()
                    {
                        AccessHash = channelInfo.AccessHash.Value, ChannelId = channelInfo.Id
                    }
                };

                res = await client.SendRequestAsync <TeleSharp.TL.Messages.TLChatFull>(req);
            }
            catch
            {
                return(-1);
            }
            return((res.FullChat as TLChannelFull).ParticipantsCount.Value);
        }
        public void EditAboutAsync(TLChannel channel, TLString about, Action<TLBool> callback, Action<TLRPCError> faultCallback = null)
        {
            var obj = new TLEditAbout { Channel = channel.ToInputChannel(), About = about };

            const string caption = "channels.editAbout";
            SendInformativeMessage<TLBool>(caption, obj, callback.SafeInvoke, faultCallback);
        }
Exemple #6
0
        private async void RevokeLinkExecute(TLChannel channel)
        {
            var dialog = new TLMessageDialog();

            dialog.Title               = "Revoke link";
            dialog.Message             = string.Format("Are you sure you want to revoke the link t.me/{0}?\r\n\r\nThe channel \"{1}\" will become private.", channel.Username, channel.DisplayName);
            dialog.PrimaryButtonText   = "Revoke";
            dialog.SecondaryButtonText = "Cancel";

            var confirm = await dialog.ShowAsync();

            if (confirm == ContentDialogResult.Primary)
            {
                var response = await ProtoService.UpdateUsernameAsync(channel.ToInputChannel(), string.Empty);

                if (response.IsSucceeded)
                {
                    channel.HasUsername = false;
                    channel.Username    = null;
                    channel.RaisePropertyChanged(() => channel.HasUsername);
                    channel.RaisePropertyChanged(() => channel.Username);

                    HasTooMuchUsernames = false;
                    AdminedPublicChannels.Clear();
                }
            }
        }
Exemple #7
0
        private async void RevokeLinkExecute(TLChannel channel)
        {
            var dialog = new TLMessageDialog();

            dialog.Title               = Strings.Android.AppName;
            dialog.Message             = string.Format(Strings.Android.RevokeLinkAlert, channel.Username, channel.DisplayName);
            dialog.PrimaryButtonText   = Strings.Android.RevokeButton;
            dialog.SecondaryButtonText = Strings.Android.Cancel;

            var confirm = await dialog.ShowQueuedAsync();

            if (confirm == ContentDialogResult.Primary)
            {
                var response = await ProtoService.UpdateUsernameAsync(channel.ToInputChannel(), string.Empty);

                if (response.IsSucceeded)
                {
                    channel.HasUsername = false;
                    channel.Username    = null;
                    channel.RaisePropertyChanged(() => channel.HasUsername);
                    channel.RaisePropertyChanged(() => channel.Username);

                    HasTooMuchUsernames = false;
                    AdminedPublicChannels.Clear();
                }
            }
        }
Exemple #8
0
        private async void forward()
        {
            List <TLChannel> TargetChannel = new List <TLChannel>();

            TLChannel          targetchanel = TargetChannel[0];
            TLInputPeerChannel cha          = new TLInputPeerChannel();

            cha.ChannelId  = targetchanel.Id;
            cha.AccessHash = (long)targetchanel.AccessHash;


            Random rand = new Random();

            TLVector <long> a = new TLVector <long>();

            a.lists.Add(rand.Next());
            TLVector <int> b = new TLVector <int>();

            b.lists.Add(tlMessage.id);
            TLRequestForwardMessages aa = new TLRequestForwardMessages();

            aa.FromPeer    = peer;
            aa.ToPeer      = cha;
            aa.RandomId    = a;
            aa.MessageId   = tlMessage.id;
            aa.Id          = b;
            aa.Silent      = true;
            aa.WithMyScore = true;

            TLUpdates rr = await client.SendRequestAsync <TLUpdates>(aa);
        }
        public void EditTitleAsync(TLChannel channel, string title, Action <TLUpdatesBase> callback, Action <TLRPCError> faultCallback = null)
        {
            var obj = new TLChannelsEditTitle {
                Channel = channel.ToInputChannel(), Title = title
            };

            const string caption = "channels.editTitle";

            SendInformativeMessage <TLUpdatesBase>(caption, obj,
                                                   result =>
            {
                var multiPts = result as ITLMultiPts;
                if (multiPts != null)
                {
                    _updatesService.SetState(multiPts, caption);
                }
                else
                {
                    ProcessUpdates(result, null);
                }

                callback?.Invoke(result);
            },
                                                   faultCallback, flags: RequestFlag.InvokeAfter);
        }
Exemple #10
0
 private void ChannelOpenExecute(TLChannel channel)
 {
     if (channel != null)
     {
         NavigationService.NavigateToDialog(channel);
     }
 }
        public void EditAdminAsync(TLChannel channel, TLInputUserBase userId, TLChannelParticipantRoleBase role, Action <TLBool> callback, Action <TLRPCError> faultCallback = null)
        {
            var obj = new TLEditAdmin {
                Channel = channel.ToInputChannel(), UserId = userId, Role = role
            };

            const string caption = "channels.editAdmin";

            SendInformativeMessage <TLBool>(caption, obj,
                                            result =>
            {
                if (result.Value)
                {
                    if (channel.AdminsCount != null)
                    {
                        if (role is TLChannelRoleEmpty)
                        {
                            channel.AdminsCount = new TLInt(channel.AdminsCount.Value - 1);
                        }
                        else
                        {
                            channel.AdminsCount = new TLInt(channel.AdminsCount.Value + 1);
                        }

                        _cacheService.Commit();
                    }
                }

                callback.SafeInvoke(result);
            },
                                            faultCallback);
        }
        private void ContinueUploadingPhoto(TLChannel channel)
        {
            if (_photo != null)
            {
                MTProtoService.EditPhotoAsync(channel, new TLInputChatUploadedPhoto {
                    File = _photo, Crop = new TLInputPhotoCropAuto()
                },
                                              result2 => Execute.BeginOnUIThread(() =>
                {
                    var updates2 = result2 as TLUpdates;
                    if (updates2 != null)
                    {
                        channel = updates2.Chats.FirstOrDefault() as TLChannel;
                        if (channel != null)
                        {
                            ContinueNextStep(channel);
                        }
                    }
                }),
                                              error2 => Execute.BeginOnUIThread(() =>
                {
                    IsWorking = false;
                    NotifyOfPropertyChange(() => CanCreateChannel);

                    Execute.ShowDebugMessage("channels.editPhoto error " + error2);
                }));
            }
        }
        public void KickFromChannelAsync(TLChannel channel, TLInputUserBase userId, TLBool kicked, Action <TLUpdatesBase> callback, Action <TLRPCError> faultCallback = null)
        {
            var obj = new TLKickFromChannel {
                Channel = channel.ToInputChannel(), UserId = userId, Kicked = kicked
            };

            const string caption = "channels.kickFromChannel";

            SendInformativeMessage <TLUpdatesBase>(caption, obj,
                                                   result =>
            {
                if (channel.ParticipantsCount != null)
                {
                    channel.ParticipantsCount = new TLInt(channel.ParticipantsCount.Value - 1);
                }
                _cacheService.Commit();

                var multiPts = result as IMultiPts;
                if (multiPts != null)
                {
                    _updatesService.SetState(multiPts, caption);
                }
                else
                {
                    ProcessUpdates(result, null);
                }

                callback.SafeInvoke(result);
            },
                                                   faultCallback);
        }
Exemple #14
0
        public async Task <Channel> GetChannelAsync(string username)
        {
            var req = new TLRequestResolveUsername()
            {
                Username = username
            };
            TLResolvedPeer peer;

            try
            {
                peer = await _client.SendRequestAsync <TLResolvedPeer>(req);
            }
            catch (InvalidOperationException)
            {
                return(null);
            }
            if (peer.Chats.Count == 0)
            {
                return(null);
            }
            TLChannel channel = (TLChannel)peer.Chats[0];

            if (!channel.AccessHash.HasValue)
            {
                return(null);
            }
            return(new Channel()
            {
                ChannelId = channel.Id,
                AccessHash = channel.AccessHash ?? 0,
                Title = channel.Title,
                Username = channel.Username
            });
        }
Exemple #15
0
        public async Task <Channel> GetChannelAsync(int channelId, long accessHash)
        {
            var req = new TLRequestGetFullChannel()
            {
                Channel = new TLInputChannel()
                {
                    ChannelId  = channelId,
                    AccessHash = accessHash
                }
            };

            TeleSharp.TL.Messages.TLChatFull fullChat;
            try
            {
                fullChat = await _client.SendRequestAsync <TeleSharp.TL.Messages.TLChatFull>(req);
            }
            catch (InvalidOperationException)
            {
                return(null);
            }
            TLChannel channel = (TLChannel)fullChat.Chats[0];

            return(new Channel()
            {
                ChannelId = channel.Id,
                AccessHash = channel.AccessHash ?? 0,
                Title = channel.Title,
                Username = channel.Username
            });
        }
Exemple #16
0
        public async Task<List<TLChannelFull>> GetFullInfoCannelsAsync()
        {
            _fullInfoCannels.Clear();
            var dialogs = (TLDialogsSlice)await _client.GetUserDialogsAsync();

            foreach (var item in dialogs.Chats)
            {
                if (item is TLChannel)
                {
                    try
                    {
                        TLChannel chat = item as TLChannel;

                        if (chat.Creator)
                        {
                            var chan = await _client.SendRequestAsync<TLChatFull>(new TLRequestGetFullChannel()
                            {
                                Channel = new TLInputChannel()
                                { ChannelId = chat.Id, AccessHash = (long)chat.AccessHash }
                            });

                            TLChannelFull tLChannelFull = chan.FullChat as TLChannelFull;
                            tLChannelFull.About = chat.Title;
                            _fullInfoCannels.Add(tLChannelFull);
                        }
                    }
                    catch (Exception ex)
                    {
                        Debug.WriteLine(ex.Message + "\n" + ex.StackTrace);
                    }
                }
            }
            return _fullInfoCannels;
        }
        public BitmapImage this[TLChannel channel]
        {
            get
            {
                if (channel == null)
                {
                    return(null);
                }

                var key = (object)channel.Photo;
                if (key == null)
                {
                    key = channel.Title;
                }

                if (_context.TryGetValue(key, out Tuple <TLBitmapSource, WeakReference <BitmapImage> > reference) &&
                    reference.Item2.TryGetTarget(out BitmapImage target))
                {
                    return(target);
                }

                var bitmap = new TLBitmapSource(channel);
                _context[key] = new Tuple <TLBitmapSource, WeakReference <BitmapImage> >(bitmap, new WeakReference <BitmapImage>(bitmap.Image));
                return(bitmap.Image);
            }
        }
Exemple #18
0
        public void EditChannelAboutAsync(TLChannel channel, TLString about, System.Action callback)
        {
            if (TLString.Equals(about, channel.About, StringComparison.Ordinal))
            {
                callback.SafeInvoke();
                return;
            }

            IsWorking = true;
            MTProtoService.EditAboutAsync(channel, about,
                                          statedMessage => Execute.BeginOnUIThread(() =>
            {
                IsWorking = false;

                channel.About = about;
                CacheService.Commit();

                callback.SafeInvoke();
            }),
                                          error => Execute.BeginOnUIThread(() =>
            {
                Execute.ShowDebugMessage("channels.editAbout error " + error);

                IsWorking = false;

                if (error.CodeEquals(ErrorCode.BAD_REQUEST) &&
                    error.TypeEquals(ErrorType.CHAT_ABOUT_NOT_MODIFIED))
                {
                }
                callback.SafeInvoke();
            }));
        }
Exemple #19
0
        public void DeleteUserHistoryAsync(TLChannel channel, TLInputUserBase userId, Action <TLMessagesAffectedHistory> callback, Action <TLRPCError> faultCallback = null)
        {
            var obj = new TLChannelsDeleteUserHistory {
                Channel = channel.ToInputChannel(), UserId = userId
            };

            const string caption = "channels.deleteUserHistory";

            SendInformativeMessage <TLMessagesAffectedHistory>(caption, obj,
                                                               result =>
            {
                var multiChannelPts = result as ITLMultiChannelPts;
                if (multiChannelPts != null)
                {
                    if (channel.Pts == null || channel.Pts.Value + multiChannelPts.PtsCount != multiChannelPts.Pts)
                    {
                        Execute.ShowDebugMessage(string.Format("channel_id={0} channel_pts={1} affectedHistory24[channel_pts={2} channel_pts_count={3}]", channel.Id, channel.Pts, multiChannelPts.Pts, multiChannelPts.PtsCount));
                    }
                    channel.Pts = multiChannelPts.Pts;
                }

                callback?.Invoke(result);
            },
                                                               faultCallback);
        }
Exemple #20
0
        public async Task <bool> JoinChannel(string channelname)
        {
            try
            {
                TLChannel channel = await FindChannel(channelname);

                var req = new TeleSharp.TL.Channels.TLRequestJoinChannel()
                {
                    Channel = new TLInputChannel
                    {
                        ChannelId  = channel.Id,
                        AccessHash = (long)channel.AccessHash
                    }
                };
                TLUpdates resJoinChannel = await client.SendRequestAsync <TLUpdates>(req);

                return(true);
            }
            catch (Exception ex)
            {
                if (ex.Message == "AUTH_KEY_UNREGISTERED")
                {
                    bool sessionRemoved = this.RemoveSession();
                    if (sessionRemoved)
                    {
                        await this.Reconnect();
                    }
                }
                return(false);
            }
        }
Exemple #21
0
        public void EditAdminAsync(TLChannel channel, TLInputUserBase userId, TLChannelAdminRights rights, Action <TLUpdatesBase> callback, Action <TLRPCError> faultCallback = null)
        {
            var obj = new TLChannelsEditAdmin {
                Channel = channel.ToInputChannel(), UserId = userId, AdminRights = rights
            };

            const string caption = "channels.editAdmin";

            SendInformativeMessage <TLUpdatesBase>(caption, obj,
                                                   result =>
            {
                var multiPts = result as ITLMultiPts;
                if (multiPts != null)
                {
                    _updatesService.SetState(multiPts, caption);
                }
                else
                {
                    ProcessUpdates(result, null);
                }

                GetFullChannelAsync(channel.ToInputChannel(),
                                    messagesChatFull => callback?.Invoke(result),
                                    faultCallback);
            },
                                                   faultCallback);
        }
Exemple #22
0
        public void EditPhotoAsync(TLChannel channel, TLInputChatPhotoBase photo, Action <TLUpdatesBase> callback, Action <TLRPCError> faultCallback = null)
        {
            var obj = new TLChannelsEditPhoto {
                Channel = channel.ToInputChannel(), Photo = photo
            };

            const string caption = "channels.editPhoto";

            SendInformativeMessage <TLUpdatesBase>(caption, obj,
                                                   result =>
            {
                var multiPts = result as ITLMultiPts;
                if (multiPts != null)
                {
                    _updatesService.SetState(multiPts, caption);
                }
                else
                {
                    ProcessUpdates(result, null, true);
                }

                callback?.Invoke(result);
            },
                                                   faultCallback);
        }
Exemple #23
0
        public void DeleteChannelAsync(TLChannel channel, Action <TLUpdatesBase> callback, Action <TLRPCError> faultCallback = null)
        {
            var obj = new TLChannelsDeleteChannel {
                Channel = channel.ToInputChannel()
            };

            const string caption = "channels.deleteChannel";

            SendInformativeMessage <TLUpdatesBase>(caption, obj,
                                                   result =>
            {
                var multiPts = result as ITLMultiPts;
                if (multiPts != null)
                {
                    _updatesService.SetState(multiPts, caption);
                }
                else
                {
                    ProcessUpdates(result, null);
                }

                callback?.Invoke(result);
            },
                                                   faultCallback);
        }
Exemple #24
0
        public void LeaveChannelAsync(TLChannel channel, Action <TLUpdatesBase> callback, Action <TLRPCError> faultCallback = null)
        {
            var obj = new TLChannelsLeaveChannel {
                Channel = channel.ToInputChannel()
            };

            const string caption = "channels.leaveChannel";

            SendInformativeMessage <TLUpdatesBase>(caption, obj,
                                                   result =>
            {
                channel.IsLeft = true;
                if (channel.ParticipantsCount != null)
                {
                    channel.ParticipantsCount = new int?(channel.ParticipantsCount.Value - 1);
                }
                _cacheService.Commit();

                var multiPts = result as ITLMultiPts;
                if (multiPts != null)
                {
                    _updatesService.SetState(multiPts, caption);
                }
                else
                {
                    ProcessUpdates(result, null);
                }

                callback?.Invoke(result);
            },
                                                   faultCallback);
        }
Exemple #25
0
 public Chat(TLChannel tlChannel)
 {
     Id         = tlChannel.id;
     Title      = tlChannel.title;
     AccessHash = tlChannel.access_hash;
     IsChannel  = true;
 }
Exemple #26
0
        public static async Task <TLVector <TLAbsMessage> > GetPosts(TelegramClient client, string channelName, int count)
        {
            TLChannel channel = await Searcher.SearchChannelAsync(client, channelName);

            var posts = await CounterPostsAsync(channel, client, false, count);

            return(posts);
        }
Exemple #27
0
        private async Task <TLChannel> FindChannel(string channelname)
        {
            var found = await client.SearchUserAsync(channelname);

            TLChannel tLChannel = (TLChannel)found.Chats.Where(x => ((TLChannel)x).Username == channelname).FirstOrDefault();

            return(tLChannel);
        }
        public ChannelBlockedContactsViewModel(ICacheService cacheService, ICommonErrorHandler errorHandler, IStateService stateService, INavigationService navigationService, IMTProtoService mtProtoService, ITelegramEventAggregator eventAggregator)
            : base(cacheService, errorHandler, stateService, navigationService, mtProtoService, eventAggregator)
        {
            Channel = StateService.CurrentChat as TLChannel;
            StateService.CurrentChat = null;

            eventAggregator.Subscribe(this);
        }
Exemple #29
0
        public static async Task <TLVector <TLAbsMessage> > GetAllPosts(TelegramClient client, string channelName)
        {
            TLChannel channel = await Searcher.SearchChannelAsync(client, channelName);

            var allPosts = await CounterPostsAsync(channel, client, true);

            return(allPosts);
        }
Exemple #30
0
        public CreateChannelStep3ViewModel(ICacheService cacheService, ICommonErrorHandler errorHandler, IStateService stateService, INavigationService navigationService, IMTProtoService mtProtoService, ITelegramEventAggregator eventAggregator)
            : base(cacheService, errorHandler, stateService, navigationService, mtProtoService, eventAggregator)
        {
            GroupedUsers = new ObservableCollection <TLUserBase>();

            _newChannel             = StateService.NewChannel;
            StateService.NewChannel = null;
        }