wip: channel subscription type streaming
This commit is contained in:
parent
99793f2e20
commit
b3e9c3d6ce
|
@ -1560,3 +1560,201 @@ function pollParse(poll, acct_id, emojis) {
|
|||
</div>`
|
||||
return pollHtml
|
||||
}
|
||||
|
||||
//MastodonBaseStreaming
|
||||
var mastodonBaseWs = {}
|
||||
var mastodonBaseWsStatus = {}
|
||||
function mastodonBaseStreaming(acct_id) {
|
||||
const mute = getFilterTypeByAcct(acct_id, type)
|
||||
mastodonBaseWsStatus[domain] = 'undetected'
|
||||
const domain = localStorage.getItem(`domain_${acct_id}`)
|
||||
const at = localStorage.getItem(`acct_${acct_id}_at`)
|
||||
const start = `wss://cutls.com/api/v1/streaming/?at=${at}`
|
||||
mastodonBaseWs[domain] = new WebSocket(start)
|
||||
mastodonBaseWs[domain].onopen = function () {
|
||||
mastodonBaseWsStatus[domain] = 'available'
|
||||
}
|
||||
mastodonBaseWs[domain].onmessage = function () {
|
||||
const typeA = JSON.parse(mess.data).event
|
||||
if (typeA == 'delete') {
|
||||
$(`[unique-id=${JSON.parse(mess.data).payload}]`).hide()
|
||||
$(`[unique-id=${JSON.parse(mess.data).payload}]`).remove()
|
||||
} else if (typeA == 'update' || typeA == 'conversation') {
|
||||
if (
|
||||
!$('#unread_' + tlid + ' .material-icons').hasClass('teal-text')
|
||||
) {
|
||||
//markers show中はダメ
|
||||
const tl = JSON.parse(mess.data).stream
|
||||
const obj = JSON.parse(JSON.parse(mess.data).payload)
|
||||
const tls = getTlMeta(tl[0], tl, acct_id)
|
||||
insertTl(obj, tls)
|
||||
} else if (typeA == 'filters_changed') {
|
||||
filterUpdate(acct_id)
|
||||
} else if (~typeA.indexOf('announcement')) {
|
||||
announ(acct_id, tlid)
|
||||
}
|
||||
}
|
||||
}
|
||||
mastodonBaseWs[domain].onerror = function (error) {
|
||||
console.error("Error closing " + tlid)
|
||||
console.error(error)
|
||||
mastodonBaseWsStatus[domain] = 'cannotuse'
|
||||
mastodonBaseWs[domain] = false
|
||||
return false
|
||||
}
|
||||
mastodonBaseWs[domain].onclose = function () {
|
||||
console.warn("Closing " + tlid)
|
||||
mastodonBaseWs[domain] = false
|
||||
mastodonBaseWsStatus[domain] = 'cannotuse'
|
||||
connectMisskey(acct_id, true)
|
||||
return false
|
||||
}
|
||||
}
|
||||
function insertTl(obj, tls) {
|
||||
for (const timeline of tls) {
|
||||
const { id, voice } = timeline
|
||||
if ($(`#timeline_${id} [toot-id=${obj.id}]`).length) {
|
||||
if (voice) {
|
||||
say(obj.content)
|
||||
}
|
||||
const template = parse([obj], type, acct_id, tlid, '', mute, type)
|
||||
if (
|
||||
$(`timeline_box_${tlid}_box .tl-box`).scrollTop() === 0
|
||||
) {
|
||||
$(`#timeline_${tlid}`).prepend(template)
|
||||
} else {
|
||||
const pool = localStorage.getItem('pool_' + tlid)
|
||||
if (pool) {
|
||||
pool = template + pool
|
||||
} else {
|
||||
pool = template
|
||||
}
|
||||
localStorage.setItem('pool_' + tlid, pool)
|
||||
}
|
||||
scrollck()
|
||||
additional(acct_id, tlid)
|
||||
jQuery('time.timeago').timeago()
|
||||
}
|
||||
}
|
||||
}
|
||||
function getTlMeta(type, data, num) {
|
||||
const acct_id = num.toString()
|
||||
const columns = localStorage.getItem('column')
|
||||
const obj = JSON.parse(columns)
|
||||
let ret = []
|
||||
let i = 0
|
||||
switch (type) {
|
||||
case 'user':
|
||||
for (const tl of obj) {
|
||||
if (tl.domain != acct_id) continue
|
||||
if (tl.type == 'mix' || tl.type == 'home') {
|
||||
let voice = false
|
||||
if (localStorage.getItem('voice_' + i)) voice = true
|
||||
ret.push({
|
||||
id: i,
|
||||
voice: voice
|
||||
})
|
||||
}
|
||||
i++
|
||||
}
|
||||
break
|
||||
case 'public:local':
|
||||
for (const tl of obj) {
|
||||
if (tl.domain != acct_id) continue
|
||||
if (tl.type == 'mix' || tl.type == 'local') {
|
||||
let voice = false
|
||||
if (localStorage.getItem('voice_' + i)) voice = true
|
||||
ret.push({
|
||||
id: i,
|
||||
voice: voice
|
||||
})
|
||||
}
|
||||
i++
|
||||
}
|
||||
break
|
||||
case 'public:local:media':
|
||||
for (const tl of obj) {
|
||||
if (tl.domain != acct_id) continue
|
||||
if (tl.type == 'local-media') {
|
||||
let voice = false
|
||||
if (localStorage.getItem('voice_' + i)) voice = true
|
||||
ret.push({
|
||||
id: i,
|
||||
voice: voice
|
||||
})
|
||||
}
|
||||
i++
|
||||
}
|
||||
break;
|
||||
case 'public':
|
||||
for (const tl of obj) {
|
||||
if (tl.domain != acct_id) continue
|
||||
if (tl.type == 'pub') {
|
||||
let voice = false
|
||||
if (localStorage.getItem('voice_' + i)) voice = true
|
||||
ret.push({
|
||||
id: i,
|
||||
voice: voice
|
||||
})
|
||||
}
|
||||
i++
|
||||
}
|
||||
break;
|
||||
case 'public:media':
|
||||
for (const tl of obj) {
|
||||
if (tl.domain != acct_id) continue
|
||||
if (tl.type == 'pub-media') {
|
||||
let voice = false
|
||||
if (localStorage.getItem('voice_' + i)) voice = true
|
||||
ret.push({
|
||||
id: i,
|
||||
voice: voice
|
||||
})
|
||||
}
|
||||
i++
|
||||
}
|
||||
break;
|
||||
case 'list':
|
||||
for (const tl of obj) {
|
||||
if (tl.domain != acct_id) continue
|
||||
if (tl.type == 'list' && tl.data == data[1]) {
|
||||
let voice = false
|
||||
if (localStorage.getItem('voice_' + i)) voice = true
|
||||
ret.push({
|
||||
id: i,
|
||||
voice: voice
|
||||
})
|
||||
}
|
||||
i++
|
||||
}
|
||||
break;
|
||||
case 'hashtag':
|
||||
for (const tl of obj) {
|
||||
if (tl.domain != acct_id) continue
|
||||
const columnDataRaw = tl.data
|
||||
let columnData
|
||||
if (!columnDataRaw.name) {
|
||||
columnData = { name: columnDataRaw }
|
||||
} else {
|
||||
columnData = columnDataRaw
|
||||
}
|
||||
if (tl.type == 'tag') {
|
||||
let voice = false
|
||||
let can = false
|
||||
if (columnData.name == data[1]) can = true
|
||||
if (columnData.any.split(',').includes(data[1])) can = true
|
||||
|
||||
if (localStorage.getItem('voice_' + i)) voice = true
|
||||
ret.push({
|
||||
id: i,
|
||||
voice: voice
|
||||
})
|
||||
}
|
||||
i++
|
||||
}
|
||||
break;
|
||||
default:
|
||||
console.log(`Sorry, we are out of ${expr}.`);
|
||||
}
|
||||
return ret
|
||||
}
|
|
@ -247,6 +247,28 @@ function reload(type, cc, acct_id, tlid, data, mute, delc, voice, mode) {
|
|||
}
|
||||
}, 100)
|
||||
} else {
|
||||
var domain = localStorage.getItem('domain_' + acct_id)
|
||||
if(mastodonBaseWs[domain] == 'cannnotopen') {
|
||||
oldStreaming(type, cc, acct_id, tlid, data, mute, delc, voice, mode)
|
||||
} else if(mastodonBaseWs[domain] == 'undetected') {
|
||||
var mbws = setInterval(function () {
|
||||
if(mastodonBaseWs[domain] == 'cannnotopen') {
|
||||
oldStreaming(type, cc, acct_id, tlid, data, mute, delc, voice, mode)
|
||||
clearInterval(mbws)
|
||||
} else if(mastodonBaseWs[domain] == 'available') {
|
||||
stremaingSubscribe(type, cc, acct_id, tlid, data, mute, delc, voice, mode)
|
||||
clearInterval(mbws)
|
||||
}
|
||||
}, 1000)
|
||||
} else if(mastodonBaseWs[domain] == 'available') {
|
||||
stremaingSubscribe(type, cc, acct_id, tlid, data, mute, delc, voice, mode)
|
||||
}
|
||||
}
|
||||
}
|
||||
function stremaingSubscribe(type, cc, acct_id, tlid, data, mute, delc, voice, mode) {
|
||||
|
||||
}
|
||||
function oldStreaming(type, cc, acct_id, tlid, data, mute, delc, voice, mode) {
|
||||
var misskey = false
|
||||
if (localStorage.getItem('streaming_' + acct_id)) {
|
||||
var wss = localStorage.getItem('streaming_' + acct_id)
|
||||
|
@ -434,8 +456,6 @@ function reload(type, cc, acct_id, tlid, data, mute, delc, voice, mode) {
|
|||
return false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//一定のスクロールで発火
|
||||
function moreload(type, tlid) {
|
||||
var multi = localStorage.getItem('column')
|
||||
|
|
Loading…
Reference in New Issue
Block a user