Fix streaming for megalodon 10

This commit is contained in:
AkiraFukushima 2024-03-19 01:14:58 +09:00
parent 5447069d4a
commit d6a527e2dd
No known key found for this signature in database
GPG Key ID: B6E51BAC4DE1A957
3 changed files with 8 additions and 14 deletions

View File

@ -1,5 +1,5 @@
import { Account } from '@/db'
import generator, { Entity, MegalodonInterface, WebSocketInterface } from 'megalodon'
import { Entity, MegalodonInterface, WebSocketInterface } from 'megalodon'
import { useEffect, useState, useCallback, useRef } from 'react'
import { FormattedMessage, useIntl } from 'react-intl'
import { Virtuoso } from 'react-virtuoso'
@ -42,10 +42,8 @@ export default function Notifications(props: Props) {
setFilters(f)
const res = await loadNotifications(props.client)
setNotifications(res)
const instance = await props.client.getInstance()
const c = generator(props.account.sns, instance.data.urls.streaming_api, props.account.access_token, 'Whalebird')
updateMarker(props.client)
streaming.current = c.userSocket()
streaming.current = await props.client.userStreaming()
streaming.current.on('connect', () => {
console.log('connected to notifications')
})

View File

@ -1,5 +1,5 @@
import { Account } from '@/db'
import generator, { Entity, MegalodonInterface, WebSocketInterface } from 'megalodon'
import { Entity, MegalodonInterface, WebSocketInterface } from 'megalodon'
import { useEffect, useState, useCallback, useRef } from 'react'
import { Virtuoso } from 'react-virtuoso'
import Status from './status/Status'
@ -57,27 +57,25 @@ export default function Timeline(props: Props) {
setFilters(f)
const res = await loadTimeline(props.timeline, props.client)
setStatuses(res)
const instance = await props.client.getInstance()
const c = generator(props.account.sns, instance.data.urls.streaming_api, props.account.access_token, 'Whalebird')
setList(null)
switch (props.timeline) {
case 'home': {
streaming.current = c.userSocket()
streaming.current = await props.client.userStreaming()
break
}
case 'local': {
streaming.current = c.localSocket()
streaming.current = await props.client.localStreaming()
break
}
case 'public': {
streaming.current = c.publicSocket()
streaming.current = await props.client.publicStreaming()
break
}
default: {
const match = props.timeline.match(/list_(\d+)/)
if (match && match[1] && typeof match[1] === 'string') {
const res = await props.client.getList(match[1])
streaming.current = c.listSocket(match[1])
streaming.current = await props.client.listStreaming(match[1])
setList(res.data)
}
break

View File

@ -62,7 +62,6 @@ export const AccountsProvider: React.FC<Props> = ({ children }) => {
if (!account.id) return
// Start user streaming for notification
const client = generator(account.sns, account.url, account.access_token, 'Whalebird')
const instance = await client.getInstance()
const notifications = (await client.getNotifications()).data
try {
const res = await client.getMarkers(['notifications'])
@ -79,8 +78,7 @@ export const AccountsProvider: React.FC<Props> = ({ children }) => {
console.error(err)
}
const ws = generator(account.sns, instance.data.urls.streaming_api, account.access_token, 'Whalebird')
const socket = ws.userSocket()
const socket = await client.userStreaming()
streamings.current = Object.assign({}, streamings.current, {
[account.id]: socket
})