From d6a6e59d6c509cb34de2f72eb63f790fe1c12d01 Mon Sep 17 00:00:00 2001 From: Luke Barnard Date: Mon, 6 Nov 2017 16:37:16 +0000 Subject: [PATCH] Indicate admins in the group member list with a sheriff badge --- .../views/groups/GroupMemberTile.js | 6 ++--- src/components/views/rooms/EntityTile.js | 27 ++++++++++++------- src/components/views/rooms/MemberTile.js | 8 +++++- src/groups.js | 1 + 4 files changed, 29 insertions(+), 13 deletions(-) diff --git a/src/components/views/groups/GroupMemberTile.js b/src/components/views/groups/GroupMemberTile.js index f40c7ed1c5..84c2adcb41 100644 --- a/src/components/views/groups/GroupMemberTile.js +++ b/src/components/views/groups/GroupMemberTile.js @@ -61,9 +61,9 @@ export default withMatrixClient(React.createClass({ ); return ( - ); }, diff --git a/src/components/views/rooms/EntityTile.js b/src/components/views/rooms/EntityTile.js index 1df19340cd..ffcb289437 100644 --- a/src/components/views/rooms/EntityTile.js +++ b/src/components/views/rooms/EntityTile.js @@ -47,7 +47,7 @@ function presenceClassForMember(presenceState, lastActiveAgo) { } } -module.exports = React.createClass({ +const EntityTile = React.createClass({ displayName: 'EntityTile', propTypes: { @@ -140,16 +140,19 @@ module.exports = React.createClass({ } let power; - const powerLevel = this.props.powerLevel; - if (powerLevel >= 50 && powerLevel < 99) { - power = {_t("Moderator")}; - } - if (powerLevel >= 99) { - power = {_t("Admin")}; + const powerStatus = this.props.powerStatus; + if (powerStatus) { + const src = { + [EntityTile.POWER_STATUS_MODERATOR]: "img/mod.svg", + [EntityTile.POWER_STATUS_ADMIN]: "img/admin.svg", + }[powerStatus]; + const alt = { + [EntityTile.POWER_STATUS_MODERATOR]: _t("Moderator"), + [EntityTile.POWER_STATUS_ADMIN]: _t("Admin"), + }[powerStatus]; + power = {alt}; } - - const MemberAvatar = sdk.getComponent('avatars.MemberAvatar'); const BaseAvatar = sdk.getComponent('avatars.BaseAvatar'); const av = this.props.avatarJsx || ; @@ -168,3 +171,9 @@ module.exports = React.createClass({ ); }, }); + +EntityTile.POWER_STATUS_MODERATOR = "moderator"; +EntityTile.POWER_STATUS_ADMIN = "admin"; + + +export default EntityTile; diff --git a/src/components/views/rooms/MemberTile.js b/src/components/views/rooms/MemberTile.js index e21f7c91f4..4848c4b258 100644 --- a/src/components/views/rooms/MemberTile.js +++ b/src/components/views/rooms/MemberTile.js @@ -86,13 +86,19 @@ module.exports = React.createClass({ } this.member_last_modified_time = member.getLastModifiedTime(); + // We deliberately leave power levels that are not 100 or 50 undefined + const powerStatus = { + 100: EntityTile.POWER_STATUS_ADMIN, + 50: EntityTile.POWER_STATUS_MODERATOR, + }[this.props.member.powerLevel]; + return ( + name={name} powerStatus={powerStatus} /> ); }, }); diff --git a/src/groups.js b/src/groups.js index 6c266e0fb6..957db1d85b 100644 --- a/src/groups.js +++ b/src/groups.js @@ -36,6 +36,7 @@ export function groupMemberFromApiObject(apiObject) { userId: apiObject.user_id, displayname: apiObject.displayname, avatarUrl: apiObject.avatar_url, + isAdmin: apiObject.is_admin, }; }