【发布时间】:2019-07-27 19:18:46
【问题描述】:
我正在开发一个 android 聊天应用程序,其中有用户可以用来写消息的聊天室。在聊天室中,他们可以选择订阅该房间。这样做的目的是在将新消息添加到房间时接收推送通知。
我使用 Cloud Functions 和 Topics 制作了这个功能。这是我的代码:
exports.pushNotification = functions.database.ref('/messages/{pushId}/{id}').onCreate((change, context) => {
const pushId = context.params.pushId;
const originalText = change.val();
const payload = {
notification: {
title: originalText.message,
body: originalText.sender,
sound: "default"
},
};
const options = {
priority: "high",
timeToLive: 60 * 60 * 24
};
return admin.messaging().sendToTopic(pushId, payload, options);
});
问题 如果用户订阅了某个主题并发送了一条消息,那么同一用户也会收到通知。如何防止发送消息的用户收到通知?
【问题讨论】:
标签: android firebase firebase-cloud-messaging