<commit_before>var eejs = require('ep_etherpad-lite/node/eejs')

/*
* Handle incoming delete requests from clients
*/
exports.handleMessage = function(hook_name, context, callback){
  var Pad = require('ep_etherpad-lite/node/db/Pad.js').Pad

  // Firstly ignore any request that aren't about chat
  var isDeleteRequest = false;
  if(context) {
    if(context.message && context.message){
      if(context.message.type === 'COLLABROOM'){
        if(context.message.data){
          if(context.message.data.type){
            if(context.message.data.type === 'ep_push2delete'){
              isDeleteRequest = true;
            }
          }
        }
      }
    }
  }
  if(!isDeleteRequest){
    callback(false);
    return false;
  }
  
  console.log('DELETION REQUEST!')

  var packet = context.message.data;
  /***
    What's available in a packet?
    * action -- The action IE chatPosition
    * padId -- The padId of the pad both authors are on
    ***/
  if(packet.action === 'deletePad'){
    var pad = new Pad(packet.padId)
    pad.remove(function(er) {
      if(er) console.warn('ep_push2delete', er)
      callback([null]);
    })
  }
}

exports.eejsBlock_editbarMenuRight = function(hook_name, args, cb) {
  args.content = eejs.require('ep_push2delete/templates/delete_button.ejs') + args.content;
  cb()
}<commit_msg>don't show delete button on read-only pads<commit_after>var eejs = require('ep_etherpad-lite/node/eejs')

/*
* Handle incoming delete requests from clients
*/
exports.handleMessage = function(hook_name, context, callback){
  var Pad = require('ep_etherpad-lite/node/db/Pad.js').Pad

  // Firstly ignore any request that aren't about chat
  var isDeleteRequest = false;
  if(context) {
    if(context.message && context.message){
      if(context.message.type === 'COLLABROOM'){
        if(context.message.data){
          if(context.message.data.type){
            if(context.message.data.type === 'ep_push2delete'){
              isDeleteRequest = true;
            }
          }
        }
      }
    }
  }
  if(!isDeleteRequest){
    callback(false);
    return false;
  }
  
  console.log('DELETION REQUEST!')

  var packet = context.message.data;
  /***
    What's available in a packet?
    * action -- The action IE chatPosition
    * padId -- The padId of the pad both authors are on
    ***/
  if(packet.action === 'deletePad'){
    var pad = new Pad(packet.padId)
    pad.remove(function(er) {
      if(er) console.warn('ep_push2delete', er)
      callback([null]);
    })
  }
}

exports.eejsBlock_editbarMenuRight = function(hook_name, args, cb) {
  if(!args.renderContext.req.match(/^\/(p\/r\..{16})/)) {
    args.content = eejs.require('ep_push2delete/templates/delete_button.ejs') + args.content;
  }
  cb();
};
{'fraction_non_alphanumeric': 0.14228675136116153, 'fraction_numerical': 0.0029038112522686023, 'mean_word_length': 2.82246879334258, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3531889', 'n_tokens_mistral': 912, 'n_tokens_neox': 891, 'n_words': 179}