Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
saveMarker: function(_data, _callback) {
var markersData = Ti.App.Properties.getObject("markers");
_data.userid = {
__type: "Pointer",
className: "_User",
objectId: Parse.currentUser
};
_data.map = App.Map.currentMap.id;
_data.ACL = {};
_data.ACL[Parse.currentUser] = {
read: true,
write: true
};
if(_data.share === "Public") {
_data.ACL["*"] = { read: true };
}
Ti.API.debug(_data);
// We're editing if we have an existing ID
getMessages: function(_callback) {
Parse.query("messages", {
toUser: {
__type: "Pointer",
className: "_User",
objectId: Parse.currentUser
}
}, function(_response) {
if(_response.success && _response.success.results && _response.success.results.length > 0) {
_callback({
success: _response.success.results
});
// Set messages as read (should this go here or in a controller?)
Model.readMessages(_response.success.results);
} else {
_callback({ failed: true });
}
});
},
/**
getFriends: function(_callback) {
Parse.query("friends", {
user: {
__type: "Pointer",
className: "_User",
objectId: Parse.currentUser
}
}, function(_response) {
Ti.API.debug(_response);
if(_response.success && _response.success.results.length > 0) {
Model.getFriendsByFriendClassObjectId(
_response.success.results[0].objectId,
_callback || null
);
} else {
// If, for some reason the friend object doesn't exist for this user, create it.
if(_response.success.results.length == 0) {
Model.createFriendsObject();
}
if(_callback) {
_callback({ failed: true });
});
}
});
// Delete old friend request record
Parse.deleteObject("friendRequest", _friendRequestId);
}
var existingObject = null;
// Check if current user object exists and save friend to him
Parse.query("friends", {
user: {
__type: "Pointer",
className: "_User",
objectId: Parse.currentUser
}
}, function(_response) {
Ti.API.debug(_response);
if(_response.success && _response.success.results.length > 0) {
existingObject = _response.success.results[0];
// Check if friend object exists and save current user to him
Parse.query("friends", {
user: {
__type: "Pointer",
className: "_User",
objectId: _friendId
}
}, function(_res) {
Ti.API.debug(_res);
}, function(_res) {
Ti.API.debug(_res);
if(_res.success && _res.success.results.length > 0) {
// Create the friend relations if successful (this should be done in cloud code, but we're keeping it all client side for now
buildRequest(Parse.currentUser, _friendId, existingObject, function(_buildReq) {
if(_buildReq.success) {
buildRequest(_friendId, Parse.currentUser, _res.success.results[0], function(_buildTwoReq) {
if(_buildTwoReq.success) {
// Send push message about acceptation
Model.createMessage({
toUser: _friendId,
fromUser: Parse.currentUser,
messageType: "friend",
message: Parse.userObject.username + " accepted your friend request."
});
_callback({
success: true
});
} else {
_callback({ success: false });
var _data = {
user: {
__type: "Pointer",
className: "_User",
objectId: Parse.currentUser
},
marker: {
__type: "Pointer",
className: "marker",
objectId: _marker.objectId
},
text: _comment
};
_data.ACL = {};
_data.ACL[Parse.currentUser] = {
read: true,
write: true
};
// Make sure the owner has ability to manage this comment
_data.ACL[_marker.userid.objectId] = {
read: true,
write: true
};
_data.ACL["*"] = { read: true };
Parse.saveObject("comments", _data, function(_response) {
_callback(_response);
if(_response.success) {
// Create a message for this comment
if(Parse.currentUser !== _marker.userid.objectId) {
allowAccessToFriendObject: function(_friendId) {
Parse.query("friends", {
user: {
__type: "Pointer",
className: "_User",
objectId: Parse.currentUser
}
}, function(_response) {
if(_response.success && _response.success.results.length > 0) {
var data = _response.success.results[0];
data.ACL[_friendId] = {
read: true,
write: true
};
Parse.updateObject("friends", data.objectId, {
ACL: data.ACL
}, function(_res) {
Ti.API.debug(_res);
});
} else {
Parse.updateObject("marker", _data.objectId, _data, function(_response) {
if(_response.success) {
_.extend(markersData[_data.objectId], _data);
Ti.App.Properties.setObject("markers", markersData);
_callback({ success: _response.success });
} else {
_callback({ failure: _response });
}
});
} else {
_.extend(markersData[_data.objectId], _data);
Ti.App.Properties.setObject("markers", markersData);
_callback({ success: _data });
}
} else {
if(Parse.currentUser) {
Parse.saveObject("marker", _data, function(_response) {
if(_response.success) {
_data.objectId = _response.success.objectId;
markersData[_data.objectId] = _data;
Ti.App.Properties.setObject("markers", markersData);
_callback({ success: _response.success });
} else {
_callback({ failure: _response });
}
});
} else {
_data.objectId = _.random(0,10000);
markersData[_data.objectId] = _data;
Ti.App.Properties.setObject("markers", markersData);
_callback({ success: _data });
}
getFriendRequests: function(_callback) {
Parse.query("friendRequest", {
include: "fromUser,toUser",
toUser: {
__type: "Pointer",
className: "_User",
objectId: Parse.currentUser
}
}, function(_response) {
if(_response.success) {
_callback({
success: _response.success
});
} else {
_callback({
failed: _response
});
}
});
},
/**
write: true
};
if(_friendId) {
ACL[_friendId] = {
read: true,
write: true
};
}
Parse.saveObject("friends", {
ACL: ACL,
user: {
__type: "Pointer",
className: "_User",
objectId: _friendId || Parse.currentUser
}
}, function(_res) {
Ti.API.debug("Saving Friends Object: ", _res);
});
}
});
},