Fix avatar colors and text capitalization

This commit is contained in:
Oswaldo Acauan 2017-08-03 09:36:26 -03:00
parent 14f586faad
commit b53636ec19
5 changed files with 23 additions and 18 deletions

View File

@ -1,25 +1,10 @@
import stringHash from 'string-hash';
import { check } from 'meteor/check'; import { check } from 'meteor/check';
import addUser from '../modifiers/addUser'; import addUser from '../modifiers/addUser';
const COLOR_LIST = [
'#d32f2f', '#c62828', '#b71c1c', '#d81b60', '#c2185b', '#ad1457', '#880e4f',
'#8e24aa', '#7b1fa2', '#6a1b9a', '#4a148c', '#5e35b1', '#512da8', '#4527a0',
'#311b92', '#3949ab', '#303f9f', '#283593', '#1a237e', '#1976d2', '#1565c0',
'#0d47a1', '#0277bd', '#01579b', '#00838f', '#006064', '#00796b', '#00695c',
'#004d40', '#2e7d32', '#1b5e20', '#33691e', '#827717', '#bf360c', '#6d4c41',
'#5d4037', '#4e342e', '#3e2723', '#757575', '#616161', '#424242', '#212121',
'#546e7a', '#455a64', '#37474f', '#263238',
];
export default function handleUserJoined({ body }, meetingId) { export default function handleUserJoined({ body }, meetingId) {
const user = body; const user = body;
check(user, Object); check(user, Object);
/* While the akka-apps dont generate a color we just pick one return addUser(meetingId, user);
from a list based on the userId */
const color = COLOR_LIST[stringHash(user.intId) % COLOR_LIST.length];
return addUser(meetingId, Object.assign(user, { color }));
} }

View File

@ -1,9 +1,22 @@
import { check } from 'meteor/check'; import { check } from 'meteor/check';
import Logger from '/imports/startup/server/logger'; import Logger from '/imports/startup/server/logger';
import Users from '/imports/api/2.0/users'; import Users from '/imports/api/2.0/users';
import stringHash from 'string-hash';
import flat from 'flat'; import flat from 'flat';
import addVoiceUser from '/imports/api/2.0/voice-users/server/modifiers/addVoiceUser'; import addVoiceUser from '/imports/api/2.0/voice-users/server/modifiers/addVoiceUser';
const COLOR_LIST = [
'#d32f2f', '#c62828', '#b71c1c', '#d81b60', '#c2185b', '#ad1457', '#880e4f',
'#8e24aa', '#7b1fa2', '#6a1b9a', '#4a148c', '#5e35b1', '#512da8', '#4527a0',
'#311b92', '#3949ab', '#303f9f', '#283593', '#1a237e', '#1976d2', '#1565c0',
'#0d47a1', '#0277bd', '#01579b', '#00838f', '#006064', '#00796b', '#00695c',
'#004d40', '#2e7d32', '#1b5e20', '#33691e', '#827717', '#bf360c', '#6d4c41',
'#5d4037', '#4e342e', '#3e2723', '#757575', '#616161', '#424242', '#212121',
'#546e7a', '#455a64', '#37474f', '#263238',
];
export default function addUser(meetingId, user) { export default function addUser(meetingId, user) {
check(meetingId, String); check(meetingId, String);
@ -54,6 +67,10 @@ export default function addUser(meetingId, user) {
userRole === ROLE_MODERATOR ? 'moderator' : false, userRole === ROLE_MODERATOR ? 'moderator' : false,
].filter(Boolean); ].filter(Boolean);
/* While the akka-apps dont generate a color we just pick one
from a list based on the userId */
const color = COLOR_LIST[stringHash(user.intId) % COLOR_LIST.length];
const modifier = { const modifier = {
$set: Object.assign( $set: Object.assign(
{ {
@ -61,6 +78,7 @@ export default function addUser(meetingId, user) {
connectionStatus: 'online', connectionStatus: 'online',
roles: userRoles, roles: userRoles,
sortName: user.name.trim().toLowerCase(), sortName: user.name.trim().toLowerCase(),
color,
}, },
flat(user), flat(user),
), ),

View File

@ -135,7 +135,7 @@ export default class MessageListItem extends Component {
color={user.color} color={user.color}
moderator={user.isModerator} moderator={user.isModerator}
> >
{user.name.slice(0, 2)} {user.name.toLowerCase().slice(0, 2)}
</UserAvatar> </UserAvatar>
</div> </div>
<div className={styles.content}> <div className={styles.content}>

View File

@ -364,7 +364,7 @@ class UserListItem extends Component {
> >
{user.emoji.status !== 'none' ? {user.emoji.status !== 'none' ?
<Icon iconName={normalizeEmojiName(user.emoji.status)} /> : <Icon iconName={normalizeEmojiName(user.emoji.status)} /> :
user.name.slice(0, 2)} user.name.toLowerCase().slice(0, 2)}
</UserAvatar> </UserAvatar>
</div> </div>
{this.renderUserName()} {this.renderUserName()}

View File

@ -12,6 +12,8 @@ const mapUser = (user) => {
const mappedUser = { const mappedUser = {
id: user.userId, id: user.userId,
name: user.name, name: user.name,
color: user.color,
avatar: user.avatar,
emoji: { emoji: {
status: user.emoji, status: user.emoji,
changedAt: user.emojiTime, changedAt: user.emojiTime,