thedesk/app/js/tl/tl.js

1213 lines
33 KiB
JavaScript
Raw Normal View History

2018-01-28 23:22:43 +11:00
//TL取得
2019-11-09 00:52:54 +11:00
moreloading = false
var errorct = 0
2018-08-21 04:26:14 +10:00
function tl(type, data, acct_id, tlid, delc, voice, mode) {
2019-11-09 00:52:54 +11:00
scrollevent()
$('#unread_' + tlid + ' .material-icons').removeClass('teal-text')
localStorage.removeItem('pool')
var domain = localStorage.getItem('domain_' + acct_id)
2018-04-01 07:00:27 +10:00
//タグとかの場合はカラム追加して描画
2019-11-09 00:52:54 +11:00
if (tlid == 'add') {
console.log('add new column')
var newtab = $('.box').length
2018-01-28 23:22:43 +11:00
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
2019-11-09 00:52:54 +11:00
}
var multi = localStorage.getItem('column')
var obj = JSON.parse(multi)
localStorage.setItem('card_' + obj.length, 'true')
obj.push(add)
var json = JSON.stringify(obj)
localStorage.setItem('column', json)
parseColumn('add')
return
2018-01-28 23:22:43 +11:00
}
2019-05-11 02:31:15 +10:00
2018-01-28 23:22:43 +11:00
if (!type) {
2019-11-09 00:52:54 +11:00
var type = localStorage.getItem('now')
2018-01-28 23:22:43 +11:00
if (!type) {
//デフォルト
2019-11-09 00:52:54 +11:00
var type = 'local'
2018-01-28 23:22:43 +11:00
}
}
2019-11-09 00:52:54 +11:00
if (type == 'mix' && localStorage.getItem('mode_' + domain) != 'misskey') {
2018-01-28 23:22:43 +11:00
//Integratedなら飛ばす
2019-11-09 00:52:54 +11:00
$('#notice_' + tlid).text(
'Integrated TL(' + localStorage.getItem('user_' + acct_id) + '@' + domain + ')'
)
$('#notice_icon_' + tlid).text('merge_type')
mixtl(acct_id, tlid, 'integrated', delc, voice)
return
} else if (type == 'plus') {
2018-03-27 13:39:35 +11:00
//Local+なら飛ばす
2019-11-09 00:52:54 +11:00
$('#notice_' + tlid).text(
'Local+ TL(' + localStorage.getItem('user_' + acct_id) + '@' + domain + ')'
)
$('#notice_icon_' + tlid).text('people_outline')
mixtl(acct_id, tlid, 'plus', delc, voice)
return
} else if (type == 'notf') {
2018-01-28 23:22:43 +11:00
//通知なら飛ばす
2019-11-09 00:52:54 +11:00
notf(acct_id, tlid, 'direct')
$('#notice_' + tlid).text(
cap(type, data, acct_id) + '(' + localStorage.getItem('user_' + acct_id) + '@' + domain + ')'
)
$('#notice_icon_' + tlid).text('notifications')
return
2019-11-16 06:58:37 +11:00
} else if (type == 'bookmark') {
//ブックマークなら飛ばす
getBookmark(acct_id, tlid)
$('#notice_' + tlid).text(
cap(type, data, acct_id) + '(' + localStorage.getItem('user_' + acct_id) + '@' + domain + ')'
)
$('#notice_icon_' + tlid).text('bookmark')
return
} else if (type == 'home') {
//ホームならお知らせ「も」取りに行く
announ(acct_id, tlid);
2019-11-16 06:58:37 +11:00
}
2019-11-09 00:52:54 +11:00
localStorage.setItem('now', type)
todo(cap(type) + ' TL Loading...')
var at = localStorage.getItem('acct_' + acct_id + '_at')
if (type != 'noauth') {
2019-05-11 02:31:15 +10:00
var hdr = {
2019-11-09 00:52:54 +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 = {
2019-11-09 00:52:54 +11:00
'content-type': 'application/json'
}
domain = acct_id
$('#notice_' + tlid).text('Glance TL(' + domain + ')')
2018-03-27 13:39:35 +11:00
}
2019-11-09 00:52:54 +11: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
2019-05-11 02:31:15 +10:00
}
2019-11-09 00:52:54 +11:00
if (type == 'local-media' || type == 'pub-media') {
req.mediaOnly = true
2019-05-11 02:31:15 +10:00
}
2019-11-09 00:52:54 +11:00
if (type == 'tag') {
req.tag = data
2019-05-11 02:31:15 +10:00
}
2019-11-09 00:52:54 +11:00
if (type == 'list') {
req.listId = data
2019-05-11 02:31:15 +10:00
}
2019-11-09 00:52:54 +11:00
req.limit = 20
2019-05-11 02:31:15 +10:00
var i = {
method: method,
headers: hdr,
2019-11-04 03:10:06 +11:00
body: JSON.stringify(req)
2019-11-09 00:52:54 +11:00
}
2019-05-11 02:31:15 +10:00
} else {
2019-11-09 00:52:54 +11:00
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-11-09 00:52:54 +11:00
if (type == 'dm') {
var start = 'https://' + domain + '/api/v1/conversations'
2019-05-11 02:31:15 +10:00
} else {
2019-11-09 00:52:54 +11:00
var start = 'https://' + domain + '/api/v1/timelines/' + url
2019-05-11 02:31:15 +10:00
}
2019-11-09 00:52:54 +11:00
var method = 'GET'
2019-05-11 02:31:15 +10:00
var i = {
method: method,
headers: hdr
2019-11-09 00:52:54 +11:00
}
2019-05-11 02:31:15 +10:00
}
2019-11-09 00:52:54 +11:00
console.log(['Try to get timeline of ' + tlid, start])
2019-11-04 03:10:06 +11:00
fetch(start, i)
.then(function(response) {
if (!response.ok) {
response.text().then(function(text) {
2019-11-09 00:52:54 +11:00
setLog(response.url, response.status, text)
})
2019-11-04 03:10:06 +11:00
}
2019-11-09 00:52:54 +11:00
return response.json()
2019-11-04 03:10:06 +11:00
})
.catch(function(error) {
2019-11-09 00:52:54 +11:00
todo(error)
setLog(start, 'JSON', error)
console.error(error)
2019-11-04 03:10:06 +11:00
})
.then(function(json) {
2019-11-09 00:52:54 +11:00
console.log(['Result of getting timeline of ' + tlid, json])
$('#landing_' + tlid).hide()
2019-11-09 04:05:15 +11:00
var mute = getFilterTypeByAcct(acct_id, type)
2019-11-04 03:10:06 +11:00
if (misskey) {
2019-11-09 00:52:54 +11:00
var templete = misskeyParse(json, type, acct_id, tlid, '', mute)
2019-11-04 03:10:06 +11:00
} else {
2019-11-09 00:52:54 +11:00
var templete = parse(json, type, acct_id, tlid, '', mute, type)
localStorage.setItem('lastobj_' + tlid, json[0].id)
2019-09-07 02:33:30 +10:00
}
2019-11-09 00:52:54 +11:00
$('#timeline_' + tlid).html(templete)
additional(acct_id, tlid)
jQuery('time.timeago').timeago()
todc()
reload(type, '', acct_id, tlid, data, mute, delc, voice)
if (type == 'home' || type == 'notf') {
2019-11-04 03:10:06 +11:00
//Markers
2019-11-09 00:52:54 +11:00
var markers = localStorage.getItem('markers')
if (markers == 'yes') {
markers = true
2019-11-04 03:10:06 +11:00
} else {
2019-11-09 00:52:54 +11:00
markers = false
2019-11-04 03:10:06 +11:00
}
if (markers) {
2019-11-09 00:52:54 +11:00
getMarker(tlid, type, acct_id)
2019-11-04 03:10:06 +11:00
}
}
2019-11-09 00:52:54 +11:00
$(window).scrollTop(0)
})
2018-01-28 23:22:43 +11:00
}
//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) {
2019-11-09 00:52:54 +11:00
var type = localStorage.getItem('now')
2018-01-28 23:22:43 +11:00
}
2019-11-09 00:52:54 +11:00
var domain = localStorage.getItem('domain_' + acct_id)
var at = localStorage.getItem('acct_' + acct_id + '_at')
localStorage.setItem('now', type)
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 + '"}}'
2019-11-04 03:10:06 +11:00
var mskyset = setInterval(function() {
2019-05-11 02:31:15 +10:00
if (misskeywsstate[key]) {
2019-11-09 00:52:54 +11:00
misskeyws[key].send(send)
clearInterval(mskyset)
2019-05-08 01:48:59 +10:00
}
2019-11-09 00:52:54 +11:00
}, 100)
2019-05-11 02:31:15 +10:00
} else {
2019-11-09 00:52:54 +11:00
var misskey = false
if (localStorage.getItem('streaming_' + acct_id)) {
var wss = localStorage.getItem('streaming_' + acct_id)
2019-05-11 02:31:15 +10:00
} else {
2019-11-09 00:52:54 +11:00
var wss = 'wss://' + domain
2018-09-17 21:55:00 +10:00
}
2019-11-09 00:52:54 +11:00
if (type == 'home') {
var start = wss + '/api/v1/streaming/?stream=user&access_token=' + at
} else if (type == 'pub') {
var start = wss + '/api/v1/streaming/?stream=public&access_token=' + at
} else if (type == 'pub-media') {
var start = wss + '/api/v1/streaming/?stream=public:media&access_token=' + at
} else if (type == 'local') {
var start = wss + '/api/v1/streaming/?stream=public:local&access_token=' + at
} else if (type == 'local-media') {
var start =
wss + '/api/v1/streaming/?stream=public:local:media&only_media=true&access_token=' + at
} else if (type == 'tag') {
if (type == 'tag') {
var tag = localStorage.getItem('tag-range')
if (tag == 'local') {
data = data + '&local=true'
2018-07-30 21:03:49 +10:00
}
2018-03-14 05:31:31 +11:00
}
2019-11-09 00:52:54 +11:00
var start = wss + '/api/v1/streaming/?stream=hashtag&tag=' + data + '&access_token=' + at
} else if (type == 'noauth') {
var start = 'wss://' + acct_id + '/api/v1/streaming/?stream=public:local'
} else if (type == 'list') {
var start = wss + '/api/v1/streaming/?stream=list&list=' + data + '&access_token=' + at
} else if (type == 'dm') {
var start = wss + '/api/v1/streaming/?stream=direct&access_token=' + at
2018-03-14 05:31:31 +11:00
}
2019-11-09 00:52:54 +11:00
var wsid = websocket.length
localStorage.setItem('wss_' + tlid, wsid)
websocket[wsid] = new WebSocket(start)
2019-11-04 03:10:06 +11:00
websocket[wsid].onopen = function(mess) {
2019-11-09 00:52:54 +11:00
console.table({
tlid: tlid,
type: 'Connect Streaming API' + type,
domain: domain,
message: [mess]
})
errorct = 0
$('#notice_icon_' + tlid).removeClass('red-text')
}
2019-11-04 03:10:06 +11:00
websocket[wsid].onmessage = function(mess) {
2019-11-09 00:52:54 +11:00
console.log([tlid + ':Receive Streaming API:', JSON.parse(mess.data)])
2019-05-11 02:31:15 +10:00
if (misskey) {
2019-11-09 00:52:54 +11:00
if (JSON.parse(mess.data).type == 'note') {
var obj = JSON.parse(mess.data).body
2019-05-11 02:31:15 +10:00
if (voice) {
2019-11-09 00:52:54 +11:00
say(obj.text)
2019-05-11 02:31:15 +10:00
}
2019-11-04 03:10:06 +11:00
websocketNotf[acct_id].send(
JSON.stringify({
2019-11-09 00:52:54 +11:00
type: 'capture',
2019-11-04 03:10:06 +11:00
id: obj.id
})
2019-11-09 00:52:54 +11:00
)
var templete = misskeyParse([obj], type, acct_id, tlid, '', mute)
var pool = localStorage.getItem('pool_' + tlid)
2019-05-11 02:31:15 +10:00
if (pool) {
2019-11-09 00:52:54 +11:00
pool = templete + pool
2019-05-11 02:31:15 +10:00
} else {
2019-11-09 00:52:54 +11:00
pool = templete
2019-05-11 02:31:15 +10:00
}
2019-11-09 00:52:54 +11:00
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 {
2019-11-09 00:52:54 +11:00
var typeA = JSON.parse(mess.data).event
if (typeA == 'delete') {
var obj = JSON.parse(mess.data).payload
if (delc == 'true') {
2020-04-08 15:54:14 +10:00
$('#timeline_' + tlid + ' [unique-id=' + JSON.parse(mess.data).payload + ']').addClass(
2019-11-09 00:52:54 +11:00
'emphasized'
)
2020-04-08 15:54:14 +10:00
$('#timeline_' + tlid + ' [unique-id=' + JSON.parse(mess.data).payload + ']').addClass(
2019-11-09 00:52:54 +11:00
'by_delcatch'
)
2019-05-11 02:31:15 +10:00
} else {
2020-04-08 15:54:14 +10:00
$('[unique-id=' + JSON.parse(mess.data).payload + ']').hide()
$('[unique-id=' + JSON.parse(mess.data).payload + ']').remove()
2019-05-11 02:31:15 +10:00
}
2019-11-09 00:52:54 +11:00
} else if (typeA == 'update' || typeA == 'conversation') {
if (!$('#unread_' + tlid + ' .material-icons').hasClass('teal-text')) {
2019-09-07 02:33:30 +10:00
//markers show中はダメ
2019-11-09 00:52:54 +11:00
var obj = JSON.parse(JSON.parse(mess.data).payload)
if ($('#timeline_' + tlid + ' [toot-id=' + obj.id + ']').length < 1) {
2019-09-07 02:33:30 +10:00
if (voice) {
2019-11-09 00:52:54 +11:00
say(obj.content)
2019-09-07 02:33:30 +10:00
}
2019-11-09 00:52:54 +11:00
var templete = parse([obj], type, acct_id, tlid, '', mute, type)
if ($('timeline_box_' + tlid + '_box .tl-box').scrollTop() === 0) {
$('#timeline_' + tlid).prepend(templete)
2019-05-11 02:31:15 +10:00
} else {
2019-11-09 00:52:54 +11:00
var pool = localStorage.getItem('pool_' + tlid)
2019-09-07 02:33:30 +10:00
if (pool) {
2019-11-09 00:52:54 +11:00
pool = templete + pool
2019-09-07 02:33:30 +10:00
} else {
2019-11-09 00:52:54 +11:00
pool = templete
2019-09-07 02:33:30 +10:00
}
2019-11-09 00:52:54 +11:00
localStorage.setItem('pool_' + tlid, pool)
2019-05-11 02:31:15 +10:00
}
2019-11-09 00:52:54 +11:00
scrollck()
additional(acct_id, tlid)
jQuery('time.timeago').timeago()
2019-09-07 02:33:30 +10:00
} else {
2019-11-09 00:52:54 +11:00
todo('二重取得発生中')
2018-08-21 04:26:14 +10:00
}
2019-05-11 02:31:15 +10:00
2019-11-09 00:52:54 +11:00
todc()
2019-09-07 02:33:30 +10:00
}
2019-11-09 00:52:54 +11:00
} else if (typeA == 'filters_changed') {
filterUpdate(acct_id)
} else if (~typeA.indexOf('announcement')) {
announ(acct_id, tlid)
2018-07-30 21:03:49 +10:00
}
}
2019-11-09 00:52:54 +11:00
}
2019-11-04 03:10:06 +11:00
websocket[wsid].onerror = function(error) {
2019-11-09 00:52:54 +11:00
console.error('Error closing')
console.error(error)
if (mode == 'error') {
$('#notice_icon_' + tlid).addClass('red-text')
todo('WebSocket Error ' + error)
2019-05-11 02:31:15 +10:00
} else {
2019-11-09 00:52:54 +11:00
errorct++
console.log(errorct)
2019-05-11 02:31:15 +10:00
if (errorct < 3) {
2019-11-09 00:52:54 +11:00
reconnector(tlid, type, acct_id, data, 'error')
2019-05-11 02:31:15 +10:00
}
2018-08-23 03:29:39 +10:00
}
2019-11-09 00:52:54 +11:00
return false
}
2019-11-04 03:10:06 +11:00
websocket[wsid].onclose = function() {
2019-11-09 00:52:54 +11:00
console.warn('Closing ' + tlid)
if (mode == 'error') {
$('#notice_icon_' + tlid).addClass('red-text')
todo('WebSocket Closed')
2019-05-11 02:31:15 +10:00
} else {
2019-11-09 00:52:54 +11:00
errorct++
console.log(errorct)
2019-05-11 02:31:15 +10:00
if (errorct < 3) {
2019-11-09 00:52:54 +11:00
reconnector(tlid, type, acct_id, data, 'error')
2019-05-11 02:31:15 +10:00
}
2018-08-23 03:29:39 +10:00
}
2019-11-09 00:52:54 +11:00
return false
}
2019-05-08 01:48:59 +10:00
}
2018-01-28 23:22:43 +11:00
}
//一定のスクロールで発火
function moreload(type, tlid) {
2019-11-09 00:52:54 +11:00
var multi = localStorage.getItem('column')
var obj = JSON.parse(multi)
var acct_id = obj[tlid].domain
2018-01-28 23:22:43 +11:00
if (!type) {
2019-11-09 00:52:54 +11:00
var type = obj[tlid].type
2019-05-11 02:31:15 +10:00
} else {
2019-11-09 00:52:54 +11:00
var data
2018-02-05 01:56:31 +11:00
}
2019-11-09 00:52:54 +11:00
if (type == 'tag') {
var data = obj[tlid].data
var tag = localStorage.getItem('tag-range')
if (tag == 'local') {
data = data + '&local=true'
2018-03-14 05:31:31 +11:00
}
2019-11-09 00:52:54 +11:00
} else if (type == 'list') {
var data = obj[tlid].data
2018-01-28 23:22:43 +11:00
}
2019-11-09 00:52:54 +11:00
var sid = $('#timeline_' + tlid + ' .cvo')
2019-11-04 03:10:06 +11:00
.last()
2019-11-09 00:52:54 +11:00
.attr('unique-id')
2019-03-06 19:08:48 +11:00
if (sid && !moreloading) {
2019-11-09 00:52:54 +11:00
if (
type == 'mix' &&
localStorage.getItem('mode_' + localStorage.getItem('domain_' + acct_id)) != 'misskey'
) {
mixmore(tlid, 'integrated')
return
} else if (
type == 'plus' &&
localStorage.getItem('mode_' + localStorage.getItem('domain_' + acct_id)) != 'misskey'
) {
mixmore(tlid, 'plus')
return
} else if (type == 'notf') {
notfmore(tlid)
return
} else if (type == 'tootsearch') {
var data = obj[tlid].data
moreTs(tlid, data)
return
2019-11-16 06:58:37 +11:00
} else if (type == 'bookmark') {
getBookmark(acct_id, tlid, true)
return
2018-01-28 23:22:43 +11:00
}
2019-11-09 00:52:54 +11:00
moreloading = true
localStorage.setItem('now', type)
todo(cap(type) + ' TL MoreLoading')
if (type != 'noauth') {
var at = localStorage.getItem('acct_' + acct_id + '_at')
2019-05-11 02:31:15 +10:00
var hdr = {
2019-11-09 00:52:54 +11:00
'content-type': 'application/json',
Authorization: 'Bearer ' + at
}
var domain = localStorage.getItem('domain_' + acct_id)
2019-05-11 02:31:15 +10:00
} else {
var hdr = {
2019-11-09 00:52:54 +11:00
'content-type': 'application/json'
}
domain = acct_id
2018-07-30 21:03:49 +10:00
}
2019-11-09 00:52:54 +11:00
if (localStorage.getItem('mode_' + domain) == 'misskey') {
var misskey = true
2019-05-11 02:31:15 +10:00
hdr = {
2019-11-09 00:52:54 +11:00
'content-type': 'application/json'
}
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-11-09 00:52:54 +11:00
if (type == 'local-media' || type == 'pub-media') {
req.mediaOnly = true
2018-07-30 21:03:49 +10:00
}
2019-11-09 00:52:54 +11:00
if (type == 'tag') {
req.tag = data
2018-07-30 21:03:49 +10:00
}
2019-11-09 00:52:54 +11:00
if (type == 'list') {
req.listId = data
2018-07-30 21:03:49 +10:00
}
2019-11-09 00:52:54 +11:00
req.untilId = sid
req.limit = 20
2019-05-11 02:31:15 +10:00
var i = {
2018-07-30 21:03:49 +10:00
method: method,
headers: hdr,
2019-11-04 03:10:06 +11:00
body: JSON.stringify(req)
2019-11-09 00:52:54 +11:00
}
2019-05-11 02:31:15 +10:00
} else {
2019-11-09 00:52:54 +11:00
var misskey = false
var start = 'https://' + domain + '/api/v1/timelines/' + com(type, data) + 'max_id=' + sid
if (type == 'dm') {
var start = 'https://' + domain + '/api/v1/conversations?' + 'max_id=' + sid
2019-03-16 21:06:03 +11:00
}
2019-11-09 00:52:54 +11:00
var method = 'GET'
2019-05-11 02:31:15 +10:00
var i = {
2018-07-30 21:03:49 +10:00
method: method,
headers: hdr
2019-11-09 00:52:54 +11:00
}
2018-07-30 21:03:49 +10:00
}
2019-11-04 03:10:06 +11:00
fetch(start, i)
.then(function(response) {
if (!response.ok) {
response.text().then(function(text) {
2019-11-09 00:52:54 +11:00
setLog(response.url, response.status, text)
})
2019-11-04 03:10:06 +11:00
}
2019-11-09 00:52:54 +11:00
return response.json()
2019-11-04 03:10:06 +11:00
})
.catch(function(error) {
2019-11-09 00:52:54 +11:00
todo(error)
setLog(start, 'JSON', error)
console.error(error)
2019-11-04 03:10:06 +11:00
})
.then(function(json) {
2019-11-09 04:05:15 +11:00
var mute = getFilterTypeByAcct(acct_id, type)
2019-11-04 03:10:06 +11:00
if (misskey) {
2019-11-09 00:52:54 +11:00
var templete = misskeyParse(json, '', acct_id, tlid, '', mute)
2019-11-04 03:10:06 +11:00
} else {
2019-11-09 00:52:54 +11:00
var templete = parse(json, '', acct_id, tlid, '', mute, type)
2019-11-04 03:10:06 +11:00
}
2019-11-09 00:52:54 +11:00
$('#timeline_' + tlid).append(templete)
additional(acct_id, tlid)
jQuery('time.timeago').timeago()
moreloading = false
todc()
})
2018-01-28 23:22:43 +11:00
}
}
2019-04-08 01:14:06 +10:00
//TL差分取得
function tlDiff(type, data, acct_id, tlid, delc, voice, mode) {
2019-11-09 00:52:54 +11:00
console.log('Get diff of TL' + tlid)
var multi = localStorage.getItem('column')
var obj = JSON.parse(multi)
var acct_id = obj[tlid].domain
2019-04-08 01:14:06 +10:00
if (!type) {
2019-11-09 00:52:54 +11:00
var type = obj[tlid].type
2019-05-11 02:31:15 +10:00
} else {
2019-11-09 00:52:54 +11:00
var data
2019-04-08 01:14:06 +10:00
}
2019-11-09 00:52:54 +11:00
if (type == 'tag') {
var data = obj[tlid].data
var tag = localStorage.getItem('tag-range')
if (tag == 'local') {
data = data + '&local=true'
2019-04-08 01:14:06 +10:00
}
2019-11-09 00:52:54 +11:00
} else if (type == 'list') {
var data = obj[tlid].data
2019-04-08 01:14:06 +10:00
}
2019-11-09 00:52:54 +11:00
var sid = $('#timeline_' + tlid + ' .cvo')
2019-11-04 03:10:06 +11:00
.first()
2019-11-09 00:52:54 +11:00
.attr('unique-id')
2019-04-08 01:14:06 +10:00
if (sid && !moreloading) {
2019-11-09 00:52:54 +11:00
if (
type == 'mix' &&
localStorage.getItem('mode_' + localStorage.getItem('domain_' + acct_id)) != 'misskey'
) {
return
} else if (
type == 'plus' &&
localStorage.getItem('mode_' + localStorage.getItem('domain_' + acct_id)) != 'misskey'
) {
return
} else if (type == 'notf') {
return
2019-04-08 01:14:06 +10:00
}
2019-11-09 00:52:54 +11:00
moreloading = true
localStorage.setItem('now', type)
todo(cap(type) + ' TL MoreLoading')
if (type != 'noauth') {
var at = localStorage.getItem('acct_' + acct_id + '_at')
2019-05-11 02:31:15 +10:00
var hdr = {
2019-11-09 00:52:54 +11:00
'content-type': 'application/json',
Authorization: 'Bearer ' + at
}
var domain = localStorage.getItem('domain_' + acct_id)
2019-05-11 02:31:15 +10:00
} else {
var hdr = {
2019-11-09 00:52:54 +11:00
'content-type': 'application/json'
}
domain = acct_id
2019-04-08 01:14:06 +10:00
}
2019-11-09 00:52:54 +11:00
if (localStorage.getItem('mode_' + domain) == 'misskey') {
var misskey = true
2019-05-11 02:31:15 +10:00
hdr = {
2019-11-09 00:52:54 +11:00
'content-type': 'application/json'
2019-04-08 01:14:06 +10:00
}
2019-11-09 00:52:54 +11: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-11-09 00:52:54 +11:00
if (type == 'local-media' || type == 'pub-media') {
req.mediaOnly = true
2019-04-08 01:14:06 +10:00
}
2019-11-09 00:52:54 +11:00
if (type == 'tag') {
req.tag = data
2019-04-08 01:14:06 +10:00
}
2019-11-09 00:52:54 +11:00
if (type == 'list') {
req.listId = data
}
req.sinceId = sid
req.limit = 20
2019-05-11 02:31:15 +10:00
var i = {
2019-04-08 01:14:06 +10:00
method: method,
headers: hdr,
2019-11-04 03:10:06 +11:00
body: JSON.stringify(req)
2019-11-09 00:52:54 +11:00
}
2019-05-11 02:31:15 +10:00
} else {
2019-11-09 00:52:54 +11:00
var misskey = false
var start = 'https://' + domain + '/api/v1/timelines/' + com(type, data) + 'since_id=' + sid
if (type == 'dm') {
var start = 'https://' + domain + '/api/v1/conversations?' + 'since_id=' + sid
2019-04-08 01:14:06 +10:00
}
2019-11-09 00:52:54 +11:00
var method = 'GET'
2019-05-11 02:31:15 +10:00
var i = {
2019-04-08 01:14:06 +10:00
method: method,
headers: hdr
2019-11-09 00:52:54 +11:00
}
2019-04-08 01:14:06 +10:00
}
2019-05-11 02:31:15 +10:00
2019-11-04 03:10:06 +11:00
fetch(start, i)
.then(function(response) {
if (!response.ok) {
response.text().then(function(text) {
2019-11-09 00:52:54 +11:00
setLog(response.url, response.status, text)
})
2019-11-04 03:10:06 +11:00
}
2019-11-09 00:52:54 +11:00
return response.json()
2019-11-04 03:10:06 +11:00
})
.catch(function(error) {
2019-11-09 00:52:54 +11:00
todo(error)
setLog(start, 'JSON', error)
console.error(error)
2019-11-04 03:10:06 +11:00
})
.then(function(json) {
2019-11-09 00:52:54 +11:00
console.log(['Result diff of TL' + tlid, json])
2019-11-04 03:10:06 +11:00
if (misskey) {
2019-11-09 00:52:54 +11:00
var templete = misskeyParse(json, '', acct_id, tlid, '', mute)
2019-11-04 03:10:06 +11:00
} else {
2019-11-09 00:52:54 +11:00
var templete = parse(json, '', acct_id, tlid, '', mute, type)
2019-11-04 03:10:06 +11:00
}
2019-11-09 00:52:54 +11:00
$('#timeline_' + tlid).prepend(templete)
additional(acct_id, tlid)
jQuery('time.timeago').timeago()
moreloading = false
todc()
})
2019-04-08 01:14:06 +10:00
}
}
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) {
2019-11-09 00:52:54 +11:00
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-11-04 03:10:06 +11:00
Object.keys(websocket).forEach(function(tlid) {
2018-01-28 23:22:43 +11:00
if (websocketOld[tlid]) {
2019-11-09 00:52:54 +11:00
websocketOld[tlid].close()
console.log('%c Close Streaming API: Old' + tlid, 'color:blue')
2018-01-28 23:22:43 +11:00
}
if (websocket[0]) {
2019-11-09 00:52:54 +11:00
console.log(websocket[0])
websocket[tlid].close()
console.log('%c Close Streaming API:' + tlid, 'color:blue')
2018-01-28 23:22:43 +11:00
}
2019-11-09 00:52:54 +11:00
})
websocket = []
2019-11-09 04:05:15 +11:00
Object.keys(wsHome).forEach(function(tlid) {
if (wsHome[tlid]) {
wsHome[tlid].close()
2019-11-09 00:52:54 +11:00
console.log('%c Close Streaming API:Integrated Home' + tlid, 'color:blue')
2018-01-28 23:22:43 +11:00
}
2019-11-09 00:52:54 +11:00
})
2019-11-09 04:05:15 +11:00
wsHome = []
Object.keys(wsLocal).forEach(function(tlid) {
if (wsLocal[tlid]) {
wsLocal[tlid].close()
2019-11-09 00:52:54 +11:00
console.log('%c Close Streaming API:Integrated Local' + tlid, 'color:blue')
2018-01-28 23:22:43 +11:00
}
2019-11-09 00:52:54 +11:00
})
2019-11-09 04:05:15 +11:00
wsLocal = []
2019-11-04 03:10:06 +11:00
Object.keys(websocketNotf).forEach(function(tlid) {
2018-02-05 01:56:31 +11:00
if (websocketNotf[tlid]) {
2019-11-09 00:52:54 +11:00
websocketNotf[tlid].close()
console.log('%c Close Streaming API:Notf' + tlid, 'color:blue')
2018-02-05 01:56:31 +11:00
}
2019-11-09 00:52:54 +11:00
})
2019-11-04 03:10:06 +11:00
Object.keys(misskeyws).forEach(function(tlid) {
2019-05-11 02:31:15 +10:00
if (misskeyws[tlid]) {
2019-11-09 00:52:54 +11:00
misskeyws[tlid].close()
console.log('%c Close Streaming API:Misskey' + tlid, 'color:blue')
2019-05-11 02:31:15 +10:00
}
2019-11-09 00:52:54 +11: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
//独自ロケール
2019-11-09 00:52:54 +11:00
var locale = localStorage.getItem('locale')
if (locale == 'yes') {
var locale = false
2018-03-27 13:39:35 +11:00
}
2019-11-09 00:52:54 +11:00
if (type == 'home') {
if (localStorage.getItem('home_' + acct_id) && !locale) {
var response = localStorage.getItem('home_' + acct_id)
2019-05-11 02:31:15 +10:00
} else {
2019-11-09 00:52:54 +11:00
var response = 'Home TL'
2018-03-20 15:55:25 +11:00
}
2019-11-09 00:52:54 +11:00
} else if (type == 'local') {
if (localStorage.getItem('local_' + acct_id) && !locale) {
var response = localStorage.getItem('local_' + acct_id)
2019-05-11 02:31:15 +10:00
} else {
2019-11-09 00:52:54 +11:00
var response = 'Local TL'
2018-03-20 15:55:25 +11:00
}
2019-11-09 00:52:54 +11:00
} else if (type == 'local-media') {
if (localStorage.getItem('local_' + acct_id) && !locale) {
var response = localStorage.getItem('local_' + acct_id) + '(' + lang.lang_tl_media + ')'
2019-05-11 02:31:15 +10:00
} else {
2019-11-09 00:52:54 +11:00
var response = 'Local TL(Media)'
2018-06-12 01:44:28 +10:00
}
2019-11-09 00:52:54 +11:00
} else if (type == 'pub') {
if (localStorage.getItem('public_' + acct_id) && !locale) {
var response = localStorage.getItem('public_' + acct_id)
2019-05-11 02:31:15 +10:00
} else {
2019-11-09 00:52:54 +11:00
var response = 'Federated TL'
2018-03-20 15:55:25 +11:00
}
2019-11-09 00:52:54 +11:00
} else if (type == 'pub-media') {
if (localStorage.getItem('public_' + acct_id) && !locale) {
var response = localStorage.getItem('public_' + acct_id) + '(' + lang.lang_tl_media + ')'
2019-05-11 02:31:15 +10:00
} else {
2019-11-09 00:52:54 +11:00
var response = 'Federated TL(Media)'
2018-06-12 01:44:28 +10:00
}
2019-11-09 00:52:54 +11:00
} else if (type == 'tag') {
var response = '#' + escapeHTML(data)
} else if (type == 'list') {
var ltitle = localStorage.getItem('list_' + data + '_' + acct_id)
var response = 'List(' + ltitle + ')'
} else if (type == 'notf') {
if (localStorage.getItem('notification_' + acct_id) && !locale) {
var response = localStorage.getItem('notification_' + acct_id)
2019-05-11 02:31:15 +10:00
} else {
2019-11-09 00:52:54 +11:00
var response = 'Notification TL'
2018-03-20 15:55:25 +11:00
}
2019-11-09 00:52:54 +11:00
} else if (type == 'noauth') {
var response = 'Glance TL'
} else if (type == 'dm') {
var response = 'DM'
} else if (type == 'mix') {
if (localStorage.getItem('mode_' + localStorage.getItem('domain_' + acct_id)) == 'misskey') {
var response = 'Social TL'
2019-05-11 02:31:15 +10:00
} else {
2019-11-09 00:52:54 +11:00
var response = 'Integrated'
2018-08-10 01:18:35 +10:00
}
2019-11-09 00:52:54 +11:00
} else if (type == 'plus') {
var response = 'Local+'
} else if (type == 'webview') {
var response = 'Twitter'
} else if (type == 'tootsearch') {
var response = 'tootsearch(' + escapeHTML(data) + ')'
2019-11-16 06:58:37 +11:00
} else if (type == 'bookmark') {
var response = 'Bookmarks'
2018-01-28 23:22:43 +11:00
}
2019-11-09 00:52:54 +11:00
return response
2018-01-28 23:22:43 +11:00
}
//TLのURL
function com(type, data) {
2019-11-09 00:52:54 +11:00
if (type == 'home') {
return 'home?'
} else if (type == 'local' || type == 'noauth') {
return 'public?local=true&'
} else if (type == 'local-media') {
return 'public?local=true&only_media=true&'
} else if (type == 'pub') {
return 'public?'
} else if (type == 'pub-media') {
return 'public?only_media=true&'
} else if (type == 'tag') {
return 'tag/' + data + '?'
} else if (type == 'list') {
return 'list/' + data + '?'
} else if (type == 'dm') {
return 'direct?'
2019-11-16 06:58:37 +11:00
} else if (type == 'bookmark') {
return 'bookmarks?'
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-11-09 00:52:54 +11: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'
} else if (type == 'list') {
return 'userList'
2019-05-08 01:48:59 +10:00
}
}
2018-07-30 21:03:49 +10:00
function misskeycom(type, data) {
2019-11-09 00:52:54 +11:00
if (type == 'home') {
return 'timeline'
} else if (type == 'mix') {
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'
} else if (type == 'list') {
return 'user-list-timeline'
2018-07-30 21:03:49 +10:00
}
}
2018-02-25 02:59:53 +11:00
//TLのアイコン
function icon(type) {
2019-11-09 00:52:54 +11:00
if (type == 'home') {
var response = 'home'
} else if (type == 'local') {
var response = 'people_outline'
} else if (type == 'local-media') {
var response = 'people_outline'
} else if (type == 'pub') {
var response = 'language'
} else if (type == 'pub-media') {
var response = 'language'
} else if (type == 'tag') {
var response = 'whatshot'
} else if (type == 'list') {
var response = 'view_headline'
} else if (type == 'notf') {
var response = 'notifications'
} else if (type == 'noauth') {
var response = 'people_outline'
} else if (type == 'dm') {
var response = 'mail_outline'
} else if (type == 'mix') {
var response = 'merge_type'
} else if (type == 'plus') {
var response = 'merge_type'
} else if (type == 'webview') {
var response = 'language'
} else if (type == 'tootsearch') {
var response = 'search'
2019-11-16 06:58:37 +11:00
} else if (type == 'bookmark') {
var response = 'bookmark'
2018-02-25 02:59:53 +11:00
}
2019-11-09 00:52:54 +11:00
return response
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-11-09 00:52:54 +11:00
console.log('%c Reconnector:' + mode + '(timeline' + tlid + ')', 'color:pink')
if (type == 'mix' || type == 'integrated' || type == 'plus') {
if (localStorage.getItem('voice_' + tlid)) {
var voice = true
2019-05-11 02:31:15 +10:00
} else {
2019-11-09 00:52:54 +11:00
var voice = false
2019-05-11 02:31:15 +10:00
}
2019-11-09 04:05:15 +11:00
var mute = getFilterTypeByAcct(acct_id, type)
2019-11-09 00:52:54 +11:00
var wssh = localStorage.getItem('wssH_' + tlid)
2019-11-09 04:05:15 +11:00
wsHome[wssh].close()
2019-11-09 00:52:54 +11:00
var wssl = localStorage.getItem('wssL_' + tlid)
2019-11-09 04:05:15 +11:00
wsLocal[wssl].close()
2019-11-09 00:52:54 +11:00
mixre(acct_id, tlid, type, mute, '', voice, mode)
} else if (type == 'notf') {
notfColumn(acct_id, tlid, '')
2019-05-11 02:31:15 +10:00
} else {
2019-11-09 00:52:54 +11:00
var wss = localStorage.getItem('wss_' + tlid)
websocket[wss].close()
if (localStorage.getItem('voice_' + tlid)) {
var voice = true
2019-05-11 02:31:15 +10:00
} else {
2019-11-09 00:52:54 +11:00
var voice = false
2018-08-17 03:21:40 +10:00
}
2019-11-09 04:05:15 +11:00
var mute = getFilterTypeByAcct(acct_id, type)
2019-11-09 00:52:54 +11:00
reload(type, '', acct_id, tlid, data, mute, '', voice, mode)
2018-08-17 03:21:40 +10:00
}
2019-11-09 00:52:54 +11:00
M.toast({ html: lang.lang_tl_reconnect, displayLength: 2000 })
2018-08-17 03:21:40 +10:00
}
2019-09-07 02:33:30 +10:00
function columnReload(tlid, type) {
2019-11-09 00:52:54 +11:00
$('#notice_icon_' + tlid).addClass('red-text')
$('#unread_' + tlid + ' .material-icons').removeClass('teal-text')
2019-11-16 06:58:37 +11:00
var multi = localStorage.getItem('column')
var obj = JSON.parse(multi)
var acct_id = obj[tlid].domain
2019-11-09 00:52:54 +11:00
if (type == 'mix' || type == 'integrated' || type == 'plus') {
if (localStorage.getItem('voice_' + tlid)) {
var voice = true
} else {
2019-11-09 00:52:54 +11:00
var voice = false
}
2019-11-09 04:05:15 +11:00
var mute = getFilterTypeByAcct(acct_id, type)
2019-11-09 00:52:54 +11:00
var wssh = localStorage.getItem('wssH_' + tlid)
2019-11-09 04:24:42 +11:00
wsHome[wssh].close()
2019-11-09 00:52:54 +11:00
var wssl = localStorage.getItem('wssL_' + tlid)
2019-11-09 04:24:42 +11:00
wsLocal[wssl].close()
2019-11-09 00:52:54 +11:00
parseColumn(tlid)
} else if (type == 'notf') {
$('#notice_icon_' + tlid).removeClass('red-text')
notfColumn(acct_id, tlid, '')
2019-11-16 06:58:37 +11:00
} else if (type == 'bookmark') {
$('#notice_icon_' + tlid).removeClass('red-text')
getBookmark(acct_id, tlid, false)
} else {
2019-11-09 00:52:54 +11:00
var wss = localStorage.getItem('wss_' + tlid)
websocket[wss].close()
if (localStorage.getItem('voice_' + tlid)) {
var voice = true
} else {
2019-11-09 00:52:54 +11:00
var voice = false
}
2019-11-09 04:05:15 +11:00
var mute = getFilterTypeByAcct(acct_id, type)
2019-11-09 00:52:54 +11:00
parseColumn(tlid)
}
}
2019-09-07 02:33:30 +10:00
//Markers
function getMarker(tlid, type, acct_id) {
2019-11-09 00:52:54 +11:00
var domain = localStorage.getItem('domain_' + acct_id)
var at = localStorage.getItem('acct_' + acct_id + '_at')
if (type == 'home') {
var add = 'home'
} else if (type == 'notf') {
var add = 'notifications'
2019-09-07 02:33:30 +10:00
}
2019-11-09 00:52:54 +11:00
var start = 'https://' + domain + '/api/v1/markers?timeline=' + add
2019-09-07 02:33:30 +10:00
fetch(start, {
2019-11-09 00:52:54 +11:00
method: 'GET',
2019-09-07 02:33:30 +10:00
headers: {
2019-11-09 00:52:54 +11:00
'content-type': 'application/json',
Authorization: 'Bearer ' + at
2019-10-31 02:30:26 +11:00
}
2019-11-04 03:10:06 +11:00
})
.then(function(response) {
if (!response.ok) {
response.text().then(function(text) {
2019-11-09 00:52:54 +11:00
setLog(response.url, response.status, text)
})
2019-11-04 03:10:06 +11:00
}
2019-11-09 00:52:54 +11:00
return response.json()
2019-11-04 03:10:06 +11:00
})
.catch(function(error) {
2019-11-09 00:52:54 +11:00
$('#unread_' + tlid).attr('title', lang.lang_layout_unread + ':' + lang.lang_nothing)
$('#unread_' + tlid).attr('data-id', '')
return false
2019-11-04 03:10:06 +11:00
})
.then(function(json) {
if (json) {
if (json[add]) {
2019-11-09 00:52:54 +11:00
json = json[add]
$('#unread_' + tlid).attr(
'title',
lang.lang_layout_unread + ':' + json.updated_at + ' v' + json.version
)
$('#unread_' + tlid).attr('data-id', json.last_read_id)
2019-11-04 03:10:06 +11:00
} else {
2019-11-09 00:52:54 +11:00
$('#unread_' + tlid).attr('title', lang.lang_layout_unread + ':' + lang.lang_nothing)
$('#unread_' + tlid).attr('data-id', '')
2019-11-04 03:10:06 +11:00
}
2019-09-07 02:33:30 +10:00
} else {
2019-11-09 00:52:54 +11:00
$('#unread_' + tlid).attr('title', lang.lang_layout_unread + ':' + lang.lang_nothing)
$('#unread_' + tlid).attr('data-id', '')
2019-09-07 02:33:30 +10:00
}
2019-11-09 00:52:54 +11:00
})
2019-09-07 02:33:30 +10:00
}
function showUnread(tlid, type, acct_id) {
2019-11-09 00:52:54 +11:00
if ($('#unread_' + tlid + ' .material-icons').hasClass('teal-text')) {
goTop(tlid)
return
2019-09-07 02:33:30 +10:00
}
2019-11-09 00:52:54 +11:00
$('#unread_' + tlid + ' .material-icons').addClass('teal-text')
var domain = localStorage.getItem('domain_' + acct_id)
var at = localStorage.getItem('acct_' + acct_id + '_at')
var id = $('#unread_' + tlid).attr('data-id')
if (type == 'home') {
var add = 'timelines/home?min_id=' + id
} else if (type == 'notf') {
var add = 'notifications?min_id=' + id
2019-09-07 02:33:30 +10:00
}
2019-11-09 00:52:54 +11:00
var start = 'https://' + domain + '/api/v1/' + add
2019-09-07 02:33:30 +10:00
fetch(start, {
2019-11-09 00:52:54 +11:00
method: 'GET',
2019-09-07 02:33:30 +10:00
headers: {
2019-11-09 00:52:54 +11:00
'content-type': 'application/json',
Authorization: 'Bearer ' + at
2019-09-07 02:33:30 +10:00
}
2019-11-04 03:10:06 +11:00
})
.then(function(response) {
if (!response.ok) {
response.text().then(function(text) {
2019-11-09 00:52:54 +11:00
setLog(response.url, response.status, text)
})
2019-11-04 03:10:06 +11:00
}
2019-11-09 00:52:54 +11:00
return response.json()
2019-11-04 03:10:06 +11:00
})
.catch(function(error) {
2019-11-09 00:52:54 +11:00
todo(error)
setLog(start, 'JSON', error)
console.error(error)
2019-11-04 03:10:06 +11:00
})
.then(function(json) {
if (!json || !json.length) {
2019-11-09 00:52:54 +11:00
columnReload(tlid, type)
2019-11-04 03:10:06 +11:00
}
2019-11-09 04:05:15 +11:00
var mute = getFilterTypeByAcct(acct_id, type)
2019-11-09 00:52:54 +11:00
var templete = parse(json, type, acct_id, tlid, '', mute, type)
var len = json.length - 1
$('#timeline_' + tlid).html(templete)
if ($('#timeline_' + tlid + ' .cvo:eq(' + len + ')').length) {
var to = $('#timeline_' + tlid + ' .cvo:eq(' + len + ')').offset().top
$('#timeline_box_' + tlid + '_box .tl-box').scrollTop(to)
2019-11-04 03:10:06 +11:00
}
2019-11-09 00:52:54 +11:00
additional(acct_id, tlid)
jQuery('time.timeago').timeago()
todc()
})
2019-09-07 02:33:30 +10:00
}
2019-11-09 00:52:54 +11:00
var ueloadlock = false
2019-09-07 02:46:50 +10:00
function ueload(tlid) {
if (ueloadlock) {
2019-11-09 00:52:54 +11:00
return false
2019-09-07 02:33:30 +10:00
}
2019-11-09 00:52:54 +11:00
ueloadlock = true
var multi = localStorage.getItem('column')
var obj = JSON.parse(multi)
var acct_id = obj[tlid * 1].domain
var type = obj[tlid * 1].type
var domain = localStorage.getItem('domain_' + acct_id)
var at = localStorage.getItem('acct_' + acct_id + '_at')
var id = $('#timeline_' + tlid + ' .cvo:eq(0)').attr('unique-id')
if (type == 'home') {
var add = 'timelines/home?min_id=' + id
} else if (type == 'notf') {
var add = 'notifications?min_id=' + id
2019-09-07 02:33:30 +10:00
}
2019-11-09 00:52:54 +11:00
var start = 'https://' + domain + '/api/v1/' + add
2019-09-07 02:33:30 +10:00
fetch(start, {
2019-11-09 00:52:54 +11:00
method: 'GET',
2019-09-07 02:33:30 +10:00
headers: {
2019-11-09 00:52:54 +11:00
'content-type': 'application/json',
Authorization: 'Bearer ' + at
2019-09-08 10:39:26 +10:00
}
2019-11-04 03:10:06 +11:00
})
.then(function(response) {
if (!response.ok) {
response.text().then(function(text) {
2019-11-09 00:52:54 +11:00
setLog(response.url, response.status, text)
})
2019-11-04 03:10:06 +11:00
}
2019-11-09 00:52:54 +11:00
return response.json()
2019-11-04 03:10:06 +11:00
})
.catch(function(error) {
2019-11-09 00:52:54 +11:00
todo(error)
setLog(start, 'JSON', error)
console.error(error)
2019-11-04 03:10:06 +11:00
})
.then(function(json) {
if (!json) {
2019-11-09 00:52:54 +11:00
columnReload(tlid, type)
2019-11-04 03:10:06 +11:00
}
2019-11-09 04:05:15 +11:00
var mute = getFilterTypeByAcct(acct_id, type)
2019-11-09 00:52:54 +11:00
var templete = parse(json, '', acct_id, tlid, '', mute, type)
var len = json.length - 1
$('#timeline_' + tlid).prepend(templete)
if ($('#timeline_' + tlid + ' .cvo:eq(' + len + ')').length) {
var to = $('#timeline_' + tlid + ' .cvo:eq(' + len + ')').offset().top
$('#timeline_box_' + tlid + '_box .tl-box').scrollTop(to)
2019-11-04 03:10:06 +11:00
}
2019-11-09 00:52:54 +11:00
additional(acct_id, tlid)
jQuery('time.timeago').timeago()
todc()
ueloadlock = false
})
2019-09-07 02:33:30 +10:00
}
2019-09-22 20:55:59 +10:00
function asRead(callback) {
2019-09-07 02:46:50 +10:00
//Markers
2019-11-09 00:52:54 +11:00
var markers = localStorage.getItem('markers')
if (markers == 'no') {
markers = false
2019-09-07 02:46:50 +10:00
} else {
2019-11-09 00:52:54 +11:00
markers = true
2019-09-07 02:46:50 +10:00
}
if (markers) {
2019-11-09 00:52:54 +11:00
var multi = localStorage.getItem('column')
var obj = JSON.parse(multi)
var obl = obj.length
ct = 0
2019-09-22 20:55:59 +10:00
for (var i = 0; i < obl; i++) {
2019-11-09 00:52:54 +11:00
var acct_id = obj[i].domain
var type = obj[i].type
if (type == 'home' || type == 'notf') {
if (type == 'home') {
var id = $('#timeline_' + i + ' .cvo:eq(0)').attr('unique-id')
2019-09-07 02:46:50 +10:00
var poster = {
home: {
last_read_id: id
}
2019-11-09 00:52:54 +11:00
}
2019-09-08 10:39:26 +10:00
} else {
2019-11-09 00:52:54 +11:00
var id = $('#timeline_' + i + ' .cvo:eq(0)').attr('data-notf')
2019-09-07 02:46:50 +10:00
var poster = {
notifications: {
last_read_id: id
}
2019-11-09 00:52:54 +11:00
}
2019-09-07 02:46:50 +10:00
}
2019-09-22 20:55:59 +10:00
2019-11-09 00:52:54 +11:00
var domain = localStorage.getItem('domain_' + acct_id)
var at = localStorage.getItem('acct_' + acct_id + '_at')
var httpreq = new XMLHttpRequest()
var start = 'https://' + domain + '/api/v1/markers'
httpreq.open('POST', start, true)
httpreq.setRequestHeader('Content-Type', 'application/json')
httpreq.setRequestHeader('Authorization', 'Bearer ' + at)
httpreq.responseType = 'json'
httpreq.send(JSON.stringify(poster))
2019-11-04 03:10:06 +11:00
httpreq.onreadystatechange = function() {
2019-09-07 02:46:50 +10:00
if (httpreq.readyState === 4) {
2019-11-09 00:52:54 +11:00
var json = httpreq.response
2019-11-04 03:10:06 +11:00
if (this.status !== 200) {
2019-11-09 00:52:54 +11:00
setLog(start, this.status, this.response)
2019-11-04 03:10:06 +11:00
}
2019-11-09 00:52:54 +11:00
console.log(json)
ct++
2019-09-22 20:55:59 +10:00
if (ct == obl && callback) {
2019-11-09 00:52:54 +11:00
postMessage(['asReadComp', ''], '*')
2019-09-22 20:55:59 +10:00
}
2019-09-07 02:46:50 +10:00
}
2019-11-09 00:52:54 +11:00
}
2019-09-07 02:46:50 +10:00
}
2019-09-07 02:33:30 +10:00
}
}
2019-09-07 02:46:50 +10:00
}
2019-09-22 20:55:59 +10:00
function asReadEnd() {
//Markers
2019-11-09 00:52:54 +11:00
var markers = localStorage.getItem('markers')
if (markers == 'no') {
markers = false
2019-09-22 20:55:59 +10:00
} else {
2019-11-09 00:52:54 +11:00
markers = true
2019-09-22 20:55:59 +10:00
}
if (markers) {
2019-11-09 00:52:54 +11:00
asRead(true)
2019-09-22 20:55:59 +10:00
Swal.fire({
title: lang.lang_tl_postmarkers_title,
html: lang.lang_tl_postmarkers,
timer: 3000,
onBeforeOpen: () => {
2019-11-09 00:52:54 +11:00
Swal.showLoading()
2019-09-22 20:55:59 +10:00
},
2019-11-04 03:10:06 +11:00
onClose: () => {}
2019-11-09 00:52:54 +11:00
}).then(result => {})
2019-09-22 20:55:59 +10:00
} else {
2019-11-09 00:52:54 +11:00
postMessage(['asReadComp', ''], '*')
2019-09-22 20:55:59 +10:00
}
2019-11-04 03:10:06 +11:00
}
2019-11-16 06:58:37 +11:00
//ブックマーク
function getBookmark(acct_id, tlid, more) {
moreloading = true
console.log(acct_id, tlid, more)
if (more) {
var sid = $('#timeline_' + tlid + ' .notif-marker')
.last()
.attr('data-maxid')
var ad = '?max_id=' + sid
} else {
var ad = ''
}
var at = localStorage.getItem('acct_' + acct_id + '_at')
var domain = localStorage.getItem('domain_' + acct_id)
var start = 'https://' + domain + '/api/v1/bookmarks' + ad
var httpreq = new XMLHttpRequest()
httpreq.open('GET', start, true)
httpreq.setRequestHeader('Content-Type', 'application/json')
httpreq.setRequestHeader('Authorization', 'Bearer ' + at)
httpreq.responseType = 'json'
httpreq.send()
httpreq.onreadystatechange = function() {
if (httpreq.readyState === 4) {
var json = httpreq.response
if (this.status !== 200) {
setLog(start, this.status, this.response)
}
var max_ids = httpreq.getResponseHeader('link')
var max_id = 0
if (max_ids) {
max_ids = max_ids.match(/[?&]{1}max_id=([0-9]+)/)
if (max_ids) {
max_id = max_ids[1]
}
}
var templete = parse(json, 'bookmark', acct_id, tlid, -1, null)
templete = templete + '<div class="hide notif-marker" data-maxid="' + max_id + '"></div>'
if (more) {
$('#timeline_' + tlid).append(templete)
} else {
$('#timeline_' + tlid).html(templete)
}
$('#landing_' + tlid).hide()
jQuery('time.timeago').timeago()
moreloading = false
todc()
}
}
}
//Announcement
function announ(acct_id, tlid) {
var at = localStorage.getItem('acct_' + acct_id + '_at')
var domain = localStorage.getItem('domain_' + acct_id)
var start = 'https://' + domain + '/api/v1/announcements'
var httpreq = new XMLHttpRequest()
httpreq.open('GET', start, true)
httpreq.setRequestHeader('Content-Type', 'application/json')
httpreq.setRequestHeader('Authorization', 'Bearer ' + at)
httpreq.responseType = 'json'
httpreq.send()
httpreq.onreadystatechange = function() {
if (httpreq.readyState === 4) {
var json = httpreq.response
if (this.status !== 200) {
setLog(start, this.status, this.response)
}
if (json.length > 0) {
$('.notf-announ_' + acct_id).removeClass('hide')
2020-01-30 01:22:53 +11:00
var ct = 0
for (var i = 0; i < json.length; i++) {
if (localStorage.getItem('announ_' + acct_id) == json[i].id) {
break
}
ct++
}
if(ct > 0) {
$('.notf-announ_' + acct_id + '_ct').text(ct)
}
} else {
$('.notf-announ_' + acct_id).addClass('hide')
}
var templete = announParse(json, acct_id, tlid)
$('#announce_' + tlid).html(templete)
jQuery('time.timeago').timeago()
todc()
}
}
}