Example #1
0
 public Task ConvertContactIdToParticipant(Contact contact,
                                           Contact.ID contactId, Action <DisaParticipant> result)
 {
     return(Task.Factory.StartNew(() =>
     {
         var telegramContact = contact as TelegramContact;
         result(new DisaParticipant(TelegramUtils.GetUserName(telegramContact.User), telegramContact.User.Id.ToString(CultureInfo.InvariantCulture)));
     }));
 }
Example #2
0
 public Task ConvertContactIdToParticipant(Contact contact,
                                           Contact.ID contactId, Action <DisaParticipant> result)
 {
     return(Task.Factory.StartNew(() =>
     {
         User user = null;
         if (contact is TelegramContact)
         {
             user = (contact as TelegramContact).User;
         }
         else if (contact is TelegramBotContact)
         {
             user = (contact as TelegramBotContact).User;
         }
         result(new DisaParticipant(TelegramUtils.GetUserName(user), user.Id.ToString(CultureInfo.InvariantCulture)));
     }));
 }
 public Task FetchBubbleGroupAddressFromLink(string link, Action<Tuple<Contact, Contact.ID>> result)
 {
     return Task.Factory.StartNew(() =>
     {
         string linkUsefulPart;
         var linkType = GetLinkType(link, out linkUsefulPart);
         DebugPrint("Link useful part " + ObjectDumper.Dump(linkType));
         switch (linkType)
         {
             case LinkType.Invalid:
                 result(new Tuple<Contact, Contact.ID>(null, null));
                 break;
             case LinkType.PrivateGroup:
                 IChat alreadyJoinedChat;
                 bool linkCheck = CheckLink(linkUsefulPart, out alreadyJoinedChat);
                 if (linkCheck)
                 {
                     if (alreadyJoinedChat != null)
                     {
                         SetResultAsChat(alreadyJoinedChat, TelegramUtils.GetChatId(alreadyJoinedChat), result);
                         return;
                     }
                     var updates = JoinChat(linkUsefulPart);
                     DebugPrint("Updates " + ObjectDumper.Dump(updates));
                     var updatesObj = updates as Updates;
                     if (updatesObj != null)
                     {
                         var chatObj = updatesObj.Chats[0];
                         SetResultAsChat(chatObj, TelegramUtils.GetChatId(chatObj), result);
                     }
                     
                 }
                 else
                 {
                     result(new Tuple<Contact, Contact.ID>(null,null));  
                 }
                 break;
             case LinkType.PublicGroup:
                 JoinChannelIfLeft(linkUsefulPart);
                 var chat = _dialogs.GetChat(uint.Parse(linkUsefulPart));
                 SetResultAsChat(chat, linkUsefulPart, result);
                 break;
             case LinkType.PublicUser:
                 var user = _dialogs.GetUser(uint.Parse(linkUsefulPart));
                 var userObj = user as User;
                 var userContact = new TelegramContact
                 {
                     Available = TelegramUtils.GetAvailable(user),
                     LastSeen = TelegramUtils.GetLastSeenTime(user),
                     FirstName = userObj?.FirstName,
                     LastName = userObj?.LastName,
                     User = userObj,
                 };
                 var userContactId = new Contact.ID
                 {
                     Id = linkUsefulPart,
                     Service = this
                 };
                 result(new Tuple<Contact, Contact.ID>(userContact, userContactId));
                 break;
             default:
                 result(new Tuple<Contact, Contact.ID>(null, null));
                 break;
         }
     });
 }
Example #4
0
        public Task FetchBubbleGroupAddressFromLink(string link, Action <Tuple <Contact, Contact.ID> > result)
        {
            return(Task.Factory.StartNew(() =>
            {
                string linkUsefulPart;
                var linkType = GetLinkType(link, out linkUsefulPart);
                switch (linkType)
                {
                case LinkType.Invalid:
                    result(new Tuple <Contact, Contact.ID>(null, null));
                    break;

                case LinkType.PrivateGroup:
                    IChat alreadyJoinedChat;
                    bool linkCheck = CheckLink(linkUsefulPart, out alreadyJoinedChat);
                    if (linkCheck)
                    {
                        if (alreadyJoinedChat != null)
                        {
                            SetResultAsChat(alreadyJoinedChat, TelegramUtils.GetChatId(alreadyJoinedChat), result);
                            return;
                        }
                        var updates = JoinChat(linkUsefulPart);
                        var updatesObj = updates as Updates;
                        if (updatesObj != null)
                        {
                            var chatObj = updatesObj.Chats[0];
                            SetResultAsChat(chatObj, TelegramUtils.GetChatId(chatObj), result);
                        }
                    }
                    else
                    {
                        result(new Tuple <Contact, Contact.ID>(null, null));
                    }
                    break;

                case LinkType.PublicGroup:
                    JoinChannelIfLeft(linkUsefulPart);
                    var chat = _dialogs.GetChat(uint.Parse(linkUsefulPart));
                    SetResultAsChat(chat, linkUsefulPart, result);
                    break;

                case LinkType.PublicUser:
                    var user = _dialogs.GetUser(uint.Parse(linkUsefulPart));
                    var userObj = user as User;
                    var userContact = new TelegramContact
                    {
                        Available = TelegramUtils.GetAvailable(user),
                        LastSeen = TelegramUtils.GetLastSeenTime(user),
                        FirstName = userObj?.FirstName,
                        LastName = userObj?.LastName,
                        User = userObj,
                    };
                    var userContactId = new Contact.ID
                    {
                        Id = linkUsefulPart,
                        Service = this
                    };
                    result(new Tuple <Contact, Contact.ID>(userContact, userContactId));
                    break;

                default:
                    result(new Tuple <Contact, Contact.ID>(null, null));
                    break;
                }
            }));
        }