Disable friends chat in pad messenger

pull/1/head
yflory 6 years ago
parent 1895d6cbd8
commit 6c27d2964c

@ -125,6 +125,8 @@
}
#cp-app-contacts-container.cp-app-contacts-inapp {
#cp-app-contacts-friendlist {
display: none;
/*
transition: width 0.2s ease-in-out 0.2s;
width: 68px;
.cp-app-contacts-friend {
@ -145,6 +147,7 @@
font-size: 18px;
}
}
*/
}
}

@ -262,6 +262,14 @@
display: flex;
justify-content: space-between;
align-items: center;
button {
width: 20px;
font-size: 16px;
padding: 0;
border: none;
height: 20px;
cursor: pointer;
}
}
.cp-toolbar-userlist-name-input {
flex: 1;
@ -278,14 +286,6 @@
min-height: 0;
text-overflow: ellipsis;
}
.cp-toolbar-userlist-name-edit {
width: 20px;
font-size: 16px;
padding: 0;
border: none;
height: 20px;
cursor: pointer;
}
.cp-toolbar-userlist-friend {
padding: 0;
}
@ -387,7 +387,7 @@
color: @toolbar-color;
color: var(--toolbar-color);
}
.cp-toolbar-userlist-name-edit {
.cp-toolbar-userlist-button {
color: @toolbar-userlist-name-edit;
color: var(--toolbar-userlist-name-edit);
background: transparent;

@ -204,7 +204,7 @@ define([
};
// Make sure the data we have about our friends are up-to-date when we see them online
var checkFriendData = function (curve, data) {
var checkFriendData = function (curve, data, channel) {
if (curve === proxy.curvePublic) { return; }
var friend = getFriend(proxy, curve);
if (!friend) { return; }
@ -217,7 +217,7 @@ define([
});
eachHandler('update', function (f) {
f(clone(data), types);
f(clone(data), types, channel);
});
};
@ -261,7 +261,7 @@ define([
// the sender field. This is to prevent replay attacks.
if (parsed[2] !== sender || !parsed[1]) { return; }
channel.mapId[sender] = parsed[1];
checkFriendData(parsed[1].curvePublic, parsed[1]);
checkFriendData(parsed[1].curvePublic, parsed[1], channel.id);
eachHandler('join', function (f) {
f(parsed[1], channel.id);
});
@ -328,7 +328,7 @@ define([
return true;
}
if (parsedMsg[0] === Types.update) {
checkFriendData(parsedMsg[1], parsedMsg[3]);
checkFriendData(parsedMsg[1], parsedMsg[3], channel.id);
return;
}
if (parsedMsg[0] === Types.unfriend) {
@ -809,7 +809,10 @@ define([
};
var ready = false;
var initialized = false;
var init = function () {
if (initialized) { return; }
initialized = true;
var friends = getFriendList(proxy);
nThen(function (waitFor) {
@ -827,7 +830,7 @@ define([
emit('READY');
});
};
init();
//init();
var getRooms = function (data, cb) {
if (data && data.curvePublic) {
@ -931,6 +934,10 @@ define([
messenger.execCommand = function (obj, cb) {
var cmd = obj.cmd;
var data = obj.data;
if (cmd === 'INIT_FRIENDS') {
init();
return void cb();
}
if (cmd === 'IS_READY') {
return void cb(ready);
}

@ -1366,10 +1366,11 @@ define([
channel: channel,
});
});
messenger.on('update', function (info, types) {
messenger.on('update', function (info, types, channel) {
sendMessengerEvent('CONTACTS_UPDATE', {
types: types,
info: info,
channel: channel
});
});
messenger.on('friend', function (curvePublic) {

@ -35,7 +35,7 @@ define([], function () {
});
sFrameChan.on('EV_CONTACTS_UPDATE', function (data) {
_handlers.update.forEach(function (f) {
f(data.info, data.types);
f(data.info, data.types, data.channel);
});
});
sFrameChan.on('EV_CONTACTS_FRIEND', function (data) {

@ -234,16 +234,15 @@ Messenger, MessengerUI, Messages) {
var name = data.name || Messages.anonymous;
var $span = $('<span>', {'class': 'cp-avatar'});
var $rightCol = $('<span>', {'class': 'cp-toolbar-userlist-rightcol'});
var $nameSpan = $('<span>', {'class': 'cp-toolbar-userlist-name'}).text(name).appendTo($rightCol);
var $nameSpan = $('<span>', {'class': 'cp-toolbar-userlist-name'}).appendTo($rightCol);
var $nameValue = $('<span>', {
'class': 'cp-toolbar-userlist-name-value'
}).text(name).appendTo($nameSpan);
var isMe = data.uid === user.uid;
if (isMe && !priv.readOnly) {
$nameSpan.html('');
var $nameValue = $('<span>', {
'class': 'cp-toolbar-userlist-name-value'
}).text(name).appendTo($nameSpan);
if (!Config.disableProfile) {
var $button = $('<button>', {
'class': 'fa fa-pencil cp-toolbar-userlist-name-edit',
'class': 'fa fa-pencil cp-toolbar-userlist-button',
title: Messages.user_rename
}).appendTo($nameSpan);
$button.hover(function (e) { e.preventDefault(); e.stopPropagation(); });
@ -299,16 +298,24 @@ Messenger, MessengerUI, Messages) {
$('<span>', {'class': 'cp-toolbar-userlist-friend'}).text(Messages.userlist_pending)
.appendTo($rightCol);
} else {
$('<span>', {
'class': 'fa fa-user-plus cp-toolbar-userlist-friend',
$('<button>', {
'class': 'fa fa-user-plus cp-toolbar-userlist-button',
'title': Messages._getKey('userlist_addAsFriendTitle', [
name
])
}).appendTo($rightCol).click(function (e) {
}).appendTo($nameSpan).click(function (e) {
e.stopPropagation();
Common.sendFriendRequest(data.netfluxId);
});
}
} else if (Common.isLoggedIn() && data.curvePublic && friends[data.curvePublic]) {
$('<button>', {
'class': 'fa fa-comments-o cp-toolbar-userlist-button',
'title': Messages.userlist_chat
}).appendTo($nameSpan).click(function (e) {
e.stopPropagation();
Common.openURL('/contacts/');
});
}
if (data.profile) {
$span.addClass('cp-userlist-clickable');

@ -45,6 +45,8 @@ define([
var metadataMgr = common.getMetadataMgr();
var origin = metadataMgr.getPrivateData().origin;
var isApp = typeof(toolbar) !== "undefined";
$container.addClass('cp-app-contacts-initializing');
var messaging = h('div#cp-app-contacts-messaging', [
@ -52,7 +54,7 @@ define([
h('div.cp-app-contacts-info', [
h('h2', Messages.contacts_info1_new),
h('ul', [
toolbar ? h('li', [
isApp ? h('li', [
Messages.contacts_info2_new,
h('ul', [
h('li', Messages.contacts_info2a_new)
@ -124,7 +126,7 @@ define([
var onResize = function () {
// Don't update the width if we are in the contacts app
if (!toolbar) { return; }
if (!isApp) { return; }
var w = $userlist[0].offsetWidth - $userlist[0].clientWidth;
$userlist.css('width', (68 + w)+'px');
};
@ -401,6 +403,7 @@ define([
};
var updateStatus = function (id) {
if (!state.channels[id]) { return; }
var $status = find.inList(id).find('.cp-app-contacts-status');
messenger.getStatus(id, function (e, online) {
// if error maybe you shouldn't display this friend...
@ -525,6 +528,8 @@ define([
messenger.on('message', function (message) {
var chanId = message.channel;
var channel = state.channels[chanId];
if (!channel) { return; }
var chat = getChat(chanId);
@ -532,12 +537,6 @@ define([
var el_message = markup.message(message);
var channel = state.channels[chanId];
if (!channel) {
console.log(message);
console.error('expected channel [%s] to be open', chanId);
return;
}
common.notify();
channel.messages.push(message);
@ -588,8 +587,11 @@ define([
});
// change in your friend list
messenger.on('update', function (info, types) {
messenger.on('update', function (info, types, channel) {
if (!info || !info.curvePublic) { return; }
// Make sure we don't store useless data (friends data in pad chat or the other way)
if (channel && !state.channels[channel]) { return; }
var curvePublic = info.curvePublic;
contactsData[curvePublic] = info;
@ -636,7 +638,7 @@ define([
var execCommand = function (cmd, data, cb) {
sframeChan.query('Q_CHAT_COMMAND', {cmd: cmd, data: data}, function (err, obj) {
if (err || obj.error) { return void cb(err || obj.error); }
if (err || (obj && obj.error)) { return void cb(err || (obj && obj.error)); }
cb(void 0, obj);
});
};
@ -686,10 +688,16 @@ define([
reorderRooms();
updateStatus(id);
if (isApp && room.isPadChat) {
$container.removeClass('cp-app-contacts-initializing');
display(room.id);
}
});
};
messenger.on('friend', function (curvePublic) {
if (isApp) { return; }
debug('new friend: ', curvePublic);
execCommand('GET_ROOMS', {curvePublic: curvePublic}, function (err, rooms) {
if (err) { return void console.error(err); }
@ -699,6 +707,7 @@ define([
});
messenger.on('unfriend', function (curvePublic, removedByMe) {
if (isApp) { return; }
var channel = state.channels[state.active];
$userlist.find(userQuery(curvePublic)).remove();
$messages.find(userQuery(curvePublic)).remove();
@ -741,6 +750,7 @@ define([
var ready = false;
var onMessengerReady = function () {
if (isApp) { return; }
if (ready) { return; }
ready = true;
@ -769,8 +779,6 @@ define([
room.name = name;
rooms.forEach(initializeRoom);
});
$container.removeClass('cp-app-contacts-initializing');
};
var onDisconnect = function () {
@ -784,9 +792,12 @@ define([
// Initialize chat when outer is ready (all channels loaded)
// TODO: try again in outer if fail to load a channel
execCommand('IS_READY', null, function (err, yes) {
if (yes) { onMessengerReady(); }
});
if (!isApp) {
execCommand('INIT_FRIENDS', null, function () {});
execCommand('IS_READY', null, function (err, yes) {
if (yes) { onMessengerReady(); }
});
}
sframeChan.on('EV_CHAT_EVENT', function (obj) {
if (obj.ev === 'READY') {
onMessengerReady();

Loading…
Cancel
Save