29 lines
616 B
TypeScript
29 lines
616 B
TypeScript
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;
|
|
};
|