/// <summary>
        /// create a new instance of the view model.
        /// </summary>
        /// <param name="tp">a OneNote page object</param>
        /// <param name="highlighter">object to generate a highlight description of the link title</param>
        /// <param name="onenote">OneNote application object proxy</param>
        internal HitHighlightedPageLinkModel(TaggedPage tp, TextSplitter highlighter, OneNoteProxy onenote)
            : base(tp.Title, tp.ID)
        {
            IsSelected  = false;
            _page       = tp;
            _highlights = highlighter.SplitText(_page.Title);

            HitCount = _highlights.Count((f) => f.IsMatch);
            _onenote = onenote;
        }
Exemple #2
0
        protected override async Task <ISlackActionResponse> Respond(SlackActionPayload payload, MemeMessage message)
        {
            if (payload == null)
            {
                throw new ArgumentNullException(nameof(payload));
            }
            if (message == null)
            {
                throw new ArgumentNullException(nameof(message));
            }

            var response = await DatabaseRepo.InsertResponse(
                messageId : message.Id,
                responseUrl : payload.ResponseUrl,
                teamId : payload.Team.Id,
                teamDomain : payload.Team.Domain,
                channelId : payload.Channel.Id,
                channelName : payload.Channel.Name,
                userId : payload.User.Id,
                userName : payload.User.Name);

            var config = await _configService.GetConfig();

            var template = await _configService.GetTemplate(message.TemplateId, message.UserId);

            var boxes = template.Boxes ?? config.TemplateDefaults.Boxes;
            var lines = _textSplitter.SplitText(message.Message, boxes.Count);

            var elements = lines.SelectWithIndex((line, i) => new SlackDialogText
            {
                Label    = String.IsNullOrEmpty(boxes[i].Label) ? $"Line {i + 1}" : boxes[i].Label,
                Name     = $"line{i}",
                Optional = true,
                Value    = line,
            }).ToList <ISlackDialogElement>();

            elements.Add(new SlackDialogSelect
            {
                Label    = "Post anonymously",
                Name     = "isAnonymous",
                Optional = false,
                Value    = message.IsAnonymous.ToString(),
                Options  = new[]
                {
                    new SlackDialogOption
                    {
                        Label = "Yes",
                        Value = Boolean.TrueString,
                    },
                    new SlackDialogOption
                    {
                        Label = "No",
                        Value = Boolean.FalseString,
                    },
                }
            });

            await _slackClient.DialogOpen(new SlackApiDialogOpenRequest
            {
                TriggerId = payload.TriggerId,
                Dialog    = new SlackDialog
                {
                    CallbackId  = $"{Constants.CallbackIds.Edit}:{response.Guid}",
                    Title       = "Edit",
                    SubmitLabel = "Preview",
                    Elements    = elements,
                }
            });

            return(new SlackEmptyResponse());
        }