Commit c8dce542 authored by MrMan's avatar MrMan

Add handling for matchedUserDetected to tinder match store

parent f461a1a2
Pipeline #2748273 skipped
......@@ -29,6 +29,7 @@ let TinderMatchStore = Reflux.createStore({
// Subscribe to actions
this.listenTo(Actions.retrieveMatchedUserInfo, this.retrieveMatchedUserInfo);
this.listenTo(Actions.sendMessageToMatch, this.sendMessageToMatch);
this.listenTo(Actions.matchResultDetected, this.matchResultDetected);
// Save the Tinder access token when provided by the TinderUpdateStore
TinderUpdateStore.listen(store => {
......@@ -56,6 +57,30 @@ let TinderMatchStore = Reflux.createStore({
return !_.isEmpty(this.state.tinderAccessToken);
},
// Handle a match result detected (usually from a "like" sentiment expression)
matchResultDetected(user) {
console.log("[TINDER MATCH STORE] Detected a match from like sentiment expression, user:", user);
this.addMatchedUser(user);
},
/**
* Add a matched user
*
* @param {object} user - the matched user
*/
addMatchedUser(user) {
let userId = _.get(user, "_id");
if (_.isUndefined(userId)) {
console.log("[TINDER MATCH STORE] Failed to add matched user, invalid user object:", user);
return;
}
this.state.matchedUserInfo[userId] = user;
this.backupState();
this.trigger(this.state);
},
/**
* Retrieve info for a matched user
*
......@@ -77,16 +102,7 @@ let TinderMatchStore = Reflux.createStore({
}
let user = resp.results;
let userId = _.get(user, "_id");
if (_.isUndefined(userId)) {
console.log("[TINDER MATCH STORE] Invalid user object received from Tinder API:", user);
return;
}
this.state.matchedUserInfo[userId] = user;
if (!_.has(this.state.matchedUserInfo, userId)) { this.backupState(); }
this.trigger(this.state);
this.addMatchedUser(user); // Will trigger as necessary
})
.catch(err => {
console.log("[TINDER MATCH STORE] Error occurred while trying to get matched user's info:", err);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment