|
|
|
|
@ -83,6 +83,8 @@ function rank(a, b) {
@@ -83,6 +83,8 @@ function rank(a, b) {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
function matchFilters(e, f) { |
|
|
|
|
if (f.state && f.state !== "all") { if ((e.state || null) !== f.state) return false; } |
|
|
|
|
else if (!f.state) { if (e.state === "archive") return false; } |
|
|
|
|
if (f.track && e.track !== f.track) return false; |
|
|
|
|
if (f.scope && e.scope !== f.scope) return false; |
|
|
|
|
if (f.importance && e.importance !== f.importance) return false; |
|
|
|
|
@ -98,7 +100,7 @@ function opList(state, args) {
@@ -98,7 +100,7 @@ function opList(state, args) {
|
|
|
|
|
let totalBytes = 0; |
|
|
|
|
for (const e of items) totalBytes += e.bytes || 0; |
|
|
|
|
return { |
|
|
|
|
items: items.map(function (e) { return { id: e.id, track: e.track, scope: e.scope, key: e.key, importance: e.importance, tags: e.tags || [], bytes: e.bytes, updatedAt: e.updatedAt, recallCount: e.recallCount, preview: preview(e.text, pv) }; }), |
|
|
|
|
items: items.map(function (e) { return { id: e.id, track: e.track, scope: e.scope, key: e.key, importance: e.importance, state: e.state || null, tags: e.tags || [], bytes: e.bytes, updatedAt: e.updatedAt, recallCount: e.recallCount, preview: preview(e.text, pv) }; }), |
|
|
|
|
totalBytes: totalBytes, matched: items.length, previewChars: pv |
|
|
|
|
}; |
|
|
|
|
} |
|
|
|
|
@ -139,7 +141,7 @@ function opSearch(state, args) {
@@ -139,7 +141,7 @@ function opSearch(state, args) {
|
|
|
|
|
}).sort(rank).slice(0, limit); |
|
|
|
|
let totalBytes = 0; |
|
|
|
|
for (const e of hits) totalBytes += e.bytes || 0; |
|
|
|
|
return { items: hits.map(function (e) { return { id: e.id, key: e.key, track: e.track, importance: e.importance, tags: e.tags || [], bytes: e.bytes, preview: preview(e.text, pv) }; }), totalBytes: totalBytes, matched: hits.length }; |
|
|
|
|
return { items: hits.map(function (e) { return { id: e.id, key: e.key, track: e.track, importance: e.importance, state: e.state || null, tags: e.tags || [], bytes: e.bytes, preview: preview(e.text, pv) }; }), totalBytes: totalBytes, matched: hits.length }; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
function opBudgets(state) { |
|
|
|
|
@ -205,7 +207,14 @@ function opWrite(state, args) {
@@ -205,7 +207,14 @@ function opWrite(state, args) {
|
|
|
|
|
} |
|
|
|
|
e.importance = args.importance; |
|
|
|
|
} |
|
|
|
|
if (args.state === 'active' || args.state === 'done' || args.state === 'archive') e.state = args.state; |
|
|
|
|
if (args.state === 'active' || args.state === 'done' || args.state === 'archive') { |
|
|
|
|
// replace checks directive limit
|
|
|
|
|
if (args.state === 'active' && e.state !== 'active' && String(e.key).indexOf('directive_') === 0) { |
|
|
|
|
const dirCount = state.entries.filter(function (x) { return String(x.key).indexOf('directive_') === 0 && x.state === 'active' && (x.chatId || '') === (e.chatId || '') && x.id !== e.id; }).length; |
|
|
|
|
if (dirCount >= DIRECTIVES_PER_CHAT) throw new Error('E_TOO_MANY_DIRECTIVES: limit ' + DIRECTIVES_PER_CHAT + ' per chat'); |
|
|
|
|
} |
|
|
|
|
e.state = args.state; |
|
|
|
|
} |
|
|
|
|
if (typeof args.chatId === 'string') e.chatId = args.chatId; |
|
|
|
|
e.version = (e.version || 1) + 1; |
|
|
|
|
e.updatedAt = nowIso(); |
|
|
|
|
|