thedesk/app/js/tl/tl.js

863 lines
25 KiB
JavaScript
Raw Normal View History

2018-01-28 23:22:43 +11:00
//TL取得
2019-05-11 02:31:15 +10:00
moreloading = false;
2018-08-21 04:26:14 +10:00
function tl(type, data, acct_id, tlid, delc, voice, mode) {
2018-01-28 23:22:43 +11:00
scrollevent();
localStorage.removeItem("morelock");
localStorage.removeItem("pool");
2018-01-31 03:43:01 +11:00
var domain = localStorage.getItem("domain_" + acct_id);
2018-04-01 07:00:27 +10:00
//タグとかの場合はカラム追加して描画
2018-01-28 23:22:43 +11:00
if (tlid == "add") {
2019-05-19 16:17:05 +10:00
console.log("add new column");
2018-01-28 23:22:43 +11:00
var newtab = $(".box").length;
var add = {
domain: acct_id,
2018-04-01 07:00:27 +10:00
type: type,
2018-01-28 23:22:43 +11:00
data: data
};
var multi = localStorage.getItem("column");
var obj = JSON.parse(multi);
2019-05-11 02:31:15 +10:00
localStorage.setItem("card_" + obj.length, "true");
2018-01-28 23:22:43 +11:00
obj.push(add);
var json = JSON.stringify(obj);
localStorage.setItem("column", json);
parseColumn('add');
2018-01-28 23:22:43 +11:00
return;
}
2019-05-11 02:31:15 +10:00
2018-01-28 23:22:43 +11:00
if (!type) {
var type = localStorage.getItem("now");
if (!type) {
//デフォルト
var type = "local";
}
}
2019-05-11 02:31:15 +10:00
if (type == "mix" && localStorage.getItem("mode_" + domain) != "misskey") {
2018-01-28 23:22:43 +11:00
//Integratedなら飛ばす
2019-05-11 02:31:15 +10:00
$("#notice_" + tlid).text("Integrated TL(" + localStorage.getItem(
2018-01-31 03:43:01 +11:00
"user_" + acct_id) + "@" + domain + ")");
2019-05-11 02:31:15 +10:00
$("#notice_icon_" + tlid).text("merge_type");
mixtl(acct_id, tlid, "integrated", delc, voice);
2018-01-28 23:22:43 +11:00
return;
2019-05-11 02:31:15 +10:00
} else if (type == "plus") {
2018-03-27 13:39:35 +11:00
//Local+なら飛ばす
2019-05-11 02:31:15 +10:00
$("#notice_" + tlid).text("Local+ TL(" + localStorage.getItem(
2018-03-27 13:39:35 +11:00
"user_" + acct_id) + "@" + domain + ")");
2019-05-11 02:31:15 +10:00
$("#notice_icon_" + tlid).text("people_outline");
mixtl(acct_id, tlid, "plus", delc, voice);
2018-03-27 13:39:35 +11:00
return;
2019-05-11 02:31:15 +10:00
} else if (type == "notf") {
2018-01-28 23:22:43 +11:00
//通知なら飛ばす
2019-01-26 14:24:26 +11:00
notf(acct_id, tlid, 'direct');
2018-03-20 15:55:25 +11:00
$("#notice_" + tlid).text(cap(type, data, acct_id) + "(" + localStorage.getItem(
2018-01-28 23:22:43 +11:00
"user_" + acct_id) + "@" + domain + ")");
2019-05-11 02:31:15 +10:00
$("#notice_icon_" + tlid).text("notifications");
2018-01-28 23:22:43 +11:00
return;
2019-03-06 22:56:39 +11:00
}/*else if (type == "dm") {
2019-03-06 19:08:48 +11:00
//DMなら飛ばす
dm(acct_id, tlid, "plus",delc,voice);
$("#notice_" + tlid).text(cap(type, data, acct_id) + "(" + localStorage.getItem(
"user_" + acct_id) + "@" + domain + ")");
2019-03-16 21:06:03 +11:00
$("#notice_icon_" + tlid).text("mail_outline");
2019-03-06 19:08:48 +11:00
return;
2019-03-06 22:56:39 +11:00
}*/
2018-01-28 23:22:43 +11:00
localStorage.setItem("now", type);
todo(cap(type) + " TL Loading...");
2019-05-11 02:31:15 +10:00
var at = localStorage.getItem("acct_" + acct_id + "_at");
if (type != "noauth") {
var hdr = {
2018-03-27 13:39:35 +11:00
'content-type': 'application/json',
'Authorization': 'Bearer ' + at
};
$("#notice_" + tlid).text(cap(type, data, acct_id) + "(" + localStorage.getItem(
"user_" + acct_id) + "@" + domain + ")");
2019-05-11 02:31:15 +10:00
} else {
var hdr = {
2018-03-27 13:39:35 +11:00
'content-type': 'application/json'
};
2019-05-11 02:31:15 +10:00
domain = acct_id;
2018-03-27 13:39:35 +11:00
$("#notice_" + tlid).text("Glance TL(" + domain + ")");
}
2019-05-11 02:31:15 +10:00
$("#notice_icon_" + tlid).text(icon(type));
if (localStorage.getItem("mode_" + domain) == "misskey") {
var misskey = true;
var url = misskeycom(type, data);
var start = "https://" + domain + "/api/notes/" + url;
var method = "POST";
var req = {};
if (type != "noauth") {
req.i = at;
}
if (type == "local-media" || type == "pub-media") {
req.mediaOnly = true;
}
if (type == "tag") {
req.tag = data;
}
if (type == "list") {
req.listId = data;
}
req.limit = 20;
var i = {
method: method,
headers: hdr,
body: JSON.stringify(req),
}
} else {
var misskey = false;
var url = com(type, data);
if (type == "tag") {
var tag = localStorage.getItem("tag-range");
if (tag == "local") {
url = url + "local=true";
2019-03-16 21:06:03 +11:00
}
2018-03-14 05:31:31 +11:00
}
2019-05-11 02:31:15 +10:00
if (type == "dm") {
var start = "https://" + domain + "/api/v1/conversations";
} else {
var start = "https://" + domain + "/api/v1/timelines/" + url;
}
var method = "GET";
var i = {
method: method,
headers: hdr
};
}
2019-05-19 17:39:30 +10:00
console.log(["Try to get timeline of " + tlid, start])
2019-05-11 02:31:15 +10:00
fetch(start, i).then(function (response) {
2018-01-28 23:22:43 +11:00
return response.json();
2019-05-11 02:31:15 +10:00
}).catch(function (error) {
2018-01-28 23:22:43 +11:00
todo(error);
console.error(error);
2019-05-11 02:31:15 +10:00
}).then(function (json) {
2019-05-19 17:39:30 +10:00
console.log(["Result of getting timeline of " + tlid, json])
2018-08-17 03:21:40 +10:00
$("#landing_" + tlid).hide();
2019-05-11 02:31:15 +10:00
if (localStorage.getItem("filter_" + acct_id) != "undefined") {
var mute = getFilterType(JSON.parse(localStorage.getItem("filter_" + acct_id)), type);
} else {
var mute = [];
2018-07-17 01:39:06 +10:00
}
2019-05-11 02:31:15 +10:00
if (misskey) {
2018-07-30 21:03:49 +10:00
var templete = misskeyParse(json, type, acct_id, tlid, "", mute);
2019-05-11 02:31:15 +10:00
} else {
2019-03-16 21:06:03 +11:00
var templete = parse(json, type, acct_id, tlid, "", mute, type);
2019-05-11 02:31:15 +10:00
localStorage.setItem("lastobj_" + tlid, json[0].id)
2018-07-30 21:03:49 +10:00
}
2018-01-28 23:22:43 +11:00
$("#timeline_" + tlid).html(templete);
additional(acct_id, tlid);
jQuery("time.timeago").timeago();
todc();
2019-05-11 02:31:15 +10:00
reload(type, '', acct_id, tlid, data, mute, delc, voice);
2018-01-28 23:22:43 +11:00
$(window).scrollTop(0);
});
}
//Streaming接続
2018-08-21 04:26:14 +10:00
function reload(type, cc, acct_id, tlid, data, mute, delc, voice, mode) {
2018-01-28 23:22:43 +11:00
if (!type) {
var type = localStorage.getItem("now");
}
var domain = localStorage.getItem("domain_" + acct_id);
2019-05-11 02:31:15 +10:00
var at = localStorage.getItem("acct_" + acct_id + "_at");
2018-01-28 23:22:43 +11:00
localStorage.setItem("now", type);
2019-05-11 02:31:15 +10:00
if (localStorage.getItem("mode_" + domain) == "misskey") {
var misskey = true;
var key = localStorage.getItem("misskey_wss_" + acct_id)
var send = '{"type":"connect","body":{"channel":"' + typePs(type) + '","id":"' + tlid + '"}}'
var mskyset = setInterval(function () {
if (misskeywsstate[key]) {
2019-05-08 01:48:59 +10:00
misskeyws[key].send(send)
2019-05-11 02:31:15 +10:00
clearInterval(mskyset)
2019-05-08 01:48:59 +10:00
}
2019-05-11 02:31:15 +10:00
}, 100);
} else {
var misskey = false;
if (localStorage.getItem("streaming_" + acct_id)) {
var wss = localStorage.getItem("streaming_" + acct_id)
} else {
var wss = "wss://" + domain
2018-09-17 21:55:00 +10:00
}
2018-07-30 21:03:49 +10:00
if (type == "home") {
2018-09-17 21:55:00 +10:00
var start = wss +
2018-07-30 21:03:49 +10:00
"/api/v1/streaming/?stream=user&access_token=" + at;
} else if (type == "pub") {
2018-09-17 21:55:00 +10:00
var start = wss +
2018-07-30 21:03:49 +10:00
"/api/v1/streaming/?stream=public&access_token=" + at;
} else if (type == "pub-media") {
2018-09-17 21:55:00 +10:00
var start = wss +
2018-07-30 21:03:49 +10:00
"/api/v1/streaming/?stream=public:media&access_token=" + at;
} else if (type == "local") {
2018-09-17 21:55:00 +10:00
var start = wss +
2018-07-30 21:03:49 +10:00
"/api/v1/streaming/?stream=public:local&access_token=" + at;
} else if (type == "local-media") {
2018-09-17 21:55:00 +10:00
var start = wss +
2018-07-30 21:03:49 +10:00
"/api/v1/streaming/?stream=public:local:media&only_media=true&access_token=" + at;
} else if (type == "tag") {
2019-05-11 02:31:15 +10:00
if (type == "tag") {
2018-07-30 21:03:49 +10:00
var tag = localStorage.getItem("tag-range");
2019-05-11 02:31:15 +10:00
if (tag == "local") {
data = data + "&local=true";
2018-07-30 21:03:49 +10:00
}
2018-03-14 05:31:31 +11:00
}
2018-09-17 21:55:00 +10:00
var start = wss +
2019-05-11 02:31:15 +10:00
"/api/v1/streaming/?stream=hashtag&tag=" + data + "&access_token=" + at;
2018-07-30 21:03:49 +10:00
} else if (type == "noauth") {
2019-05-11 02:31:15 +10:00
var start = "wss://" + acct_id +
2018-07-30 21:03:49 +10:00
"/api/v1/streaming/?stream=public:local";
2019-05-11 02:31:15 +10:00
} else if (type == "list") {
2018-09-17 21:55:00 +10:00
var start = wss +
2019-05-11 02:31:15 +10:00
"/api/v1/streaming/?stream=list&list=" + data + "&access_token=" + at;
} else if (type == "dm") {
2018-09-17 21:55:00 +10:00
var start = wss +
2018-07-30 21:03:49 +10:00
"/api/v1/streaming/?stream=direct&access_token=" + at;
2018-03-14 05:31:31 +11:00
}
2019-05-11 02:31:15 +10:00
var wsid = websocket.length;
localStorage.setItem("wss_" + tlid, wsid);
websocket[wsid] = new WebSocket(start);
websocket[wsid].onopen = function (mess) {
2019-05-19 17:39:30 +10:00
console.table({ "tlid": tlid, "type": "Connect Streaming API" + type, "domain": domain, "message": [mess] })
2019-05-11 02:31:15 +10:00
$("#notice_icon_" + tlid).removeClass("red-text");
}
websocket[wsid].onmessage = function (mess) {
2019-05-19 17:39:30 +10:00
console.log([tlid + ":Receive Streaming API:", JSON.parse(mess.data)]);
2019-05-11 02:31:15 +10:00
if (misskey) {
if (JSON.parse(mess.data).type == "note") {
var obj = JSON.parse(mess.data).body;
if (voice) {
say(obj.text)
}
websocketNotf[acct_id].send(JSON.stringify({
type: 'capture',
id: obj.id
}))
var templete = misskeyParse([obj], type, acct_id, tlid, "", mute);
var pool = localStorage.getItem("pool_" + tlid);
if (pool) {
pool = templete + pool;
} else {
pool = templete
}
localStorage.setItem("pool_" + tlid, pool);
scrollck();
jQuery("time.timeago").timeago();
2018-07-30 21:03:49 +10:00
}
2019-05-11 02:31:15 +10:00
} else {
var typeA = JSON.parse(mess.data).event;
if (typeA == "delete") {
var del = localStorage.getItem("delete");
if (del > 10) {
reconnector(tlid, type, acct_id, data)
} else {
localStorage.setItem("delete", del * 1 + 1)
}
var obj = JSON.parse(mess.data).payload;
if (delc == "true") {
$("#timeline_" + tlid + " [toot-id=" + JSON.parse(mess.data).payload + "]").addClass("emphasized");
$("#timeline_" + tlid + " [toot-id=" + JSON.parse(mess.data).payload + "]").addClass("by_delcatch");
} else {
$("[toot-id=" + JSON.parse(mess.data).payload + "]").hide();
$("[toot-id=" + JSON.parse(mess.data).payload + "]").remove();
}
} else if (typeA == "update" || typeA == "conversation") {
localStorage.removeItem("delete");
var obj = JSON.parse(JSON.parse(mess.data).payload);
if ($("#timeline_" + tlid + " [toot-id=" + obj.id + "]").length < 1) {
if (voice) {
say(obj.content)
}
var templete = parse([obj], type, acct_id, tlid, "", mute, type);
if ($("timeline_box_" + tlid + "_box .tl-box").scrollTop() === 0) {
$("#timeline_" + tlid).prepend(templete);
2018-08-21 04:26:14 +10:00
} else {
2019-05-11 02:31:15 +10:00
var pool = localStorage.getItem("pool_" + tlid);
if (pool) {
pool = templete + pool;
} else {
pool = templete
}
localStorage.setItem("pool_" + tlid, pool);
2018-08-21 04:26:14 +10:00
}
2019-05-11 02:31:15 +10:00
scrollck();
additional(acct_id, tlid);
jQuery("time.timeago").timeago();
} else {
todo("二重取得発生中");
2018-07-30 21:03:49 +10:00
}
2019-05-11 02:31:15 +10:00
todc();
} else if (typeA == "filters_changed") {
filterUpdate(acct_id);
2018-07-30 21:03:49 +10:00
}
}
2019-05-11 02:31:15 +10:00
2018-01-28 23:22:43 +11:00
}
2019-05-11 02:31:15 +10:00
websocket[wsid].onerror = function (error) {
console.error("Error closing");
console.error(error);
if (mode == "error") {
$("#notice_icon_" + tlid).addClass("red-text");
todo('WebSocket Error ' + error);
} else {
var errorct = localStorage.getItem("wserror_" + tlid) * 1 + 1;
localStorage.setItem("wserror_" + tlid, errorct);
if (errorct < 3) {
reconnector(tlid, type, acct_id, data, "error");
}
2018-08-23 03:29:39 +10:00
}
2019-05-11 02:31:15 +10:00
return false;
};
websocket[wsid].onclose = function () {
2019-05-19 17:39:30 +10:00
console.warn("Closing " + tlid);
2019-05-11 02:31:15 +10:00
if (mode == "error") {
$("#notice_icon_" + tlid).addClass("red-text");
todo('WebSocket Closed');
} else {
var errorct = localStorage.getItem("wserror_" + tlid) * 1 + 1;
localStorage.setItem("wserror_" + tlid, errorct);
if (errorct < 3) {
reconnector(tlid, type, acct_id, data, "error");
}
2018-08-23 03:29:39 +10:00
}
2019-05-11 02:31:15 +10:00
return false;
};
2019-05-08 01:48:59 +10:00
}
2018-01-28 23:22:43 +11:00
}
//一定のスクロールで発火
function moreload(type, tlid) {
var multi = localStorage.getItem("column");
var obj = JSON.parse(multi);
var acct_id = obj[tlid].domain;
if (!type) {
2018-01-31 03:43:01 +11:00
var type = obj[tlid].type;
2019-05-11 02:31:15 +10:00
} else {
2018-02-05 01:56:31 +11:00
var data;
}
2019-05-11 02:31:15 +10:00
if (type == "tag") {
var data = obj[tlid].data;
2018-03-14 05:31:31 +11:00
var tag = localStorage.getItem("tag-range");
2019-05-11 02:31:15 +10:00
if (tag == "local") {
data = data + "&local=true";
2018-03-14 05:31:31 +11:00
}
2019-05-11 02:31:15 +10:00
} else if (type == "list") {
var data = obj[tlid].data;
2018-01-28 23:22:43 +11:00
}
2018-07-19 02:05:53 +10:00
var sid = $("#timeline_" + tlid + " .cvo").last().attr("unique-id");
2019-03-06 19:08:48 +11:00
if (sid && !moreloading) {
2019-05-11 02:31:15 +10:00
if (type == "mix" && localStorage.getItem("mode_" + localStorage.getItem("domain_" + acct_id)) != "misskey") {
mixmore(tlid, "integrated");
2018-03-27 13:39:35 +11:00
return;
2019-05-11 02:31:15 +10:00
} else if (type == "plus" && localStorage.getItem("mode_" + localStorage.getItem("domain_" + acct_id)) != "misskey") {
mixmore(tlid, "plus");
2018-01-28 23:22:43 +11:00
return;
2019-05-11 02:31:15 +10:00
} else if (type == "notf") {
2018-03-15 06:42:48 +11:00
notfmore(tlid);
return;
2019-05-11 02:31:15 +10:00
} else if (type == "tootsearch") {
var data = obj[tlid].data;
moreTs(tlid, data);
2019-04-11 13:52:38 +10:00
return;
2018-01-28 23:22:43 +11:00
}
2019-05-11 02:31:15 +10:00
moreloading = true;
2018-01-28 23:22:43 +11:00
localStorage.setItem("now", type);
todo(cap(type) + " TL MoreLoading");
2019-05-11 02:31:15 +10:00
if (type != "noauth") {
var at = localStorage.getItem("acct_" + acct_id + "_at");
var hdr = {
2018-01-28 23:22:43 +11:00
'content-type': 'application/json',
'Authorization': 'Bearer ' + at
2018-07-30 21:03:49 +10:00
};
2019-05-11 02:31:15 +10:00
var domain = localStorage.getItem("domain_" + acct_id);
} else {
var hdr = {
2018-07-30 21:03:49 +10:00
'content-type': 'application/json'
};
2019-05-11 02:31:15 +10:00
domain = acct_id;
2018-07-30 21:03:49 +10:00
}
2019-05-11 02:31:15 +10:00
if (localStorage.getItem("mode_" + domain) == "misskey") {
var misskey = true;
hdr = {
2018-07-30 21:03:49 +10:00
'content-type': 'application/json'
};
2019-05-11 02:31:15 +10:00
var url = misskeycom(type, data);
var start = "https://" + domain + "/api/notes/" + url;
var method = "POST";
var req = {};
if (type != "noauth") {
req.i = at;
2018-07-30 21:03:49 +10:00
}
2019-05-11 02:31:15 +10:00
if (type == "local-media" || type == "pub-media") {
req.mediaOnly = true;
2018-07-30 21:03:49 +10:00
}
2019-05-11 02:31:15 +10:00
if (type == "tag") {
req.tag = data;
2018-07-30 21:03:49 +10:00
}
2019-05-11 02:31:15 +10:00
if (type == "list") {
req.listId = data;
2018-07-30 21:03:49 +10:00
}
2019-05-11 02:31:15 +10:00
req.untilId = sid;
req.limit = 20;
var i = {
2018-07-30 21:03:49 +10:00
method: method,
headers: hdr,
body: JSON.stringify(req),
}
2019-05-11 02:31:15 +10:00
} else {
var misskey = false;
var start = "https://" + domain + "/api/v1/timelines/" + com(type, data) +
"max_id=" + sid;
if (type == "dm") {
2019-03-16 21:06:03 +11:00
var start = "https://" + domain + "/api/v1/conversations?" +
"max_id=" + sid;
}
2019-05-11 02:31:15 +10:00
var method = "GET";
var i = {
2018-07-30 21:03:49 +10:00
method: method,
headers: hdr
};
}
2019-05-11 02:31:15 +10:00
fetch(start, i).then(function (response) {
2018-01-28 23:22:43 +11:00
return response.json();
2019-05-11 02:31:15 +10:00
}).catch(function (error) {
2018-01-28 23:22:43 +11:00
todo(error);
console.error(error);
2019-05-11 02:31:15 +10:00
}).then(function (json) {
2019-06-22 00:17:56 +10:00
if (localStorage.getItem("filter_" + acct_id) != "undefined") {
var mute = getFilterType(JSON.parse(localStorage.getItem("filter_" + acct_id)), type);
} else {
var mute = [];
}
2019-05-11 02:31:15 +10:00
if (misskey) {
var templete = misskeyParse(json, '', acct_id, tlid, "", mute);
} else {
var templete = parse(json, '', acct_id, tlid, "", mute, type);
2018-07-30 21:03:49 +10:00
}
2018-01-28 23:22:43 +11:00
$("#timeline_" + tlid).append(templete);
additional(acct_id, tlid);
jQuery("time.timeago").timeago();
2019-05-11 02:31:15 +10:00
moreloading = false;
2018-01-28 23:22:43 +11:00
todc();
});
}
}
2019-04-08 01:14:06 +10:00
//TL差分取得
function tlDiff(type, data, acct_id, tlid, delc, voice, mode) {
2019-05-19 17:39:30 +10:00
console.log("Get diff of TL" + tlid)
2019-04-08 01:14:06 +10:00
var multi = localStorage.getItem("column");
var obj = JSON.parse(multi);
var acct_id = obj[tlid].domain;
if (!type) {
var type = obj[tlid].type;
2019-05-11 02:31:15 +10:00
} else {
2019-04-08 01:14:06 +10:00
var data;
}
2019-05-11 02:31:15 +10:00
if (type == "tag") {
var data = obj[tlid].data;
2019-04-08 01:14:06 +10:00
var tag = localStorage.getItem("tag-range");
2019-05-11 02:31:15 +10:00
if (tag == "local") {
data = data + "&local=true";
2019-04-08 01:14:06 +10:00
}
2019-05-11 02:31:15 +10:00
} else if (type == "list") {
var data = obj[tlid].data;
2019-04-08 01:14:06 +10:00
}
var sid = $("#timeline_" + tlid + " .cvo").first().attr("unique-id");
if (sid && !moreloading) {
2019-05-11 02:31:15 +10:00
if (type == "mix" && localStorage.getItem("mode_" + localStorage.getItem("domain_" + acct_id)) != "misskey") {
2019-04-08 01:14:06 +10:00
return;
2019-05-11 02:31:15 +10:00
} else if (type == "plus" && localStorage.getItem("mode_" + localStorage.getItem("domain_" + acct_id)) != "misskey") {
2019-04-08 01:14:06 +10:00
return;
2019-05-11 02:31:15 +10:00
} else if (type == "notf") {
2019-04-08 01:14:06 +10:00
return;
}
2019-05-11 02:31:15 +10:00
moreloading = true;
2019-04-08 01:14:06 +10:00
localStorage.setItem("now", type);
todo(cap(type) + " TL MoreLoading");
2019-05-11 02:31:15 +10:00
if (type != "noauth") {
var at = localStorage.getItem("acct_" + acct_id + "_at");
var hdr = {
2019-04-08 01:14:06 +10:00
'content-type': 'application/json',
'Authorization': 'Bearer ' + at
};
2019-05-11 02:31:15 +10:00
var domain = localStorage.getItem("domain_" + acct_id);
} else {
var hdr = {
2019-04-08 01:14:06 +10:00
'content-type': 'application/json'
};
2019-05-11 02:31:15 +10:00
domain = acct_id;
2019-04-08 01:14:06 +10:00
}
2019-05-11 02:31:15 +10:00
if (localStorage.getItem("mode_" + domain) == "misskey") {
var misskey = true;
hdr = {
2019-04-08 01:14:06 +10:00
'content-type': 'application/json'
};
2019-05-11 02:31:15 +10:00
var url = misskeycom(type, data);
var start = "https://" + domain + "/api/notes/" + url;
var method = "POST";
var req = {};
if (type != "noauth") {
req.i = at;
2019-04-08 01:14:06 +10:00
}
2019-05-11 02:31:15 +10:00
if (type == "local-media" || type == "pub-media") {
req.mediaOnly = true;
2019-04-08 01:14:06 +10:00
}
2019-05-11 02:31:15 +10:00
if (type == "tag") {
req.tag = data;
2019-04-08 01:14:06 +10:00
}
2019-05-11 02:31:15 +10:00
if (type == "list") {
req.listId = data;
2019-04-08 01:14:06 +10:00
}
2019-05-11 02:31:15 +10:00
req.sinceId = sid;
req.limit = 20;
var i = {
2019-04-08 01:14:06 +10:00
method: method,
headers: hdr,
body: JSON.stringify(req),
}
2019-05-11 02:31:15 +10:00
} else {
var misskey = false;
var start = "https://" + domain + "/api/v1/timelines/" + com(type, data) +
"since_id=" + sid;
if (type == "dm") {
2019-04-08 01:14:06 +10:00
var start = "https://" + domain + "/api/v1/conversations?" +
"since_id=" + sid;
}
2019-05-11 02:31:15 +10:00
var method = "GET";
var i = {
2019-04-08 01:14:06 +10:00
method: method,
headers: hdr
};
}
2019-05-11 02:31:15 +10:00
fetch(start, i).then(function (response) {
2019-04-08 01:14:06 +10:00
return response.json();
2019-05-11 02:31:15 +10:00
}).catch(function (error) {
2019-04-08 01:14:06 +10:00
todo(error);
console.error(error);
2019-05-11 02:31:15 +10:00
}).then(function (json) {
2019-05-19 17:39:30 +10:00
console.log(["Result diff of TL" + tlid, json]);
2019-05-11 02:31:15 +10:00
if (misskey) {
var templete = misskeyParse(json, '', acct_id, tlid, "", mute);
} else {
var templete = parse(json, '', acct_id, tlid, "", mute, type);
2019-04-08 01:14:06 +10:00
}
$("#timeline_" + tlid).prepend(templete);
additional(acct_id, tlid);
jQuery("time.timeago").timeago();
2019-05-11 02:31:15 +10:00
moreloading = false;
2019-04-08 01:14:06 +10:00
todc();
});
}
}
2019-04-11 13:52:38 +10:00
//TL再取得
2019-05-11 02:31:15 +10:00
function reloadTL(type, data, acct_id, key, delc, voice) {
tl(type, data, acct_id, key, delc, voice, "");
2019-04-11 13:52:38 +10:00
}
2018-01-28 23:22:43 +11:00
//WebSocket切断
function tlCloser() {
2019-05-11 02:31:15 +10:00
Object.keys(websocket).forEach(function (tlid) {
2018-01-28 23:22:43 +11:00
if (websocketOld[tlid]) {
websocketOld[tlid].close();
2019-05-19 17:39:30 +10:00
console.log("%c Close Streaming API: Old" + tlid, "color:blue");
2018-01-28 23:22:43 +11:00
}
if (websocket[0]) {
console.log(websocket[0]);
websocket[tlid].close();
2019-05-19 17:39:30 +10:00
console.log("%c Close Streaming API:" + tlid, "color:blue");
2018-01-28 23:22:43 +11:00
}
});
websocket = [];
2019-05-11 02:31:15 +10:00
Object.keys(websocketHome).forEach(function (tlid) {
2018-01-28 23:22:43 +11:00
if (websocketHome[tlid]) {
websocketHome[tlid].close();
2019-05-19 17:39:30 +10:00
console.log("%c Close Streaming API:Integrated Home" + tlid, "color:blue");
2018-01-28 23:22:43 +11:00
}
});
websocketHome = [];
2019-05-11 02:31:15 +10:00
Object.keys(websocketLocal).forEach(function (tlid) {
2018-01-28 23:22:43 +11:00
if (websocketLocal[tlid]) {
websocketLocal[tlid].close();
2019-05-19 17:39:30 +10:00
console.log("%c Close Streaming API:Integrated Local" + tlid, "color:blue");
2018-01-28 23:22:43 +11:00
}
});
websocketLocal = [];
2019-05-11 02:31:15 +10:00
Object.keys(websocketNotf).forEach(function (tlid) {
2018-02-05 01:56:31 +11:00
if (websocketNotf[tlid]) {
websocketNotf[tlid].close();
2019-05-19 17:39:30 +10:00
console.log("%c Close Streaming API:Notf" + tlid, "color:blue");
2018-02-05 01:56:31 +11:00
}
});
2019-05-11 02:31:15 +10:00
Object.keys(misskeyws).forEach(function (tlid) {
if (misskeyws[tlid]) {
misskeyws[tlid].close();
2019-05-19 17:39:30 +10:00
console.log("%c Close Streaming API:Misskey" + tlid, "color:blue");
2019-05-11 02:31:15 +10:00
}
});
2019-05-19 17:39:30 +10:00
misskeyws = {}
2018-01-28 23:22:43 +11:00
}
//TLのタイトル
2018-03-20 15:55:25 +11:00
function cap(type, data, acct_id) {
2018-03-27 13:39:35 +11:00
//独自ロケール
var locale = localStorage.getItem("locale");
2019-05-11 02:31:15 +10:00
if (locale == "yes") {
var locale = false;
2018-03-27 13:39:35 +11:00
}
2018-01-28 23:22:43 +11:00
if (type == "home") {
2019-05-11 02:31:15 +10:00
if (localStorage.getItem("home_" + acct_id) && !locale) {
var response = localStorage.getItem("home_" + acct_id);
} else {
var response = "Home TL";
2018-03-20 15:55:25 +11:00
}
2018-01-28 23:22:43 +11:00
} else if (type == "local") {
2019-05-11 02:31:15 +10:00
if (localStorage.getItem("local_" + acct_id) && !locale) {
var response = localStorage.getItem("local_" + acct_id);
} else {
var response = "Local TL";
2018-03-20 15:55:25 +11:00
}
2018-06-12 01:44:28 +10:00
} else if (type == "local-media") {
2019-05-11 02:31:15 +10:00
if (localStorage.getItem("local_" + acct_id) && !locale) {
var response = localStorage.getItem("local_" + acct_id) + "(" + lang.lang_tl_media + ")";
} else {
var response = "Local TL(Media)";
2018-06-12 01:44:28 +10:00
}
2018-01-28 23:22:43 +11:00
} else if (type == "pub") {
2019-05-11 02:31:15 +10:00
if (localStorage.getItem("public_" + acct_id) && !locale) {
var response = localStorage.getItem("public_" + acct_id);
} else {
var response = "Federated TL";
2018-03-20 15:55:25 +11:00
}
2018-06-12 01:44:28 +10:00
} else if (type == "pub-media") {
2019-05-11 02:31:15 +10:00
if (localStorage.getItem("public_" + acct_id) && !locale) {
var response = localStorage.getItem("public_" + acct_id) + "(" + lang.lang_tl_media + ")";
} else {
var response = "Federated TL(Media)";
2018-06-12 01:44:28 +10:00
}
2018-01-28 23:22:43 +11:00
} else if (type == "tag") {
2019-05-11 02:31:15 +10:00
var response = "#" + escapeHTML(data)
2018-01-28 23:22:43 +11:00
} else if (type == "list") {
2019-05-11 02:31:15 +10:00
var ltitle = localStorage.getItem("list_" + data + "_" + acct_id);
var response = "List(" + ltitle + ")"
2018-01-28 23:22:43 +11:00
} else if (type == "notf") {
2019-05-11 02:31:15 +10:00
if (localStorage.getItem("notification_" + acct_id) && !locale) {
var response = localStorage.getItem("notification_" + acct_id);
} else {
var response = "Notification TL";
2018-03-20 15:55:25 +11:00
}
2018-03-27 13:39:35 +11:00
} else if (type == "noauth") {
2019-05-11 02:31:15 +10:00
var response = "Glance TL"
2018-05-02 14:14:03 +10:00
} else if (type == "dm") {
2019-05-11 02:31:15 +10:00
var response = "DM"
2018-07-29 17:37:54 +10:00
} else if (type == "mix") {
2019-05-11 02:31:15 +10:00
if (localStorage.getItem("mode_" + localStorage.getItem("domain_" + acct_id)) == "misskey") {
var response = "Social TL"
} else {
var response = "Integrated"
2018-08-10 01:18:35 +10:00
}
2018-07-29 17:37:54 +10:00
} else if (type == "plus") {
2019-05-11 02:31:15 +10:00
var response = "Local+"
} else if (type == "webview") {
var response = "Twitter"
} else if (type == "tootsearch") {
var response = "tootsearch(" + escapeHTML(data) + ")";
2018-01-28 23:22:43 +11:00
}
2018-03-20 15:55:25 +11:00
return response;
2018-01-28 23:22:43 +11:00
}
//TLのURL
function com(type, data) {
if (type == "home") {
return "home?"
2018-03-27 13:39:35 +11:00
} else if (type == "local" || type == "noauth") {
2018-01-28 23:22:43 +11:00
return "public?local=true&"
2018-06-12 01:44:28 +10:00
} else if (type == "local-media") {
return "public?local=true&only_media=true&"
2018-01-28 23:22:43 +11:00
} else if (type == "pub") {
return "public?"
2018-06-12 01:44:28 +10:00
} else if (type == "pub-media") {
return "public?only_media=true&"
2018-01-28 23:22:43 +11:00
} else if (type == "tag") {
return "tag/" + data + "?"
2019-05-11 02:31:15 +10:00
} else if (type == "list") {
2018-01-28 23:22:43 +11:00
return "list/" + data + "?"
2019-05-11 02:31:15 +10:00
} else if (type == "dm") {
2019-03-06 22:56:39 +11:00
return "direct?"
2018-01-28 23:22:43 +11:00
}
}
2019-05-08 01:48:59 +10:00
//Misskey
2019-05-11 02:31:15 +10:00
function typePs(type) {
2019-05-08 01:48:59 +10:00
if (type == "home") {
return "homeTimeline"
} else if (type == "local" || type == "noauth") {
return "localTimeline"
} else if (type == "local-media") {
return "localTimeline"
} else if (type == "pub") {
return "globalTimeline"
} else if (type == "mix") {
return "hybridTimeline"
} else if (type == "tag") {
return "hashtag"
2019-05-11 02:31:15 +10:00
} else if (type == "list") {
2019-05-08 01:48:59 +10:00
return "userList"
}
}
2018-07-30 21:03:49 +10:00
function misskeycom(type, data) {
if (type == "home") {
return "timeline"
2019-05-11 02:31:15 +10:00
} else if (type == "mix") {
2018-07-30 21:03:49 +10:00
return "hybrid-timeline"
} else if (type == "local" || type == "noauth") {
return "local-timeline"
} else if (type == "local-media") {
return "local-timeline"
} else if (type == "pub") {
return "global-timeline"
} else if (type == "pub-media") {
return "global-timeline"
} else if (type == "tag") {
return "search_by_tag"
2019-05-11 02:31:15 +10:00
} else if (type == "list") {
2018-07-30 21:03:49 +10:00
return "user-list-timeline"
}
}
2018-02-25 02:59:53 +11:00
//TLのアイコン
function icon(type) {
if (type == "home") {
2019-05-11 02:31:15 +10:00
var response = "home";
} else if (type == "local") {
2019-05-11 02:31:15 +10:00
var response = "people_outline";
} else if (type == "local-media") {
2019-05-11 02:31:15 +10:00
var response = "people_outline";
} else if (type == "pub") {
2019-05-11 02:31:15 +10:00
var response = "language";
} else if (type == "pub-media") {
2019-05-11 02:31:15 +10:00
var response = "language";
2018-02-25 02:59:53 +11:00
} else if (type == "tag") {
2019-05-11 02:31:15 +10:00
var response = "whatshot";
2018-04-01 07:00:27 +10:00
} else if (type == "list") {
2019-05-11 02:31:15 +10:00
var response = "view_headline";
} else if (type == "notf") {
2019-05-11 02:31:15 +10:00
var response = "notifications";
} else if (type == "noauth") {
2019-05-11 02:31:15 +10:00
var response = "people_outline";
} else if (type == "dm") {
2019-05-11 02:31:15 +10:00
var response = "mail_outline";
} else if (type == "mix") {
2019-05-11 02:31:15 +10:00
var response = "merge_type";
} else if (type == "plus") {
2019-05-11 02:31:15 +10:00
var response = "merge_type";
} else if (type == "webview") {
var response = "language";
} else if (type == "tootsearch") {
var response = "search";
2018-02-25 02:59:53 +11:00
}
return response;
2018-08-17 03:21:40 +10:00
}
2019-05-11 02:31:15 +10:00
function strAlive() {
var date = new Date();
var a = date.getTime();
var unix = Math.floor(a / 1000);
2018-08-17 03:21:40 +10:00
var col = localStorage.getItem("column");
2019-05-11 02:31:15 +10:00
if (col) {
2018-08-17 03:21:40 +10:00
var obj = JSON.parse(col);
2019-05-11 02:31:15 +10:00
Object.keys(obj).forEach(function (key) {
if ($("#notice_icon_" + key).hasClass("red-text")) {
var type = obj[key].type;
var acct_id = obj[key].domain;
var data = obj[key].data;
2018-08-23 03:29:39 +10:00
localStorage.removeItem("wserror_" + tlid)
2019-05-11 02:31:15 +10:00
reconnector(key, type, acct_id, data, "error");
2018-08-17 03:21:40 +10:00
}
});
}
2018-08-23 03:29:39 +10:00
return;
2018-08-17 03:21:40 +10:00
}
2019-05-11 02:31:15 +10:00
function strAliveInt() {
setTimeout(strAlive, 10000);
2018-08-17 03:21:40 +10:00
}
2019-05-11 02:31:15 +10:00
function reconnector(tlid, type, acct_id, data, mode) {
2019-05-19 17:39:30 +10:00
console.log("%c Reconnector:" + mode + "(timeline" + tlid + ")", "color:pink")
2019-05-11 02:31:15 +10:00
if (type == "mix" || type == "integrated" || type == "plus") {
if (localStorage.getItem("voice_" + tlid)) {
var voice = true;
} else {
var voice = false;
}
if (localStorage.getItem("filter_" + acct_id) != "undefined") {
var mute = getFilterType(JSON.parse(localStorage.getItem("filter_" + acct_id)), type);
} else {
var mute = [];
}
var wssh = localStorage.getItem("wssH_" + tlid);
2018-08-17 03:21:40 +10:00
websocketHome[wssh].close();
2019-05-11 02:31:15 +10:00
var wssl = localStorage.getItem("wssL_" + tlid);
2018-08-17 03:21:40 +10:00
websocketLocal[wssl].close();
2019-05-11 02:31:15 +10:00
mixre(acct_id, tlid, type, mute, "", voice, mode);
} else if (type == "notf") {
2019-04-22 02:51:32 +10:00
notfColumn(acct_id, tlid, "")
2019-05-11 02:31:15 +10:00
} else {
var wss = localStorage.getItem("wss_" + tlid);
2018-08-17 03:21:40 +10:00
websocket[wss].close();
2019-05-11 02:31:15 +10:00
if (localStorage.getItem("voice_" + tlid)) {
var voice = true;
} else {
var voice = false;
2018-08-17 03:21:40 +10:00
}
2019-05-11 02:31:15 +10:00
if (localStorage.getItem("filter_" + acct_id) != "undefined") {
var mute = getFilterType(JSON.parse(localStorage.getItem("filter_" + acct_id)), type);
} else {
var mute = [];
2018-08-17 03:21:40 +10:00
}
2019-05-11 02:31:15 +10:00
reload(type, '', acct_id, tlid, data, mute, "", voice, mode);
2018-08-17 03:21:40 +10:00
}
2019-06-07 02:11:04 +10:00
M.toast({ html: lang.lang_tl_reconnect, displayLength: 2000 })
2018-08-17 03:21:40 +10:00
}
function columnReload(tlid, type){
$("#notice_icon_" + tlid).addClass("red-text");
if (type == "mix" || type == "integrated" || type == "plus") {
if (localStorage.getItem("voice_" + tlid)) {
var voice = true;
} else {
var voice = false;
}
if (localStorage.getItem("filter_" + acct_id) != "undefined") {
var mute = getFilterType(JSON.parse(localStorage.getItem("filter_" + acct_id)), type);
} else {
var mute = [];
}
var wssh = localStorage.getItem("wssH_" + tlid);
websocketHome[wssh].close();
var wssl = localStorage.getItem("wssL_" + tlid);
websocketLocal[wssl].close();
parseColumn(tlid)
} else if (type == "notf") {
notfColumn(acct_id, tlid, "")
} else {
var wss = localStorage.getItem("wss_" + tlid);
websocket[wss].close();
if (localStorage.getItem("voice_" + tlid)) {
var voice = true;
} else {
var voice = false;
}
if (localStorage.getItem("filter_" + acct_id) != "undefined") {
var mute = getFilterType(JSON.parse(localStorage.getItem("filter_" + acct_id)), type);
} else {
var mute = [];
}
parseColumn(tlid)
}
}
2018-08-17 03:21:40 +10:00
strAliveInt()