Skip to content

Commit

Permalink
Merge pull request #14 from arestov/fix-namespaceless-events
Browse files Browse the repository at this point in the history
Fixes #13 (namespaceless events)
  • Loading branch information
arestov committed Mar 20, 2016
2 parents 31c956e + e09e459 commit c579a0f
Show file tree
Hide file tree
Showing 18 changed files with 245 additions and 214 deletions.
16 changes: 6 additions & 10 deletions js/LfmAuth.js
Expand Up @@ -63,9 +63,6 @@ var LfmLogin = spv.inh(pv.Model, {
});





var LfmScrobble = spv.inh(LfmLogin, {
init: function(target){
target.wch(target.app, 'settings-lfm-scrobbling', 'scrobbling');
Expand All @@ -76,12 +73,11 @@ var LfmScrobble = spv.inh(LfmLogin, {
beforeRequest: function() {
this.bindAuthCallback();
},
act: function () {
this.app.setSetting('lfm-scrobbling', true);
},
bindAuthCallback: function(){
var _this = this;
this.auth.once("session.input_click", function() {
_this.app.setSetting('lfm-scrobbling', true);
//_this.auth.setScrobbling(true);
}, {exlusive: true});
pvUpdate(this.app, 'lfm_auth_request', this);
},
setScrobbling: function(state) {
pvUpdate(this, 'scrobbling', state);
Expand Down Expand Up @@ -184,15 +180,15 @@ var LfmAuth = spv.inh(pv.Model, {
get_lfm_token: function(){
var _this = this;
this.api.get('auth.getToken', false, {nocache: true})
.done(function(r){
.then(function(r){
_this.newtoken = r.token;
});
},
try_to_login: function(callback){
var _this = this;
if (_this.newtoken ){
_this.api.get('auth.getSession', {'token':_this.newtoken })
.done(function(r){
.then(function(r){
if (!r.error) {
_this.login(r,callback);
pvUpdate(_this, 'session', true);
Expand Down
2 changes: 1 addition & 1 deletion js/SeesuServerAPI.js
Expand Up @@ -262,7 +262,7 @@ var SeesuServerAPI = spv.inh(pv.Eventor, {
}, function(su_sess){
if (su_sess.secret_container && su_sess.sid){
_this.app.vk_api.get('storage.get', {key:su_sess.secret_container})
.done(function(r){
.then(function(r){
if (r && r.response){
_this.setAuth({
userid: su_sess.userid,
Expand Down
2 changes: 1 addition & 1 deletion js/initAPIs.js
Expand Up @@ -181,7 +181,7 @@ function initAPIs(self, app_serv, app_env, cache_ajax, resortQueue, addQueue) {
}


self.lfm_auth.on('session.ga_tracking', function(){
self.lfm_auth.on('session', function(){
self.trackEvent('Auth to lfm', 'end');
});
self.lfm_auth.on('want-open-url', function(wurl){
Expand Down
2 changes: 1 addition & 1 deletion js/libs/LastfmAPIExtended.js
Expand Up @@ -47,7 +47,7 @@ LastfmAPI.extendTo(LastfmAPIExtended, {
}

_this.post('track.scrobble', post_m_obj)
.done(function(){
.then(function(){
_this.music = [];
_this.stSet('lfm_scrobble_music', '');
});
Expand Down
16 changes: 8 additions & 8 deletions js/libs/TorrentsAudioSearch.js
Expand Up @@ -380,14 +380,14 @@ TorqueSearch.prototype = {
FuncsStack.chain([
function() {
var chain_link = this;
core.torrent_search
.findAudio(msq)
.done(function(r) {
chain_link.completePart(r);
})
.fail(function() {
deferred.reject();
});
var req = core.torrent_search
.findAudio(msq);

req.then(function(r) {
chain_link.completePart(r);
}, function() {
deferred.reject();
});
//find torrents
},
function(links_list) {
Expand Down
4 changes: 1 addition & 3 deletions js/libs/nigma.search.js
Expand Up @@ -76,7 +76,7 @@ NigmaAPI.prototype = {
dataType: "text",
data: params_full,
timeout: 20000
}).done(success).fail(function(xhr){
}).then(success, function(xhr){
deferred.reject.apply(deferred, arguments);
});

Expand Down Expand Up @@ -240,5 +240,3 @@ NigmaMusicSearch.prototype = {
}

};


40 changes: 23 additions & 17 deletions js/models/SeesuListening.js
Expand Up @@ -64,29 +64,35 @@ return pv.behavior({

pvUpdate(target, 'sending_like', true);

this.api('relations.setLike', {to: this.state('user')})
.done(function(resp) {
if (!resp.done) {return;}
pvUpdate(target, 'like_just_sended', true);
})
.always(function() {
pvUpdate(target, 'sending_like', false);
});
var req = this.api('relations.setLike', {to: this.state('user')});

req.then(function(resp) {
if (!resp.done) {return;}
pvUpdate(target, 'like_just_sended', true);
});

var anyway = function() {
pvUpdate(target, 'sending_like', false);
};
req.then(anyway, anyway);
return req;
},
acceptInvite: function() {
var target = this;

pvUpdate(target, 'sending_accept', true);

this.api('relations.acceptInvite', {from: this.state('user')})
.done(function(resp) {
if (!resp.done) {return;}
pvUpdate(target, 'invite_accepted', true);
pvUpdate(target, 'just_accepted_est', resp.done.est);
})
.always(function() {
pvUpdate(target, 'sending_accept', false);
});
var req = this.api('relations.acceptInvite', {from: this.state('user')});
req.then(function(resp) {
if (!resp.done) {return;}
pvUpdate(target, 'invite_accepted', true);
pvUpdate(target, 'just_accepted_est', resp.done.est);
});
var anyway = function() {
pvUpdate(target, 'sending_accept', false);
};
req.then(anyway, anyway);
return req;
}
}, pv.HModel, function SeesuListening(){});
});
2 changes: 1 addition & 1 deletion js/models/Song.js
Expand Up @@ -366,7 +366,7 @@ var pvUpdate = pv.update;
return;
}
var duration = Math.round(mopla.getDuration()/1000) || '';
if (this.app.settings['lfm-scrobbling']){
if (this.app.settings['lfm-scrobbling'] && this.app.lfm.sk){
this.app.lfm.nowplay({
artist: this.artist,
track: this.track,
Expand Down
96 changes: 53 additions & 43 deletions js/models/song/SongActSharing.js
Expand Up @@ -5,17 +5,20 @@ var app_env = app_serv.app_env;
var pvState = pv.state;

var struserSuggest = spv.inh(invstg.BaseSuggest, {
init: function(self, opts, wrap) {
var user = wrap.user;
self.mo = wrap.mo;
self.row = wrap.row;
self.user_id = user.id;
self.photo = user.photo;
self.online = self.online;
init: function(self, opts, params) {
self.app = params.app;
self.mo = params.mo;
self.row = params.row;

var user = params.user;

self.user_id = user.state('userid');
self.photo = user.state('photo');
// self.online = self.online;
//self.name = user.name;
self.text_title = user.first_name + " " + user.last_name;
self.text_title = user.state('first_name') + " " + user.state('last_name');
self.updateManyStates({
photo: user.photo,
photo: user.state('photo'),
text_title: self.text_title
});
}
Expand Down Expand Up @@ -76,6 +79,22 @@ var StrusersRSSection = spv.inh(invstg.SearchSection, {
}
});
}


self.friends_page = self.app.routePathByModels('/users/me/vk:friends');

self.friends_page.on('child_change-list_items', function(e) {
pv.updateNesting(this, 'friends', e.value);
this.changeQuery('');
this.searchByQuery(this.state('query'));
}, self.getContextOpts());

self.lwch(self, 'can_search', function(state) {
if (!state){return;}

this.friends_page.preloadStart();
this.searchFriends();
});
}
}, {
resItem: struserSuggest,
Expand All @@ -92,6 +111,7 @@ var StrusersRSSection = spv.inh(invstg.SearchSection, {
return vk_env || has_vk_api;
}
],
'compx-can_search': [['can_search_friends']],
'compx-can_search_friends': [
['vk_env', 'has_vk_api', 'can_searchf_vkopt'],
function(vk_env, has_vk_api, can_searchf_vkopt) {
Expand All @@ -117,18 +137,17 @@ var StrusersRSSection = spv.inh(invstg.SearchSection, {
},
searchByQuery: function(query) {
this.changeQuery(query);
var _this = this;
this.app
.once("vk-friends.share-row", function(list){
_this.handleVKFriendsSearch(list);
}, {exlusive: true})
.getVKFriends();
this.searchFriends();
},
handleVKFriendsSearch: function(list){
searchFriends: function(){
var list = this.getNesting('friends') || [];
var query = this.state('query');
var r = (query ? spv.searchInArray(list, query, ["first_name", "last_name"]) : list);
if (!this.state('can_search')){
return;
}
var r = (query ? spv.searchInArray(list, query, ["states.first_name", "states.last_name"]) : list);
if (r.length){
r = r.concat();
r = r.slice();
for (var i = 0; i < r.length; i++) {
r[i] = {
mo: this.mo,
Expand All @@ -137,7 +156,6 @@ var StrusersRSSection = spv.inh(invstg.SearchSection, {
};
}
}

this.appendResults(r, true);
},
postToVKWall: function() {
Expand Down Expand Up @@ -178,53 +196,47 @@ var LFMUserSuggest = spv.inh(invstg.BaseSuggest, {


var LFMFriendsSection = spv.inh(invstg.SearchSection, {
//'nest-lfm_friends': ['#/users/me/lfm:friends', 'can_share'],
'nest-friends': ['#/users/me/lfm:friends', 'can_share', 'can_share'],
init: function(target) {
target.mo = target.map_parent.mo;
target.rpl = target.map_parent.map_parent;

target.friends_page = target.app.routePathByModels('/users/me/lfm:friends');

target.lfm_friends = target.app.routePathByModels('/users/me/lfm:friends');
//su.routePathByModels('/users/me/lfm:neighbours')
//preloadStart

target.lfm_friends.on('child_change-list_items', function(e) {
target.friends_page.on('child_change-list_items', function(e) {
pv.updateNesting(this, 'friends', e.value);
this.changeQuery('');
this.searchByQuery(this.state('query'));


}, target.getContextOpts());

target.wch(target, 'can_share', function(e) {
if (e.value){
this.lfm_friends.preloadStart();
this.searchLFMFriends();
}
target.lwch(target, 'can_search', function(state) {
if (!state){return;}

this.friends_page.preloadStart();
this.searchFriends();
});
},
}, {

searchByQuery: function(query) {
this.changeQuery(query);
this.searchLFMFriends();
this.searchFriends();
},
'compx-can_search': [['can_share']],
'compx-can_share':{
depends_on: ['^^active_view', '#lfm_userid'],
fn: function(active_view, lfm_userid) {
return lfm_userid && active_view;
}
},
searchLFMFriends: function(){
searchFriends: function(){
var list = this.getNesting('friends') || [];
var query = this.state('query');
if (!this.state('can_share')){
if (!this.state('can_search')){
return;
}
var r = (query ? spv.searchInArray(list, query, ["states.userid", "states.realname"]) : list);
if (r.length){
r = r.concat();
r = r.slice();
for (var i = 0; i < r.length; i++) {
r[i] = {
mo: this.mo,
Expand Down Expand Up @@ -282,7 +294,7 @@ var LFMOneUserSection = spv.inh(invstg.SearchSection, {

target.wch(target, 'can_share', function(e) {
if (e.value){
this.searchLFMFriends();
this.searchFriends();
}
});
}
Expand Down Expand Up @@ -313,7 +325,7 @@ var LFMOneUserSection = spv.inh(invstg.SearchSection, {
this.addRequest(
this.app.lfm
.get('user.getInfo', {user: q})
.done(function(r){
.then(function(r){
if (!_this.doesNeed(q)){return;}
_this.loaded();

Expand All @@ -332,14 +344,12 @@ var LFMOneUserSection = spv.inh(invstg.SearchSection, {
//r = r && parser(r, this.resItem, method);
_this.appendResults(result, true);


})
.fail(function(){
}, function(){
if (!_this.doesNeed(q)){return;}
_this.loaded();
}));
}, 200),
searchLFMFriends: function(){
searchFriends: function(){
var list = this.getNesting('friends') || [];
var query = this.state('query');
var r = (query ? spv.searchInArray(list, query, ["states.userid", "states.realname"]) : list);
Expand Down

0 comments on commit c579a0f

Please sign in to comment.