Esempio n. 1
0
        public async Task <IActionResult> GetInfractionsAsync([FromBody] TableParameters tableParams)
        {
            var sortingCriteria = tableParams.Sort.ToInfractionSummarySortingCriteria();

            var searchCriteria = tableParams.Filters.ToInfractionSearchCriteria();

            searchCriteria.GuildId = UserGuild.Id;

            var pagingCriteria = tableParams.ToPagingCriteria();

            var result = await ModerationService.SearchInfractionsAsync(
                searchCriteria,
                sortingCriteria,
                pagingCriteria);

            var outranksValues = new Dictionary <ulong, bool>();

            foreach (var(guildId, subjectId) in result.Records
                     .Select(x => (guildId: x.GuildId, subjectId: x.Subject.Id))
                     .Distinct())
            {
                outranksValues[subjectId]
                    = await ModerationService.DoesModeratorOutrankUserAsync(guildId, SocketUser.Id, subjectId);
            }

            var mapped = result.Records.Select(
                x => new InfractionData
            {
                Id       = x.Id,
                GuildId  = x.GuildId,
                Type     = x.Type,
                Reason   = x.Reason,
                Duration = x.Duration,
                Subject  = x.Subject,

                CreateAction  = x.CreateAction,
                RescindAction = x.RescindAction,
                DeleteAction  = x.DeleteAction,

                CanRescind
                    = x.RescindAction is null &&
                      x.DeleteAction is null &&
                      (x.Type == InfractionType.Mute || x.Type == InfractionType.Ban) &&
                      outranksValues[x.Subject.Id],

                CanDelete
                    = x.DeleteAction is null &&
                      outranksValues[x.Subject.Id],
            }).ToArray();