Buffer TOC-sent IMs for SSE replay on refresh
This commit is contained in:
parent
c7225315d3
commit
b80e262c78
1 changed files with 10 additions and 1 deletions
|
|
@ -1,5 +1,6 @@
|
|||
import { Router } from 'express';
|
||||
import * as oscar from '../oscar.js';
|
||||
import { broadcast } from '../poller.js';
|
||||
import { requireLogin } from './auth.js';
|
||||
import { cleanMessage, cleanScreenName, cleanText } from '../validate.js';
|
||||
|
||||
|
|
@ -18,7 +19,15 @@ messagesRouter.post('/im', requireLogin, async (req, res) => {
|
|||
try {
|
||||
if (req.oscar.tocConnected && req.oscar.toc) {
|
||||
req.oscar.toc.sendIM(to, message);
|
||||
return res.json({ ok: true, transport: 'toc' });
|
||||
const msgId = `toc-${Date.now()}-${Math.random().toString(36).slice(2, 10)}`;
|
||||
broadcast(req.oscar, {
|
||||
type: 'sentIM',
|
||||
time: Date.now(),
|
||||
seqNum: null,
|
||||
data: { sender: { aimId: req.oscar.screenName }, dest: { aimId: to }, message, msgId, iSent: true },
|
||||
raw: { type: 'sentIM', eventData: { sender: { aimId: req.oscar.screenName }, dest: { aimId: to }, message, msgId, iSent: true } },
|
||||
});
|
||||
return res.json({ ok: true, transport: 'toc', data: { msgId } });
|
||||
}
|
||||
const data = await oscar.sendIM(req.oscar.aimsid, to, message);
|
||||
res.json({ ok: true, data, transport: 'webapi' });
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue