How to create success notification in apache ofbiz - apache

is there any way to create success notification whenever i create any information via a form in ofbiz.
for example: I want to have success notification when a product is created
Thanks in advance.

You can send a notification like this, but first you have to ask the user if he wants to allow notifications.
Notification.requestPermission(function() {
if (Notification.permission === 'granted') {
// user approved.
// use of new Notification(...) syntax will now be successful
new Notification('Success', { body: 'Success!' });
} else if (Notification.permission === 'denied') {
// user denied.
} else { // Notification.permission === 'default'
// user didn’t make a decision.
// You can’t send notifications until they grant permission.
}
});

Related

How to distinguish connected users in WebSocket?

I'm trying to create an event in express.js, where connected users will be sent to the client.
My goal is that in client side user can see who belongs that particular message sent from.
As it describes in docs and as I could also run in localhost, broadcasting messages works fine.
wss.on("connection", function connection(ws) {
ws.on("message", function message(data) {
wss.clients.forEach(function each(client) {
if (client !== ws && client.readyState === WebSocket.OPEN) {
client.send(data);
}
});
});
});
So before sending messages to client, there should be another event where connected username should be sent, so that in client side can be defined who that particular message belongs.
My idea is to create users object which supposed to keep track of all connected users like here.
const users = {};
wss.on("connection", function connection(ws) {
ws.on("userName", function message(userName) {//this doesn't work
const user = {
name: userName,
id: uuid(), // some unique id, no idea if websocket has or not
};
users[id]= user
ws.send("user", user) // current user who belongs the message to
ws.send("users", users) // users to show connected users list
});
ws.on("message", function message(data) {
wss.clients.forEach(function each(client) {
if (client !== ws && client.readyState === WebSocket.OPEN) {
client.send(data);
}
});
});
});
user event doesn't work, it is just my idea but not sure if how to do it correctly.
Any help will be appreciated.

React Native Expo In App Purchase send custom variable to setPurchaseListener

I am implementing In App Purchase function in Expo bare workflow using Expo-In-App-Purchase library. In their documentation it says you need to implement setPurchaseListener on a global scope.
That's currently how I have it set up in my App.tsx file:
// Set purchase listener
setPurchaseListener(async ({ responseCode, results, errorCode }) => {
if (responseCode === IAPResponseCode.OK) {
for (const purchase of results!) {
if (!purchase.acknowledged) {
const {
orderId,
purchaseToken,
acknowledged,
transactionReceipt,
productId,
}: InAppPurchase = purchase;
// in android, consumeItem should be set to false to acknowledge the purchase
// in iOS this isn't needed because it's already specified in app store connect
const consumeItem = Platform.OS === "ios";
finishTransactionAsync(purchase, consumeItem).then(
(response) => {
//send call to back end
}
);
}
}
} else if (responseCode === IAPResponseCode.USER_CANCELED) {
//Do nothing. User cancelled
} else {
console.warn(
`Something went wrong with the purchase. Received response code ${responseCode} and errorCode ${errorCode}`
);
//catch all for all errors
if (
errorCode === IAPErrorCode.SERVICE_TIMEOUT ||
errorCode === IAPErrorCode.SERVICE_DISCONNECTED ||
errorCode === IAPErrorCode.SERVICE_UNAVAILABLE
) {
showMessage(`Service unavailable (${errorCode})`, true);
} else {
showMessage(
`Something went wrong with the purchase. Error code (${errorCode}). Please contact us with the error code if this persists`,
true
);
}
}
});
My question is if I have this defined in my App.tsx file, how is it possible to send a custom variable to my back end after a user purchases something? For example, someone can be in multiple leagues, they buy something for a particular league that they are in, how can I send the success back to my back end stating that the purchase was made for a particular league?
Would I just need to add multiple setPurchaseListeners? If that's so, is there a way to stop listening after a user navigates away from a page?

I can't get pushToken in Safari

In my work, we tried integrate Safari Push unsuccessful. We have the files .p12 and the .cer
When executing in Safari, not work, no response. If change the name of callback, for example for console.log('hi')... print "hi" and in the console, I see the error
"TypeError: undefined in not an object (evaluating
'window.safari.pushNotification.requestPErmission('https://fabse.tv,
pushId, { user: '123456'}, console.log('hi'))')"
This is my code:
my pushId: 'web.fbase.tv'
setupPushWeb() {
const isSafari = /^((?!chrome|android).)*safari/i.test(navigator.userAgent);
var checkRemotePermission = function (permissionData) {
if (permissionData.permission === 'default') {
// This is a new web service URL and its validity is unknown.
window.safari.pushNotification.requestPermission(
'https://fbase.tv', // The web service URL.
'web.fbase.tv', // The Website Push ID.
{user_id: '4741619481'}, // Data used to help you identify the user.
console.log('hola') // The callback function.
);
}
else if (permissionData.permission === 'denied') {
// The user said no.
}
else if (permissionData.permission === 'granted') {
// The web service URL is a valid push provider, and the user said yes.
// permissionData.deviceToken is now available to use.
}
}
if(isSafari) {
if ('safari' in window && 'pushNotification' in window.safari) {
var permissionData = window.safari.pushNotification.permission('web.fbase.tv');
checkRemotePermission(permissionData);
}
} else {
//Firebase integration Fine

Set up listeners only after permission is verified

I am using react-native-notifications - Version 2.1.7 library to receive notifications in a react-native mobile app. I don't want to set up the notification-related listeners until the user has provided permission to receive notifications.
Q1. The documentation says that it is highly recommended to keep listeners registration at global scope rather than at screen scope. What problems should I expect if I set up listeners at a screen, at which the user is asked to provide permission?
Q2. The device token listener NotificationsAndroid.setRegistrationTokenUpdateListener() does NOT seem to work if it is inside a promise. What am I missing here? Please, see my code below.
// This function is called when the user clicks on the button "Provide permission to receive notifications."
const _requestPermissionNotification = async () => {
let hasPermission = false;
try {
hasPermission = await NotificationsAndroid.isRegisteredForRemoteNotifications();
}
catch (error) {
Alert.alert(
"Notification",
"To utilise the full functionality of this app, Permission to receive notifications is required.",
[{ text: "Ok." }]
);
} // end of: try/catch
if (hasPermission) {
// A. Register Token
// THIS LISTENER DOES NOT SEEM TO WORK UNLESS IT IS SET UP OUTSIDE THE COMPONENT!
NotificationsAndroid.setRegistrationTokenUpdateListener((deviceToken) => {
console.log("PermissionsScreen - setRegistrationTokenUpdateListener - deviceToken:", deviceToken);
});
// B. Pending Notifications
PendingNotifications.getInitialNotification()
.then((notification) => {
console.log("PermissionsScreen - getInitialNotification - notification:", notification);
})
.catch((err) => console.error("getInitialNotifiation failed", err));
// C. Notification Opened
NotificationsAndroid.setNotificationOpenedListener((notification) => {
console.log("PermissionsScreen - setNotificationOpenedListener - :data", notification.getData());
});
// D.a Notification Received
NotificationsAndroid.setNotificationReceivedListener((notification) => {
console.log("PermissionsScreen - setNotificationReceivedListener - data:", notification.getData());
});
// D.b Notification Received "IN FOREGROUND"
NotificationsAndroid.setNotificationReceivedInForegroundListener((notification) => {
console.log("PermissionsScreen - setNotificationReceivedInForegroundListener (foreground)", notification.getData());
});
} // end of: if()
}; // end of: _requestPermissionNotification()
It seems that version 3.1.1 of React-Native-Notifications does not have these limitations anymore.
The following code, which uses the new commands, can be used inside a promise and inside a component.
// Step A.1: Register this app to receive notifications.
Notifications.registerRemoteNotifications();
// Step A.2: Get the device token
Notifications.events().registerRemoteNotificationsRegistered( (event) => {
console.log("deviceToken:", event.deviceToken);
});

FB JS SDK - How to check whether any user has logged in for the first time

I'm using this function as event handler for my onclick event and it is working fine -
var facebookLogin = function() {
checkLoginState(function(data) {
if (data.status !== 'connected') {
FB.login(function(response) {
if (response.status === 'connected')
// I do what I want to do here if login is succesful.
}, {scope: scopes});
}
})
}
But is there a way so that I can get to know that the user has logged in for the first time so that I can save him into my database or perform certain actions?
Every time a user logs in, get the Facebook ID with the getId() method.
If the ID does not exist in your database, add his information to your database, if it does, you know what he has logged in before.