sulla icon indicating copy to clipboard operation
sulla copied to clipboard

[feat] Make all send functions work even if no chat exists

Open robertsLando opened this issue 4 years ago • 2 comments

Actually the only method that work in case a chat doesn't exists is sendMessageToId

It basically works by getting the first chat model in store, force to change the chat id (the number to send the message) and use it's sendMessage function to send a message.

I basically suggest to create a WAPI method

window.WAPI.getChat = function(chatId, done) {
 const idUser = new Store.WidFactory.createWid(chatid);
  Store.Chat.find(idUser).then((chat) => {
  if(!chat) {
   // firstly check if there is a contact and if not use the trick used in sendMessageToId
  }
  })
}

In this way we can use this function in all methods that send something to a chat to make them work even without an existing chat

robertsLando avatar Apr 08 '20 08:04 robertsLando

It is a good idea, however, I would like to keep wapi.js functions as agnostic as possible. I rather adding this in sulla side so sulla can be the smart part of wapi, just have to check if it doesn't affect performance

danielcardeenas avatar Apr 10 '20 02:04 danielcardeenas

@danielcardeenas The other easier solution so would be to send caption using sendMessageToId if no chat is found and then send the file/location/giphy or everything wanted

robertsLando avatar Apr 10 '20 13:04 robertsLando