|
|
@@ -116,6 +116,20 @@ class BoltService {
|
|
|
await this.createPageInGrowi(view, body);
|
|
|
});
|
|
|
|
|
|
+ this.bolt.action('showNextResults', async({
|
|
|
+ ack, action,
|
|
|
+ }) => {
|
|
|
+ await ack();
|
|
|
+ const parsedValue = JSON.parse(action.value);
|
|
|
+
|
|
|
+ const command = parsedValue.command;
|
|
|
+ const args = parsedValue.args;
|
|
|
+ const offset = parsedValue.offset;
|
|
|
+
|
|
|
+ const newOffset = offset + 10;
|
|
|
+ this.showEphemeralSearchResults(command, args, newOffset);
|
|
|
+ });
|
|
|
+
|
|
|
this.bolt.action('shareSearchResults', async({
|
|
|
body, ack, say, action,
|
|
|
}) => {
|
|
|
@@ -137,7 +151,7 @@ class BoltService {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- async getSearchResultPaths(command, args) {
|
|
|
+ async getSearchResultPaths(command, args, offset = 0) {
|
|
|
const firstKeyword = args[1];
|
|
|
if (firstKeyword == null) {
|
|
|
this.client.chat.postEphemeral({
|
|
|
@@ -150,12 +164,16 @@ class BoltService {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- // remove leading 'search'.
|
|
|
- args.shift();
|
|
|
- const keywords = args.join(' ');
|
|
|
+ const keywordsArr = [];
|
|
|
+ for (let i = 1; i < args.length; i++) {
|
|
|
+ keywordsArr.push(args[i]);
|
|
|
+ }
|
|
|
+ const keywords = keywordsArr.join(' ');
|
|
|
+
|
|
|
const { searchService } = this.crowi;
|
|
|
- const option = { limit: 10 };
|
|
|
- const results = await searchService.searchKeyword(keywords, null, {}, option);
|
|
|
+ const options = { limit: 10, offset };
|
|
|
+ const results = await searchService.searchKeyword(keywords, null, {}, options);
|
|
|
+
|
|
|
|
|
|
// no search results
|
|
|
if (results.data.length === 0) {
|
|
|
@@ -164,7 +182,7 @@ class BoltService {
|
|
|
channel: command.channel_id,
|
|
|
user: command.user_id,
|
|
|
blocks: [
|
|
|
- this.generateMarkdownSectionBlock(`*No page that matches your keyword(s) "${args}".*`),
|
|
|
+ this.generateMarkdownSectionBlock(`*No page that matches your keyword(s) "${keywords}".*`),
|
|
|
this.generateMarkdownSectionBlock(':mag: *Help: Searching*'),
|
|
|
this.divider(),
|
|
|
this.generateMarkdownSectionBlock('`word1` `word2` (divide with space) \n Search pages that include both word1, word2 in the title or body'),
|
|
|
@@ -189,11 +207,16 @@ class BoltService {
|
|
|
return data._source.path;
|
|
|
});
|
|
|
|
|
|
- return resultPaths;
|
|
|
+ return {
|
|
|
+ resultPaths, offset, keywords,
|
|
|
+ };
|
|
|
}
|
|
|
|
|
|
- async showEphemeralSearchResults(command, args) {
|
|
|
- const resultPaths = await this.getSearchResultPaths(command, args);
|
|
|
+ async showEphemeralSearchResults(command, args, offsetNum) {
|
|
|
+ const {
|
|
|
+ resultPaths, offset, keywords,
|
|
|
+ } = await this.getSearchResultPaths(command, args, offsetNum);
|
|
|
+
|
|
|
if (resultPaths == null) {
|
|
|
return;
|
|
|
}
|
|
|
@@ -221,7 +244,7 @@ class BoltService {
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
- const keywordsAndDesc = `keyword(s) : "${args}" \n ${searchResultsDesc}.`;
|
|
|
+ const keywordsAndDesc = `keyword(s) : "${keywords}" \n ${searchResultsDesc}.`;
|
|
|
|
|
|
try {
|
|
|
await this.client.chat.postEphemeral({
|
|
|
@@ -240,6 +263,7 @@ class BoltService {
|
|
|
text: 'Next',
|
|
|
},
|
|
|
action_id: 'showNextResults',
|
|
|
+ value: JSON.stringify({ offset, command, args }),
|
|
|
},
|
|
|
{
|
|
|
type: 'button',
|