SHA256
НЕ ПРОВЕРЕНО: UI редактирования и удаления личных сообщений
This commit is contained in:
@@ -2006,32 +2006,45 @@ export class AuthService {
|
||||
return response.payload || {};
|
||||
}
|
||||
|
||||
async sendDirectMessage({ login, toLogin, text, storagePwd }) {
|
||||
async sendDirectMessageRevision({
|
||||
login,
|
||||
toLogin,
|
||||
text = '',
|
||||
storagePwd,
|
||||
timeMs,
|
||||
nonce,
|
||||
revisionTimeMs = 0,
|
||||
}) {
|
||||
const cleanFromLogin = String(login || '').trim();
|
||||
const cleanToLogin = String(toLogin || '').trim();
|
||||
const cleanText = String(text || '');
|
||||
if (!cleanFromLogin || !cleanToLogin) throw new Error('Не передан login/toLogin');
|
||||
if (!cleanText) throw new Error('Пустое сообщение');
|
||||
const timeMs = Date.now();
|
||||
const nonce = Math.floor(Math.random() * 0x100000000);
|
||||
const normalizedTimeMs = Number(timeMs);
|
||||
const normalizedNonce = Number(nonce);
|
||||
const normalizedRevisionTimeMs = Number(revisionTimeMs || 0);
|
||||
if (!Number.isFinite(normalizedTimeMs) || normalizedTimeMs <= 0) throw new Error('Некорректный timeMs');
|
||||
if (!Number.isFinite(normalizedNonce) || normalizedNonce < 0) throw new Error('Некорректный nonce');
|
||||
if (!Number.isFinite(normalizedRevisionTimeMs) || normalizedRevisionTimeMs < 0) throw new Error('Некорректный revisionTimeMs');
|
||||
const encryptedBodyBytes = utf8Bytes(cleanText);
|
||||
|
||||
const incomingBlock = await this.buildSignedDmV1Block({
|
||||
login: cleanFromLogin,
|
||||
toLogin: cleanToLogin,
|
||||
storagePwd,
|
||||
timeMs,
|
||||
nonce,
|
||||
timeMs: normalizedTimeMs,
|
||||
nonce: normalizedNonce,
|
||||
messageType: DM2_TYPE_INCOMING,
|
||||
revisionTimeMs: normalizedRevisionTimeMs,
|
||||
encryptedBodyBytes,
|
||||
});
|
||||
const outgoingBlock = await this.buildSignedDmV1Block({
|
||||
login: cleanFromLogin,
|
||||
toLogin: cleanToLogin,
|
||||
storagePwd,
|
||||
timeMs,
|
||||
nonce,
|
||||
timeMs: normalizedTimeMs,
|
||||
nonce: normalizedNonce,
|
||||
messageType: DM2_TYPE_OUTGOING_COPY,
|
||||
revisionTimeMs: normalizedRevisionTimeMs,
|
||||
encryptedBodyBytes,
|
||||
});
|
||||
|
||||
@@ -2043,10 +2056,36 @@ export class AuthService {
|
||||
...payload,
|
||||
localIncomingBlobB64: bytesToBase64(incomingBlock),
|
||||
localOutgoingBlobB64: bytesToBase64(outgoingBlock),
|
||||
localBaseKey: dm2BaseKey({ toLogin: cleanToLogin, fromLogin: cleanFromLogin, timeMs, nonce }),
|
||||
localBaseKey: dm2BaseKey({ toLogin: cleanToLogin, fromLogin: cleanFromLogin, timeMs: normalizedTimeMs, nonce: normalizedNonce }),
|
||||
};
|
||||
}
|
||||
|
||||
async sendDirectMessage({ login, toLogin, text, storagePwd }) {
|
||||
const cleanText = String(text || '');
|
||||
if (!cleanText) throw new Error('Пустое сообщение');
|
||||
return this.sendDirectMessageRevision({
|
||||
login,
|
||||
toLogin,
|
||||
text: cleanText,
|
||||
storagePwd,
|
||||
timeMs: Date.now(),
|
||||
nonce: Math.floor(Math.random() * 0x100000000),
|
||||
revisionTimeMs: 0,
|
||||
});
|
||||
}
|
||||
|
||||
async deleteDirectMessage({ login, toLogin, storagePwd, timeMs, nonce, revisionTimeMs }) {
|
||||
return this.sendDirectMessageRevision({
|
||||
login,
|
||||
toLogin,
|
||||
text: '',
|
||||
storagePwd,
|
||||
timeMs,
|
||||
nonce,
|
||||
revisionTimeMs,
|
||||
});
|
||||
}
|
||||
|
||||
async sendReadReceipt({ login, toLogin, storagePwd, refToLogin, refFromLogin, refTimeMs, refNonce, refType = DM2_TYPE_INCOMING }) {
|
||||
const timeMs = Date.now();
|
||||
const nonce = Math.floor(Math.random() * 0x100000000);
|
||||
|
||||
Reference in New Issue
Block a user