|
|
@ -214,10 +214,6 @@ const sendNotification = (chat, name, type) => __awaiter(void 0, void 0, void 0, |
|
|
|
return; |
|
|
|
} |
|
|
|
const unseenMessages = yield models_1.models.Message.count({ where: { sender: { [sequelize_1.Op.ne]: owner.id }, seen: false } }); |
|
|
|
// if(type==='message' && chat.type==constants.chat_types.tribe){
|
|
|
|
// debounce(()=>{
|
|
|
|
// },)
|
|
|
|
// }
|
|
|
|
const params = { |
|
|
|
device_id: owner.deviceId, |
|
|
|
notification: { |
|
|
@ -226,6 +222,24 @@ const sendNotification = (chat, name, type) => __awaiter(void 0, void 0, void 0, |
|
|
|
badge: unseenMessages |
|
|
|
} |
|
|
|
}; |
|
|
|
if (type === 'message' && chat.type == constants.chat_types.tribe) { |
|
|
|
debounce(() => { |
|
|
|
const count = tribeCounts[chat.id] ? tribeCounts[chat.id] + ' ' : ''; |
|
|
|
triggerNotification({ |
|
|
|
device_id: owner.deviceId, |
|
|
|
notification: { |
|
|
|
chat_id: chat.id, badge: unseenMessages, |
|
|
|
message: `You have ${count}new messages in ${chat.name}` |
|
|
|
} |
|
|
|
}); |
|
|
|
}, chat.id, 30000); |
|
|
|
} |
|
|
|
else { |
|
|
|
triggerNotification(params); |
|
|
|
} |
|
|
|
}); |
|
|
|
exports.sendNotification = sendNotification; |
|
|
|
function triggerNotification(params) { |
|
|
|
fetch("https://hub.sphinx.chat/api/v1/nodes/notify", { |
|
|
|
method: 'POST', |
|
|
|
body: JSON.stringify(params), |
|
|
@ -235,8 +249,7 @@ const sendNotification = (chat, name, type) => __awaiter(void 0, void 0, void 0, |
|
|
|
.then(json => { |
|
|
|
// console.log('[hub notification]', json)
|
|
|
|
}); |
|
|
|
}); |
|
|
|
exports.sendNotification = sendNotification; |
|
|
|
} |
|
|
|
// let inDebounce
|
|
|
|
// function debounce(func, delay) {
|
|
|
|
// const context = this
|
|
|
@ -244,4 +257,18 @@ exports.sendNotification = sendNotification; |
|
|
|
// clearTimeout(inDebounce)
|
|
|
|
// inDebounce = setTimeout(() => func.apply(context, args), delay)
|
|
|
|
// }
|
|
|
|
const bounceTimeouts = {}; |
|
|
|
const tribeCounts = {}; |
|
|
|
function debounce(func, id, delay) { |
|
|
|
const context = this; |
|
|
|
const args = arguments; |
|
|
|
if (bounceTimeouts[id]) |
|
|
|
clearTimeout(bounceTimeouts[id]); |
|
|
|
if (tribeCounts[id] || tribeCounts[id] === 0) |
|
|
|
tribeCounts[id] += 1; |
|
|
|
bounceTimeouts[id] = setTimeout(() => { |
|
|
|
tribeCounts[id] = 0; |
|
|
|
func.apply(context, args); |
|
|
|
}, delay); |
|
|
|
} |
|
|
|
//# sourceMappingURL=hub.js.map
|