OverviewFilesCommitsIssuesDocsReleasesPeers

keet-cli / deobfuscated / push.js

93 lines · javascript ref:
const _0x427d73=(function(){let _0x14414f=!![];return function(_0x1a0887,_0x2baae1){const _0x41da57=_0x14414f?function(){if(_0x2baae1){const _0x3a2f88=_0x2baae1.apply(_0x1a0887,arguments);return _0x2baae1=null,_0x3a2f88;}}:function(){};return _0x14414f=![],_0x41da57;};}()),_0x17e8ec=_0x427d73(this,function(){return _0x17e8ec.toString().search("(((.+)+)+)+$").toString().constructor(_0x17e8ec).search("(((.+)+)+)+$");});
_0x17e8ec();
const HypercoreId=require('hypercore-id-encoding'),CorestoreStorage=require('hypercore-storage'),MultiProfileStore=require('multi-profile-store'),notifications=require('@holepunchto/keet-push/lib/notifications.js'),{
  decodeValue}
=require('autobase/lib/values.js'),b4a=require('b4a'),{
  contract:{
    hyperdispatch:{
      decode:decodeOperation},hyperschema:{
      getEnum:getContractEnum}
  }
}
=require('./spec'),RoomType=getContractEnum("@keet/room-type"),KeetLocalDatabase=require('./lib/local');
module.exports=async function getPushNotificationInfo(_0x3cd1f7,_0x21db5d,{log:log=()=>{},profile:profile=!![]}={}){
  _0x3686db={
    _0x3bb099:0xab,_0x34a460:0x1b8,_0x3ee946:0x249},_0x4a9ee1={
    _0x50749b:0x200,_0x56f455:0x7a},_0x2c8efb=MultiProfileStore.open(_0x3cd1f7),_0x44b2fc=_0x2c8efb.active();
  if(!_0x44b2fc&&profile)return log("no active profile\x20is made"),null;
  const {
    discoveryKey:_0x6c4fff,proof:_0x46e9e5}
  =notifications.decode(_0x21db5d);
  const _0x1d7844=new CorestoreStorage(_0x44b2fc?_0x44b2fc.storage:_0x3cd1f7,{'readOnly':!![],'blockCache':![],'tableCacheIndexAndFilterBlocks':![],'optimizeFiltersForMemory':!![],'maxOpenFiles':0x1,'useDirectReads':!![],'filterPolicy':null});
  try{
    const _0x30f4f1=KeetLocalDatabase.rocks(_0x1d7844.rocks.columnFamily("keet/local-database"));
    await _0x30f4f1.ready(),log("Keet local database is ready");
    const [_0x3e3bfa,_0x29635a]=await Promise.all([_0x30f4f1.get("@local/rooms-by-discovery-key",{'discoveryKey':_0x6c4fff}),_0x30f4f1.get("@local/identity")]);
    if(!_0x3e3bfa||_0x3e3bfa.status.isRemoved)return log("Room member was removed from room"),null;
    const _0x4cdfdc=await _0x30f4f1.get("@local/room-preferences",{'roomKey':_0x3e3bfa.roomKey});
    if(_0x4cdfdc){
      if(!_0x4cdfdc.status.isActive||_0x4cdfdc.status.isFullyMuted)return null;
    }
  const _0xe6791f=await notifications.receive(_0x1d7844,_0x3e3bfa.roomKey,_0x46e9e5);
  log("Receiving notification");
  if(!_0xe6791f)return null;
  log("Notification is good");
  if(!_0xe6791f.block)return null;
  log("Notification was not blocked");
  if(!_0xe6791f.newer)return null;
  const _0x230999=_0xe6791f.key,_0x5df367=_0xe6791f.discoveryKey,_0x3a7285=decodeValue(b4a.from(_0xe6791f.proof.block.value),{'autobase':_0x3e3bfa.roomKey,'encryptionKey':_0x3e3bfa.encryptionKey,'key':_0x230999,'manifest':_0xe6791f.proof.manifest,'index':_0xe6791f.block.index}),[_0x5aae81,_0x24d12d]=await Promise.all([_0x30f4f1.get("@local/devices",{'device':{'key':_0x230999}}),_0x3a7285]),_0x491410=_0x5aae81?..device,_0x4a9bcb=decodeOperation(_0x24d12d),[_0x49c71a,_0x2eed1c]=await Promise.all([_0x491410?_0x30f4f1.get("@local/contacts",{'memberKey':_0x491410.memberKey}):null,_0x491410?_0x30f4f1.get("@local/members",{'key':_0x491410.memberKey}):null]),_0x94700f=!!_0x49c71a?..status.isBlocked;
  log("Blocked?: ",_0x94700f);
  const _0x2f29f7=_0x2eed1c&&b4a.equals(_0x2eed1c.key,_0x29635a.publicKey);
  log("Member exists\x20?:\x20"+(_0x2eed1c!==null)+(" and keys are\x20equal?:\x20")+(_0x2eed1c!==null?b4a.equals(_0x2eed1c.key,_0x29635a.publicKey):![]));
  const _0x1e1272=_0x2eed1c?_0x2eed1c.profile.displayName:null,_0x40629c=_0x2eed1c?_0x2eed1c.profile.avatar:null,_0xd835ef=_0x3e3bfa?_0x3e3bfa.config.avatar:null;
  let _0x116a2a=null;
  if(_0x4a9bcb.name==="@keet/add-chat-message"){
    const _0x42647b=_0x4a9bcb.value.header.timestamp,_0x42e0f3=_0x4a9bcb.value.message;
    if(_0x42e0f3?..files&&_0x42e0f3.files.length>0x0){
      const _0x4e69af=_0x42e0f3.files[0x0];
      _0x116a2a={
        'timestamp':_0x42647b,'type':"file",'chatText':null,'callId':null,'fileType':_0x4e69af.metadata?..mimetype,'location':null},log("Message for file");
    }else{
    if(_0x42e0f3?..event?..locationShared)_0x116a2a={
      'timestamp':_0x42647b,'type':'location','chatText':_0x42e0f3.text,'callId':null,'fileType':null,'location':_0x42e0f3.event.locationShared},log("Message\x20for location");
    else{
      if(_0x42e0f3.text)_0x116a2a={
        'timestamp':_0x42647b,'type':"text",'chatText':_0x42e0f3.text,'callId':null,'fileType':null,'location':null},log("Message\x20for text");
      else{
        if(_0x42e0f3.event.callStarted)_0x116a2a={
          'timestamp':_0x42647b,'type':'call','chatText':null,'callId':HypercoreId.encode(_0x3e3bfa.discoveryKey),'fileType':null,'location':null},log("Message for call");
        else _0x42e0f3.event.callHangup&&(_0x116a2a={'timestamp':_0x42647b,'type':"call_hangup",'chatText':null,'callId':HypercoreId.encode(_0x3e3bfa.discoveryKey),'fileType':null,'location':null},log("Message for call hangup"));
      }
  }
}
}
const _0x343c17={
  'id':null,'sender':{
    'id':HypercoreId.encode(_0x230999),'length':_0xe6791f.length,'blocked':_0x94700f,'self':_0x2f29f7,'name':_0x1e1272,'memberAvatar':_0x40629c},'room':{
    'key':_0x3e3bfa.roomKey,'title':_0x3e3bfa.config.title,'type':toCompatRoomType(_0x3e3bfa.digest.settings.roomType,log),'roomAvatar':_0xd835ef},'proof':{
    'discoveryKey':_0x5df367,'data':_0xe6791f.proof},'index':_0xe6791f.block.index,'message':_0x116a2a}
;
return _0x343c17.id=_0x343c17.sender.id+(_0x343c17.index!==-(-0xb6b)?'/b'+_0x343c17.index:'/l'+_0x343c17.sender.length),log("Returning result"),_0x343c17;
}catch(_0x3c85cb){
return log('Error:',_0x3c85cb),null;
}finally{
await _0x1d7844.close(),log("Storage closed");
}
}
;
function toCompatRoomType(_0x4e8ee8,_0x4caf27){
  _0x582ea3={
    _0x157937:0x1f0,_0xd1377b:0x12a,_0x22f4b8:0x31c},_0xaa294f={
    _0x1a725c:0x115,_0x306252:0x224}
  ;
  switch(_0x4e8ee8){
    case RoomType.Default:_0x4caf27("Room type is default");
    return'0';
    case RoomType.Broadcast:_0x4caf27("Room type is Broadcast");
    return'1';
    case RoomType.DirectMessage:_0x4caf27("Room\x20type\x20is DirectMessage");
    return'2';
    default:throw new Error("Incompatible legacy room type:",_0x4e8ee8);
  }
}