Refactoring intent receivers for invitations

This commit is contained in:
vdv committed 2023-04-17 14:45:04 +02:00
1 parent f82181347c
commit d5a8118c2a
5 files changed
+36 -36

No files matched your search

+2
View File
@@ -1,6 +1,8 @@
import { gpxReceiver } from './gpx-receiver';
import { invitationReceiver } from './invitation-receiver';
const receivers = {
invitationReceiver,
gpxReceiver,
};
@@ -0,0 +1,28 @@
import { openInvitation } from '../../components/invitation/Invitation';
const ACCEPTED_ACTIONS = ['android.intent.action.VIEW'];
const ACCEPTED_PROTOCOLS = ['geo:'];
export const invitationReceiver = (intent: any, url: URL | undefined) => {
if (!ACCEPTED_ACTIONS.includes(intent.action)) {
return false;
}
if (!url) {
return false;
}
if (!ACCEPTED_PROTOCOLS.includes(url.protocol)) {
return false;
}
const q = url.search;
const matches = q.match(/invitation=(.+)/);
if (!matches) {
return false;
}
const payload = matches[1];
openInvitation(payload);
return true;
};