All files / app/mods delete.ts

14.81% Statements 4/27
0% Branches 0/18
0% Functions 0/4
18.18% Lines 4/22

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86117x         117x   117x                                                                                                                                                 117x          
import { filter } from 'lodash-es';
import { DateTime } from 'luxon';
import { Plugin } from '../model/plugin';
import { Ref } from '../model/ref';
import { Mod, Tag } from '../model/tag';
import { hasTag, localTag, publicTag, tagOrigin } from '../util/tag';
 
export const deletePlugin: Plugin = {
  tag: 'plugin/delete',
  name: $localize`🗑️ Delete Notice`,
  config: {
    version: 1,
    internal: true,
    default: true,
    generated: $localize`Generated by jasper-ui ${DateTime.now().toISO()}`,
    description: $localize`Activates built-in delete notice support which clears refs and marks them as deleted instead of actually deleting them.`,
    aiInstructions: ` # plugin/delete
    If you are included in a conversation with more than 2 people, consider whether you should respond or not.
    If it seems inappropriate to respond, simply reply with a blank message and the plugin/delete tag. This will
    mark the AI response as completed, but will not interrupt the user.
    `,
    icons: [{ thumbnail: $localize`🗑️`, order: -1 }],
    filters: [
      { query: 'plugin/delete', label: $localize`🗑️ deleted`, title: $localize`Recycle Bin`, group: $localize`Filters 🕵️️` },
    ],
  },
};
 
export function deleteNotice(ref: Ref): Ref {
  if (hasTag('locked', ref)) {
    ref.tags!.push('plugin/delete', 'internal');
    return ref;
  }
  const tags = ['plugin/delete', 'internal'];
  tags.push(...filter(ref.tags, t => {
    if (ref.plugins?.[t]) return false;
    if (t.startsWith('+plugin/')) return false;
    if (!publicTag(t)) return true;
    if (t === 'locked') return true;
    if (t === 'public') return true;
    return false;
  }));
  if (hasTag('locked', ref)) {
    ref.tags = tags;
    return ref;
  }
  return {
    url: ref.url,
    origin: ref.origin,
    tags,
    created: ref.created,
    published: ref.published,
    modifiedString: ref.modifiedString,
  };
}
 
export function isDeletorTag(tag: string) {
  tag = localTag(tag);
  return tag === "deleted" || tag.endsWith("/deleted");
}
 
export function deletorTag(tag: string) {
  if (!tag) return "deleted"
  return localTag(tag) + "/deleted" + tagOrigin(tag);
}
 
export function deletedTag(deletor: string) {
  const local = localTag(deletor);
  if (local === "deleted") return "";
  return local.substring(0, local.length - "/deleted".length) + tagOrigin(deletor);
}
 
export function tagDeleteNotice(tag: Tag) {
  return {
    tag: tag.tag + '/deleted',
    origin: tag.origin,
    config: {},
  };
}
 
export const deleteMod: Mod = {
  plugin: [
    deletePlugin,
  ]
};