2013-08-19 22:30:57 +09:00
|
|
|
|
2015-06-02 01:27:36 +09:00
|
|
|
/*· · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · ·
|
|
|
|
· ·
|
|
|
|
· ·
|
|
|
|
· Q V I T T E R ·
|
|
|
|
· ·
|
2015-07-02 02:15:31 +09:00
|
|
|
· ·
|
2015-06-02 01:27:36 +09:00
|
|
|
· <o) ·
|
|
|
|
· /_//// ·
|
|
|
|
· (____/ ·
|
|
|
|
· (o< ·
|
|
|
|
· o> \\\\_\ ·
|
2015-07-02 02:15:31 +09:00
|
|
|
· \\) \____) ·
|
|
|
|
· ·
|
2015-06-02 01:27:36 +09:00
|
|
|
· ·
|
|
|
|
· @licstart The following is the entire license notice for the ·
|
|
|
|
· JavaScript code in this page. ·
|
|
|
|
· ·
|
|
|
|
· Copyright (C) 2015 Hannes Mannerheim and other contributors ·
|
2015-07-02 02:15:31 +09:00
|
|
|
· ·
|
2015-06-02 01:27:36 +09:00
|
|
|
· ·
|
|
|
|
· This program is free software: you can redistribute it and/or modify ·
|
|
|
|
· it under the terms of the GNU Affero General Public License as ·
|
|
|
|
· published by the Free Software Foundation, either version 3 of the ·
|
|
|
|
· License, or (at your option) any later version. ·
|
|
|
|
· ·
|
|
|
|
· This program is distributed in the hope that it will be useful, ·
|
|
|
|
· but WITHOUT ANY WARRANTY; without even the implied warranty of ·
|
|
|
|
· MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ·
|
|
|
|
· GNU Affero General Public License for more details. ·
|
|
|
|
· ·
|
|
|
|
· You should have received a copy of the GNU Affero General Public License ·
|
|
|
|
· along with this program. If not, see <http://www.gnu.org/licenses/>. ·
|
|
|
|
· ·
|
2015-07-02 02:15:31 +09:00
|
|
|
· @licend The above is the entire license notice ·
|
|
|
|
· for the JavaScript code in this page. ·
|
|
|
|
· ·
|
2015-06-02 01:27:36 +09:00
|
|
|
· · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · */
|
2015-07-02 02:15:31 +09:00
|
|
|
|
|
|
|
|
|
|
|
/* ·
|
|
|
|
·
|
|
|
|
· Current time in milliseconds, to send with each request to make sure
|
2014-05-16 11:07:30 +09:00
|
|
|
· we're not getting 304 responses.
|
|
|
|
·
|
2015-07-02 02:15:31 +09:00
|
|
|
·
|
|
|
|
· · · · · · · · · · · · · */
|
2014-05-16 11:07:30 +09:00
|
|
|
|
|
|
|
function timeNow() {
|
|
|
|
return new Date().getTime();
|
|
|
|
}
|
|
|
|
|
2013-08-19 22:30:57 +09:00
|
|
|
|
2015-01-26 03:05:09 +09:00
|
|
|
|
2015-07-02 02:15:31 +09:00
|
|
|
/* ·
|
|
|
|
·
|
|
|
|
· Get a document and replace strings
|
2015-01-26 03:05:09 +09:00
|
|
|
·
|
2015-07-02 02:15:31 +09:00
|
|
|
· @param doc: the name of the document
|
|
|
|
· @param actionOnSuccess: callback function to run on success
|
|
|
|
·
|
|
|
|
· · · · · · · · · · · · · */
|
|
|
|
|
2015-01-26 03:05:09 +09:00
|
|
|
function getDoc(doc, actionOnSuccess) {
|
|
|
|
var timeNow = new Date().getTime();
|
2015-11-05 21:27:23 +09:00
|
|
|
|
|
|
|
$.ajax({ url: window.fullUrlToThisQvitterApp + 'doc/' + window.selectedLanguage + '/' + doc + '.html',
|
|
|
|
cache: false,
|
|
|
|
type: "GET",
|
|
|
|
success: function(data) {
|
2015-01-26 03:05:09 +09:00
|
|
|
actionOnSuccess(renderDoc(data));
|
2015-11-05 21:27:23 +09:00
|
|
|
},
|
|
|
|
error: function() {
|
|
|
|
// default to english if we can't find the doc in selected language
|
|
|
|
$.ajax({ url: window.fullUrlToThisQvitterApp + 'doc/en/' + doc + '.html',
|
|
|
|
cache: false,
|
|
|
|
type: "GET",
|
|
|
|
success: function(data) {
|
2015-01-26 03:05:09 +09:00
|
|
|
actionOnSuccess(renderDoc(data));
|
|
|
|
}
|
2015-07-02 02:15:31 +09:00
|
|
|
});
|
2015-11-05 21:27:23 +09:00
|
|
|
}
|
|
|
|
});
|
2015-07-02 02:15:31 +09:00
|
|
|
}
|
2015-01-26 03:05:09 +09:00
|
|
|
function renderDoc(docHtml) {
|
|
|
|
docHtml = docHtml.replace(/{instance-name}/g,window.siteTitle);
|
|
|
|
docHtml = docHtml.replace(/{instance-url}/g,window.siteRootDomain);
|
|
|
|
docHtml = docHtml.replace(/{instance-url-with-protocol}/g,window.siteInstanceURL);
|
|
|
|
docHtml = docHtml.replace(/{nickname}/g,window.loggedIn.screen_name);
|
|
|
|
docHtml = docHtml.replace(/{instance-email}/g,window.siteEmail);
|
|
|
|
docHtml = docHtml.replace(/{instance-license-title}/g,window.siteLicenseTitle);
|
2015-07-02 02:15:31 +09:00
|
|
|
docHtml = docHtml.replace(/{instance-license-url}/g,window.siteLicenseURL);
|
|
|
|
return docHtml;
|
2015-01-26 03:05:09 +09:00
|
|
|
}
|
|
|
|
|
2015-07-02 02:15:31 +09:00
|
|
|
/* ·
|
|
|
|
·
|
2013-08-19 22:30:57 +09:00
|
|
|
· Check login credentials with http basic auth
|
2015-07-02 02:15:31 +09:00
|
|
|
·
|
2013-08-19 22:30:57 +09:00
|
|
|
· @param username: users screen name
|
|
|
|
· @param password: users password
|
|
|
|
· @param actionOnSuccess: callback function on log in success
|
2015-07-02 02:15:31 +09:00
|
|
|
·
|
2013-08-19 22:30:57 +09:00
|
|
|
· · · · · · · · · */
|
2015-07-02 02:15:31 +09:00
|
|
|
|
|
|
|
function checkLogin(username,password,actionOnSuccess) {
|
|
|
|
$.ajax({ url: window.apiRoot + 'qvitter/checklogin.json',
|
2015-11-05 21:27:23 +09:00
|
|
|
cache: false,
|
|
|
|
type: 'POST',
|
2015-07-02 02:15:31 +09:00
|
|
|
data: {
|
2014-05-16 19:36:30 +09:00
|
|
|
username: username,
|
|
|
|
password: password
|
2015-07-02 02:15:31 +09:00
|
|
|
},
|
|
|
|
dataType: 'json',
|
2016-02-27 07:18:02 +09:00
|
|
|
error: function(data) {
|
2015-12-04 00:06:02 +09:00
|
|
|
shakeLoginBox();
|
2016-02-27 07:18:02 +09:00
|
|
|
if(data.status === 403) {
|
|
|
|
showErrorMessage(window.sL.silenced);
|
|
|
|
}
|
2013-08-26 03:11:53 +09:00
|
|
|
},
|
2015-07-02 02:15:31 +09:00
|
|
|
success: function(data) {
|
2014-05-16 19:36:30 +09:00
|
|
|
if(typeof data.error == 'undefined' && data !== false) {
|
2013-08-19 22:30:57 +09:00
|
|
|
actionOnSuccess(data);
|
|
|
|
}
|
|
|
|
else {
|
2015-12-04 00:06:02 +09:00
|
|
|
shakeLoginBox();
|
2013-08-19 22:30:57 +09:00
|
|
|
}
|
|
|
|
}
|
2015-07-02 02:15:31 +09:00
|
|
|
});
|
2013-08-19 22:30:57 +09:00
|
|
|
}
|
|
|
|
|
2015-07-02 02:15:31 +09:00
|
|
|
|
|
|
|
/* ·
|
|
|
|
·
|
2013-08-19 22:30:57 +09:00
|
|
|
· Generic API GET request
|
|
|
|
·
|
|
|
|
· @param stream: any api get-request e.g. 'statuses/favs/111111.json'
|
2015-07-02 02:15:31 +09:00
|
|
|
· @param actionOnSuccess: callback function
|
|
|
|
·
|
|
|
|
· · · · · · · · · · · · · */
|
|
|
|
|
2013-08-19 22:30:57 +09:00
|
|
|
function getFromAPI(stream, actionOnSuccess) {
|
2015-11-05 21:27:23 +09:00
|
|
|
var url = window.apiRoot + stream;
|
2015-09-29 23:31:05 +09:00
|
|
|
$.ajax({ url: url,
|
2015-11-05 21:27:23 +09:00
|
|
|
cache: false,
|
2015-07-02 02:15:31 +09:00
|
|
|
type: "GET",
|
|
|
|
dataType: 'json',
|
2014-10-18 02:06:29 +09:00
|
|
|
statusCode: {
|
2015-07-02 02:15:31 +09:00
|
|
|
401:function() {
|
|
|
|
location.reload(); // we may have been logged out in another tab, reload page
|
|
|
|
}
|
2014-10-18 02:06:29 +09:00
|
|
|
},
|
2015-07-02 02:15:31 +09:00
|
|
|
success: function(data, textStatus, request) {
|
|
|
|
|
2015-09-29 23:31:05 +09:00
|
|
|
// if there's no Qvitter-Notifications header, it means we're logged out
|
|
|
|
// so if it's missing and Qvitter still thinks we're logged in, reload page
|
|
|
|
// we've probably been logged out in another tab or something
|
|
|
|
if(request.getResponseHeader('Qvitter-Notifications') === null && window.loggedIn !== false) {
|
|
|
|
location.reload();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-07-02 02:15:31 +09:00
|
|
|
displayOrHideUnreadNotifications(request.getResponseHeader('Qvitter-Notifications'));
|
2014-05-23 21:13:38 +09:00
|
|
|
|
2015-09-18 10:04:28 +09:00
|
|
|
// parse and cache any user arrays in header
|
|
|
|
var userArray = false;
|
2015-06-03 06:45:46 +09:00
|
|
|
if(request.getResponseHeader('Qvitter-User-Array') !== null) {
|
2015-09-18 10:04:28 +09:00
|
|
|
var qvitterUserArrayHeader = request.getResponseHeader('Qvitter-User-Array');
|
2015-07-02 02:15:31 +09:00
|
|
|
|
2015-09-18 10:04:28 +09:00
|
|
|
// quitter.se fix
|
|
|
|
if(window.thisSiteThinksItIsHttpButIsActuallyHttps) {
|
|
|
|
qvitterUserArrayHeader = qvitterUserArrayHeader.replace(new RegExp('http:\\\\/\\\\/' + window.siteRootDomain, 'g'), 'https:\/\/' + window.siteRootDomain);
|
|
|
|
}
|
2015-07-02 02:15:31 +09:00
|
|
|
|
2015-09-18 10:04:28 +09:00
|
|
|
userArray = iterateRecursiveReplaceHtmlSpecialChars($.parseJSON(qvitterUserArrayHeader));
|
|
|
|
userArrayCacheStore(userArray);
|
2015-06-03 06:45:46 +09:00
|
|
|
}
|
2015-07-02 02:15:31 +09:00
|
|
|
|
|
|
|
data = convertEmptyObjectToEmptyArray(data);
|
2015-01-19 04:36:08 +09:00
|
|
|
data = iterateRecursiveReplaceHtmlSpecialChars(data);
|
2015-06-05 09:17:33 +09:00
|
|
|
searchForUserDataToCache(data);
|
2015-12-04 05:41:00 +09:00
|
|
|
updateUserDataInStream();
|
2015-11-23 08:24:33 +09:00
|
|
|
searchForUpdatedNoticeData(data);
|
2015-01-19 04:36:08 +09:00
|
|
|
|
2015-09-29 23:31:05 +09:00
|
|
|
actionOnSuccess(data, userArray, request, url);
|
2014-05-16 11:07:30 +09:00
|
|
|
},
|
2016-03-21 06:32:36 +09:00
|
|
|
error: function(data, textStatus, errorThrown) {
|
|
|
|
data.textStatus = textStatus;
|
|
|
|
data.errorThrown = errorThrown;
|
2015-09-29 23:31:05 +09:00
|
|
|
actionOnSuccess(false, false, data, url);
|
2015-07-02 02:15:31 +09:00
|
|
|
remove_spinner();
|
2014-05-16 11:07:30 +09:00
|
|
|
}
|
2015-07-02 02:15:31 +09:00
|
|
|
});
|
|
|
|
}
|
2013-08-19 22:30:57 +09:00
|
|
|
|
2015-11-18 06:48:28 +09:00
|
|
|
/* ·
|
|
|
|
·
|
|
|
|
· Hello to the API! When saying hello you will e.g. also get headers
|
|
|
|
· with up-to-date unread notifications count to update etc
|
|
|
|
·
|
|
|
|
· @param callback: function to invoke when done
|
|
|
|
·
|
|
|
|
· · · · · · · · · · · · · */
|
|
|
|
|
|
|
|
function helloAPI(callback) {
|
|
|
|
getFromAPI('qvitter/hello.json',function(){
|
|
|
|
if(typeof callback == 'function') {
|
|
|
|
callback();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2013-08-19 22:30:57 +09:00
|
|
|
|
2015-11-19 00:38:19 +09:00
|
|
|
/* ·
|
|
|
|
·
|
|
|
|
· Get all people we follow, all groups we're in and everyone we've blocked
|
|
|
|
· Store in global objects
|
|
|
|
·
|
|
|
|
· @param callback: function to invoke when done
|
|
|
|
·
|
|
|
|
· · · · · · · · · · · · · */
|
|
|
|
|
|
|
|
function getAllFollowsMembershipsAndBlocks(callback) {
|
|
|
|
|
|
|
|
if(window.loggedIn === false) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
window.following = new Object();
|
|
|
|
window.groupMemberships = new Object();
|
|
|
|
window.groupNicknamesAndLocalAliases = new Array();
|
|
|
|
window.allBlocking = new Array();
|
|
|
|
|
|
|
|
getFromAPI('qvitter/allfollowing/' + window.loggedIn.screen_name + '.json',function(data){
|
|
|
|
|
|
|
|
if(data.users) {
|
|
|
|
$.each(data.users,function(k,v){
|
|
|
|
if(v[2] === false) { var avatar = window.defaultAvatarStreamSize; }
|
|
|
|
else { var avatar = v[2]; }
|
|
|
|
if(v[3]) {
|
|
|
|
// extract server base url
|
|
|
|
v[3] = v[3].substring(v[3].indexOf('://')+3,v[3].lastIndexOf(v[1])-1);
|
|
|
|
}
|
|
|
|
v[0] = v[0] || v[1]; // if name is null we go with username there too
|
|
|
|
window.following[k] = { 'id': k,'name': v[0], 'username': v[1],'avatar': avatar, 'url':v[3] };
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
if(data.groups) {
|
|
|
|
$.each(data.groups,function(k,v){
|
|
|
|
if(v[2] === false || v[2] === null) { var avatar = window.defaultAvatarStreamSize; }
|
|
|
|
else { var avatar = v[2]; }
|
|
|
|
if(v[3]) {
|
|
|
|
// extract server base url
|
|
|
|
v[3] = v[3].substring(v[3].indexOf('://')+3);
|
|
|
|
v[3] = v[3].substring(0, v[3].indexOf('/'));
|
|
|
|
}
|
|
|
|
v[0] = v[0] || v[1]; // if name is null we go with username there too
|
|
|
|
window.groupMemberships[k] = { 'id': k,'name': v[0], 'username': v[1],'avatar': avatar, 'url':v[3] };
|
|
|
|
window.groupNicknamesAndLocalAliases[k] = v[1];
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
if(data.blocks) {
|
|
|
|
window.allBlocking = data.blocks;
|
2016-03-01 03:36:50 +09:00
|
|
|
markAllNoticesFromBlockedUsersAsBlockedInJQueryObject($('body'));
|
2015-11-23 08:24:33 +09:00
|
|
|
}
|
2015-11-19 00:38:19 +09:00
|
|
|
|
|
|
|
if(typeof callback == 'function') {
|
|
|
|
callback();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2015-09-18 08:42:52 +09:00
|
|
|
/* ·
|
|
|
|
·
|
2015-09-18 20:42:19 +09:00
|
|
|
· Get user nickname by user id
|
2015-09-18 08:42:52 +09:00
|
|
|
·
|
|
|
|
· @param id: local user id
|
|
|
|
· @param callback: function to invoke when done
|
|
|
|
·
|
|
|
|
· · · · · · · · · · · · · */
|
|
|
|
|
2015-09-18 20:42:19 +09:00
|
|
|
function getNicknameByUserIdFromAPI(id, callback) {
|
|
|
|
display_spinner();
|
2015-09-18 08:42:52 +09:00
|
|
|
getFromAPI('users/show.json?id=' + id, function(data){
|
2015-09-18 20:42:19 +09:00
|
|
|
remove_spinner();
|
2015-09-18 08:42:52 +09:00
|
|
|
if(data && typeof data.screen_name != 'undefined') {
|
|
|
|
callback(data.screen_name);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
callback(false);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-09-21 09:00:03 +09:00
|
|
|
/* ·
|
|
|
|
·
|
|
|
|
· Get group nickname by group id
|
|
|
|
·
|
|
|
|
· @param id: local group id
|
|
|
|
· @param callback: function to invoke when done
|
|
|
|
·
|
|
|
|
· · · · · · · · · · · · · */
|
|
|
|
|
|
|
|
function getNicknameByGroupIdFromAPI(id, callback) {
|
|
|
|
display_spinner();
|
|
|
|
getFromAPI('statusnet/groups/show/' + id + '.json', function(data){
|
|
|
|
remove_spinner();
|
|
|
|
if(data && typeof data.nickname != 'undefined') {
|
|
|
|
callback(data.nickname);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
callback(false);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-09-01 06:53:09 +09:00
|
|
|
/* ·
|
|
|
|
·
|
|
|
|
· Update the bookmarks
|
|
|
|
·
|
|
|
|
· @param newBookmarks: the new bookmarks object to save
|
|
|
|
·
|
|
|
|
· · · · · · · · · · · · · */
|
|
|
|
|
|
|
|
function postUpdateBookmarks(newBookmarks) {
|
|
|
|
var bookmarksString = JSON.stringify(newBookmarks);
|
2015-11-05 21:27:23 +09:00
|
|
|
$.ajax({ url: window.apiRoot + 'qvitter/update_bookmarks.json',
|
|
|
|
cache: false,
|
2015-09-01 06:53:09 +09:00
|
|
|
type: "POST",
|
2016-12-30 21:25:38 +09:00
|
|
|
beforeSend: function (xhr) {
|
|
|
|
xhr.setRequestHeader('X-Qvitter-CSRF', getCookieValue('Qvitter-CSRF'));
|
|
|
|
},
|
2015-09-01 06:53:09 +09:00
|
|
|
data: {
|
|
|
|
bookmarks: bookmarksString
|
|
|
|
},
|
|
|
|
dataType:"json",
|
|
|
|
error: function(data){ console.log('error updating bookmarks'); },
|
|
|
|
success: function(data) {
|
|
|
|
// console.log('bookmarks updated successfully');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2015-01-19 04:36:08 +09:00
|
|
|
|
2015-07-02 02:15:31 +09:00
|
|
|
/* ·
|
|
|
|
·
|
2013-08-26 03:11:53 +09:00
|
|
|
· Post new link color
|
|
|
|
·
|
|
|
|
· @param newLinkColor: the new link color in hex without #
|
2015-07-02 02:15:31 +09:00
|
|
|
·
|
|
|
|
· · · · · · · · · · · · · */
|
2013-08-26 03:11:53 +09:00
|
|
|
|
|
|
|
function postNewLinkColor(newLinkColor) {
|
2015-11-05 21:27:23 +09:00
|
|
|
$.ajax({ url: window.apiRoot + 'qvitter/update_link_color.json',
|
|
|
|
cache: false,
|
2015-07-02 02:15:31 +09:00
|
|
|
type: "POST",
|
2016-12-30 21:25:38 +09:00
|
|
|
beforeSend: function (xhr) {
|
|
|
|
xhr.setRequestHeader('X-Qvitter-CSRF', getCookieValue('Qvitter-CSRF'));
|
|
|
|
},
|
2015-07-02 02:15:31 +09:00
|
|
|
data: {
|
2014-05-16 11:07:30 +09:00
|
|
|
linkcolor: newLinkColor
|
2013-08-26 03:11:53 +09:00
|
|
|
},
|
|
|
|
dataType:"json",
|
|
|
|
error: function(data){ console.log(data); },
|
2015-07-02 02:15:31 +09:00
|
|
|
success: function(data) {
|
2013-08-26 05:34:09 +09:00
|
|
|
window.userLinkColor = newLinkColor;
|
|
|
|
}
|
2015-07-02 02:15:31 +09:00
|
|
|
});
|
2013-08-26 03:11:53 +09:00
|
|
|
}
|
2015-07-02 02:15:31 +09:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* ·
|
|
|
|
·
|
2013-08-26 05:34:09 +09:00
|
|
|
· Post new background color
|
|
|
|
·
|
|
|
|
· @param newBackgroundColor: the new background color in hex without #
|
2015-07-02 02:15:31 +09:00
|
|
|
·
|
|
|
|
· · · · · · · · · · · · · */
|
2013-08-26 05:34:09 +09:00
|
|
|
|
|
|
|
function postNewBackgroundColor(newBackgroundColor) {
|
2015-11-05 21:27:23 +09:00
|
|
|
$.ajax({ url: window.apiRoot + 'qvitter/update_background_color.json',
|
|
|
|
cache: false,
|
2015-07-02 02:15:31 +09:00
|
|
|
type: "POST",
|
2016-12-30 21:25:38 +09:00
|
|
|
beforeSend: function (xhr) {
|
|
|
|
xhr.setRequestHeader('X-Qvitter-CSRF', getCookieValue('Qvitter-CSRF'));
|
|
|
|
},
|
2015-07-02 02:15:31 +09:00
|
|
|
data: {
|
2014-05-16 11:07:30 +09:00
|
|
|
backgroundcolor: newBackgroundColor
|
2013-08-26 05:34:09 +09:00
|
|
|
},
|
|
|
|
dataType:"json",
|
|
|
|
error: function(data){ console.log(data); },
|
2015-07-02 02:15:31 +09:00
|
|
|
success: function(data) {
|
2015-05-30 00:30:03 +09:00
|
|
|
// unset background image and set new color
|
|
|
|
window.loggedIn.background_image = false;
|
|
|
|
changeDesign({backgroundimage:false,backgroundcolor:newBackgroundColor});
|
2013-08-26 05:34:09 +09:00
|
|
|
}
|
2015-07-02 02:15:31 +09:00
|
|
|
});
|
2013-08-26 05:34:09 +09:00
|
|
|
}
|
2013-08-26 03:11:53 +09:00
|
|
|
|
2015-07-02 02:15:31 +09:00
|
|
|
|
2015-11-18 06:48:28 +09:00
|
|
|
/* ·
|
|
|
|
·
|
|
|
|
· Set a profile pref
|
|
|
|
·
|
|
|
|
· @param namespace: the namespace field in the db table, should be 'qvitter'
|
|
|
|
· @param topic: the topic field in the db table,
|
|
|
|
· @param data: the data to set
|
|
|
|
· @param callback: function to run when finished
|
|
|
|
·
|
|
|
|
· · · · · · · · · · · · · */
|
|
|
|
|
|
|
|
function postSetProfilePref(namespace, topic, data, callback) {
|
|
|
|
$.ajax({ url: window.apiRoot + 'qvitter/set_profile_pref.json',
|
|
|
|
cache: false,
|
|
|
|
type: "POST",
|
2016-12-30 21:25:38 +09:00
|
|
|
beforeSend: function (xhr) {
|
|
|
|
xhr.setRequestHeader('X-Qvitter-CSRF', getCookieValue('Qvitter-CSRF'));
|
|
|
|
},
|
2015-11-18 06:48:28 +09:00
|
|
|
data: {
|
|
|
|
namespace: namespace,
|
|
|
|
topic: topic,
|
|
|
|
data: data
|
|
|
|
},
|
|
|
|
dataType:"json",
|
|
|
|
error: function(data){ callback(false); },
|
|
|
|
success: function(data) {
|
|
|
|
callback(data); }
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-07-02 02:15:31 +09:00
|
|
|
|
|
|
|
/* ·
|
|
|
|
·
|
2013-08-19 22:30:57 +09:00
|
|
|
· Post follow or unfollow user request
|
|
|
|
·
|
|
|
|
· @param followOrUnfollow: either 'follow' or 'unfollow'
|
|
|
|
· @param user_id: the user id of the user we want to follow
|
|
|
|
· @param actionOnSuccess: callback function, false on error, data on success
|
2015-07-02 02:15:31 +09:00
|
|
|
·
|
|
|
|
· · · · · · · · · · · · · */
|
|
|
|
|
2013-08-19 22:30:57 +09:00
|
|
|
function APIFollowOrUnfollowUser(followOrUnfollow,user_id,this_element,actionOnSuccess) {
|
2015-07-02 02:15:31 +09:00
|
|
|
|
2013-08-19 22:30:57 +09:00
|
|
|
if(followOrUnfollow == 'follow') {
|
2015-11-05 21:27:23 +09:00
|
|
|
var postRequest = 'friendships/create.json';
|
2013-08-19 22:30:57 +09:00
|
|
|
}
|
|
|
|
else if (followOrUnfollow == 'unfollow') {
|
2015-11-05 21:27:23 +09:00
|
|
|
var postRequest = 'friendships/destroy.json';
|
2013-08-19 22:30:57 +09:00
|
|
|
}
|
2015-07-02 02:15:31 +09:00
|
|
|
|
|
|
|
$.ajax({ url: window.apiRoot + postRequest,
|
2015-11-05 21:27:23 +09:00
|
|
|
cache: false,
|
2015-07-02 02:15:31 +09:00
|
|
|
type: "POST",
|
2016-12-30 21:25:38 +09:00
|
|
|
beforeSend: function (xhr) {
|
|
|
|
xhr.setRequestHeader('X-Qvitter-CSRF', getCookieValue('Qvitter-CSRF'));
|
|
|
|
},
|
2015-07-02 02:15:31 +09:00
|
|
|
data: {
|
2014-05-16 11:07:30 +09:00
|
|
|
user_id: user_id
|
2013-08-19 22:30:57 +09:00
|
|
|
},
|
|
|
|
dataType:"json",
|
|
|
|
error: function(data){ actionOnSuccess(false,this_element); console.log(data); },
|
2015-09-15 10:58:11 +09:00
|
|
|
success: function(data) {
|
|
|
|
data = convertEmptyObjectToEmptyArray(data);
|
|
|
|
data = iterateRecursiveReplaceHtmlSpecialChars(data);
|
|
|
|
searchForUserDataToCache(data);
|
2015-12-04 05:41:00 +09:00
|
|
|
updateUserDataInStream();
|
2015-09-15 10:58:11 +09:00
|
|
|
actionOnSuccess(data,this_element);
|
|
|
|
}
|
2015-07-02 02:15:31 +09:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2016-02-02 08:44:44 +09:00
|
|
|
/* ·
|
|
|
|
·
|
2016-03-01 09:08:55 +09:00
|
|
|
· Post block or unblock user request
|
2016-02-02 08:44:44 +09:00
|
|
|
·
|
2016-03-01 09:08:55 +09:00
|
|
|
· @param blockOrUnblock: either 'block' or 'unblock'
|
|
|
|
· @param user_id: the user id of the user we want to block/unblock
|
2016-02-02 08:44:44 +09:00
|
|
|
· @param actionOnSuccess: callback function, false on error, data on success
|
|
|
|
·
|
|
|
|
· · · · · · · · · · · · · */
|
|
|
|
|
|
|
|
function APIBlockOrUnblockUser(blockOrUnblock,user_id,actionOnSuccess) {
|
|
|
|
|
|
|
|
if(blockOrUnblock == 'block') {
|
|
|
|
var postRequest = 'blocks/create.json';
|
|
|
|
}
|
|
|
|
else if (blockOrUnblock == 'unblock') {
|
|
|
|
var postRequest = 'blocks/destroy.json';
|
|
|
|
}
|
|
|
|
|
|
|
|
$.ajax({ url: window.apiRoot + postRequest,
|
|
|
|
cache: false,
|
|
|
|
type: "POST",
|
2016-12-30 21:25:38 +09:00
|
|
|
beforeSend: function (xhr) {
|
|
|
|
xhr.setRequestHeader('X-Qvitter-CSRF', getCookieValue('Qvitter-CSRF'));
|
|
|
|
},
|
2016-02-02 08:44:44 +09:00
|
|
|
data: {
|
|
|
|
id: user_id
|
|
|
|
},
|
|
|
|
dataType:"json",
|
|
|
|
error: function(data){ actionOnSuccess(false); console.log(data); },
|
|
|
|
success: function(data) {
|
|
|
|
data = convertEmptyObjectToEmptyArray(data);
|
|
|
|
data = iterateRecursiveReplaceHtmlSpecialChars(data);
|
|
|
|
searchForUserDataToCache(data);
|
|
|
|
updateUserDataInStream();
|
|
|
|
actionOnSuccess(data);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-03-01 09:08:55 +09:00
|
|
|
/* ·
|
|
|
|
·
|
|
|
|
· Post sandbox or unsandbox user request
|
|
|
|
·
|
|
|
|
· @param createOrDestroy: either 'create' or 'destroy'
|
|
|
|
· @param userId: the user id of the user we want to sandbox/unsandbox
|
|
|
|
· @param actionOnSuccess: callback function, false on error, data on success
|
|
|
|
·
|
|
|
|
· · · · · · · · · · · · · */
|
|
|
|
|
|
|
|
function APISandboxCreateOrDestroy(createOrDestroy,userId,actionOnSuccess) {
|
|
|
|
$.ajax({ url: window.apiRoot + 'qvitter/sandbox/' + createOrDestroy + '.json',
|
|
|
|
cache: false,
|
|
|
|
type: "POST",
|
2016-12-30 21:25:38 +09:00
|
|
|
beforeSend: function (xhr) {
|
|
|
|
xhr.setRequestHeader('X-Qvitter-CSRF', getCookieValue('Qvitter-CSRF'));
|
|
|
|
},
|
2016-03-01 09:08:55 +09:00
|
|
|
data: {
|
|
|
|
id: userId
|
|
|
|
},
|
|
|
|
dataType:"json",
|
|
|
|
error: function(data){ actionOnSuccess(false); console.log('sandbox error'); console.log(data); },
|
|
|
|
success: function(data) {
|
|
|
|
data = convertEmptyObjectToEmptyArray(data);
|
|
|
|
data = iterateRecursiveReplaceHtmlSpecialChars(data);
|
|
|
|
searchForUserDataToCache(data);
|
|
|
|
updateUserDataInStream();
|
2016-03-01 09:58:12 +09:00
|
|
|
rememberStreamStateInLocalStorage();
|
2016-03-01 09:08:55 +09:00
|
|
|
actionOnSuccess(data);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ·
|
|
|
|
·
|
|
|
|
· Post silence or unsilence user request
|
|
|
|
·
|
|
|
|
· @param createOrDestroy: either 'create' or 'destroy'
|
|
|
|
· @param userId: the user id of the user we want to silence/unsilence
|
|
|
|
· @param actionOnSuccess: callback function, false on error, data on success
|
|
|
|
·
|
|
|
|
· · · · · · · · · · · · · */
|
|
|
|
|
|
|
|
function APISilenceCreateOrDestroy(createOrDestroy,userId,actionOnSuccess) {
|
|
|
|
$.ajax({ url: window.apiRoot + 'qvitter/silence/' + createOrDestroy + '.json',
|
|
|
|
cache: false,
|
|
|
|
type: "POST",
|
2016-12-30 21:25:38 +09:00
|
|
|
beforeSend: function (xhr) {
|
|
|
|
xhr.setRequestHeader('X-Qvitter-CSRF', getCookieValue('Qvitter-CSRF'));
|
|
|
|
},
|
2016-03-01 09:08:55 +09:00
|
|
|
data: {
|
|
|
|
id: userId
|
|
|
|
},
|
|
|
|
dataType:"json",
|
|
|
|
error: function(data){ actionOnSuccess(false); console.log('silence error'); console.log(data); },
|
|
|
|
success: function(data) {
|
|
|
|
data = convertEmptyObjectToEmptyArray(data);
|
|
|
|
data = iterateRecursiveReplaceHtmlSpecialChars(data);
|
|
|
|
searchForUserDataToCache(data);
|
|
|
|
updateUserDataInStream();
|
2016-03-01 09:58:12 +09:00
|
|
|
rememberStreamStateInLocalStorage();
|
2016-03-01 09:08:55 +09:00
|
|
|
actionOnSuccess(data);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-07-02 02:15:31 +09:00
|
|
|
|
|
|
|
/* ·
|
|
|
|
·
|
2013-08-19 22:30:57 +09:00
|
|
|
· Post join or leave group request
|
|
|
|
·
|
|
|
|
· @param joinOrLeave: either 'join' or 'leave'
|
|
|
|
· @param group_id: group's id
|
|
|
|
· @param actionOnSuccess: callback function, false on error, data on success
|
2015-07-02 02:15:31 +09:00
|
|
|
·
|
|
|
|
· · · · · · · · · · · · · */
|
|
|
|
|
2013-08-19 22:30:57 +09:00
|
|
|
function APIJoinOrLeaveGroup(joinOrLeave,group_id,this_element,actionOnSuccess) {
|
2015-11-05 21:27:23 +09:00
|
|
|
$.ajax({ url: window.apiRoot + 'statusnet/groups/' + joinOrLeave + '.json',
|
|
|
|
cache: false,
|
2015-07-02 02:15:31 +09:00
|
|
|
type: "POST",
|
2016-12-30 21:25:38 +09:00
|
|
|
beforeSend: function (xhr) {
|
|
|
|
xhr.setRequestHeader('X-Qvitter-CSRF', getCookieValue('Qvitter-CSRF'));
|
|
|
|
},
|
2015-07-02 02:15:31 +09:00
|
|
|
data: {
|
2014-05-16 11:07:30 +09:00
|
|
|
id: group_id
|
2013-08-19 22:30:57 +09:00
|
|
|
},
|
|
|
|
dataType:"json",
|
|
|
|
error: function(data){ actionOnSuccess(false,this_element); console.log(data); },
|
2015-09-15 10:58:11 +09:00
|
|
|
success: function(data) {
|
|
|
|
data = convertEmptyObjectToEmptyArray(data);
|
|
|
|
data = iterateRecursiveReplaceHtmlSpecialChars(data);
|
|
|
|
searchForUserDataToCache(data);
|
2015-12-04 05:41:00 +09:00
|
|
|
updateUserDataInStream();
|
2015-09-15 10:58:11 +09:00
|
|
|
actionOnSuccess(data,this_element);
|
|
|
|
}
|
2015-07-02 02:15:31 +09:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2013-08-19 22:30:57 +09:00
|
|
|
|
2015-07-02 02:15:31 +09:00
|
|
|
/* ·
|
|
|
|
·
|
2014-05-28 03:40:51 +09:00
|
|
|
· Post queet
|
2013-08-19 22:30:57 +09:00
|
|
|
·
|
|
|
|
· @param queetText_txt: the text to post
|
|
|
|
· @param in_reply_to_status_id: the local id for the queet to reply to
|
2015-08-26 06:27:08 +09:00
|
|
|
· @param postToGroups: post the queet in these groups, string of ids separated by colon expected, e.g. 5:2:4
|
2013-08-19 22:30:57 +09:00
|
|
|
· @param actionOnSuccess: callback function, false on error, data on success
|
2015-07-02 02:15:31 +09:00
|
|
|
·
|
|
|
|
· · · · · · · · · · · · · */
|
|
|
|
|
2015-08-26 06:27:08 +09:00
|
|
|
function postQueetToAPI(queetText_txt, in_reply_to_status_id, postToGroups, actionOnSuccess) {
|
2016-01-15 04:50:17 +09:00
|
|
|
$.ajax({ url: window.apiRoot + 'qvitter/statuses/update.json',
|
2015-11-05 21:27:23 +09:00
|
|
|
cache: false,
|
2015-07-02 02:15:31 +09:00
|
|
|
type: "POST",
|
2016-12-30 21:25:38 +09:00
|
|
|
beforeSend: function (xhr) {
|
|
|
|
xhr.setRequestHeader('X-Qvitter-CSRF', getCookieValue('Qvitter-CSRF'));
|
|
|
|
},
|
2015-07-02 02:15:31 +09:00
|
|
|
data: {
|
2013-08-19 22:30:57 +09:00
|
|
|
status: queetText_txt,
|
|
|
|
source: 'Qvitter',
|
2015-08-26 06:27:08 +09:00
|
|
|
in_reply_to_status_id: in_reply_to_status_id,
|
|
|
|
post_to_groups: postToGroups
|
2013-08-19 22:30:57 +09:00
|
|
|
},
|
|
|
|
dataType:"json",
|
|
|
|
error: function(data){ actionOnSuccess(false); console.log(data); },
|
2015-09-06 07:26:33 +09:00
|
|
|
success: function(data) {
|
2015-09-15 10:58:11 +09:00
|
|
|
data = convertEmptyObjectToEmptyArray(data);
|
2015-09-06 07:26:33 +09:00
|
|
|
data = iterateRecursiveReplaceHtmlSpecialChars(data);
|
2015-09-15 10:58:11 +09:00
|
|
|
searchForUserDataToCache(data);
|
2015-12-04 05:41:00 +09:00
|
|
|
updateUserDataInStream();
|
2015-11-23 10:23:44 +09:00
|
|
|
searchForUpdatedNoticeData(data);
|
2015-09-06 07:26:33 +09:00
|
|
|
actionOnSuccess(data);
|
|
|
|
}
|
2015-07-02 02:15:31 +09:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* ·
|
|
|
|
·
|
2013-08-19 22:30:57 +09:00
|
|
|
· Generic POST-action
|
|
|
|
·
|
|
|
|
· @param action: the api action, e.q. 'statuses/retweet/1.json'
|
|
|
|
· @param actionOnSuccess: callback function, false on error, data on success
|
2015-07-02 02:15:31 +09:00
|
|
|
·
|
|
|
|
· · · · · · · · · · · · · */
|
|
|
|
|
2013-08-19 22:30:57 +09:00
|
|
|
function postActionToAPI(action, actionOnSuccess) {
|
2015-11-05 21:27:23 +09:00
|
|
|
$.ajax({ url: window.apiRoot + action,
|
|
|
|
cache: false,
|
2015-07-02 02:15:31 +09:00
|
|
|
type: "POST",
|
2016-12-30 21:25:38 +09:00
|
|
|
beforeSend: function (xhr) {
|
|
|
|
xhr.setRequestHeader('X-Qvitter-CSRF', getCookieValue('Qvitter-CSRF'));
|
|
|
|
},
|
2015-07-02 02:15:31 +09:00
|
|
|
data: {
|
2014-05-16 11:07:30 +09:00
|
|
|
source: 'Qvitter'
|
2013-08-19 22:30:57 +09:00
|
|
|
},
|
|
|
|
dataType:"json",
|
|
|
|
error: function(data){ actionOnSuccess(false); console.log(data); },
|
2015-07-02 02:15:31 +09:00
|
|
|
success: function(data) {
|
|
|
|
data = convertEmptyObjectToEmptyArray(data);
|
2015-09-15 10:58:11 +09:00
|
|
|
data = iterateRecursiveReplaceHtmlSpecialChars(data);
|
|
|
|
searchForUserDataToCache(data);
|
2015-12-04 05:41:00 +09:00
|
|
|
updateUserDataInStream();
|
2015-11-23 10:23:44 +09:00
|
|
|
searchForUpdatedNoticeData(data);
|
2014-05-23 21:13:38 +09:00
|
|
|
actionOnSuccess(data);
|
|
|
|
}
|
2015-07-02 02:15:31 +09:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-08-19 22:30:57 +09:00
|
|
|
|
2015-07-02 02:15:31 +09:00
|
|
|
/* ·
|
|
|
|
·
|
2013-08-19 22:30:57 +09:00
|
|
|
· Gets favs or requeets for a queet from api
|
2015-07-02 02:15:31 +09:00
|
|
|
·
|
2015-02-26 05:16:24 +09:00
|
|
|
· @param q: stream item object
|
2013-08-19 22:30:57 +09:00
|
|
|
· @param qid: the queet id
|
2015-07-02 02:15:31 +09:00
|
|
|
·
|
2013-08-19 22:30:57 +09:00
|
|
|
· · · · · · · · · */
|
2015-07-02 02:15:31 +09:00
|
|
|
|
|
|
|
function getFavsAndRequeetsForQueet(q,qid) {
|
2015-02-26 05:16:24 +09:00
|
|
|
|
|
|
|
// get immediately from localstorage cache
|
2015-07-02 23:57:51 +09:00
|
|
|
var cacheData = localStorageObjectCache_GET('favsAndRequeets',qid);
|
|
|
|
if(cacheData) {
|
|
|
|
showFavsAndRequeetsInQueet(q, cacheData);
|
|
|
|
}
|
2015-02-26 05:16:24 +09:00
|
|
|
|
2015-11-05 21:27:23 +09:00
|
|
|
$.ajax({ url: window.apiRoot + "qvitter/favs_and_repeats/" + qid + ".json",
|
|
|
|
cache: false,
|
2015-07-02 02:15:31 +09:00
|
|
|
type: "GET",
|
|
|
|
dataType: 'json',
|
|
|
|
success: function(data) {
|
2015-03-06 06:22:48 +09:00
|
|
|
|
2015-09-15 10:58:11 +09:00
|
|
|
data = iterateRecursiveReplaceHtmlSpecialChars(data);
|
|
|
|
|
2015-06-24 22:34:44 +09:00
|
|
|
if(data.favs.length > 0 || data.repeats.length > 0) {
|
2015-03-06 06:22:48 +09:00
|
|
|
localStorageObjectCache_STORE('favsAndRequeets',qid, data); // cache response
|
2013-08-19 22:30:57 +09:00
|
|
|
}
|
|
|
|
else {
|
2015-02-26 05:16:24 +09:00
|
|
|
// remove from cache and DOM if all favs and repeats are deleted
|
2015-03-06 06:22:48 +09:00
|
|
|
localStorageObjectCache_STORE('favsAndRequeets',qid, false);
|
2013-08-19 22:30:57 +09:00
|
|
|
}
|
2015-06-24 22:34:44 +09:00
|
|
|
|
2015-07-02 02:15:31 +09:00
|
|
|
showFavsAndRequeetsInQueet(q,data);
|
|
|
|
},
|
|
|
|
error: function(data) {
|
2013-08-19 22:30:57 +09:00
|
|
|
remove_spinner();
|
2015-07-02 02:15:31 +09:00
|
|
|
console.log(data);
|
2013-08-19 22:30:57 +09:00
|
|
|
}
|
2015-07-02 02:15:31 +09:00
|
|
|
});
|
2013-08-19 22:30:57 +09:00
|
|
|
}
|