Verified Commit 1f5e7639 authored by Haelwenn's avatar Haelwenn

Worker.js: Fix some formatting

parent c52715ae
......@@ -23,11 +23,11 @@ WorkerScript.onMessage =
console.log("Not loggedin")
return;
}
if(typeof msg.conf['loadImages'] !== "undefined")
loadImages = msg.conf['loadImages']
var API =
MastodonAPI({instance : msg.conf.instance, api_user_token : msg.conf.api_user_token});
if(typeof msg.conf['loadImages'] !== "undefined") loadImages = msg.conf['loadImages'];
var API = MastodonAPI({instance : msg.conf.instance, api_user_token : msg.conf.api_user_token});
if(msg.method === "POST")
{
API.post(msg.action, msg.params, function(data) {
......@@ -105,8 +105,8 @@ WorkerScript.onMessage =
console.log("descendants")
for(var j = 0; j < data[i].length; j++)
{
item = parseToot(data[i][j]);
item['id'] = item['status_id'];
item = parseToot(data[i][j]);
item['id'] = item['status_id'];
if(typeof item['attachments'] === "undefined") item['attachments'] = [];
items.push(item)
console.log(JSON.stringify(data[i][j]))
......@@ -163,7 +163,7 @@ function addDataToModel(model, mode, items) {
res[prefix + 'account_created_at'] = data["created_at"]
res[prefix + 'account_avatar'] = data["avatar"]
// /console.log(JSON.stringify(res))
// console.log(JSON.stringify(res))
return (res);
}
......@@ -184,7 +184,7 @@ function parseNotification(data) {
item = parseAccounts(item, "", data["status"]["account"])
item['status_reblog'] = true;
item['type'] = "reblog";
item['typeIcon'] = "image://theme/icon-s-retweet"
item['typeIcon'] = "image://theme/icon-s-retweet";
break;
case "favourite":
item = parseToot(data.status)
......@@ -197,13 +197,12 @@ function parseNotification(data) {
break;
case "follow":
item['type'] = "follow";
item = parseAccounts(item, "", data["account"])
item = parseAccounts(item, "reblog_", data["account"])
item['content'] = data['account']['note']
item['typeIcon'] = "image://theme/icon-s-installed"
item['attachments'] = []
break;
item = parseAccounts(item, "", data["account"]);
item = parseAccounts(item, "reblog_", data["account"]);
item['content'] = data['account']['note'];
item['typeIcon'] = "image://theme/icon-s-installed";
item['attachments'] = [];
break;
default: item['typeIcon'] = "image://theme/icon-s-sailfish"
}
......@@ -228,10 +227,14 @@ collect() {
}
}
return ret;
} function getDate(dateStr) {
}
function getDate(dateStr) {
var ts = new Date(dateStr);
return new Date(ts.getFullYear(), ts.getMonth(), ts.getDate(), 0, 0, 0)
} function parseToot(data) {
}
function parseToot(data) {
var i = 0;
var item = {};
......@@ -243,15 +246,17 @@ collect() {
item['status_in_reply_to_account_id'] = data["in_reply_to_account_id"]
item['status_reblog'] = data["reblog"] ? true : false
item['status_content'] = data["content"]
item['status_created_at'] = item['created_at'] = new Date(data["created_at"]);
item['section'] = getDate(data["created_at"]);
item['reblogs_count'] = data["reblogs_count"]
item['favourites_count'] = data["favourites_count"]
item['reblogged'] = data["reblogged"]
item['favourited'] = data["favourited"]
item['status_sensitive'] = data["sensitive"]
item['status_spoiler_text'] = data["spoiler_text"]
item['status_visibility'] = data["visibility"]
item['section'] = getDate(data["created_at"]);
item['reblogs_count'] = data["reblogs_count"]
item['favourites_count'] = data["favourites_count"]
item['reblogged'] = data["reblogged"]
item['favourited'] = data["favourited"]
item['status_sensitive'] = data["sensitive"]
item['status_spoiler_text'] = data["spoiler_text"]
item['status_visibility'] = data["visibility"]
if(item['status_reblog'])
{
......@@ -264,42 +269,46 @@ collect() {
item = parseAccounts(item, "", data['reblog']["account"])
item = parseAccounts(item, "reblog_", data["account"])
}
else {item = parseAccounts(item, "", data["account"])} item['content'] =
data['content']
.replaceAll('</span><span class="invisible">', '')
.replaceAll('<span class="invisible">', '')
.replaceAll('</span><span class="ellipsis">', '')
.replaceAll('class=""', '');
else {item = parseAccounts(item, "", data["account"])}
item['content'] = data['content']
.replaceAll('</span><span class="invisible">', '')
.replaceAll('<span class="invisible">', '')
.replaceAll('</span><span class="ellipsis">', '')
.replaceAll('class=""', '');
item['attachments'] = [];
for(i = 0; i < data['media_attachments'].length; i++)
{
var attachments = data['media_attachments'][i];
item['content'] = item['content'].replaceAll(attachments['text_url'], '')
var tmp = {
id : attachments['id'],
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'] : ''
var tmp = {
id : attachments['id'],
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)
}
if(item['status_reblog'])
{
for(i = 0; i < data['reblog']['media_attachments'].length; i++)
{
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'] : ''
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)
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment