|
|
@ -12,7 +12,7 @@ define([
|
|
|
|
var Messages = Cryptpad.Messages;
|
|
|
|
var Messages = Cryptpad.Messages;
|
|
|
|
|
|
|
|
|
|
|
|
var m = function (md) {
|
|
|
|
var m = function (md) {
|
|
|
|
var d = h('div.content');
|
|
|
|
var d = h('div.cp-app-contacts-content');
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
d.innerHTML = Marked(md || '');
|
|
|
|
d.innerHTML = Marked(md || '');
|
|
|
|
} catch (e) {
|
|
|
|
} catch (e) {
|
|
|
@ -36,6 +36,8 @@ define([
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
UI.create = function (messenger, $userlist, $messages, common) {
|
|
|
|
UI.create = function (messenger, $userlist, $messages, common) {
|
|
|
|
|
|
|
|
var origin = common.getMetadataMgr().getPrivateData().origin;
|
|
|
|
|
|
|
|
|
|
|
|
var state = window.state = {
|
|
|
|
var state = window.state = {
|
|
|
|
active: '',
|
|
|
|
active: '',
|
|
|
|
};
|
|
|
|
};
|
|
|
@ -57,21 +59,21 @@ define([
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
var notify = function (curvePublic) {
|
|
|
|
var notify = function (curvePublic) {
|
|
|
|
find.inList(curvePublic).addClass('notify');
|
|
|
|
find.inList(curvePublic).addClass('cp-app-contacts-notify');
|
|
|
|
};
|
|
|
|
};
|
|
|
|
var unnotify = function (curvePublic) {
|
|
|
|
var unnotify = function (curvePublic) {
|
|
|
|
find.inList(curvePublic).removeClass('notify');
|
|
|
|
find.inList(curvePublic).removeClass('cp-app-contacts-notify');
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
var markup = {};
|
|
|
|
var markup = {};
|
|
|
|
markup.message = function (msg) {
|
|
|
|
markup.message = function (msg) {
|
|
|
|
var curvePublic = msg.author;
|
|
|
|
var curvePublic = msg.author;
|
|
|
|
var name = displayNames[msg.author];
|
|
|
|
var name = displayNames[msg.author];
|
|
|
|
return h('div.message', {
|
|
|
|
return h('div.cp-app-contacts-message', {
|
|
|
|
title: msg.time? new Date(msg.time).toLocaleString(): '?',
|
|
|
|
title: msg.time? new Date(msg.time).toLocaleString(): '?',
|
|
|
|
'data-key': curvePublic,
|
|
|
|
'data-key': curvePublic,
|
|
|
|
}, [
|
|
|
|
}, [
|
|
|
|
name? h('div.sender', name): undefined,
|
|
|
|
name? h('div.cp-app-contacts-sender', name): undefined,
|
|
|
|
m(msg.text),
|
|
|
|
m(msg.text),
|
|
|
|
]);
|
|
|
|
]);
|
|
|
|
};
|
|
|
|
};
|
|
|
@ -81,10 +83,10 @@ define([
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
var normalizeLabels = function ($messagebox) {
|
|
|
|
var normalizeLabels = function ($messagebox) {
|
|
|
|
$messagebox.find('div.message').toArray().reduce(function (a, b) {
|
|
|
|
$messagebox.find('div.cp-app-contacts-message').toArray().reduce(function (a, b) {
|
|
|
|
var $b = $(b);
|
|
|
|
var $b = $(b);
|
|
|
|
if ($(a).data('key') === $b.data('key')) {
|
|
|
|
if ($(a).data('key') === $b.data('key')) {
|
|
|
|
$b.find('.sender').hide();
|
|
|
|
$b.find('.cp-app-contacts-sender').hide();
|
|
|
|
return a;
|
|
|
|
return a;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return b;
|
|
|
|
return b;
|
|
|
@ -92,7 +94,7 @@ define([
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
markup.chatbox = function (curvePublic, data) {
|
|
|
|
markup.chatbox = function (curvePublic, data) {
|
|
|
|
var moreHistory = h('span.more-history.fa.fa-history', {
|
|
|
|
var moreHistory = h('span.cp-app-contacts-more-history.fa.fa-history', {
|
|
|
|
title: Messages.contacts_fetchHistory,
|
|
|
|
title: Messages.contacts_fetchHistory,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
var displayName = data.displayName;
|
|
|
|
var displayName = data.displayName;
|
|
|
@ -105,14 +107,14 @@ define([
|
|
|
|
var channel = state.channels[curvePublic];
|
|
|
|
var channel = state.channels[curvePublic];
|
|
|
|
|
|
|
|
|
|
|
|
if (channel.exhausted) {
|
|
|
|
if (channel.exhausted) {
|
|
|
|
return void $moreHistory.addClass('faded');
|
|
|
|
return void $moreHistory.addClass('cp-app-contacts-faded');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
console.log('getting history');
|
|
|
|
console.log('getting history');
|
|
|
|
var sig = channel.TAIL || channel.HEAD;
|
|
|
|
var sig = channel.TAIL || channel.HEAD;
|
|
|
|
|
|
|
|
|
|
|
|
fetching = true;
|
|
|
|
fetching = true;
|
|
|
|
var $messagebox = $(getChat(curvePublic)).find('.messages');
|
|
|
|
var $messagebox = $(getChat(curvePublic)).find('.cp-app-contacts-messages');
|
|
|
|
messenger.getMoreHistory(curvePublic, sig, 10, function (e, history) {
|
|
|
|
messenger.getMoreHistory(curvePublic, sig, 10, function (e, history) {
|
|
|
|
fetching = false;
|
|
|
|
fetching = false;
|
|
|
|
if (e) { return void console.error(e); }
|
|
|
|
if (e) { return void console.error(e); }
|
|
|
@ -129,7 +131,7 @@ define([
|
|
|
|
console.error('No more messages to fetch');
|
|
|
|
console.error('No more messages to fetch');
|
|
|
|
channel.exhausted = true;
|
|
|
|
channel.exhausted = true;
|
|
|
|
console.log(channel);
|
|
|
|
console.log(channel);
|
|
|
|
return void $moreHistory.addClass('faded');
|
|
|
|
return void $moreHistory.addClass('cp-app-contacts-faded');
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
channel.TAIL = msg.sig;
|
|
|
|
channel.TAIL = msg.sig;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -151,7 +153,7 @@ define([
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
var removeHistory = h('span.remove-history.fa.fa-eraser', {
|
|
|
|
var removeHistory = h('span.cp-app-contacts-remove-history.fa.fa-eraser', {
|
|
|
|
title: Messages.contacts_removeHistoryTitle
|
|
|
|
title: Messages.contacts_removeHistoryTitle
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
@ -169,12 +171,12 @@ define([
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
var avatar = h('div.cp-avatar');
|
|
|
|
var avatar = h('div.cp-avatar');
|
|
|
|
var header = h('div.header', [
|
|
|
|
var header = h('div.cp-app-contacts-header', [
|
|
|
|
avatar,
|
|
|
|
avatar,
|
|
|
|
moreHistory,
|
|
|
|
moreHistory,
|
|
|
|
removeHistory,
|
|
|
|
removeHistory,
|
|
|
|
]);
|
|
|
|
]);
|
|
|
|
var messages = h('div.messages');
|
|
|
|
var messages = h('div.cp-app-contacts-messages');
|
|
|
|
var input = h('textarea', {
|
|
|
|
var input = h('textarea', {
|
|
|
|
placeholder: Messages.contacts_typeHere
|
|
|
|
placeholder: Messages.contacts_typeHere
|
|
|
|
});
|
|
|
|
});
|
|
|
@ -182,8 +184,8 @@ define([
|
|
|
|
title: Messages.contacts_send,
|
|
|
|
title: Messages.contacts_send,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
var rightCol = h('span.right-col', [
|
|
|
|
var rightCol = h('span.cp-app-contacts-right-col', [
|
|
|
|
h('span.name', displayName),
|
|
|
|
h('span.cp-app-contacts-name', displayName),
|
|
|
|
]);
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
|
|
var $avatar = $(avatar);
|
|
|
|
var $avatar = $(avatar);
|
|
|
@ -249,12 +251,12 @@ define([
|
|
|
|
$(input).on('keydown', onKeyDown);
|
|
|
|
$(input).on('keydown', onKeyDown);
|
|
|
|
$(sendButton).click(function () { send(input.value); });
|
|
|
|
$(sendButton).click(function () { send(input.value); });
|
|
|
|
|
|
|
|
|
|
|
|
return h('div.chat', {
|
|
|
|
return h('div.cp-app-contacts-chat', {
|
|
|
|
'data-key': curvePublic,
|
|
|
|
'data-key': curvePublic,
|
|
|
|
}, [
|
|
|
|
}, [
|
|
|
|
header,
|
|
|
|
header,
|
|
|
|
messages,
|
|
|
|
messages,
|
|
|
|
h('div.input', [
|
|
|
|
h('div.cp-app-contacts-input', [
|
|
|
|
input,
|
|
|
|
input,
|
|
|
|
sendButton,
|
|
|
|
sendButton,
|
|
|
|
]),
|
|
|
|
]),
|
|
|
@ -262,11 +264,11 @@ define([
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
var hideInfo = function () {
|
|
|
|
var hideInfo = function () {
|
|
|
|
$messages.find('.info').hide();
|
|
|
|
$messages.find('.cp-app-contacts-info').hide();
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
var updateStatus = function (curvePublic) {
|
|
|
|
var updateStatus = function (curvePublic) {
|
|
|
|
var $status = find.inList(curvePublic).find('.status');
|
|
|
|
var $status = find.inList(curvePublic).find('.cp-app-contacts-status');
|
|
|
|
// FIXME this stopped working :(
|
|
|
|
// FIXME this stopped working :(
|
|
|
|
messenger.getStatus(curvePublic, function (e, online) {
|
|
|
|
messenger.getStatus(curvePublic, function (e, online) {
|
|
|
|
// if error maybe you shouldn't display this friend...
|
|
|
|
// if error maybe you shouldn't display this friend...
|
|
|
@ -278,9 +280,9 @@ define([
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (online) {
|
|
|
|
if (online) {
|
|
|
|
return void $status
|
|
|
|
return void $status
|
|
|
|
.removeClass('offline').addClass('online');
|
|
|
|
.removeClass('cp-app-contacts-offline').addClass('cp-app-contacts-online');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$status.removeClass('online').addClass('offline');
|
|
|
|
$status.removeClass('cp-app-contacts-online').addClass('cp-app-contacts-offline');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
@ -299,11 +301,11 @@ define([
|
|
|
|
unnotify(curvePublic);
|
|
|
|
unnotify(curvePublic);
|
|
|
|
var $chat = getChat(curvePublic);
|
|
|
|
var $chat = getChat(curvePublic);
|
|
|
|
hideInfo();
|
|
|
|
hideInfo();
|
|
|
|
$messages.find('div.chat[data-key]').hide();
|
|
|
|
$messages.find('div.cp-app-contacts-chat[data-key]').hide();
|
|
|
|
if ($chat.length) {
|
|
|
|
if ($chat.length) {
|
|
|
|
var $chat_messages = $chat.find('div.message');
|
|
|
|
var $chat_messages = $chat.find('div.cp-app-contacts-message');
|
|
|
|
if (!$chat_messages.length) {
|
|
|
|
if (!$chat_messages.length) {
|
|
|
|
var $more = $chat.find('.more-history');
|
|
|
|
var $more = $chat.find('.cp-app-contacts-more-history');
|
|
|
|
$more.click();
|
|
|
|
$more.click();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return void $chat.show();
|
|
|
|
return void $chat.show();
|
|
|
@ -325,16 +327,16 @@ define([
|
|
|
|
|
|
|
|
|
|
|
|
markup.friend = function (data) {
|
|
|
|
markup.friend = function (data) {
|
|
|
|
var curvePublic = data.curvePublic;
|
|
|
|
var curvePublic = data.curvePublic;
|
|
|
|
var friend = h('div.friend.cp-avatar', {
|
|
|
|
var friend = h('div.cp-app-contacts-friend.cp-avatar', {
|
|
|
|
'data-key': curvePublic,
|
|
|
|
'data-key': curvePublic,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
var remove = h('span.remove.fa.fa-user-times', {
|
|
|
|
var remove = h('span.cp-app-contacts-remove.fa.fa-user-times', {
|
|
|
|
title: Messages.contacts_remove
|
|
|
|
title: Messages.contacts_remove
|
|
|
|
});
|
|
|
|
});
|
|
|
|
var status = h('span.status');
|
|
|
|
var status = h('span.cp-app-contacts-status');
|
|
|
|
var rightCol = h('span.right-col', [
|
|
|
|
var rightCol = h('span.cp-app-contacts-right-col', [
|
|
|
|
h('span.name', [data.displayName]),
|
|
|
|
h('span.cp-app-contacts-name', [data.displayName]),
|
|
|
|
remove,
|
|
|
|
remove,
|
|
|
|
]);
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
|
@ -343,7 +345,7 @@ define([
|
|
|
|
display(curvePublic);
|
|
|
|
display(curvePublic);
|
|
|
|
})
|
|
|
|
})
|
|
|
|
.dblclick(function () {
|
|
|
|
.dblclick(function () {
|
|
|
|
if (data.profile) { window.open('/profile/#' + data.profile); }
|
|
|
|
if (data.profile) { window.open(origin + '/profile/#' + data.profile); }
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
$(remove).click(function (e) {
|
|
|
|
$(remove).click(function (e) {
|
|
|
@ -400,7 +402,7 @@ define([
|
|
|
|
console.error("Got a message but the chat isn't open");
|
|
|
|
console.error("Got a message but the chat isn't open");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var $messagebox = $chat.find('.messages');
|
|
|
|
var $messagebox = $chat.find('.cp-app-contacts-messages');
|
|
|
|
var shouldScroll = isBottomedOut($messagebox);
|
|
|
|
var shouldScroll = isBottomedOut($messagebox);
|
|
|
|
|
|
|
|
|
|
|
|
$messagebox.append(el_message);
|
|
|
|
$messagebox.append(el_message);
|
|
|
@ -444,11 +446,12 @@ define([
|
|
|
|
var name = displayNames[curvePublic] = info.displayName;
|
|
|
|
var name = displayNames[curvePublic] = info.displayName;
|
|
|
|
|
|
|
|
|
|
|
|
// update label in friend list
|
|
|
|
// update label in friend list
|
|
|
|
find.inList(curvePublic).find('.name').text(name);
|
|
|
|
find.inList(curvePublic).find('.cp-app-contacts-name').text(name);
|
|
|
|
|
|
|
|
|
|
|
|
// update title bar and messages
|
|
|
|
// update title bar and messages
|
|
|
|
$messages.find(dataQuery(curvePublic) + ' .header .name, div.message'+
|
|
|
|
$messages.find(dataQuery(curvePublic) + ' .cp-app-contacts-header ' +
|
|
|
|
dataQuery(curvePublic) + ' div.sender').text(name).text(name);
|
|
|
|
'.cp-app-contacts-name, div.cp-app-contacts-message'+
|
|
|
|
|
|
|
|
dataQuery(curvePublic) + ' div.cp-app-contacts-sender').text(name).text(name);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
var connectToFriend = function (curvePublic, cb) {
|
|
|
|
var connectToFriend = function (curvePublic, cb) {
|
|
|
|