This commit is contained in:
Martti Malmi 2022-06-25 18:59:40 +03:00
parent 6947d3ebe9
commit 2f2399d42e
2 changed files with 13 additions and 3 deletions

View File

@ -33,11 +33,15 @@ class ChatMessageForm extends MessageForm {
sendToPrivateOrGroup() {
const chat = Session.channels[this.props.activeChat];
if (!chat) {
console.error("no chat", this.props.activeChat, "found");
return;
}
State.local.get('channels').get(this.props.activeChat).get('msgDraft').put(null);
const textEl = $(this.base).find('.new-msg');
const text = textEl.val();
if (!text.length && !chat.attachments) { return; }
chat.setTyping(false);
chat.setTyping && chat.setTyping(false);
const msg = {text};
if (this.props.replyingTo) {
msg.replyingTo = this.props.replyingTo;
@ -174,7 +178,7 @@ class ChatMessageForm extends MessageForm {
async webPush(msg) {
const chat = Session.channels[this.props.activeChat];
const myKey = Session.getKey();
const shouldWebPush = (window.location.hash === `#/chat/${ myKey.pub}`) || !(chat.activity.isActive);
const shouldWebPush = (this.props.activeChat === myKey.pub) || !(chat.activity && chat.activity.isActive);
if (shouldWebPush && chat.webPushSubscriptions) {
const subscriptions = [];
const participants = Object.keys(chat.webPushSubscriptions);
@ -189,7 +193,11 @@ class ChatMessageForm extends MessageForm {
body: await Gun.SEA.encrypt(bodyText, secret),
from:{pub: myKey.pub, epub: myKey.epub}
};
chat.webPushSubscriptions[participant].forEach(s => subscriptions.push({subscription: s, payload}));
chat.webPushSubscriptions[participant].forEach(s => {
if (s && s.endpoint) {
subscriptions.push({subscription: s, payload});
}
});
}
fetch(notificationServiceUrl, {
method: 'POST',

View File

@ -75,6 +75,8 @@ self.addEventListener('push', async ev => {
if (!data.title || !data.body) {
console.log('what?', data);
}
console.log('sw push', data);
//console.log(self.irisKey, data.from, data.from.epub);
if (self.irisKey && data.from && data.from.epub) {
const secret = await Gun.SEA.secret(data.from.epub, self.irisKey);
data.title = await Gun.SEA.decrypt(data.title, secret);