Teams app improvements
This commit is contained in:
@@ -81,10 +81,13 @@ define([
|
||||
};
|
||||
|
||||
Msg.updateMyData = function (store, curve) {
|
||||
var myData = createData(store.proxy);
|
||||
var myData = createData(store.proxy, false);
|
||||
if (store.proxy.friends) {
|
||||
store.proxy.friends.me = myData;
|
||||
}
|
||||
if (store.modules['team']) {
|
||||
store.modules['team'].updateMyData(myData);
|
||||
}
|
||||
var todo = function (friend) {
|
||||
if (!friend || !friend.notifications) { return; }
|
||||
myData.channel = friend.channel;
|
||||
|
||||
@@ -321,7 +321,16 @@ define([
|
||||
return void cb(true);
|
||||
}
|
||||
|
||||
if (invitedTo[content.team.channel]) { return void cb(true); }
|
||||
var invited = invitedTo[content.team.channel];
|
||||
if (invited) {
|
||||
console.log('removing old invitation');
|
||||
cb(false, invited);
|
||||
invitedTo[content.team.channel] = {
|
||||
type: box.type,
|
||||
hash: data.hash
|
||||
};
|
||||
return;
|
||||
}
|
||||
|
||||
var myTeams = Util.find(ctx, ['store', 'proxy', 'teams']) || {};
|
||||
var alreadyMember = Object.keys(myTeams).some(function (k) {
|
||||
@@ -330,7 +339,10 @@ define([
|
||||
});
|
||||
if (alreadyMember) { return void cb(true); }
|
||||
|
||||
invitedTo[content.team.channel] = true;
|
||||
invitedTo[content.team.channel] = {
|
||||
type: box.type,
|
||||
hash: data.hash
|
||||
};
|
||||
|
||||
cb(false);
|
||||
};
|
||||
@@ -349,6 +361,10 @@ define([
|
||||
return void cb(true);
|
||||
}
|
||||
|
||||
if (invitedTo[content.teamChannel] && content.pending) {
|
||||
return void cb(true, invitedTo[content.teamChannel]);
|
||||
}
|
||||
|
||||
cb(false);
|
||||
};
|
||||
|
||||
|
||||
@@ -258,6 +258,11 @@ proxy.mailboxes = {
|
||||
hash: hash
|
||||
};
|
||||
Handlers.add(ctx, box, message, function (dismissed, toDismiss) {
|
||||
if (toDismiss) { // List of other messages to remove
|
||||
dismiss(ctx, toDismiss, '', function () {
|
||||
console.log('Notification handled automatically');
|
||||
});
|
||||
}
|
||||
if (dismissed) { // This message should be removed
|
||||
dismiss(ctx, {
|
||||
type: type,
|
||||
@@ -267,11 +272,6 @@ proxy.mailboxes = {
|
||||
});
|
||||
return;
|
||||
}
|
||||
if (toDismiss) { // List of other messages to remove
|
||||
dismiss(ctx, toDismiss, '', function () {
|
||||
console.log('Notification handled automatically');
|
||||
});
|
||||
}
|
||||
box.content[hash] = msg;
|
||||
showMessage(ctx, type, message, null, function (obj) {
|
||||
if (!box.ready) { return; }
|
||||
|
||||
@@ -477,6 +477,7 @@ define([
|
||||
sending: false,
|
||||
messages: [],
|
||||
clients: data.clients || [],
|
||||
onUserlistUpdate: data.onUserlistUpdate || function () {},
|
||||
mapId: {},
|
||||
};
|
||||
|
||||
@@ -584,10 +585,32 @@ define([
|
||||
});
|
||||
};
|
||||
|
||||
var getOnlineList = function (ctx, chanId) {
|
||||
var channel = ctx.channels[chanId];
|
||||
if (!channel) { return; }
|
||||
var online = []; // Store online members to avoid duplicates
|
||||
|
||||
// Add ourselves
|
||||
var myData = createData(ctx.store.proxy, false);
|
||||
online.push(myData.curvePublic);
|
||||
|
||||
channel.wc.members.forEach(function (nId) {
|
||||
if (nId === ctx.store.network.historyKeeper) { return; }
|
||||
var data = channel.mapId[nId] || {};
|
||||
if (!data.curvePublic) { return; }
|
||||
if (online.indexOf(data.curvePublic) !== -1) { return; }
|
||||
online.push(data.curvePublic);
|
||||
});
|
||||
return online;
|
||||
};
|
||||
|
||||
// Display green status if one member is not me
|
||||
var getStatus = function (ctx, chanId, cb) {
|
||||
var channel = ctx.channels[chanId];
|
||||
if (!channel) { return void cb('NO_SUCH_CHANNEL'); }
|
||||
if (channel.onUserlistUpdate) {
|
||||
channel.onUserlistUpdate();
|
||||
}
|
||||
var proxy = ctx.store.proxy;
|
||||
var online = channel.wc.members.some(function (nId) {
|
||||
if (nId === ctx.store.network.historyKeeper) { return; }
|
||||
@@ -781,7 +804,7 @@ define([
|
||||
openChannel(ctx, chanData);
|
||||
};
|
||||
|
||||
var openTeamChat = function (ctx, clientId, data, _cb) {
|
||||
var openTeamChat = function (ctx, clientId, data, onUpdate, _cb) {
|
||||
var chatData = data;
|
||||
var chanId = chatData.channel;
|
||||
var secret = chatData.secret;
|
||||
@@ -820,6 +843,7 @@ define([
|
||||
return encryptor.decrypt(msg, vKey);
|
||||
},
|
||||
clients: [clientId],
|
||||
onUserlistUpdate: onUpdate,
|
||||
onReady: cb
|
||||
};
|
||||
openChannel(ctx, chanData);
|
||||
@@ -927,6 +951,10 @@ define([
|
||||
onFriendRemoved(ctx, curvePublic, chanId);
|
||||
};
|
||||
|
||||
messenger.getOnlineList = function (chanId) {
|
||||
return getOnlineList(ctx, chanId);
|
||||
};
|
||||
|
||||
messenger.storeValidateKey = function (chan, key) {
|
||||
ctx.validateKeys[chan] = key;
|
||||
};
|
||||
@@ -945,8 +973,8 @@ define([
|
||||
});
|
||||
};
|
||||
|
||||
messenger.openTeamChat = function (data, cId, cb) {
|
||||
openTeamChat(ctx, cId, data, cb);
|
||||
messenger.openTeamChat = function (data, onUpdate, cId, cb) {
|
||||
openTeamChat(ctx, cId, data, onUpdate, cb);
|
||||
};
|
||||
|
||||
messenger.removeClient = function (clientId) {
|
||||
@@ -964,9 +992,6 @@ define([
|
||||
if (cmd === 'GET_USERLIST') {
|
||||
return void getUserList(ctx, data, cb);
|
||||
}
|
||||
if (cmd === 'OPEN_TEAM_CHAT') {
|
||||
return void openTeamChat(ctx, clientId, data, cb);
|
||||
}
|
||||
if (cmd === 'OPEN_PAD_CHAT') {
|
||||
return void openPadChat(ctx, clientId, data, cb);
|
||||
}
|
||||
|
||||
@@ -544,7 +544,18 @@ define([
|
||||
if (!team) { return void cb ({error: 'ENOENT'}); }
|
||||
if (!team.roster) { return void cb({error: 'NO_ROSTER'}); }
|
||||
var state = team.roster.getState() || {};
|
||||
cb(state.members || {});
|
||||
var members = state.members || {};
|
||||
|
||||
// Add online status (using messenger data)
|
||||
var chatData = team.getChatData();
|
||||
var online = ctx.store.messenger.getOnlineList(chatData.channel) || [];
|
||||
online.forEach(function (curve) {
|
||||
if (members[curve]) {
|
||||
members[curve].online = true;
|
||||
}
|
||||
});
|
||||
|
||||
cb(members);
|
||||
};
|
||||
|
||||
var getTeamMetadata = function (ctx, data, cId, cb) {
|
||||
@@ -635,13 +646,12 @@ define([
|
||||
|
||||
var state = team.roster.getState();
|
||||
var userData = state.members[data.curvePublic];
|
||||
console.error(userData);
|
||||
team.roster.remove([data.curvePublic], function (err) {
|
||||
if (err) { return void cb({error: err}); }
|
||||
// The user has been removed, send them a notification
|
||||
if (!userData || !userData.notifications) { return cb(); }
|
||||
console.log('send notif');
|
||||
ctx.store.mailbox.sendTo('KICKED_FROM_TEAM', {
|
||||
pending: data.pending,
|
||||
user: Messaging.createData(ctx.store.proxy, false),
|
||||
teamChannel: getInviteData(ctx, teamId).channel,
|
||||
teamName: getInviteData(ctx, teamId).metadata.name
|
||||
@@ -711,7 +721,10 @@ define([
|
||||
var openTeamChat = function (ctx, data, cId, cb) {
|
||||
var team = ctx.teams[data.teamId];
|
||||
if (!team) { return void cb({error: 'ENOENT'}); }
|
||||
ctx.store.messenger.openTeamChat(team.getChatData(), cId, cb);
|
||||
var onUpdate = function () {
|
||||
ctx.emit('ROSTER_CHANGE', data.teamId, team.clients);
|
||||
};
|
||||
ctx.store.messenger.openTeamChat(team.getChatData(), onUpdate, cId, cb);
|
||||
};
|
||||
|
||||
Team.init = function (cfg, waitFor, emit) {
|
||||
@@ -776,6 +789,17 @@ define([
|
||||
});
|
||||
|
||||
};
|
||||
team.updateMyData = function (data) {
|
||||
Object.keys(ctx.teams).forEach(function (id) {
|
||||
var team = ctx.teams[id];
|
||||
if (!team.roster) { return; }
|
||||
var obj = {};
|
||||
obj[data.curvePublic] = data;
|
||||
team.roster.describe(obj, function (err) {
|
||||
if (err) { console.error(err); }
|
||||
});
|
||||
});
|
||||
};
|
||||
team.removeClient = function (clientId) {
|
||||
removeClient(ctx, clientId);
|
||||
};
|
||||
|
||||
@@ -80,6 +80,10 @@
|
||||
font-size: 25px;
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
&.empty {
|
||||
white-space: initial;
|
||||
text-align: center;
|
||||
}
|
||||
}
|
||||
.cp-team-list-open {
|
||||
width: 100%;
|
||||
@@ -104,6 +108,16 @@
|
||||
.cp-avatar {
|
||||
margin-right: 10px;
|
||||
}
|
||||
.cp-team-member-status {
|
||||
margin-left: 5px;
|
||||
width: 5px;
|
||||
height: 50px;
|
||||
display: inline-block;
|
||||
background-color: red;
|
||||
&.online {
|
||||
background-color: green;
|
||||
}
|
||||
}
|
||||
.cp-team-member-name {
|
||||
flex: 1;
|
||||
overflow: hidden;
|
||||
|
||||
@@ -281,7 +281,7 @@ define([
|
||||
for (var i = keys.length; i < MAX_TEAMS_SLOTS; i++) {
|
||||
obj[i] = {
|
||||
empty: true
|
||||
}
|
||||
};
|
||||
keys.push(i);
|
||||
}
|
||||
|
||||
@@ -290,8 +290,8 @@ define([
|
||||
keys.forEach(function (id) {
|
||||
var team = obj[id];
|
||||
if (team.empty) {
|
||||
list.push(h('div.cp-team-list-team', [
|
||||
h('span.cp-team-list-name', Messages.team_listSlot)
|
||||
list.push(h('div.cp-team-list-team.empty', [
|
||||
h('span.cp-team-list-name.empty', Messages.team_listSlot)
|
||||
]));
|
||||
return;
|
||||
}
|
||||
@@ -429,6 +429,8 @@ define([
|
||||
common.displayAvatar($(avatar), data.avatar, data.displayName);
|
||||
// Name
|
||||
var name = h('span.cp-team-member-name', data.displayName);
|
||||
// Status
|
||||
var status = h('span.cp-team-member-status'+(data.online ? '.online' : ''));
|
||||
// Actions
|
||||
var actions = h('span.cp-team-member-actions');
|
||||
var $actions = $(actions);
|
||||
@@ -436,7 +438,7 @@ define([
|
||||
var myRole = me ? (ROLES.indexOf(me.role) || 0) : -1;
|
||||
var theirRole = ROLES.indexOf(data.role) || 0;
|
||||
// If they're a member and I have a higher role than them, I can promote them to admin
|
||||
if (!isMe && myRole > theirRole && theirRole === 0) {
|
||||
if (!isMe && myRole > theirRole && theirRole === 0 && !data.pending) {
|
||||
var promote = h('span.fa.fa-angle-double-up', {
|
||||
title: Messages.team_rosterPromote
|
||||
});
|
||||
@@ -449,7 +451,7 @@ define([
|
||||
}
|
||||
// If I'm not a member and I have an equal or higher role than them, I can demote them
|
||||
// (if they're not already a MEMBER)
|
||||
if (!isMe && myRole >= theirRole && theirRole > 0) {
|
||||
if (!isMe && myRole >= theirRole && theirRole > 0 && !data.pending) {
|
||||
var demote = h('span.fa.fa-angle-double-down', {
|
||||
title: Messages.team_rosterDemote
|
||||
});
|
||||
@@ -468,6 +470,7 @@ define([
|
||||
$(remove).click(function () {
|
||||
$(remove).hide();
|
||||
APP.module.execCommand('REMOVE_USER', {
|
||||
pending: data.pending,
|
||||
teamId: APP.team,
|
||||
curvePublic: data.curvePublic,
|
||||
}, function (obj) {
|
||||
@@ -485,7 +488,8 @@ define([
|
||||
var content = [
|
||||
avatar,
|
||||
name,
|
||||
actions
|
||||
actions,
|
||||
status,
|
||||
];
|
||||
var div = h('div.cp-team-roster-member', {
|
||||
title: data.displayName
|
||||
@@ -522,6 +526,12 @@ define([
|
||||
}).map(function (k) {
|
||||
return makeMember(common, roster[k], me);
|
||||
});
|
||||
var pending = Object.keys(roster).filter(function (k) {
|
||||
if (!roster[k].pending) { return; }
|
||||
return roster[k].role === "MEMBER" || !roster[k].role;
|
||||
}).map(function (k) {
|
||||
return makeMember(common, roster[k], me);
|
||||
});
|
||||
|
||||
var header = h('div.cp-app-team-roster-header');
|
||||
var $header = $(header);
|
||||
@@ -574,7 +584,9 @@ define([
|
||||
h('h3', Messages.team_admins),
|
||||
h('div', admins),
|
||||
h('h3', Messages.team_members),
|
||||
h('div', members)
|
||||
h('div', members),
|
||||
h('h3', Messages.team_pending || 'PENDING'), // XXX
|
||||
h('div', pending)
|
||||
];
|
||||
};
|
||||
makeBlock('roster', function (common, cb) {
|
||||
|
||||
Reference in New Issue
Block a user