public Task GetContactsFavorites(Action <List <Contact> > result) { return(Task.Factory.StartNew(() => { var count = 0; var users = new List <User>(); foreach (var bubbleGroup in BubbleGroupManager.SortByMostPopular(this, true)) { var address = bubbleGroup.Address; var user = _dialogs.GetUser(uint.Parse(address)) as User; if (user != null) { users.Add(user); } count++; if (count > 6) { break; } } if (!users.Any()) { result(null); return; } var contacts = users.Select(x => CreateTelegramContact(x)) .OfType <Contact>().OrderBy(x => x.FullName).ToList(); result(contacts); })); }
public Task FetchBubbleGroup(Contact.ID[] contactIds, Action <BubbleGroup> result) { // If we have a solo, party or super group based on a SINGLE Contact.ID // in our passed in collection return that, otherwise return // null return(Task.Factory.StartNew(() => { foreach (var group in BubbleGroupManager.FindAll(this)) { if (contactIds.Length <= 1) { foreach (var contactId in contactIds) { if (BubbleGroupComparer(contactId.Id, group.Address)) { result(group); return; } } } } result(null); })); }
public Task GetContactsFavorites(Action <List <Contact> > result) { return(Task.Factory.StartNew(async() => { var count = 0; var inputUsers = new List <IInputUser>(); foreach (var bubbleGroup in BubbleGroupManager.SortByMostPopular(this, true)) { var address = bubbleGroup.Address; foreach (var user in _dialogs.Users) { var userId = TelegramUtils.GetUserId(user); if (userId == address) { var inputUser = TelegramUtils.CastUserToInputUser(user); if (inputUser != null) { inputUsers.Add(inputUser); break; } } } count++; if (count > 6) { break; } } if (!inputUsers.Any()) { result(null); } else { using (var client = new FullClientDisposable(this)) { var users = await GetUsers(inputUsers, client.Client); var contacts = users.Select(x => new TelegramContact { Available = TelegramUtils.GetAvailable(x), LastSeen = TelegramUtils.GetLastSeenTime(x), FirstName = TelegramUtils.GetUserName(x), Ids = new List <Contact.ID> { new Contact.ID { Service = this, Id = TelegramUtils.GetUserId(x).ToString(CultureInfo.InvariantCulture) } }, }).OfType <Contact>().OrderBy(x => x.FirstName).ToList(); result(contacts); } } })); }
public Task GetContactsFavorites(Action <List <Contact> > result) { return(Task.Factory.StartNew(() => { var count = 0; var users = new List <IUser>(); foreach (var bubbleGroup in BubbleGroupManager.SortByMostPopular(this, true)) { var address = bubbleGroup.Address; var user = _dialogs.GetUser(uint.Parse(address)); if (user != null) { users.Add(user); } count++; if (count > 6) { break; } } if (!users.Any()) { result(null); return; } var contacts = users.Select(x => new TelegramContact { Available = TelegramUtils.GetAvailable(x), LastSeen = TelegramUtils.GetLastSeenTime(x), FirstName = TelegramUtils.GetUserName(x), Ids = new List <Contact.ID> { new Contact.ID { Service = this, Id = TelegramUtils.GetUserId(x).ToString(CultureInfo.InvariantCulture) } }, User = x as User }).OfType <Contact>().OrderBy(x => x.FirstName).ToList(); result(contacts); })); }
public Task FetchBubbleGroup(Contact.ID[] contactIds, Action <BubbleGroup> result) { return(Task.Factory.StartNew(() => { foreach (var group in BubbleGroupManager.FindAll(this)) { if (contactIds.Length <= 1) { foreach (var contactId in contactIds) { if (BubbleGroupComparer(contactId.Id, group.Address)) { result(group); return; } } } } result(null); })); }
public Task FetchChannelBubbleGroup(Contact.ID[] contactIds, Action <BubbleGroup> result) { return(Task.Factory.StartNew(() => { // Sanity check, we are currently only processing collections passed in with a cardinality of 1 if (contactIds.Length != 1) { result(null); return; } foreach (var chat in _dialogs.GetAllChats()) { var name = TelegramUtils.GetChatTitle(chat); var upgraded = TelegramUtils.GetChatUpgraded(chat); if (upgraded) { continue; } var left = TelegramUtils.GetChatLeft(chat); if (left) { continue; } var kicked = TelegramUtils.GetChatKicked(chat); if (kicked) { continue; } var isChannel = chat is Channel; if (isChannel) { var channel = chat as Channel; if (channel.Broadcast == null) { continue; } } else { continue; } var channelAddress = TelegramUtils.GetChatId(chat); if (BubbleGroupComparer(contactIds[0].Id, channelAddress)) { var newBubble = new NewBubble( time: Time.GetNowUnixTimestamp(), direction: Bubble.BubbleDirection.Outgoing, address: channelAddress, participantAddress: null, party: true, service: this); newBubble.ExtendedParty = true; var newGroup = BubbleGroupFactory.AddNewIfNotExist(newBubble); if (newGroup == null) { newGroup = BubbleGroupManager.FindWithAddress(this, channelAddress); } result(newGroup); return; } } // OK, we didn't get a channel locally, we must be trying to join a public channel using (var client = new FullClientDisposable(this)) { // A NewChannel flow will stuff away a Contact in the ContactId.Tag field var telegramPartyContact = contactIds[0].Tag as TelegramPartyContact; if (telegramPartyContact == null) { result(null); return; } // Go for the public channel join var response = TelegramUtils.RunSynchronously(client.Client.Methods.ChannelsJoinChannelAsync(new ChannelsJoinChannelArgs { Channel = new InputChannel { ChannelId = uint.Parse(contactIds[0].Id), AccessHash = telegramPartyContact.AccessHash } })); // Process the result and add in the new public channel to our local set of groups var updates = response as Updates; if (updates != null) { SendToResponseDispatcher(updates, client.Client); _dialogs.AddChats(updates.Chats); var chat = TelegramUtils.GetChatFromUpdate(updates); var channelAddress = TelegramUtils.GetChatId(chat); var newBubble = new NewBubble( time: Time.GetNowUnixTimestamp(), direction: Bubble.BubbleDirection.Outgoing, address: channelAddress, participantAddress: null, party: true, service: this); newBubble.ExtendedParty = true; var newGroup = BubbleGroupFactory.AddNew(newBubble); result(newGroup); } else { result(null); } } })); }