2017-06-07 08:56:42 +03:00
|
|
|
Qt.include("Mastodon.js")
|
2020-06-16 17:09:28 +03:00
|
|
|
|
2023-01-18 13:03:53 +03:00
|
|
|
var debug = false;
|
2017-07-20 13:14:16 +03:00
|
|
|
var loadImages = true;
|
2022-12-16 21:20:07 +03:00
|
|
|
// used to dedupe on append/insert
|
|
|
|
var knownIds = [];
|
2022-12-20 16:33:10 +03:00
|
|
|
var max_id ;
|
2022-12-22 23:32:49 +03:00
|
|
|
var since_id;
|
2020-06-16 17:09:28 +03:00
|
|
|
|
2017-06-07 08:56:42 +03:00
|
|
|
WorkerScript.onMessage = function(msg) {
|
2023-01-03 16:13:23 +03:00
|
|
|
|
2023-01-18 11:20:27 +03:00
|
|
|
if (debug) console.log("Action > " + msg.action)
|
|
|
|
if (debug) console.log("Mode > " + msg.mode)
|
2023-01-03 20:45:22 +03:00
|
|
|
|
2023-01-18 11:20:27 +03:00
|
|
|
// this is not elegant. it's max_id and ids from MyList
|
|
|
|
// we should always get max_id on append
|
2023-01-19 19:49:41 +03:00
|
|
|
if (msg.mode === "append" && msg.params[0]) {
|
2022-12-22 23:32:49 +03:00
|
|
|
if ( msg.params[0]["name"] === "max_id" ) {
|
|
|
|
max_id = msg.params[0]["data"]
|
|
|
|
}
|
2023-01-18 11:20:27 +03:00
|
|
|
} else if ( msg.mode === "prepend" && msg.params[0]) {
|
|
|
|
|
|
|
|
// prepend could be min_id or since_id
|
|
|
|
since_id = msg.params[0]["data"]
|
|
|
|
|
|
|
|
}
|
|
|
|
// ids are always the last param
|
|
|
|
if (msg.params[2]) {
|
2022-12-22 23:32:49 +03:00
|
|
|
if ( msg.params[2]["name"] === "ids" ) {
|
|
|
|
knownIds = msg.params[2]["data"]
|
|
|
|
msg.params.pop()
|
|
|
|
}
|
2022-12-16 21:20:07 +03:00
|
|
|
}
|
2017-06-15 01:48:53 +03:00
|
|
|
|
2022-12-22 23:32:49 +03:00
|
|
|
|
2020-06-22 21:13:05 +03:00
|
|
|
/** order notifications in ASC order */
|
2017-06-15 01:48:53 +03:00
|
|
|
function orderNotifications(items){
|
2020-06-16 17:09:28 +03:00
|
|
|
for (var i = items.length-1; i > 0; i--) {
|
2017-10-25 17:30:23 +03:00
|
|
|
if (items[i].id > 0 ) //msg.conf.notificationLastID)
|
2017-06-15 01:48:53 +03:00
|
|
|
WorkerScript.sendMessage({ 'fireNotification': true, "data": items[i]})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-22 21:13:05 +03:00
|
|
|
/** Logged-in status */
|
2020-06-16 17:09:28 +03:00
|
|
|
if (!msg.conf || !msg.conf.login) {
|
2022-12-20 16:33:10 +03:00
|
|
|
//console.log("Not loggedin")
|
2017-06-07 08:56:42 +03:00
|
|
|
return;
|
|
|
|
}
|
2020-06-16 17:09:28 +03:00
|
|
|
|
2020-06-22 21:13:05 +03:00
|
|
|
/** Load images */
|
2017-07-20 13:14:16 +03:00
|
|
|
if (typeof msg.conf['loadImages'] !== "undefined")
|
|
|
|
loadImages = msg.conf['loadImages']
|
|
|
|
|
2023-01-03 20:45:22 +03:00
|
|
|
|
|
|
|
/* init API statuses */
|
|
|
|
|
2020-06-03 08:34:33 +03:00
|
|
|
var API = mastodonAPI({ instance: msg.conf.instance, api_user_token: msg.conf.api_user_token});
|
2023-01-03 16:13:23 +03:00
|
|
|
|
2023-01-05 11:48:26 +03:00
|
|
|
/*
|
|
|
|
* HEAD call for some actions
|
2023-01-03 20:45:22 +03:00
|
|
|
* we have to retrieve the Link header
|
2023-01-05 11:48:26 +03:00
|
|
|
* this falls through and continues for GET
|
2023-01-03 20:45:22 +03:00
|
|
|
*/
|
|
|
|
|
2023-01-18 13:03:53 +03:00
|
|
|
if (msg.action === "bookmarks" ||
|
|
|
|
( msg.action === "timelines/home" && msg.mode === "append") ||
|
|
|
|
( msg.action.indexOf("timelines/tag/") !== -1 ) ){
|
2023-01-03 20:45:22 +03:00
|
|
|
API.getLink(msg.action, msg.params, function(data) {
|
2023-01-05 11:48:26 +03:00
|
|
|
if (debug) console.log(JSON.stringify(data))
|
|
|
|
WorkerScript.sendMessage({ 'LinkHeader': data })
|
2023-01-03 20:45:22 +03:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/** POST statuses */
|
|
|
|
|
2017-06-07 08:56:42 +03:00
|
|
|
if (msg.method === "POST"){
|
|
|
|
API.post(msg.action, msg.params, function(data) {
|
2017-07-04 02:07:39 +03:00
|
|
|
if (msg.bgAction){
|
2022-12-20 16:33:10 +03:00
|
|
|
//console.log(JSON.stringify(data))
|
2020-06-16 17:09:28 +03:00
|
|
|
} else if (msg.action === "statuses") {
|
2017-06-16 17:45:04 +03:00
|
|
|
// status posted
|
|
|
|
if(msg.model){
|
2017-07-04 02:07:39 +03:00
|
|
|
var item = parseToot(data);
|
|
|
|
msg.model.append(item)
|
2017-06-16 17:45:04 +03:00
|
|
|
msg.model.sync();
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
for (var i in data) {
|
|
|
|
if (data.hasOwnProperty(i)) {
|
2022-12-16 21:20:07 +03:00
|
|
|
//console.log(JSON.stringify(data[i]))
|
2017-06-16 17:45:04 +03:00
|
|
|
WorkerScript.sendMessage({ 'action': msg.action, 'success': true, key: i, "data": data[i]})
|
|
|
|
}
|
2017-06-07 08:56:42 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-01-03 16:13:23 +03:00
|
|
|
API.get(msg.action, msg.params, function(data) {
|
2022-12-16 21:20:07 +03:00
|
|
|
|
2023-01-03 16:13:23 +03:00
|
|
|
var items = [];
|
|
|
|
//console.log(data)
|
2022-12-16 21:20:07 +03:00
|
|
|
|
2017-06-07 08:56:42 +03:00
|
|
|
for (var i in data) {
|
2017-06-14 17:42:28 +03:00
|
|
|
var item;
|
2017-06-07 08:56:42 +03:00
|
|
|
if (data.hasOwnProperty(i)) {
|
2017-06-07 17:09:41 +03:00
|
|
|
if(msg.action === "accounts/search") {
|
2017-10-26 17:23:16 +03:00
|
|
|
item = parseAccounts([], "", data[i]);
|
2022-12-16 21:20:07 +03:00
|
|
|
//console.log(JSON.stringify(data[i]))
|
|
|
|
console.log("has own data")
|
|
|
|
|
2017-06-07 17:09:41 +03:00
|
|
|
items.push(item)
|
2017-06-15 17:03:20 +03:00
|
|
|
|
2017-06-07 17:09:41 +03:00
|
|
|
} else if(msg.action === "notifications") {
|
2017-06-15 17:03:20 +03:00
|
|
|
// notification
|
2022-12-20 16:33:10 +03:00
|
|
|
//console.log("Get notification list")
|
2022-12-16 21:20:07 +03:00
|
|
|
//console.log(JSON.stringify(data[i]))
|
2017-06-14 17:42:28 +03:00
|
|
|
item = parseNotification(data[i]);
|
2022-12-16 21:20:07 +03:00
|
|
|
items.push(item);
|
|
|
|
|
2017-06-15 17:03:20 +03:00
|
|
|
} else if(msg.action.indexOf("statuses") >-1 && msg.action.indexOf("context") >-1 && i === "ancestors") {
|
|
|
|
// status ancestors toots - conversation
|
|
|
|
console.log("ancestors")
|
|
|
|
for (var j = 0; j < data[i].length; j ++) {
|
|
|
|
item = parseToot(data[i][j]);
|
2020-06-22 21:13:05 +03:00
|
|
|
item['id'] = item['status_id'];
|
|
|
|
if (typeof item['attachments'] === "undefined")
|
|
|
|
item['attachments'] = [];
|
2022-12-16 21:20:07 +03:00
|
|
|
// don't permit doubles
|
|
|
|
items.push(item);
|
|
|
|
//console.log(JSON.stringify(data[i][j]))
|
2017-06-15 17:03:20 +03:00
|
|
|
}
|
|
|
|
addDataToModel (msg.model, "prepend", items);
|
|
|
|
items = [];
|
|
|
|
|
|
|
|
//console.log(JSON.stringify(i))
|
|
|
|
} else if(msg.action.indexOf("statuses") >-1 && msg.action.indexOf("context") >-1 && i === "descendants") {
|
2020-06-22 21:13:05 +03:00
|
|
|
// status descendants toots - conversation
|
2017-06-15 17:03:20 +03:00
|
|
|
console.log("descendants")
|
|
|
|
for (var j = 0; j < data[i].length; j ++) {
|
|
|
|
item = parseToot(data[i][j]);
|
2020-01-25 00:11:27 +03:00
|
|
|
item['id'] = item['status_id'];
|
2017-06-22 15:49:39 +03:00
|
|
|
if (typeof item['attachments'] === "undefined")
|
|
|
|
item['attachments'] = [];
|
2022-12-16 21:20:07 +03:00
|
|
|
items.push(item);
|
|
|
|
//console.log(JSON.stringify(data[i][j]))
|
2017-06-15 17:03:20 +03:00
|
|
|
}
|
|
|
|
addDataToModel (msg.model, "append", items);
|
|
|
|
items = [];
|
2020-06-22 21:13:05 +03:00
|
|
|
|
2020-06-03 08:34:33 +03:00
|
|
|
} else if (data[i].hasOwnProperty("content")){
|
2022-12-20 16:33:10 +03:00
|
|
|
//console.log("Get Toot")
|
2017-06-14 17:42:28 +03:00
|
|
|
item = parseToot(data[i]);
|
2017-06-13 17:45:52 +03:00
|
|
|
item['id'] = item['status_id']
|
2022-12-16 21:20:07 +03:00
|
|
|
items.push(item);
|
|
|
|
|
2020-06-22 21:13:05 +03:00
|
|
|
|
2017-06-07 08:56:42 +03:00
|
|
|
} else {
|
2020-06-16 17:09:28 +03:00
|
|
|
WorkerScript.sendMessage({ 'action': msg.action, 'success': true, key: i, "data": data[i] })
|
2017-06-07 08:56:42 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-06-22 21:13:05 +03:00
|
|
|
|
2022-12-16 21:20:07 +03:00
|
|
|
if(msg.model && items.length) {
|
2017-06-07 08:56:42 +03:00
|
|
|
addDataToModel(msg.model, msg.mode, items)
|
2023-01-03 16:13:23 +03:00
|
|
|
} else {
|
|
|
|
// for some reason, home chokes.
|
|
|
|
console.log( "items.length = " + items.length)
|
2022-12-16 21:20:07 +03:00
|
|
|
}
|
2023-01-03 16:13:23 +03:00
|
|
|
|
2017-06-16 17:45:04 +03:00
|
|
|
/*if(msg.action === "notifications")
|
|
|
|
orderNotifications(items)*/
|
2023-01-03 16:13:23 +03:00
|
|
|
|
2022-12-22 23:32:49 +03:00
|
|
|
console.log("Get em all?")
|
2023-01-03 20:45:22 +03:00
|
|
|
|
2022-12-22 23:32:49 +03:00
|
|
|
WorkerScript.sendMessage({ 'updatedAll': true})
|
2017-06-07 08:56:42 +03:00
|
|
|
});
|
|
|
|
}
|
2017-06-15 01:48:53 +03:00
|
|
|
|
2017-06-07 08:56:42 +03:00
|
|
|
//WorkerScript.sendMessage({ 'notifyNewItems': length - i })
|
2022-12-22 23:32:49 +03:00
|
|
|
|
2020-06-16 17:09:28 +03:00
|
|
|
function addDataToModel (model, mode, items) {
|
2022-12-16 21:20:07 +03:00
|
|
|
|
2017-06-07 08:56:42 +03:00
|
|
|
var length = items.length;
|
2022-12-16 21:20:07 +03:00
|
|
|
var i
|
2023-01-03 20:45:22 +03:00
|
|
|
|
2023-01-05 11:48:26 +03:00
|
|
|
if (debug) console.log("Fetched > " +length + " in " + mode)
|
|
|
|
if (debug) console.log("ids > " + knownIds.length )
|
|
|
|
|
2017-06-07 08:56:42 +03:00
|
|
|
if (mode === "append") {
|
2022-12-20 16:33:10 +03:00
|
|
|
for(i = 0; i <= length-1; i++) {
|
|
|
|
if ( knownIds.indexOf( items[i]["id"]) === -1) {
|
2023-01-03 16:13:23 +03:00
|
|
|
model.append(items[i])
|
|
|
|
} else {
|
2023-01-05 11:48:26 +03:00
|
|
|
console.log("nope: " + items[i]["id"] )
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// search does not use ids
|
|
|
|
if ( knownIds.length < 1 ) model.append(items)
|
2023-01-03 16:13:23 +03:00
|
|
|
|
2017-06-07 08:56:42 +03:00
|
|
|
} else if (mode === "prepend") {
|
2022-12-16 21:20:07 +03:00
|
|
|
for(i = length-1; i >= 0 ; i--) {
|
2023-01-05 11:48:26 +03:00
|
|
|
|
2023-01-03 16:13:23 +03:00
|
|
|
model.insert(0,items[i])
|
2023-01-05 11:48:26 +03:00
|
|
|
|
2023-01-03 16:13:23 +03:00
|
|
|
/*if ( knownIds.indexOf( items[i]["id"]) === -1) {
|
2022-12-16 21:20:07 +03:00
|
|
|
model.insert(0,items[i])
|
2023-01-03 16:13:23 +03:00
|
|
|
}*/
|
2017-06-07 08:56:42 +03:00
|
|
|
}
|
|
|
|
}
|
2022-12-20 16:33:10 +03:00
|
|
|
model.sync()
|
2017-06-07 08:56:42 +03:00
|
|
|
}
|
2023-01-03 20:45:22 +03:00
|
|
|
|
2022-12-16 21:20:07 +03:00
|
|
|
function findDuplicate(arr,val) {
|
|
|
|
for(var i=0; i < arr.length; i++){
|
|
|
|
if( arr.indexOf(val) === -1 ) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2023-01-03 20:45:22 +03:00
|
|
|
|
|
|
|
/* Function: Get Account Data */
|
2020-06-16 17:09:28 +03:00
|
|
|
function parseAccounts(collection, prefix, data) {
|
|
|
|
|
|
|
|
var res = collection;
|
|
|
|
// Base attributes
|
2017-06-13 17:45:52 +03:00
|
|
|
res[prefix + 'account_id'] = data["id"]
|
|
|
|
res[prefix + 'account_username'] = data["username"]
|
|
|
|
res[prefix + 'account_acct'] = data["acct"]
|
2020-06-16 17:09:28 +03:00
|
|
|
res[prefix + 'account_url'] = data["url"]
|
|
|
|
// Display attributes
|
2017-06-13 17:45:52 +03:00
|
|
|
res[prefix + 'account_display_name'] = data["display_name"]
|
2020-06-16 17:09:28 +03:00
|
|
|
res[prefix + 'account_note'] = data["note"]
|
2017-06-13 17:45:52 +03:00
|
|
|
res[prefix + 'account_avatar'] = data["avatar"]
|
2020-05-25 18:54:02 +03:00
|
|
|
res[prefix + 'account_header'] = data["header"]
|
2020-06-16 17:09:28 +03:00
|
|
|
res[prefix + 'account_locked'] = data["locked"]
|
|
|
|
//res[prefix + 'account_emojis'] = data["emojis"]
|
|
|
|
res[prefix + 'account_discoverable'] = data["discoverable"]
|
|
|
|
// Statistical attributes
|
|
|
|
res[prefix + 'account_created_at'] = data["created_at"]
|
|
|
|
res[prefix + 'account_statuses_count'] = data["statuses_count"]
|
|
|
|
res[prefix + 'account_followers_count'] = data["followers_count"]
|
|
|
|
res[prefix + 'account_following_count'] = data["following_count"]
|
|
|
|
// Optional attributes
|
|
|
|
//res[prefix + 'account_fields'] = data["fields"]
|
|
|
|
res[prefix + 'account_bot'] = data["bot"]
|
2020-06-18 19:40:24 +03:00
|
|
|
res[prefix + 'account_group'] = data["group"]
|
2017-06-13 17:45:52 +03:00
|
|
|
|
2020-06-16 17:09:28 +03:00
|
|
|
//console.log(JSON.stringify(res))
|
2017-06-13 17:45:52 +03:00
|
|
|
return (res);
|
2017-06-07 17:09:41 +03:00
|
|
|
}
|
|
|
|
|
2020-06-22 21:13:05 +03:00
|
|
|
/** Function: Get Notification Data */
|
2017-06-07 08:56:42 +03:00
|
|
|
function parseNotification(data){
|
2017-06-13 17:45:52 +03:00
|
|
|
//console.log(JSON.stringify(data))
|
2017-06-07 08:56:42 +03:00
|
|
|
var item = {
|
|
|
|
id: data.id,
|
2017-06-16 17:45:04 +03:00
|
|
|
type: data.type,
|
|
|
|
attachments: []
|
2017-06-07 08:56:42 +03:00
|
|
|
};
|
|
|
|
switch (item['type']){
|
2020-06-22 21:13:05 +03:00
|
|
|
|
2017-06-07 08:56:42 +03:00
|
|
|
case "mention":
|
2019-12-28 23:39:28 +03:00
|
|
|
if (!data.status) {
|
2020-06-15 11:42:10 +03:00
|
|
|
break;
|
2020-04-27 17:53:48 +03:00
|
|
|
}
|
2017-06-07 17:09:41 +03:00
|
|
|
item = parseToot(data.status)
|
2017-06-07 08:56:42 +03:00
|
|
|
item['typeIcon'] = "image://theme/icon-s-alarm"
|
2020-06-16 17:09:28 +03:00
|
|
|
item['type'] = "mention"
|
2017-06-07 08:56:42 +03:00
|
|
|
break;
|
2020-06-16 17:09:28 +03:00
|
|
|
|
2017-06-07 08:56:42 +03:00
|
|
|
case "reblog":
|
2019-12-28 23:39:28 +03:00
|
|
|
if (!data.status) {
|
2020-04-27 17:53:48 +03:00
|
|
|
break;
|
|
|
|
}
|
2017-06-07 17:09:41 +03:00
|
|
|
item = parseToot(data.status)
|
2017-06-13 17:45:52 +03:00
|
|
|
item = parseAccounts(item, "reblog_", data["account"])
|
|
|
|
item = parseAccounts(item, "", data["status"]["account"])
|
2020-06-16 17:09:28 +03:00
|
|
|
item['status_reblog'] = true
|
|
|
|
item['type'] = "reblog"
|
2017-06-07 08:56:42 +03:00
|
|
|
item['typeIcon'] = "image://theme/icon-s-retweet"
|
|
|
|
break;
|
2020-06-16 17:09:28 +03:00
|
|
|
|
2017-06-07 08:56:42 +03:00
|
|
|
case "favourite":
|
2019-12-28 23:39:28 +03:00
|
|
|
if (!data.status) {
|
|
|
|
break;
|
|
|
|
}
|
2017-06-07 17:09:41 +03:00
|
|
|
item = parseToot(data.status)
|
2017-06-13 17:45:52 +03:00
|
|
|
item = parseAccounts(item, "reblog_", data["account"])
|
|
|
|
item = parseAccounts(item, "", data["status"]["account"])
|
2020-06-22 21:13:05 +03:00
|
|
|
item['status_reblog'] = true
|
|
|
|
item['type'] = "favourite"
|
2017-06-07 08:56:42 +03:00
|
|
|
item['typeIcon'] = "image://theme/icon-s-favorite"
|
|
|
|
break;
|
2020-06-16 17:09:28 +03:00
|
|
|
|
2017-06-07 08:56:42 +03:00
|
|
|
case "follow":
|
2017-06-07 17:09:41 +03:00
|
|
|
item['type'] = "follow";
|
2017-06-13 17:45:52 +03:00
|
|
|
item = parseAccounts(item, "", data["account"])
|
|
|
|
item = parseAccounts(item, "reblog_", data["account"])
|
2020-06-22 21:13:05 +03:00
|
|
|
//item['content'] = data['account']['note']
|
2020-06-16 17:09:28 +03:00
|
|
|
item['typeIcon'] = "../../images/icon-s-follow.svg"
|
2020-06-22 21:13:05 +03:00
|
|
|
//item['attachments'] = []
|
2017-06-07 08:56:42 +03:00
|
|
|
break;
|
2020-06-16 17:09:28 +03:00
|
|
|
|
2017-06-07 08:56:42 +03:00
|
|
|
default:
|
|
|
|
item['typeIcon'] = "image://theme/icon-s-sailfish"
|
|
|
|
}
|
|
|
|
|
2017-06-13 17:45:52 +03:00
|
|
|
item['id'] = data.id
|
2017-06-14 17:57:44 +03:00
|
|
|
item['created_at'] = new Date(data.created_at)
|
2017-06-16 17:45:04 +03:00
|
|
|
item['section'] = getDate(data["created_at"])
|
2017-06-07 08:56:42 +03:00
|
|
|
return item;
|
|
|
|
}
|
|
|
|
|
2020-07-03 11:45:03 +03:00
|
|
|
/** Function: */
|
2017-06-13 17:45:52 +03:00
|
|
|
function collect() {
|
|
|
|
var ret = {};
|
|
|
|
var len = arguments.length;
|
|
|
|
for (var i=0; i<len; i++) {
|
|
|
|
for (p in arguments[i]) {
|
|
|
|
if (arguments[i].hasOwnProperty(p)) {
|
|
|
|
ret[p] = arguments[i][p];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
2020-06-16 17:09:28 +03:00
|
|
|
|
2020-06-22 21:13:05 +03:00
|
|
|
/** Function: Get Status date */
|
2020-06-16 17:09:28 +03:00
|
|
|
function getDate(dateStr) {
|
2017-06-16 17:45:04 +03:00
|
|
|
var ts = new Date(dateStr);
|
|
|
|
return new Date(ts.getFullYear(), ts.getMonth(), ts.getDate(), 0, 0, 0)
|
|
|
|
}
|
2020-06-16 17:09:28 +03:00
|
|
|
|
2020-06-22 21:13:05 +03:00
|
|
|
/** Function: Get Status data */
|
2020-06-16 17:09:28 +03:00
|
|
|
function parseToot (data) {
|
2018-10-24 14:38:17 +03:00
|
|
|
var i = 0;
|
2017-06-07 08:56:42 +03:00
|
|
|
var item = {};
|
2017-10-20 16:20:33 +03:00
|
|
|
|
2017-07-04 02:07:39 +03:00
|
|
|
item['type'] = "toot"
|
2017-06-15 17:03:20 +03:00
|
|
|
item['highlight'] = false
|
2017-06-13 17:45:52 +03:00
|
|
|
item['status_id'] = data["id"]
|
2020-06-16 17:09:28 +03:00
|
|
|
item['status_created_at'] = item['created_at'] = new Date(data["created_at"])
|
|
|
|
item['status_sensitive'] = data["sensitive"]
|
|
|
|
item['status_spoiler_text'] = data["spoiler_text"]
|
|
|
|
item['status_visibility'] = data["visibility"]
|
|
|
|
item['status_language'] = data["language"]
|
2017-06-13 17:45:52 +03:00
|
|
|
item['status_uri'] = data["uri"]
|
2020-05-25 18:54:02 +03:00
|
|
|
item['status_url'] = data["url"]
|
2020-06-16 17:09:28 +03:00
|
|
|
item['status_replies_count'] = data["replies_count"]
|
|
|
|
item['status_reblogs_count'] = data["reblogs_count"]
|
|
|
|
item['status_favourites_count'] = data["favourites_count"]
|
|
|
|
item['status_favourited'] = data["favourited"]
|
|
|
|
item['status_reblogged'] = data["reblogged"]
|
|
|
|
item['status_bookmarked'] = data["bookmarked"]
|
2022-05-04 21:54:18 +03:00
|
|
|
item['content'] = data["content"]
|
2020-06-22 21:13:05 +03:00
|
|
|
item['attachments'] = data['media_attachments']
|
2017-06-13 17:45:52 +03:00
|
|
|
item['status_in_reply_to_id'] = data["in_reply_to_id"]
|
|
|
|
item['status_in_reply_to_account_id'] = data["in_reply_to_account_id"]
|
|
|
|
item['status_reblog'] = data["reblog"] ? true : false
|
2020-06-16 17:09:28 +03:00
|
|
|
item['section'] = getDate(data["created_at"])
|
2017-06-13 17:45:52 +03:00
|
|
|
|
2020-06-22 21:13:05 +03:00
|
|
|
/** If Toot is a Reblog */
|
2020-06-16 17:09:28 +03:00
|
|
|
if(item['status_reblog']) {
|
2017-06-13 17:45:52 +03:00
|
|
|
item['type'] = "reblog";
|
|
|
|
item['typeIcon'] = "image://theme/icon-s-retweet"
|
2020-07-03 11:45:03 +03:00
|
|
|
item['status_id'] = data["reblog"]["id"]
|
2018-10-24 14:38:17 +03:00
|
|
|
item['status_sensitive'] = data["reblog"]["sensitive"]
|
2020-07-03 11:45:03 +03:00
|
|
|
item['status_spoiler_text'] = data["reblog"]["spoiler_text"]
|
|
|
|
item['status_replies_count'] = data["reblog"]["replies_count"]
|
|
|
|
item['status_reblogs_count'] = data["reblog"]["reblogs_count"]
|
|
|
|
item['status_favourites_count'] = data["reblog"]["favourites_count"]
|
2022-05-04 21:54:18 +03:00
|
|
|
item['content'] = data["reblog"]["content"]
|
2017-06-13 17:45:52 +03:00
|
|
|
item = parseAccounts(item, "", data['reblog']["account"])
|
|
|
|
item = parseAccounts(item, "reblog_", data["account"])
|
|
|
|
} else {
|
|
|
|
item = parseAccounts(item, "", data["account"])
|
|
|
|
}
|
2020-06-22 21:13:05 +03:00
|
|
|
|
2020-07-03 11:45:03 +03:00
|
|
|
/** Replace HTML content in Toots */
|
2022-05-04 21:54:18 +03:00
|
|
|
item['content'] = item['content']
|
2020-06-15 11:42:10 +03:00
|
|
|
.replaceAll('</span><span class="invisible">', '')
|
|
|
|
.replaceAll('<span class="invisible">', '')
|
|
|
|
.replaceAll('</span><span class="ellipsis">', '')
|
|
|
|
.replaceAll('class=""', '');
|
2017-11-01 02:27:48 +03:00
|
|
|
|
2020-06-22 21:13:05 +03:00
|
|
|
/** Media attachements in Toots */
|
|
|
|
item['attachments'] = [];
|
2020-07-03 11:45:03 +03:00
|
|
|
for(i = 0; i < data['media_attachments'].length; i++) {
|
2017-06-16 01:56:29 +03:00
|
|
|
var attachments = data['media_attachments'][i];
|
|
|
|
item['content'] = item['content'].replaceAll(attachments['text_url'], '')
|
2017-10-26 17:23:16 +03:00
|
|
|
var tmp = {
|
|
|
|
id: attachments['id'],
|
|
|
|
type: attachments['type'],
|
2017-10-26 17:38:07 +03:00
|
|
|
url: attachments['remote_url'] && typeof attachments['remote_url'] == "string" ? attachments['remote_url'] : attachments['url'] ,
|
2020-06-15 11:42:10 +03:00
|
|
|
preview_url: loadImages ? attachments['preview_url'] : ''
|
2017-10-26 17:23:16 +03:00
|
|
|
}
|
|
|
|
item['attachments'].push(tmp)
|
2017-06-16 01:56:29 +03:00
|
|
|
}
|
2020-06-16 17:09:28 +03:00
|
|
|
|
2020-06-22 21:13:05 +03:00
|
|
|
/** Media attachements in Reblogs */
|
2020-06-16 17:09:28 +03:00
|
|
|
if(item['status_reblog']) {
|
|
|
|
for(i = 0; i < data['reblog']['media_attachments'].length ; i++) {
|
2018-09-02 14:56:57 +03:00
|
|
|
var attachments = data['reblog']['media_attachments'][i];
|
|
|
|
item['content'] = item['content'].replaceAll(attachments['text_url'], '')
|
|
|
|
var tmp = {
|
|
|
|
id: attachments['id'],
|
|
|
|
type: attachments['type'],
|
|
|
|
url: attachments['remote_url'] && typeof attachments['remote_url'] == "string" ? attachments['remote_url'] : attachments['url'],
|
|
|
|
preview_url: loadImages ? attachments['preview_url'] : ''
|
|
|
|
}
|
|
|
|
item['attachments'].push(tmp)
|
|
|
|
}
|
|
|
|
}
|
2020-06-16 17:09:28 +03:00
|
|
|
|
2018-10-24 14:38:17 +03:00
|
|
|
return addEmojis(item, data);
|
|
|
|
}
|
|
|
|
|
2020-06-22 21:13:05 +03:00
|
|
|
/** Function: Display custom Emojis in Toots */
|
2020-06-16 17:09:28 +03:00
|
|
|
function addEmojis(item, data) {
|
2018-10-24 14:38:17 +03:00
|
|
|
var emoji, i;
|
2020-06-16 17:09:28 +03:00
|
|
|
for (i = 0; i < data["emojis"].length; i++) {
|
2018-10-24 14:38:17 +03:00
|
|
|
emoji = data["emojis"][i];
|
2020-06-03 08:34:33 +03:00
|
|
|
item['content'] = item['content'].replaceAll(":"+emoji.shortcode+":", "<img src=\"" + emoji.static_url+"\" align=\"top\" width=\"50\" height=\"50\">")
|
2018-10-24 14:38:17 +03:00
|
|
|
//console.log(JSON.stringify(data["emojis"][i]))
|
|
|
|
}
|
|
|
|
if (data["reblog"])
|
2020-06-16 17:09:28 +03:00
|
|
|
for (i = 0; i < data["reblog"]["emojis"].length; i++) {
|
2018-10-24 14:38:17 +03:00
|
|
|
emoji = data["reblog"]["emojis"][i];
|
2020-06-03 08:34:33 +03:00
|
|
|
item['content'] = item['content'].replaceAll(":"+emoji.shortcode+":", "<img src=\"" + emoji.static_url+"\" align=\"top\" width=\"50\" height=\"50\">")
|
2018-10-24 14:38:17 +03:00
|
|
|
}
|
|
|
|
|
2017-06-07 08:56:42 +03:00
|
|
|
return item;
|
|
|
|
}
|