Push Fix
This commit is contained in:
parent
78997fdd83
commit
8b0a30c3cf
@ -1,3 +1,4 @@
|
||||
var push = require('../push/push');
|
||||
const {
|
||||
query,
|
||||
nonQuery
|
||||
@ -20,8 +21,8 @@ async function updateUser(uid, mid, name, picture, email) {
|
||||
|
||||
async function getmessageids(sl_id) {
|
||||
try {
|
||||
let members = query('SELECT * FROM "Shoppinglist_member" WHERE sl_id = $1;', [sl_id]);
|
||||
let admin = query('SELECT * FROM "Shoppinglist_admin" WHERE sl_id = $1;', [sl_id]);
|
||||
let members = await query('SELECT row_to_json("User") AS obj FROM "Shoppinglist_member" JOIN "User" USING (username) WHERE sl_id = $1;', [sl_id]);
|
||||
let admin = await query('SELECT row_to_json("User") AS obj FROM "Shoppinglist_admin" JOIN "User" USING (username) WHERE sl_id = $1;', [sl_id]);
|
||||
return users_to_array(admin, members);
|
||||
|
||||
} catch (error) {
|
||||
@ -193,6 +194,7 @@ async function addGroup(sl_id, name, color, hidden) {
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
}
|
||||
push.sendMultiplePush(await getmessageids(sl_id), "Gruppe wurde hinzugefügt!", "Zu " + name + " wurde die Gruppe " + name + " hinzugefügt!");
|
||||
}
|
||||
|
||||
//add item into group
|
||||
@ -497,10 +499,10 @@ function generateInviteLink() {
|
||||
function users_to_array(admin, members) {
|
||||
let users = [];
|
||||
|
||||
users.push(admin.username);
|
||||
users.push(admin[0].message_id);
|
||||
|
||||
for (let item of members) {
|
||||
users.push(item.username);
|
||||
users.push(item.message_id);
|
||||
}
|
||||
|
||||
return users;
|
||||
|
@ -1,8 +1,6 @@
|
||||
var admin = require('firebase-admin');
|
||||
|
||||
function sendPush(msgtoken, title, text){
|
||||
|
||||
|
||||
var message = {
|
||||
notification: {
|
||||
title: title,
|
||||
@ -24,24 +22,9 @@ function sendPush(msgtoken, title, text){
|
||||
}
|
||||
|
||||
function sendMultiplePush(message_ids, title, text){
|
||||
console.log(message_ids)
|
||||
var message = {
|
||||
data: {
|
||||
title: title,
|
||||
body: text
|
||||
},
|
||||
tokens: message_ids
|
||||
};
|
||||
|
||||
admin.messaging().sendMulticast(message)
|
||||
.then(function(response) {
|
||||
// See the MessagingDevicesResponse reference documentation for
|
||||
// the contents of response.
|
||||
console.log('Successfully sent message:', response);
|
||||
})
|
||||
.catch(function(error) {
|
||||
console.log('Error sending message:', error);
|
||||
});
|
||||
for(var i = 0; i < message_ids.length; i++){
|
||||
sendPush(message_ids[i], title, text);
|
||||
}
|
||||
}
|
||||
module.exports = {
|
||||
sendPush,sendMultiplePush
|
||||
|
Loading…
x
Reference in New Issue
Block a user