mirror of
https://github.com/cryptpad/cryptpad.git
synced 2026-09-14 11:05:41 +05:00
notification received when message sent
This commit is contained in:
parent
19dee98e33
commit
8f1fdf822c
@ -134,6 +134,7 @@ define(req, function(AppConfig, Default, Language) {
|
||||
}
|
||||
};
|
||||
|
||||
Messages.sent_chatMessage = "{0} has sent you a message" // XXX
|
||||
return Messages;
|
||||
|
||||
});
|
||||
|
||||
@ -181,7 +181,6 @@ const factory = (Messaging, Hash, Util, Crypto, Block) => {
|
||||
};
|
||||
// UI for accepted friend request
|
||||
handlers['FRIEND_REQUEST_ACCEPTED'] = function (ctx, box, data, cb) {
|
||||
console.log("here")
|
||||
ctx.updateMetadata();
|
||||
var curve = data.msg.content.user.curvePublic || data.msg.content.user;
|
||||
var toRemove = friendRequestDeclined[curve];
|
||||
@ -194,7 +193,6 @@ const factory = (Messaging, Hash, Util, Crypto, Block) => {
|
||||
cb(false, toRemove);
|
||||
};
|
||||
removeHandlers['FRIEND_REQUEST_ACCEPTED'] = function (ctx, box, data) {
|
||||
console.log("friend")
|
||||
var curve = data.content.user.curvePublic || data.content.user;
|
||||
if (friendRequestAccepted[curve]) { delete friendRequestAccepted[curve]; }
|
||||
};
|
||||
@ -261,6 +259,8 @@ const factory = (Messaging, Hash, Util, Crypto, Block) => {
|
||||
// Keep only one notification per channel: the stronger and more recent one
|
||||
var channels = {};
|
||||
handlers['SHARE_PAD'] = function (ctx, box, data, cb) {
|
||||
console.log("here2")
|
||||
|
||||
var msg = data.msg;
|
||||
var hash = data.hash;
|
||||
var content = msg.content;
|
||||
@ -319,6 +319,59 @@ const factory = (Messaging, Hash, Util, Crypto, Block) => {
|
||||
supportMessage = false;
|
||||
};
|
||||
|
||||
|
||||
var messageChannels = {};
|
||||
handlers['SEND_CHAT_MESSAGE'] = function (ctx, box, data, cb) {
|
||||
console.log("here2")
|
||||
|
||||
var msg = data.msg;
|
||||
var hash = data.hash;
|
||||
var content = msg.content;
|
||||
// content.name, content.title, content.href, content.password
|
||||
|
||||
if (isMuted(ctx, data)) { return void cb(true); }
|
||||
// if the shared content is a 'link' then we can't use the channel to deduplicate notifications
|
||||
// use href instead.
|
||||
var channel = content.isStatic ? content.href : Hash.hrefToHexChannelId(content.href, content.password);
|
||||
var parsed = Hash.parsePadUrl(content.href);
|
||||
var mode = parsed.hashData && parsed.hashData.mode || 'n/a';
|
||||
|
||||
var old = channels[channel];
|
||||
var toRemove;
|
||||
if (old) {
|
||||
// New hash is weaker, ignore
|
||||
if (old.mode === 'edit' && mode === 'view') {
|
||||
return void cb(true);
|
||||
}
|
||||
// New hash is not weaker, clear the old one
|
||||
toRemove = old.data;
|
||||
}
|
||||
|
||||
if (content.password) {
|
||||
content.password = encryptPassword(ctx, content.password);
|
||||
}
|
||||
|
||||
// Update the data
|
||||
messageChannels[channel] = {
|
||||
mode: mode,
|
||||
data: {
|
||||
type: box.type,
|
||||
hash: hash
|
||||
}
|
||||
};
|
||||
|
||||
cb(false, toRemove);
|
||||
};
|
||||
removeHandlers['SEND_CHAT_MESSAGE'] = function (ctx, box, data, hash) {
|
||||
var content = data.content;
|
||||
var channel = Hash.hrefToHexChannelId(content.href, content.password);
|
||||
var old = messageChannels[channel];
|
||||
if (old && old.data && old.data.hash === hash) {
|
||||
delete messageChannels[channel];
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
// Incoming edit rights request: add data before sending it to inner
|
||||
handlers['REQUEST_PAD_ACCESS'] = function (ctx, box, data, cb) {
|
||||
var msg = data.msg;
|
||||
@ -349,7 +402,6 @@ const factory = (Messaging, Hash, Util, Crypto, Block) => {
|
||||
};
|
||||
|
||||
handlers['GIVE_PAD_ACCESS'] = function (ctx, box, data, cb) {
|
||||
console.log("msgs2")
|
||||
var msg = data.msg;
|
||||
var content = msg.content;
|
||||
|
||||
@ -369,7 +421,6 @@ const factory = (Messaging, Hash, Util, Crypto, Block) => {
|
||||
};
|
||||
|
||||
handlers['ADD_TO_ACCESS_LIST'] = function(ctx, common, data, cb) {
|
||||
|
||||
var msg = data.msg;
|
||||
var content = msg.content;
|
||||
var channel = content.channel;
|
||||
@ -681,7 +732,6 @@ const factory = (Messaging, Hash, Util, Crypto, Block) => {
|
||||
// Keep only one notification per channel: the stronger and more recent one
|
||||
var comments = {};
|
||||
handlers['COMMENT_REPLY'] = function (ctx, box, data, cb) {
|
||||
console.log("hello@")
|
||||
var msg = data.msg;
|
||||
var hash = data.hash;
|
||||
var content = msg.content;
|
||||
|
||||
@ -368,21 +368,20 @@ proxy.mailboxes = {
|
||||
};
|
||||
var notify = box.ready;
|
||||
Handlers.add(ctx, box, message, function (dismissed, toDismiss, invalid) {
|
||||
console.log("hello???", toDismiss, invalid, dismissed)
|
||||
// if (toDismiss) { // List of other messages to remove
|
||||
// dismiss(ctx, toDismiss, '', function () {
|
||||
// console.log('Notification handled automatically');
|
||||
// });
|
||||
// }
|
||||
// if (invalid || dismissed) { // This message should be removed
|
||||
// dismiss(ctx, {
|
||||
// type: type,
|
||||
// hash: hash
|
||||
// }, '', function () {
|
||||
// console.log('Notification handled automatically');
|
||||
// });
|
||||
// return;
|
||||
// }
|
||||
if (toDismiss) { // List of other messages to remove
|
||||
dismiss(ctx, toDismiss, '', function () {
|
||||
console.log('Notification handled automatically');
|
||||
});
|
||||
}
|
||||
if (invalid || dismissed) { // This message should be removed
|
||||
dismiss(ctx, {
|
||||
type: type,
|
||||
hash: hash
|
||||
}, '', function () {
|
||||
console.log('Notification handled automatically');
|
||||
});
|
||||
return;
|
||||
}
|
||||
msg.ctime = time || 0;
|
||||
box.content[hash] = msg;
|
||||
if (opts.dump) { return; }
|
||||
|
||||
@ -293,7 +293,6 @@ const factory = (Crypto, Hash, Util, Realtime, Messaging,
|
||||
};
|
||||
|
||||
var onDirectMessage = function (ctx, msg, sender) {
|
||||
console.log("here!!")
|
||||
var hk = ctx.store.network.historyKeeper;
|
||||
if (sender !== hk) { return void onIdMessage(ctx, msg, sender); }
|
||||
var parsed = JSON.parse(msg);
|
||||
@ -398,15 +397,9 @@ const factory = (Crypto, Hash, Util, Realtime, Messaging,
|
||||
};
|
||||
|
||||
var onMessage = function (ctx, msg, sender, chan) {
|
||||
console.log("wkjhdkejdh")
|
||||
var channel = ctx.channels[chan.id];
|
||||
if (!channel) { return; }
|
||||
pushMsg(ctx, channel, msg);
|
||||
// ctx.emit('FRIEND_REQUEST_ACCEPTED', {
|
||||
// curvePublic: curvePublic,
|
||||
// fromMe: true
|
||||
// }, ctx.friendsClients);
|
||||
|
||||
};
|
||||
|
||||
var onFriendRemoved = function (ctx, curvePublic, chanId) {
|
||||
|
||||
@ -657,17 +657,8 @@ define([
|
||||
debug(message);
|
||||
|
||||
var el_message = markup.message(message);
|
||||
console.log("PROXY", message, contactsData)
|
||||
|
||||
common.mailbox.sendTo("COMMENT_REPLY", {
|
||||
channel: channel,
|
||||
content: "hello"
|
||||
}, {
|
||||
channel: contactsData[message.author].notifications,
|
||||
curvePublic: message.author
|
||||
})
|
||||
// ProxyManager.sendNotification()
|
||||
console.log("hello!!")
|
||||
|
||||
if (message.type === 'MSG') {
|
||||
var name = UI.getDisplayName(typeof message.name !== "undefined" ?
|
||||
message.name:
|
||||
@ -677,11 +668,15 @@ define([
|
||||
msg: message.text,
|
||||
force: toolbar && toolbar.team && !toolbar['chat'].hasClass('cp-leftside-active')
|
||||
});
|
||||
|
||||
common.mailbox.sendTo("SEND_CHAT_MESSAGE", {
|
||||
name: name
|
||||
}, {
|
||||
channel: contactsData[channel.curvePublic].notifications,
|
||||
curvePublic: channel.curvePublic
|
||||
})
|
||||
}
|
||||
// ctx.emit('FRIEND_REQUEST_ACCEPTED', {
|
||||
// curvePublic: curvePublic,
|
||||
// fromMe: true
|
||||
// }, ctx.friendsClients);
|
||||
|
||||
notifyToolbar();
|
||||
|
||||
channel.messages.push(message);
|
||||
|
||||
@ -90,6 +90,7 @@ define([
|
||||
|
||||
// Share pad
|
||||
handlers['SHARE_PAD'] = function(common, data) {
|
||||
console.log("here1", common, data)
|
||||
var content = data.content;
|
||||
var msg = content.msg;
|
||||
var type = Hash.parsePadUrl(msg.content.href).type;
|
||||
@ -141,6 +142,25 @@ define([
|
||||
}
|
||||
};
|
||||
|
||||
// Send chat message
|
||||
handlers['SEND_CHAT_MESSAGE'] = function(common, data) {
|
||||
var content = data.content;
|
||||
var msg = content.msg;
|
||||
var key = 'sent_chatMessage'; // Msg.notification_padSharedTeam
|
||||
|
||||
var name = Util.fixHTML(msg.content.name) || Messages.anonymous;
|
||||
content.getFormatText = function() {
|
||||
return Messages._getKey(key, [name]);
|
||||
};
|
||||
content.handler = function() {
|
||||
common.openURL('/contacts/');
|
||||
defaultDismiss(common, data)();
|
||||
};
|
||||
if (!content.archived) {
|
||||
content.dismissHandler = defaultDismiss(common, data);
|
||||
}
|
||||
};
|
||||
|
||||
// New support message from the admins
|
||||
handlers['SUPPORT_MESSAGE'] = function(common, data) {
|
||||
var content = data.content;
|
||||
@ -364,7 +384,6 @@ define([
|
||||
};
|
||||
|
||||
handlers['COMMENT_REPLY'] = function(common, data) {
|
||||
console.log("hello$")
|
||||
var content = data.content;
|
||||
var msg = content.msg;
|
||||
|
||||
|
||||
@ -122,6 +122,8 @@ define([
|
||||
channel: data.notifications,
|
||||
curvePublic: data.curvePublic
|
||||
});
|
||||
|
||||
console.log("here!", privateData.channel, data.notifications, data.curvePublic)
|
||||
});
|
||||
|
||||
};
|
||||
|
||||
Loading…
Reference in New Issue
Block a user