Users check-in location based where to start? - javascript

Im working on App using React Native using user location, what i wanna do is while app is closed to check if user is at a location that already exists in the database and if he is
Show a notification saying “ are you at John Doe place “
So to get started i need to know what’s needed to check user location in the background, and then compare the user location in the database and get the results if he is at some location that exists in the database show notifications
Any place where i should start ?

You will probably have to have:
Previously requested the appropriate rights to the user (location, notifications,..)
A background task running periodically or a watcher on the user's position
A way to access the user's
location (see navigator.geolocation.getCurrentPosition(...) or navigator.geolocation.watchPosition(...))
You can combine that with network calls and notifications and you should be able to get to the desired behavior.
This example may help you getting started.

You can use the Geolocation API to get user location, if they permit the app to know their location. I'd add it to a snippet here but stackoverflow has disabled use of the Geolocation API.
const successCallback = positionObj => console.log(positionObj);
const errorCallback = positionError => console.error(positionError);
navigator.geolocation.getCurrentPosition(successCallback, errorCallback);
Working JSFiddle here.

Related

Send Notifications using target feeds with getstream.io

I've been working with getstream.io for a while
and currently I'm facing an issue with the notifications.
To start using notifications I thought it was easier to implement in reactions due to having the targetFeeds property, but I'm facing an access error. I'm trying achieve it doing the next.
UserA commenting in UserB publication
// Client is initialized with UserA info
const comment = await client.reactions.add('comment', activity.id, { data }, { targetFeeds: [`notifications:UserB.ID`] });
My question is how to send a notification to UserB notification feed.
The result I expect is userB receiving a notification like "userA has commented in your publication" or alike.
I believe the default feed for notifications is 'notification' (no s.)
Also I'm not fully aware of what you are tying to accomplish, but just a heads up there is also the TO field for targeting.
https://getstream.io/docs/targeting/?language=js
The issue as first pointed by Sanchaz was that I was using notifications as slug for the notification feed instead of notification, I thought that wasn't the case because I created the notification feed with notifications slug.
StreamIO support stated that if the notification feed doesn't match notification slug, the default permissions doesn't apply, therefore the solution was to rename the slug from notifications to notification.

Firebase: How to always force a sign-in?

Working in Eclipse, & using the provided methods in Firebase' docs, I was able to setup logins for several providers such as Google and Facebook, using the redirect option. I basically click on a button for the provider on my web page, & it takes me to the login screen where I can enter a UID and password (e.g. Google sign-in)
However, once I authenticate properly with a valid account, and even if I sign-out, I get logged into the same account, without ever getting the screen prompting to log in. Where is this information persisted? Closing out Eclipse, or turning the computer off, does nothing to help, so I believe this is all being saved somewhere.
How do I "forget" previous attempts, so that I can see a provider's log in screen, each and every time?
You can use setCustomParameters on AuthProviders.
For example, in the case of Google: https://firebase.google.com/docs/reference/js/firebase.auth.GoogleAuthProvider#setCustomParameters
var provider = new firebase.auth.GoogleAuthProvider();
provider.setCustomParameters({prompt: 'select_account'});
firebase.auth().signInWithPopup(provider);
This will not forget the previous attempt but it will prompt the user to select an existing account or a new one.

Using mod_scorm_insert_scorm_tracks

I'm interfacing my App with Moodle and I'm successfully calling mod_scorm_get_scorm_sco_tracks and mod_scorm_get_scorm_attempt_count via Ajax (XMLHttpRequest) for a given user (userid).
Now I want my App to push some SCORM tracks back to Moodle.
So I'm trying to use mod_scorm_insert_scorm_tracks but with no success.
The problem is that this method does not take an userid parameter, so I don't understand how to use it (and if I try to add userid to input params I get an invalid parameter exception).
I had kind of success (no error message) by sending this:
scoid=206&attempt=2&tracks[0][element]=cmi.completion_status&tracks[0][value]=completed&tracks[1][element]=cmi.interactions.0.id&tracks[1][value]=multiplechoice_page_1_1&tracks[2][element]=cmi.interactions.0.learner_response&tracks[2][value]=White&tracks[3][element]=cmi.interactions.0.result&tracks[3][value]=correct&tracks[4][element]=cmi.interactions.0.description&tracks[4][value]=Which%20color%20was%20Garibaldi's%20white%20horse%3F&tracks[5][element]=cmi.interactions.1.id&tracks[5][value]=hotobject_page_2_1&tracks[6][element]=cmi.interactions.1.learner_response&tracks[6][value]=butterfly&tracks[7][element]=cmi.interactions.1.result&tracks[7][value]=incorrect&tracks[8][element]=cmi.interactions.1.description&tracks[8][value]=Where%20is%20the%20fish%3F&tracks[9][element]=cmi.score.max&tracks[9][value]=2&tracks[10][element]=cmi.score.raw&tracks[10][value]=1&tracks[11][element]=cmi.score.scaled&tracks[11][value]=0.5&tracks[12][element]=cmi.session_time&tracks[12][value]=PT0H0M15S&tracks[13][element]=timemodified&tracks[13][value]=1480947821&tracks[14][element]=userid&tracks[14][value]=26&tracks[15][element]=scoid&tracks[15][value]=206&wstoken=69f2471506c4c49ff47cd0de0c4c9f01&wsfunction=mod_scorm_insert_scorm_tracks&moodlewsrestformat=json
However, since I cannot specify the user those data belongs to, my user's attempts does not update (as predictable).
This is the response from Moodle:
{"trackids":[44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59],"warnings":[]}
I've tried inserting the userid info into traks (tracks[14][element]=userid&tracks[14][value]=26) but still no luck.
So, the questions are:
Which user are those tracks inserted to considering that I'm calling it from an external app, so there's no logged in user in Moodle?
How can I specify that those tracks are for a give userid?
the user identity comes from the HTTP Context of a full login into Moodle: you can't provide SCORM tracking info on behalf of any user but the actual logged-in user.
More at:
https://github.com/moodle/moodle/blob/d33c67bc4744f901bf389607cfbbb683ef1c7d80/mod/scorm/classes/external.php#L451
https://github.com/moodle/moodle/blob/0b8e0c374f89ca20e5b9e7c9370761810811edc6/lib/externallib.php#L481
HTH,
Matteo

Parse master key cloud code following users

I'm building a simple social network app for iOS with parse and I'm currently working on the relationships, such as follower and following. I have follower and following column in my data browser saved as an array so I can save all the usernames. So this is what I'm having trouble with: Say the current user is viewing a user's profile and clicks follow I need to have the current user's name save in the follower array of the user he/she is viewing. Now as far as I know I can't o this on the client side, and it isn't a good idea anyway for security reasons to do ether. So I want to try to use the Master Key and cloud code to add each of the user's names to their appropriate array. I have never used cloud code before and I want to make sure that this is the best way to do this. I set up the Cloud Code I just don't know where to begin. Any suggestions would be appreciated!
I would start by creating a new function in main.js in your cloud code folder. Just insert the Parse.Cloud.useMasterKey(); part at the beginning. I would send up the object id of the user you are modifying, then in the function grab the array from that user, and add the current user to it. Then save and send back a success variable.
To call this from Xcode you would have something like this:
[PFCloud callFunctionInBackground:#"editFollowers" withParameters:#{#"user": Put objectId for user here}
block:^(NSString *response, NSError *error) {
if (!error) {
}
}];

make turn on/off or deauthorized user from my app, and list action of user from app

I submitting an app to Facebook with open graph news read type by javascript.
All done so well with flow from user asking for authorized my app, and show the button help user can public the article then they can remove if they want to.
Today I got the request from Facebook need to change my app:
requirements
(https://developers.facebook.com/docs/opengraph/actions/builtin/#read).
Please make sure your users can (1) Turn sharing on/off globally on
each page an article appears. (2) Remove articles they shared within
your app on each page an article appears. (3) Only generate read
actions when you're sure someone is interested in reading the article
- only publish after 10 seconds.
The third request is easy just use timeout to show the button submit after user read article.
The seconds is so hard because I don't know how to full the array list of pass action of user doing with my app include action id and title of article they post which I can use to create "remove link" for each of them if user want to.
The fist request I did search for method of javascript to de-authorized the app from user (not revoke permission) so I can ask user to be reauthorized if they need.
Please help.
Beside I see very nice 2 sample in guild page
https://developers.facebook.com/attachment/OG_App_PublishToggle.png
https://developers.facebook.com/attachment/OG_App_DeleteActivity.png
But they din't give out the link of live site using it.
or may be that is one of Facebook markup similar "recommend box" , but how/where we can get it?
Please advices for the script or sample as Facebook dose will be help full
regards
UPDATE 1 I found the way to reauthorized all app or revoke one permission.
here the function:
var permsNeededPub = "publish_stream";
///notice that if permission is "publish_actions" revoke function not work
function xlfb_revokePerm() {
FB.api("/me/permissions", "delete",{permission:permsNeededPub}, function(response){
console.log(response);
if(response){
console.log(' Remove success '+permsNeededPub);
}
});
}
function xlfb_removeApp() {
FB.api("/me/permissions", "delete", function(response){
console.log("User removed the app from acount: "+response);
});
};
The seconds is so hard because I don't know how to full the array list of pass action of user doing with my app include action id and title of article they post which I can use to create "remove link" for each of them if user want to.
Whenever a user takes an OG action on your site - save the action_instance_id you are getting back from the API call and whatever extra data you might need to your database.
The fist request I did search for method of javascript to de-authorized the app from user (not revoke permission) so I can ask user to be reauthorized if they need.
Why would you want to de-authorize the app?
All that’s required here is to have a global on/off switch for all sharing activity – so if the user sets it to off, then you just don’t publish any actions for him as long as he leaves this setting set to off.

Categories