Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Typing notification when a whatsapp user start typing... #170

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions background.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ browser.runtime.onMessage.addListener(function (messageEvent, sender, callback)
// these are the default values. we will update them according to the storage
var onlineUpdatesHook = false;
var typingUpdatesHook = false;
var notifytyping = false;
var readConfirmationsHook = true;
var showReadWarning = true;
var safetyDelay = 0;
Expand All @@ -62,6 +63,7 @@ browser.runtime.onMessage.addListener(function (messageEvent, sender, callback)

chrome.storage.local.get(['onlineUpdatesHook',
'typingUpdatesHook',
'notifytyping',
'readConfirmationsHook',
'showReadWarning',
'safetyDelay',
Expand All @@ -78,6 +80,10 @@ browser.runtime.onMessage.addListener(function (messageEvent, sender, callback)
{
typingUpdatesHook = storage["typingUpdatesHook"];
}
if (storage["notifytyping"] != undefined)
{
notifytyping = storage["notifytyping"];
}
if (storage["readConfirmationsHook"] != undefined)
{
readConfirmationsHook = storage["readConfirmationsHook"];
Expand Down Expand Up @@ -110,6 +116,7 @@ browser.runtime.onMessage.addListener(function (messageEvent, sender, callback)
{
onlineUpdatesHook: onlineUpdatesHook,
typingUpdatesHook: typingUpdatesHook,
notifytyping: notifytyping,
readConfirmationsHook: readConfirmationsHook,
showReadWarning: showReadWarning,
safetyDelay: safetyDelay,
Expand Down
16 changes: 15 additions & 1 deletion core/node_handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,15 +194,29 @@ NodeHandler.onSentEncNode = async function (encNode, remoteJid)
NodeHandler.interceptReceivedNode = async function (node)
{
var isAllowed = true;
var tag = node.tag;

if (node.tag == "message")
if (tag == "message")
{
var [isAllowed, node] = await NodeHandler.onReceivedMessageNode(node);
}else if(tag == 'chatstate' ){
NodeHandler.onChatStateReceived(node);
}

return [isAllowed, node];
}

NodeHandler.onChatStateReceived = async function(node){
const chatState = node.content[0].tag;
const user = node.attrs.from?._jid?.user || 'Someone';

if(chatState === 'composing'){
console.warn(`${user} is typing...`);
// push notification to windows
new Notification(`${user} is typing...`);
}
}

NodeHandler.onReceivedMessageNode = async function(messageNode)
{
var isAllowed = true;
Expand Down
54 changes: 53 additions & 1 deletion core/ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ async function addIconIfNeeded()
document.getElementById("incognito-option-show-device-type").addEventListener("click", onShowDeviceTypesTick);
document.getElementById("incognito-option-auto-receipt").addEventListener("click", onAutoReceiptsTick);
document.getElementById("incognito-option-status-downloading").addEventListener("click", onStatusDownloadingTick);
document.getElementById("incognito-option-notify-typing").addEventListener("click", onNotifyTyping);
for (var nextButton of document.getElementsByClassName('incognito-next-button'))
{
nextButton.addEventListener("click", onNextButtonClicked);
Expand Down Expand Up @@ -237,6 +238,9 @@ function generateDropContent(options)
var allowStatusDownloadTitle = "Allow status downloading";
var allowStatusDownloadCaption = "Adds a button to download statuses";

var typingStatusNotiTitle = "Nofify typing..."
var typingStatusNoti = "Notify when someone is typing a message to you"

var readConfirmationCheckbox = (options.readConfirmationsHook ? "checked incognito-checked'> \
<div class='checkmark incognito-mark incognito-marked'> </div>" :
"unchecked " + "'> <div class='checkmark incognito-mark" + "'> </div>");
Expand All @@ -246,6 +250,9 @@ function generateDropContent(options)
var typingUpdatesCheckbox = (options.typingUpdatesHook ? "checked incognito-checked'> \
<div class='checkmark incognito-mark incognito-marked'> </div>" :
"unchecked " + "'> <div class='checkmark incognito-mark" + "'> </div>");
var allowStatusDownloadCheckbox = (options.allowStatusDownload ? "checked incognito-checked'> \
<div class='checkmark incognito-mark incognito-marked'> </div>" :
"unchecked " + "'> <div class='checkmark incognito-mark" + "'> </div>");
var saveDeletedMessagesCheckbox = (options.saveDeletedMsgs ? "checked incognito-checked'> \
<div class='checkmark incognito-mark incognito-marked'> </div>" :
"unchecked " + "'> <div class='checkmark incognito-mark" + "'> </div>");
Expand All @@ -255,11 +262,12 @@ function generateDropContent(options)
var autoReceiptCheckbox = (options.autoReceiptOnReplay ? "checked incognito-checked'> \
<div class='checkmark incognito-mark incognito-marked'> </div>" :
"unchecked " + "'> <div class='checkmark incognito-mark" + "'> </div>");
var allowStatusDownloadCheckbox = (options.allowStatusDownload ? "checked incognito-checked'> \
var notifiTypingCheckbox = (options.notifytyping ? "checked incognito-checked'> \
<div class='checkmark incognito-mark incognito-marked'> </div>" :
"unchecked " + "'> <div class='checkmark incognito-mark" + "'> </div>");



var dropContent = ` \
<div class='incognito-options-container' dir='ltr'>
<div class='incognito-options-title'>Incognito options</div>
Expand Down Expand Up @@ -348,6 +356,14 @@ function generateDropContent(options)
${allowStatusDownloadTitle}
<div class='incognito-options-description'>${allowStatusDownloadCaption}</div>
</div>
<div id='incognito-option-notify-typing' class='incognito-options-item' style='cursor: pointer;'>
<div class='checkbox-container-incognito' style=''>
<div class='checkbox checkbox checkbox-incognito ${notifiTypingCheckbox}
</div>
</div>
${typingStatusNotiTitle}
<div class='incognito-options-description'>${typingStatusNoti}</div>
</div>
<div class='incognito-options-item' style='cursor: pointer;'>
More options coming soon!
</div>
Expand Down Expand Up @@ -579,6 +595,42 @@ function onShowDeviceTypesTick()
}));
}

function onNotifyTyping()
{
var notifyTyping = false;
var checkbox = document.querySelector("#incognito-option-notify-typing .checkbox-incognito");

var checkmark = checkbox.firstElementChild;

if (checkbox.getAttribute("class").indexOf("unchecked") > -1)
{
tickCheckbox(checkbox, checkmark);
notifyTyping = true;

if(Notification.permission !== "granted"){
Notification.requestPermission();
}

setInterval(() => {
const event = new Event('focus');
window.dispatchEvent(event);
}, 1500);
}
else
{
untickCheckbox(checkbox, checkmark);

notifyTyping = false;
}
browser.runtime.sendMessage({ name: "setOptions", notifytyping: notifyTyping });
document.dispatchEvent(new CustomEvent('onOptionsUpdate',
{
detail: JSON.stringify({ notifyTyping: notifyTyping })
}));

// starting interval for always focusing window
}

function onAutoReceiptsTick()
{
var autoReceipts = false;
Expand Down