notifications: Send message received from desktop app notification reply.

Adds a electron_bridge event that takes in message id and reply recived from
the notification reply and sends a message. We do this in webapp so desktop
doesn't have to depend on narrow and channel modules.

We also modify zjunit to reset window.electron_bridge after every run
to avoid leaking it.
This commit is contained in:
Priyank Patel 2019-07-16 00:52:55 +00:00 committed by Tim Abbott
parent ba7a0934e3
commit e69c2f1aa2
2 changed files with 41 additions and 0 deletions

View File

@ -41,6 +41,7 @@ exports.restore = function () {
delete require.cache[require.resolve(fn)]; delete require.cache[require.resolve(fn)];
}); });
dependencies = []; dependencies = [];
delete global.window.electron_bridge;
_.extend(global, old_builtins); _.extend(global, old_builtins);
old_builtins = {}; old_builtins = {};
}; };

View File

@ -269,6 +269,46 @@ exports.notify_above_composebox = function (note, link_class, link_msg_id, link_
$('#out-of-view-notification').show(); $('#out-of-view-notification').show();
}; };
if (window.electron_bridge !== undefined) {
// The code below is for sending a message received from notification reply which
// is often refered to as inline reply feature. This is done so desktop app doesn't
// have to depend on channel.post for setting crsf_token and narrow.by_topic
// to narrow to the message being sent.
window.electron_bridge.send_notification_reply_message_supported = true;
window.electron_bridge.on_event('send_notification_reply_message', function (message_id, reply) {
var message = message_store.get(message_id);
var data = {
type: message.type,
content: reply,
to: message.type === 'private' ? message.reply_to : message.stream,
topic: util.get_message_topic(message),
};
function success() {
if (message.type === 'stream') {
narrow.by_topic(message_id, {trigger: 'desktop_notification_reply'});
} else {
narrow.by_recipient(message_id, {trigger: 'desktop_notification_reply'});
}
}
function error(error) {
window.electron_bridge.send_event('send_notification_reply_message_failed', {
data: data,
message_id: message_id,
error: error,
});
}
channel.post({
url: '/json/messages',
data: data,
success: success,
error: error,
});
});
}
function process_notification(notification) { function process_notification(notification) {
var i; var i;
var notification_object; var notification_object;