DataMcFly / sms-contact

SMS Contact Center powered by Data McFly, Twilio and Node.js
http://blog.datamcfly.com/2015/01/29/sms-contact-twilio
4 stars 4 forks source link

How to create a button to delete a conversation? #1

Closed NikV closed 9 years ago

NikV commented 9 years ago

What would be the best way to delete an individual chat with a user?

freekrai commented 9 years ago

You can trigger a delete using datamcflyRef.remove('id of document'); to make it work first, you'd have to query all threads that were part of that individual chat then remove it. So since we group the conversation by the initial fromNumber, you could do something like this:

datamcflyRef.where({'fromNumber':NUMBER}).on("value", function(snapshot) {
   snapshot.forEach( function(chat){
      datamcflyFef.remove( chat.value()._id, function( removed ) {
         console.log('Deleted Document : ', removed.value() );
      });
  });
});
NikV commented 9 years ago

Thanks for the function! Where would I put this in the code?

freekrai commented 9 years ago

You could put it into the chatmanager, you may have to make a few changes to it though as the reference is this.datamcflyRef I think

NikV commented 9 years ago

Made the changes, but seems like it gives an error everywhere I put it in chatmanger.

freekrai commented 9 years ago

Can you share your chatmanager and I'll take a look? :)

NikV commented 9 years ago

Right now, it currently looks the same as the one in this github repo :)

freekrai commented 9 years ago

Ok, you can take a look at this file and go from there https://gist.github.com/freekrai/71de95a4b05b8a48854f

It may a tad rough as I didn't have a chance to test it as I'm mobile this morning :)

NikV commented 9 years ago

Getting closer! Getting an error though on 113: Cannot read property 'remove' of undefined

freekrai commented 9 years ago

.remove is definitely a function in the library, so try now with the latest push.

Just changed the this.datamcflyRef to _this.datamcflyRef

NikV commented 9 years ago

Where did you change that? No change if I replace the normal this. before the remove()

freekrai commented 9 years ago

Look at the gist...

NikV commented 9 years ago

Woops, sorry, I see that!