]> git.localhorst.tv Git - alttp.git/blobdiff - resources/js/helpers/User.js
log who sent manual random chats
[alttp.git] / resources / js / helpers / User.js
index b94b777091601790abdaf2440027206b8f5c7ea4..b00c853542d6eb739ec6fec3cec8f0771473ae49 100644 (file)
@@ -1,3 +1,18 @@
+export const getUserName = user => (user &&
+       (user.nickname || user.discord_nickname || user.username)) || '';
+
+export const compareUsername = (a, b) => {
+       const a_name = getUserName(a);
+       const b_name = getUserName(b);
+       return a_name.localeCompare(b_name);
+};
+
+export const findResult = (user, round) => {
+       if (!user || !user.id) return null;
+       if (!round || !round.results || !round.results.length) return null;
+       return round.results.find(result => result.user_id == user.id);
+};
+
 export const compareFinished = round => (a, b) => {
        const a_result = findResult(a, round);
        const b_result = findResult(b, round);
@@ -34,24 +49,16 @@ export const compareResult = round => (a, b) => {
        return compareUsername(a, b);
 };
 
-export const compareUsername = (a, b) => {
-       const a_name = getUserName(a);
-       const b_name = getUserName(b);
-       return a_name.localeCompare(b_name);
-};
-
-export const findResult = (user, round) => {
-       if (!user || !user.id) return null;
-       if (!round || !round.results || !round.results.length) return null;
-       return round.results.find(result => result.user_id == user.id);
+export const getAvatarUrl = user => {
+       if (user && user.avatar) {
+               if (user.avatar_cached) {
+                       return `/media/avatar/${user.id}/${user.avatar}.png`;
+               }
+               return `//cdn.discordapp.com/avatars/${user.id}/${user.avatar}.png`;
+       }
+       return '/default-avatar.png';
 };
 
-export const getAvatarUrl = user => user && user.avatar
-       ? `//cdn.discordapp.com/avatars/${user.id}/${user.avatar}.png`
-       : '/default-avatar.png';
-
-export const getUserName = user => (user && (user.nickname || user.username)) || '';
-
 export const hasFinishedRound = (user, round) => {
        const result = findResult(user, round);
        return result && result.has_finished;