MCPcopy
hub / github.com/jsfiddle/togetherjs / saveChatMessage

Function saveChatMessage

togetherjs/chat.js:346–364  ·  view source on GitHub ↗
(obj)

Source from the content-addressed store, hash-verified

344 var maxLogMessages = 100;
345
346 function saveChatMessage(obj) {
347 assert(obj.peerId);
348 assert(obj.messageId);
349 assert(obj.date);
350 assert(typeof obj.text == "string");
351
352 loadChatLog().then(function (log) {
353 for (var i = log.length - 1; i >= 0; i--) {
354 if (log[i].messageId === obj.messageId) {
355 return;
356 }
357 }
358 log.push(obj);
359 if (log.length > maxLogMessages) {
360 log.splice(0, log.length - maxLogMessages);
361 }
362 storage.tab.set(chatStorageKey, log);
363 });
364 }
365
366 function loadChatLog() {
367 return storage.tab.get(chatStorageKey, []);

Callers 1

chat.jsFile · 0.85

Calls 2

loadChatLogFunction · 0.85
assertFunction · 0.50

Tested by

no test coverage detected