v0.12.26 FCM feature changes
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "rosterchirp-backend",
|
"name": "rosterchirp-backend",
|
||||||
"version": "0.12.25",
|
"version": "0.12.26",
|
||||||
"description": "RosterChirp backend server",
|
"description": "RosterChirp backend server",
|
||||||
"main": "src/index.js",
|
"main": "src/index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|||||||
@@ -224,12 +224,14 @@ io.on('connection', async (socket) => {
|
|||||||
message.reactions = [];
|
message.reactions = [];
|
||||||
io.to(R('group', groupId)).emit('message:new', message);
|
io.to(R('group', groupId)).emit('message:new', message);
|
||||||
|
|
||||||
// Push notifications for private groups
|
// Push notifications
|
||||||
|
const senderName = socket.user.display_name || socket.user.name || 'Someone';
|
||||||
|
const msgBody = (content || (imageUrl ? '📷 Image' : '')).slice(0, 100);
|
||||||
|
|
||||||
if (group.type === 'private') {
|
if (group.type === 'private') {
|
||||||
const members = await query(schema,
|
const members = await query(schema,
|
||||||
'SELECT user_id FROM group_members WHERE group_id = $1', [groupId]
|
'SELECT user_id FROM group_members WHERE group_id = $1', [groupId]
|
||||||
);
|
);
|
||||||
const senderName = socket.user.display_name || socket.user.name || 'Someone';
|
|
||||||
for (const m of members) {
|
for (const m of members) {
|
||||||
if (m.user_id === userId) continue;
|
if (m.user_id === userId) continue;
|
||||||
const memberKey = `${schema}:${m.user_id}`;
|
const memberKey = `${schema}:${m.user_id}`;
|
||||||
@@ -246,7 +248,21 @@ io.on('connection', async (socket) => {
|
|||||||
// after the PWA was backgrounded (OS kills WebSocket before ping timeout).
|
// after the PWA was backgrounded (OS kills WebSocket before ping timeout).
|
||||||
sendPushToUser(schema, m.user_id, {
|
sendPushToUser(schema, m.user_id, {
|
||||||
title: senderName,
|
title: senderName,
|
||||||
body: (content || (imageUrl ? '📷 Image' : '')).slice(0, 100),
|
body: msgBody,
|
||||||
|
url: '/', groupId, badge: 1,
|
||||||
|
}).catch(() => {});
|
||||||
|
}
|
||||||
|
} else if (group.type === 'public') {
|
||||||
|
// Push to all users who have registered an FCM token — everyone is implicitly
|
||||||
|
// a member of every public group. Skip the sender.
|
||||||
|
const subUsers = await query(schema,
|
||||||
|
'SELECT DISTINCT user_id FROM push_subscriptions WHERE fcm_token IS NOT NULL AND user_id != $1',
|
||||||
|
[userId]
|
||||||
|
);
|
||||||
|
for (const sub of subUsers) {
|
||||||
|
sendPushToUser(schema, sub.user_id, {
|
||||||
|
title: `${senderName} in ${group.name}`,
|
||||||
|
body: msgBody,
|
||||||
url: '/', groupId, badge: 1,
|
url: '/', groupId, badge: 1,
|
||||||
}).catch(() => {});
|
}).catch(() => {});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -36,6 +36,10 @@ async function sendPushToUser(schema, userId, payload) {
|
|||||||
'SELECT * FROM push_subscriptions WHERE user_id = $1 AND fcm_token IS NOT NULL',
|
'SELECT * FROM push_subscriptions WHERE user_id = $1 AND fcm_token IS NOT NULL',
|
||||||
[userId]
|
[userId]
|
||||||
);
|
);
|
||||||
|
if (subs.length === 0) {
|
||||||
|
console.log(`[Push] No FCM token for user ${userId} (schema=${schema})`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
for (const sub of subs) {
|
for (const sub of subs) {
|
||||||
try {
|
try {
|
||||||
await messaging.send({
|
await messaging.send({
|
||||||
@@ -70,6 +74,7 @@ async function sendPushToUser(schema, userId, payload) {
|
|||||||
fcm_options: { link: payload.url || '/' },
|
fcm_options: { link: payload.url || '/' },
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
console.log(`[Push] Sent to user ${userId} device=${sub.device} schema=${schema}`);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
// Remove stale tokens
|
// Remove stale tokens
|
||||||
const stale = [
|
const stale = [
|
||||||
|
|||||||
2
build.sh
2
build.sh
@@ -13,7 +13,7 @@
|
|||||||
# ─────────────────────────────────────────────────────────────
|
# ─────────────────────────────────────────────────────────────
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
|
|
||||||
VERSION="${1:-0.12.25}"
|
VERSION="${1:-0.12.26}"
|
||||||
ACTION="${2:-}"
|
ACTION="${2:-}"
|
||||||
REGISTRY="${REGISTRY:-}"
|
REGISTRY="${REGISTRY:-}"
|
||||||
IMAGE_NAME="rosterchirp"
|
IMAGE_NAME="rosterchirp"
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "rosterchirp-frontend",
|
"name": "rosterchirp-frontend",
|
||||||
"version": "0.12.25",
|
"version": "0.12.26",
|
||||||
"private": true,
|
"private": true,
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "vite",
|
"dev": "vite",
|
||||||
|
|||||||
Reference in New Issue
Block a user