Showing
3 changed files
with
41 additions
and
12 deletions
1 | const { marketMultiSearch } = require("../search/marketSearch"); | 1 | const { marketMultiSearch } = require("../search/marketSearch"); |
2 | const setCarouselMessage = require("../message/setCarouselMessage"); | 2 | const setCarouselMessage = require("../message/setCarouselMessage"); |
3 | +const combineCarouselMessage = require("../message/combineCarouselMessage"); | ||
4 | + | ||
3 | // Database APIs | 5 | // Database APIs |
4 | const db = require("../../apis/database"); | 6 | const db = require("../../apis/database"); |
5 | // API List | 7 | // API List |
... | @@ -18,7 +20,7 @@ const multiCheckMamul = (client) => { | ... | @@ -18,7 +20,7 @@ const multiCheckMamul = (client) => { |
18 | client.multicast(userIds, [ | 20 | client.multicast(userIds, [ |
19 | { | 21 | { |
20 | type: "text", | 22 | type: "text", |
21 | - text: `유저님의 ${keywords[i]} 매물 알림이 도착했어요!`, | 23 | + text: `유저님의 매물 알림이 도착했어요!`, |
22 | }, | 24 | }, |
23 | setCarouselMessage(res, keywords[i]), | 25 | setCarouselMessage(res, keywords[i]), |
24 | ]); | 26 | ]); |
... | @@ -29,19 +31,35 @@ const multiCheckMamul = (client) => { | ... | @@ -29,19 +31,35 @@ const multiCheckMamul = (client) => { |
29 | }; | 31 | }; |
30 | 32 | ||
31 | const checkMamul = (client, userId) => { | 33 | const checkMamul = (client, userId) => { |
34 | + let combinedCarousel = { | ||
35 | + type: "flex", | ||
36 | + altText: `유저님의 매물 알림이 도착했어요!`, | ||
37 | + contents: { | ||
38 | + type: "carousel", | ||
39 | + contents: [], | ||
40 | + }, | ||
41 | + }; | ||
42 | + let carousel = {}; | ||
32 | db.getKeywordsByUserId(userId).then((keywords) => { | 43 | db.getKeywordsByUserId(userId).then((keywords) => { |
33 | for (let i = 0, pending = Promise.resolve(); i < keywords.length; i++) { | 44 | for (let i = 0, pending = Promise.resolve(); i < keywords.length; i++) { |
45 | + if (i % 4 == 0) { | ||
46 | + combinedCarousel["contents"]["contents"] = []; | ||
47 | + } | ||
34 | pending = marketMultiSearch(keywords[i]).then((res) => { | 48 | pending = marketMultiSearch(keywords[i]).then((res) => { |
35 | - client.multicast( | 49 | + carousel = setCarouselMessage(res, keywords[i]); |
36 | - [userId], | 50 | + combineCarouselMessage(combinedCarousel, carousel); |
37 | - [ | 51 | + if (i % 4 == 3 || i === keywords.length - 1) { |
38 | - { | 52 | + client.multicast( |
39 | - type: "text", | 53 | + [userId], |
40 | - text: `유저님의 ${keywords[i]} 매물 알림이 도착했어요!`, | 54 | + [ |
41 | - }, | 55 | + { |
42 | - setCarouselMessage(res, keywords[i]), | 56 | + type: "text", |
43 | - ] | 57 | + text: `유저님의 매물 알림이 도착했어요!`, |
44 | - ); | 58 | + }, |
59 | + combinedCarousel, | ||
60 | + ] | ||
61 | + ); | ||
62 | + } | ||
45 | }); | 63 | }); |
46 | } | 64 | } |
47 | }); | 65 | }); | ... | ... |
1 | +const combineCarouselMessage = (mergedCarousel, carousel) => { | ||
2 | + for (let i = 0; i < carousel["contents"]["contents"].length; i++) { | ||
3 | + mergedCarousel["contents"]["contents"].push( | ||
4 | + carousel["contents"]["contents"][i] | ||
5 | + ); | ||
6 | + } | ||
7 | + | ||
8 | + return mergedCarousel; | ||
9 | +}; | ||
10 | + | ||
11 | +module.exports = combineCarouselMessage; |
... | @@ -124,7 +124,7 @@ function setCarouselMessage(mamuls, keyword) { | ... | @@ -124,7 +124,7 @@ function setCarouselMessage(mamuls, keyword) { |
124 | }; | 124 | }; |
125 | let carouselMessage = { | 125 | let carouselMessage = { |
126 | type: "flex", | 126 | type: "flex", |
127 | - altText: `유저님의 ${keyword}매물 알림!`, | 127 | + altText: `유저님의 ${keyword}매물이 왔어요!`, |
128 | contents: { | 128 | contents: { |
129 | type: "carousel", | 129 | type: "carousel", |
130 | contents: flexMessages, | 130 | contents: flexMessages, | ... | ... |
-
Please register or login to post a comment