VKModule.postMessageToUserWall = function postMessageToUserWall(uid, message, fileName, appUrl, success) {
VK.api("photos.getWallUploadServer", function (data) {
if (data.response) {
$.ajax({
url: "http://localhost:8080/rest/vk/wall",
type: "POST",
data: JSON.stringify({upload_url:data.response.upload_url, file_name:fileName}),
contentType:"application/json; charset=utf-8",
dataType:"json",
success: function(response){
VK.api("photos.saveWallPhoto", {user_id:uid, photo:response.photo, server:response.server, hash:response.hash}, function(data){
VK.api("wall.post", {owner_id:uid, message:message, attachments:"photo" + uid + "_" + data.response[0].id + "," + appUrl}, function(result){
success(result);
});
});
},
error: function(response){
console.log("ERROR");
//TODO send error message to server
}
});
}
});
};