Created
December 16, 2017 20:58
-
-
Save sjcotto/41ab50ed18dd25c05b96fb3b30876713 to your computer and use it in GitHub Desktop.
Revisions
-
sjcotto created this gist
Dec 16, 2017 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,48 @@ function isChatMessage(message) { if (message.__x_isSentByMe) { return false; } if (message.__x_isNotification) { return false; } if (!message.__x_isUserCreatedType) { return false; } return true; } function getUnreadChats() { var Chats = Store.Chat.models; var Output = []; for (chat in Chats) { if (isNaN(chat)) { continue; }; var temp = {}; temp.contact = Chats[chat].__x_formattedTitle; temp.id = Chats[chat].__x_id; temp.messages = []; var messages = Chats[chat].msgs.models; for (var i = messages.length - 1; i >= 0; i--) { if (!messages[i].__x_isNewMsg) { break; } else { if (!isChatMessage(messages[i])) { continue } messages[i].__x_isNewMsg = false; temp.messages.push({ message: messages[i].__x_body, timestamp: messages[i].__x_t, type : messages[i].__x_type, e : messages[i] }); } } if(temp.messages.length > 0) { Output.push(temp); } } console.log("Unread messages: ", Output); return Output; } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,17 @@ function sendMsg (id, text) { var Chats = Store.Chat.models; var contact = id; var message = text; for (chat in Chats) { if (isNaN(chat)) { continue; }; var temp = {}; temp.contact = Chats[chat].__x__formattedTitle; temp.id = Chats[chat].__x_id; if(temp.id.search(contact)!=-1 && temp.id.search('g.us')==-1 ){ Chats[chat].sendMessage(message); return true } } }