This commit is contained in:
Timothy Jaeryang Baek committed 2026-11-09 16:04:13 +09:00
1 parent 62849662d9
commit 553b18a34d
10 files changed
+81 -46

No files matched your search

+12 -7
View File
@@ -1217,14 +1217,19 @@ async def app_channel_reply_handler(channel_id, message_id, user_id):
# An inactive/removed app or one without write access cannot post a public reply.
log.warning('Could not save app error reply: app=%s message=%s', app_id, message_id)
await emit_to_users(
'events:app',
'events',
{
'app_id': app_id,
'app_name': app_name,
'channel_id': channel_id,
'message_id': message_id,
'parent_id': parent_id,
'reply': {'type': 'error', 'content': detail},
'data': {
'type': 'channel:app',
'data': {
'app_id': app_id,
'app_name': app_name,
'channel_id': channel_id,
'message_id': message_id,
'parent_id': parent_id,
'reply': {'type': 'error', 'content': detail},
},
}
},
[user_id],
)
+2 -2
View File
@@ -566,8 +566,8 @@ async def update_note_by_id(
event_data['data'] = note.data
await sio.emit(
'events:note',
event_data,
'events',
{'data': {'type': 'note:updated', 'data': event_data}},
to=f'note:{note.id}',
)
+10 -1
View File
@@ -81,4 +81,13 @@ async def revalidate_comment_subscription(sio, sid, session_user):
key: value for key, value in session['comments_resources'].items() if tuple(value) != resource
}
await sio.save_session(sid, session)
await sio.emit('comments:unavailable', {'resource_type': resource[0], 'resource_id': resource[1]}, to=sid)
await sio.emit(
'events',
{
'data': {
'type': 'comments:unavailable',
'data': {'resource_type': resource[0], 'resource_id': resource[1]},
}
},
to=sid,
)
+7 -2
View File
@@ -156,8 +156,13 @@ class Relay:
async def invite(self, state, channel):
await self.sio.emit(
'encryption:available',
{'channel': channel, 'session': state['session'] if state else None},
'events',
{
'data': {
'type': 'encryption:available',
'data': {'channel': channel, 'session': state['session'] if state else None},
}
},
room=f'channel:{channel}',
)
+16 -6
View File
@@ -304,8 +304,13 @@ async def publish_note_presence(note_id: str):
if REDIS is not None and not await lock.owned():
return
await sio.emit(
'note:presence',
{'note_id': note_id, 'users': sorted(people.values(), key=lambda person: person['id'])},
'events',
{
'data': {
'type': 'note:presence',
'data': {'note_id': note_id, 'users': sorted(people.values(), key=lambda person: person['id'])},
}
},
room=f'note:{note_id}',
)
@@ -1159,11 +1164,16 @@ async def document_save_handler(document_id, data, user):
)
if saved:
await sio.emit(
'events:note',
'events',
{
'id': note_id,
'page': get_page(saved.data, page['id']),
'updated_at': saved.updated_at,
'data': {
'type': 'note:updated',
'data': {
'id': note_id,
'page': get_page(saved.data, page['id']),
'updated_at': saved.updated_at,
},
}
},
to=f'note:{note_id}',
)
+1 -1
View File
@@ -94,7 +94,7 @@ async def _has_write_access_to_note(note, user_id: str) -> bool:
async def _emit_note_updated(request: Request, user: dict, note) -> None:
await sio.emit('events:note', note.model_dump(), to=f'note:{note.id}')
await sio.emit('events', {'data': {'type': 'note:updated', 'data': note.model_dump()}}, to=f'note:{note.id}')
await publish_event(
request,
EVENTS.NOTE_UPDATED,
+9 -5
View File
@@ -51,10 +51,14 @@
if (!enabled || !connection || !channelId) return;
let alive = true;
let revision = 0;
const receive = (event: { channel: string; session: string | null }) => {
if (event.channel === channelId) {
const receive = (event: {
data?: { type?: string; data?: { channel: string; session: string | null } };
}) => {
if (event?.data?.type !== 'encryption:available') return;
const data = event.data.data;
if (data?.channel === channelId) {
revision++;
invitationSession = event.session;
invitationSession = data.session;
}
};
const clear = () => {
@@ -71,13 +75,13 @@
})
.catch(() => {});
};
connection.on('encryption:available', receive);
connection.on('events', receive);
connection.on('disconnect', clear);
connection.on('connect', query);
query();
stopInvitation = () => {
alive = false;
connection.off('encryption:available', receive);
connection.off('events', receive);
connection.off('disconnect', clear);
connection.off('connect', query);
};
+5 -3
View File
@@ -49,7 +49,9 @@
appReplies = {};
}
const receiveAppChannelReply = (event) => {
const receiveAppChannelReply = (message) => {
if (message?.data?.type !== 'channel:app' || !message.data.data) return;
const event = message.data.data;
if (event.reply?.type === 'ack') return;
if (event.channel_id !== channel?.id || (event.parent_id ?? null) !== (thread ? id : null))
return;
@@ -59,8 +61,8 @@
onMount(() => {
const appSocket = $socket;
appSocket?.on('events:app', receiveAppChannelReply);
return () => appSocket?.off('events:app', receiveAppChannelReply);
appSocket?.on('events', receiveAppChannelReply);
return () => appSocket?.off('events', receiveAppChannelReply);
});
const loadMoreMessages = async () => {
@@ -125,13 +125,18 @@
);
};
const changed = (event: { data?: { type?: string; data?: CommentResource } }) => {
if (event?.data?.type !== 'comments:changed' || !event.data.data) return;
const data = event.data.data;
const { type, data } = event?.data ?? {};
if (!data) return;
if (
data.resource_type !== resource?.resource_type ||
data.resource_id !== resource?.resource_id
)
return;
if (type === 'comments:unavailable') {
fail(new CommentError(403, $i18n.t('Comments are no longer available.')));
return;
}
if (type !== 'comments:changed') return;
clearTimeout(refreshTimer);
refreshTimer = setTimeout(refresh, 150);
};
@@ -139,13 +144,6 @@
join();
refresh();
};
const unavailable = (data: CommentResource) => {
if (
data?.resource_type === resource?.resource_type &&
data?.resource_id === resource?.resource_id
)
fail(new CommentError(403, $i18n.t('Comments are no longer available.')));
};
const revealInitialPosition = () => {
if (!alive || loading || !revealPending || !commentList) return;
if (commentList.querySelector('[aria-busy="true"]')) return;
@@ -211,11 +209,9 @@
connection?.emit('comments:leave', { subscription_id: subscriptionId });
connection?.off('events', changed);
connection?.off('connect', reconnect);
connection?.off('comments:unavailable', unavailable);
connection = $socket;
connection?.on('events', changed);
connection?.on('connect', reconnect);
connection?.on('comments:unavailable', unavailable);
join();
}
onDestroy(() => {
@@ -224,7 +220,6 @@
connection?.emit('comments:leave', { subscription_id: subscriptionId });
connection?.off('events', changed);
connection?.off('connect', reconnect);
connection?.off('comments:unavailable', unavailable);
});
</script>
+12 -7
View File
@@ -438,10 +438,8 @@
note.access_grants = [];
}
$socket?.off('events:note', noteEventHandler);
$socket?.on('events:note', noteEventHandler);
$socket?.off('note:presence', presenceEventHandler);
$socket?.on('note:presence', presenceEventHandler);
$socket?.off('events', noteEventHandler);
$socket?.on('events', noteEventHandler);
$socket?.off('disconnect', clearPresence);
$socket?.on('disconnect', clearPresence);
$socket?.off('connect', joinNote);
@@ -1000,7 +998,15 @@ ${content}
inputElement?.insertContent(content);
};
const noteEventHandler = async (_note) => {
const noteEventHandler = async (event) => {
const { type, data } = event?.data ?? {};
if (!data) return;
if (type === 'note:presence') {
presenceEventHandler(data);
return;
}
if (type !== 'note:updated') return;
const _note = data;
if (_note.id !== id || !note) return;
if (_note.page) {
const remote = _note.page;
@@ -1053,8 +1059,7 @@ ${content}
loadGeneration++;
if (note?.id) $socket?.emit('note:leave', { note_id: note.id });
if (debounceTimeout) clearTimeout(debounceTimeout);
$socket?.off('events:note', noteEventHandler);
$socket?.off('note:presence', presenceEventHandler);
$socket?.off('events', noteEventHandler);
$socket?.off('disconnect', clearPresence);
$socket?.off('connect', joinNote);