#317 nice reload

This commit is contained in:
cutls 2020-09-06 22:57:20 +09:00
parent e402e0e7a7
commit 9d0f4096f8
3 changed files with 222 additions and 210 deletions

View File

@ -1572,15 +1572,15 @@ function mastodonBaseStreaming(acct_id) {
const start = `wss://${domain}/api/v1/streaming/?access_token=${at}`
mastodonBaseWs[domain] = new WebSocket(start)
mastodonBaseWs[domain].onopen = function () {
mastodonBaseWsStatus[domain] = 'connecting'
setTimeout(function () {
mastodonBaseWsStatus[domain] = 'available'
}, 1000)
}, 3000)
mastodonBaseWs[domain].send(`{"type":"subscribe","stream":"user"}`)
$('.notice_icon_acct_' + acct_id).removeClass('red-text')
}
mastodonBaseWs[domain].onmessage = function (mess) {
const typeA = JSON.parse(mess.data).event
console.log(domain + ':' + typeA)
if (typeA == 'delete') {
$(`[unique-id=${JSON.parse(mess.data).payload}]`).hide()
$(`[unique-id=${JSON.parse(mess.data).payload}]`).remove()
@ -1589,7 +1589,6 @@ function mastodonBaseStreaming(acct_id) {
const tl = JSON.parse(mess.data).stream
const obj = JSON.parse(JSON.parse(mess.data).payload)
const tls = getTlMeta(tl[0], tl, acct_id, obj)
console.log(domain + ':' + tls)
insertTl(obj, tls)
} else if (typeA == 'filters_changed') {
filterUpdate(acct_id)
@ -1623,19 +1622,23 @@ function mastodonBaseStreaming(acct_id) {
notf(acct_id, 0) //fallback
console.error("Error closing " + domain)
console.error(error)
if (mastodonBaseWsStatus[domain] == 'available') location.reload()
if (mastodonBaseWsStatus[domain] == 'available') alert(domain)
mastodonBaseWsStatus[domain] = 'cannotuse'
setTimeout(function () {
mastodonBaseWsStatus[domain] = 'cannotuse'
}, 2000)
}, 3000)
mastodonBaseWs[domain] = false
return false
}
mastodonBaseWs[domain].onclose = function () {
notf(acct_id, 0) //fallback
console.warn("Closing " + domain)
if (mastodonBaseWsStatus[domain] == 'available') location.reload()
if (mastodonBaseWsStatus[domain] == 'available') alert(domain)
mastodonBaseWs[domain] = false
mastodonBaseWsStatus[domain] = 'cannotuse'
setTimeout(function () {
mastodonBaseWsStatus[domain] = 'cannotuse'
}, 3000)
return false
}
}

View File

@ -206,7 +206,7 @@ function tl(type, data, acct_id, tlid, delc, voice, mode) {
additional(acct_id, tlid)
jQuery('time.timeago').timeago()
todc()
reload(type, '', acct_id, tlid, data, mute, delc, voice)
reload(type, 'from timeline to reload', acct_id, tlid, data, mute, delc, voice)
if (type == 'home' || type == 'notf') {
//Markers
var markers = localStorage.getItem('markers')
@ -250,30 +250,36 @@ function reload(type, cc, acct_id, tlid, data, mute, delc, voice, mode) {
var domain = localStorage.getItem('domain_' + acct_id)
if (mastodonBaseWsStatus[domain] == 'cannotuse') {
oldStreaming(type, cc, acct_id, tlid, data, mute, delc, voice, mode)
} else if(mastodonBaseWs[domain] == 'undetected') {
} else if (mastodonBaseWsStatus[domain] == 'undetected' || mastodonBaseWsStatus[domain] == 'connecting') {
const mbws = setInterval(function () {
if (mastodonBaseWsStatus[domain] == 'cannotuse') {
oldStreaming(type, cc, acct_id, tlid, data, mute, delc, voice, mode)
clearInterval(mbws)
} else if (mastodonBaseWsStatus[domain] == 'available') {
stremaingSubscribe(type, cc, acct_id, tlid, data, mute, delc, voice, mode)
$('#notice_icon_' + tlid).removeClass('red-text')
stremaingSubscribe(type, acct_id, data)
clearInterval(mbws)
}
}, 1000)
} else if (mastodonBaseWsStatus[domain] == 'available') {
stremaingSubscribe(type, cc, acct_id, tlid, data, mute, delc, voice, mode)
$('#notice_icon_' + tlid).removeClass('red-text')
stremaingSubscribe(type, acct_id, data)
}
}
}
function stremaingSubscribe(type, cc, acct_id, tlid, data, mute, delc, voice, mode) {
function stremaingSubscribe(type, acct_id, data, unsubscribe) {
let command = 'subscribe'
if (unsubscribe) command = 'unsubscribe'
let stream
const domain = localStorage.getItem('domain_' + acct_id)
if(type == 'home') return false
if (type === 'local' || type === 'mix') { stream = 'public:local' }
else if (type === 'local-media') { stream = 'public:local:media' }
else if (type === 'pub') { stream = 'public' }
else if (type === 'pub-media') { stream = 'public:media' }
else if (type === 'list') {
mastodonBaseWs[domain].send(`{"type":"subscribe","stream":"list","list":"${data}"}`)
mastodonBaseWs[domain].send(`{"type":"${command}","stream":"list","list":"${data}"}`)
return true
} else if (type === 'tag') {
let arr = []
let name = data
@ -282,12 +288,16 @@ function stremaingSubscribe(type, cc, acct_id, tlid, data, mute, delc, voice, mo
if (data.any) arr = arr.concat(data.any.split(','))
if (data.all) arr = arr.concat(data.all.split(','))
for (const tag of arr) {
mastodonBaseWs[domain].send(`{"type":"subscribe","stream":"hashtag","tag":"${tag}"}`)
mastodonBaseWs[domain].send(`{"type":"${command}","stream":"hashtag","tag":"${tag}"}`)
}
return true
}
mastodonBaseWs[domain].send(`{"type":"${command}","stream":"${stream}"`)
}
function oldStreaming(type, cc, acct_id, tlid, data, mute, delc, voice, mode) {
var misskey = false
const domain = localStorage.getItem(`domain_${acct_id}`)
var at = localStorage.getItem('acct_' + acct_id + '_at')
if (localStorage.getItem('streaming_' + acct_id)) {
var wss = localStorage.getItem('streaming_' + acct_id)
} else {
@ -1037,7 +1047,7 @@ function reconnector(tlid, type, acct_id, data, mode) {
var voice = false
}
var mute = getFilterTypeByAcct(acct_id, type)
reload(type, '', acct_id, tlid, data, mute, '', voice, mode)
var domain = localStorage.getItem('domain_' + acct_id)
}
M.toast({ html: lang.lang_tl_reconnect, displayLength: 2000 })
}
@ -1047,6 +1057,12 @@ function columnReload(tlid, type) {
var multi = localStorage.getItem('column')
var obj = JSON.parse(multi)
var acct_id = obj[tlid].domain
var domain = localStorage.getItem('domain_' + acct_id)
if (mastodonBaseWsStatus[domain] == 'available') {
stremaingSubscribe(type, acct_id, obj[tlid].data, true)
parseColumn(tlid, true)
return true
}
if (type == 'mix' || type == 'integrated' || type == 'plus') {
if (localStorage.getItem('voice_' + tlid)) {
var voice = true
@ -1066,15 +1082,10 @@ function columnReload(tlid, type) {
$('#notice_icon_' + tlid).removeClass('red-text')
getBookmark(acct_id, tlid, false)
} else {
var wss = localStorage.getItem('wss_' + tlid)
websocket[wss].close()
if (localStorage.getItem('voice_' + tlid)) {
var voice = true
} else {
var voice = false
}
var mute = getFilterTypeByAcct(acct_id, type)
parseColumn(tlid)
parseColumn(tlid, false)
}
}
//Markers

View File

@ -42,18 +42,16 @@ function parseColumn(target, dontclose) {
var multi = localStorage.getItem('multi')
if (multi) {
var obj = JSON.parse(multi)
var templete
Object.keys(obj).forEach(function (key) {
var acct = obj[key]
localStorage.setItem('name_' + key, acct.name)
localStorage.setItem('user_' + key, acct.user)
localStorage.setItem('user-id_' + key, acct.id)
localStorage.setItem('prof_' + key, acct.prof)
localStorage.setItem('domain_' + key, acct.domain)
localStorage.setItem('acct_' + key + '_at', acct.at)
mastodonBaseStreaming(key)
if(!target) mastodonBaseStreaming(key)
ckdb(key)
//フィルターデータ読もう
getFilter(key)