MCPcopy Create free account
hub / github.com/OpenAnonymity/oa-chat / saveSessionWithMessages

Method saveSessionWithMessages

chat/db.js:271–289  ·  view source on GitHub ↗
(session, messages)

Source from the content-addressed store, hash-verified

269 }
270
271 async saveSessionWithMessages(session, messages) {
272 return new Promise((resolve, reject) => {
273 const transaction = this.db.transaction(['sessions', 'messages'], 'readwrite');
274 const sessionsStore = transaction.objectStore('sessions');
275 const messagesStore = transaction.objectStore('messages');
276
277 transaction.oncomplete = () => {
278 this.emitStorageEvent('sessions-updated', { sessionId: session.id });
279 this.emitStorageEventDebounced('messages-updated', session.id, { sessionId: session.id }, 500);
280 resolve();
281 };
282 transaction.onerror = () => reject(transaction.error);
283
284 sessionsStore.put(session);
285 (messages || []).forEach(message => {
286 messagesStore.put(message);
287 });
288 transaction.onabort = () => reject(transaction.error || new Error('The chat message was not committed.'));
289 });
290 }
291
292 async updateSessionSearchIndex(sessionId, fields) {

Callers 3

importSessionsMethod · 0.80
saveSessionWithMessagesFunction · 0.80

Calls 2

emitStorageEventMethod · 0.95

Tested by

no test coverage detected