예제 #1
0
        private async void ExecuteSendTweetCommand()
        {
            IsSending = true;
            List <Tuple <ulong, ulong> > statusIds = new List <Tuple <ulong, ulong> >();

            if (ScheduleInformation?.IsTweetScheduled == true)
            {
                var accountIds = Accounts.Where(a => a.Use).Select(a => a.Context.UserId);
                var fileNames  = AttachedMedias.Select(m => m.FileName);
                ScheduleInformation.ScheduleTweet(Text, InReplyTo?.Id, accountIds, fileNames);
            }
            else
            {
                var statuses = await SendTweet();

                statusIds.AddRange(statuses);
            }

            if (ScheduleInformation?.IsDeletionScheduled == true)
            {
                ScheduleInformation.ScheduleDeletion(statusIds, Text);
            }

            if (ScheduleInformation?.IsTweetScheduled == true)
            {
                await CloseOrReload();
            }

            IsSending = false;
        }
예제 #2
0
        public async Task OnLoad(object data)
        {
            bool loadImage = data as bool? ?? true;

            foreach (var acc in Accounts)
            {
                acc.UseChanged -= Acc_UseChanged;
            }

            Accounts = ContextList?.Contexts?.Select(c => new AccountEntry(c, loadImage)).ToList();
            if (Accounts == null)
            {
                LogTo.Warn("No accounts found");
                return;
            }

            foreach (var acc in Accounts)
            {
                acc.UseChanged += Acc_UseChanged;
            }

            var defAccount = Accounts.FirstOrDefault(a => a.IsDefault) ?? Accounts.First();

            defAccount.Use = true;

            if (PreSelectedAccounts.Any())
            {
                foreach (var acc in Accounts)
                {
                    acc.Use = PreSelectedAccounts.Contains(acc.Context.UserId);
                }
            }

            RaisePropertyChanged(nameof(Accounts));

            InitializeText();
            ConfirmationSet = false;

            Medias.Clear();
            AttachedMedias.Clear();

            KnownUserNames = (await Cache.GetKnownUsers().ConfigureAwait(false)).Select(u => u.UserName).ToList();
            RaisePropertyChanged(nameof(KnownUserNames));
            KnownHashtags = (await Cache.GetKnownHashtags().ConfigureAwait(false)).ToList();
            RaisePropertyChanged(nameof(KnownHashtags));

            ScheduleDate        = DateTime.Now;
            ScheduleTime        = DateTime.Now;
            DeletionDate        = DateTime.Now;
            DeletionTime        = DateTime.Now;
            IsTweetScheduled    = false;
            IsDeletionScheduled = false;
        }
예제 #3
0
        private void ScheduleTweet()
        {
            var job = new SchedulerJob
            {
                JobType         = SchedulerJobType.CreateStatus,
                Text            = Text,
                AccountIds      = Accounts.Where(a => a.Use).Select(a => a.Context.UserId).ToList(),
                TargetTime      = ScheduleDate + ScheduleTime.TimeOfDay,
                InReplyToStatus = InReplyTo?.Id ?? 0,
                FilesToAttach   = AttachedMedias.Select(m => m.FileName).ToList()
            };

            Scheduler.AddJob(job);
        }
예제 #4
0
        private async void ExecuteDeleteMediaCommand(ulong id)
        {
            var csa = new ConfirmServiceArgs(Strings.ConfirmMediaRemoval);

            if (!await ViewServiceRepository.Confirm(csa))
            {
                return;
            }

            Medias.RemoveAll(m => m.MediaID == id);
            for (int i = 0; i < AttachedMedias.Count; ++i)
            {
                if (AttachedMedias[i].MediaId == id)
                {
                    await Dispatcher.RunAsync(() => AttachedMedias.RemoveAt(i));

                    break;
                }
            }
        }
예제 #5
0
        private async Task AttachImage(string fileName)
        {
            IsSending = true;

            if (Path.GetExtension(fileName) == ".gif")
            {
                if (GifValidator.Validate(fileName) != GifValidator.ValidationResult.Ok)
                {
                    Notifier.DisplayMessage(Strings.ImageSizeTooBig, NotificationType.Error);
                    IsSending = false;
                    return;
                }
            }

            byte[] mediaData = File.ReadAllBytes(fileName);
            if (mediaData.Length > TwitterConfig.MaxImageSize)
            {
                Notifier.DisplayMessage(Strings.ImageSizeTooBig, NotificationType.Error);
                IsSending = false;
                return;
            }

            var usedAccounts     = Accounts.Where(a => a.Use).ToArray();
            var acc              = usedAccounts.First();
            var additionalOwners = usedAccounts.Skip(1).Select(a => a.Context.UserId);

            string mediaType = TwitterHelper.GetMimeType(fileName);
            var    media     = await acc.Context.Twitter.UploadMediaAsync(mediaData, mediaType, additionalOwners).ContinueWith(t =>
            {
                IsSending = false;
                return(t.Result);
            });

            await Dispatcher.RunAsync(() =>
            {
                Medias.Add(media);
                AttachedMedias.Add(new MediaItem(media.MediaID, mediaData, fileName));
            });
        }
예제 #6
0
        public async Task OnLoad(object data)
        {
            foreach (var acc in Accounts)
            {
                acc.UseChanged -= Acc_UseChanged;
            }

            Accounts = ContextList.Contexts.Select(c => new AccountEntry(c)).ToList();
            foreach (var acc in Accounts)
            {
                acc.UseChanged += Acc_UseChanged;
            }

            var defAccount = Accounts.FirstOrDefault(a => a.IsDefault) ?? Accounts.First();

            defAccount.Use = true;

            if (PreSelectedAccounts.Any())
            {
                foreach (var acc in Accounts)
                {
                    acc.Use = PreSelectedAccounts.Contains(acc.Context.UserId);
                }
            }

            RaisePropertyChanged(nameof(Accounts));

            InitializeText();
            ConfirmationSet = false;

            Medias.Clear();
            AttachedMedias.Clear();

            KnownUserNames = (await Cache.GetKnownUsers().ConfigureAwait(false)).Select(u => u.UserName).ToList();
            RaisePropertyChanged(nameof(KnownUserNames));
            KnownHashtags = (await Cache.GetKnownHashtags().ConfigureAwait(false)).ToList();
            RaisePropertyChanged(nameof(KnownHashtags));
        }
예제 #7
0
        private async void ExecuteAttachImageCommand()
        {
            var fsa          = new FileServiceArgs("Image files|*.png;*.jpg;*.jpeg;*.bmp;*.gif");
            var selectedFile = await ViewServiceRepository.OpenFile(fsa).ConfigureAwait(false);

            if (selectedFile == null)
            {
                return;
            }

            IsSending = true;

            byte[] mediaData = File.ReadAllBytes(selectedFile);
            if (mediaData.Length > TwitterConfig.MaxImageSize)
            {
                Notifier.DisplayMessage(Strings.ImageSizeTooBig, NotificationType.Error);
                IsSending = false;
                return;
            }

            var usedAccounts = Accounts.Where(a => a.Use).ToArray();

            var acc = usedAccounts.First();
            var additionalOwners = usedAccounts.Skip(1).Select(a => a.Context.UserId);

            string mediaType = GetMimeType(selectedFile);
            var    media     = await acc.Context.Twitter.UploadMediaAsync(mediaData, mediaType, additionalOwners).ContinueWith(t =>
            {
                IsSending = false;
                return(t.Result);
            });

            await Dispatcher.RunAsync(() =>
            {
                Medias.Add(media);
                AttachedMedias.Add(new MediaItem(media.MediaID, mediaData));
            });
        }