Example #1
0
        public void SendMessageToSelectedFriends()
        {
            for (int i = 0; i < users_count; i++)
            {
                if (!users_api[i].IsAuthorized)
                {
                    continue;
                }

                List <FriendsListItem>   items    = applicationContract.GetFriendsListItems();
                List <SendMessageStatus> statuses = new List <SendMessageStatus>();

                MessagesSendParams sendParams = new MessagesSendParams();

                foreach (FriendsListItem item in items)
                {
                    if (!item.SocialNetworkName.Equals(getSocialNetworkName()))
                    {
                        continue;
                    }
                    if (!item.IsChecked)
                    {
                        continue;
                    }
                    if (item.User.ID != Convert.ToString(users_api[i].UserId))
                    {
                        continue;
                    }

                    sendParams.UserId  = Convert.ToInt64(item.Friend.ID);
                    sendParams.Message = applicationContract.GetMessage();

                    SendMessageStatus status = new SendMessageStatus();
                    status.SocialNetworkName = getSocialNetworkName();
                    status.UserNameTo        = item.Friend.Name;
                    status.UserNameFrom      = getUserAccountName(i);
                    status.IsMessageSended   = true;

                    try
                    {
                        users_api[i].Messages.Send(sendParams);
                    }
                    catch (VkApiException ex)
                    {
                        status.IsMessageSended = false;
                    }

                    statuses.Add(status);
                }
                applicationContract.AddSendMessageStatuses(statuses);
            }
        }
Example #2
0
        public void SendMessageToSelectedFriends()
        {
            foreach (SlackHelper user_helper in users_helpers)
            {
                if (!user_helper.IsAuthorized)
                {
                    continue;
                }

                Responses.SlackIMListResponse slackIMListResponse = user_helper.Im_List();

                if (!slackIMListResponse.Ok)
                {
                    continue;
                }

                List <Models.SlackIM> ims = slackIMListResponse.IMs?.ToList();

                if (ims == null)
                {
                    continue;
                }

                List <FriendsListItem>   friends_items = applicationContract.GetFriendsListItems();
                List <SendMessageStatus> statuses      = new List <SendMessageStatus>();

                foreach (FriendsListItem friend_item in friends_items)
                {
                    if (!friend_item.SocialNetworkName.Equals(getSocialNetworkName()))
                    {
                        continue;
                    }
                    if (!friend_item.IsChecked)
                    {
                        continue;
                    }
                    if (friend_item.User.ID != user_helper.User.ID)
                    {
                        continue;
                    }

                    String channel_id = null;

                    foreach (Models.SlackIM im in ims)
                    {
                        if (friend_item.Friend.ID == im.User)
                        {
                            channel_id = im.ID;
                            break;
                        }
                    }

                    if (channel_id == null)
                    {
                        continue;
                    }

                    SendMessageStatus status = new SendMessageStatus();
                    status.SocialNetworkName = getSocialNetworkName();
                    status.UserNameTo        = friend_item.Friend.Name;
                    status.UserNameFrom      = friend_item.User.Name;
                    status.IsMessageSended   = user_helper.Chat_MeMessage(channel_id, applicationContract.GetMessage()).Ok;
                    statuses.Add(status);
                }

                applicationContract.AddSendMessageStatuses(statuses);
            }
        }