diff --git a/d2m/actions/register-user.test.js b/d2m/actions/register-user.test.js index 34470ba8..74818eaa 100644 --- a/d2m/actions/register-user.test.js +++ b/d2m/actions/register-user.test.js @@ -3,7 +3,27 @@ const {_memberToStateContent} = require("./register-user") const {test} = require("supertape") const testData = require("../../test/data") -test("member2state: general", async t => { +test("member2state: without member nick or avatar", async t => { + t.deepEqual( + await _memberToStateContent(testData.member.kumaccino.user, testData.member.kumaccino, testData.guild.general.id), + { + avatar_url: "mxc://cadence.moe/UpAeIqeclhKfeiZNdIWNcXXL", + displayname: "kumaccino", + membership: "join", + "moe.cadence.ooye.member": { + avatar: "/avatars/113340068197859328/b48302623a12bc7c59a71328f72ccb39.png?size=1024" + }, + "uk.half-shot.discord.member": { + bot: false, + displayColor: 10206929, + id: "113340068197859328", + username: "@kumaccino" + } + } + ) +}) + +test("member2state: with member nick and avatar", async t => { t.deepEqual( await _memberToStateContent(testData.member.sheep.user, testData.member.sheep, testData.guild.general.id), { diff --git a/db/data-for-test.sql b/db/data-for-test.sql index ec9f9ec2..e88b967b 100644 --- a/db/data-for-test.sql +++ b/db/data-for-test.sql @@ -93,6 +93,7 @@ INSERT INTO file (discord_url, mxc_url) VALUES ('https://cdn.discordapp.com/attachments/112760669178241024/1141501302497615912/piper_2.png', 'mxc://cadence.moe/KQYdXKRcHWjDYDLPkTOOWOjA'), ('https://cdn.discordapp.com/attachments/112760669178241024/1128084851023675515/RDT_20230704_0936184915846675925224905.jpg', 'mxc://cadence.moe/WlAbFSiNRIHPDEwKdyPeGywa'), ('https://cdn.discordapp.com/guilds/112760669178241024/users/134826546694193153/avatars/38dd359aa12bcd52dd3164126c587f8c.png?size=1024', 'mxc://cadence.moe/rfemHmAtcprjLEiPiEuzPhpl'), -('https://cdn.discordapp.com/icons/112760669178241024/a_f83622e09ead74f0c5c527fe241f8f8c.png?size=1024', 'mxc://cadence.moe/zKXGZhmImMHuGQZWJEFKJbsF'); +('https://cdn.discordapp.com/icons/112760669178241024/a_f83622e09ead74f0c5c527fe241f8f8c.png?size=1024', 'mxc://cadence.moe/zKXGZhmImMHuGQZWJEFKJbsF'), +('https://cdn.discordapp.com/avatars/113340068197859328/b48302623a12bc7c59a71328f72ccb39.png?size=1024', 'mxc://cadence.moe/UpAeIqeclhKfeiZNdIWNcXXL'); COMMIT; diff --git a/matrix/file.js b/matrix/file.js index 965ec1ce..7d74d5da 100644 --- a/matrix/file.js +++ b/matrix/file.js @@ -27,15 +27,15 @@ async function uploadDiscordFileToMxc(path) { } // Are we uploading this file RIGHT NOW? Return the same inflight promise with the same resolution - let existing = inflight.get(url) - if (typeof existing === "string") { - return existing + const existingInflight = inflight.get(url) + if (existingInflight) { + return existingInflight } // Has this file already been uploaded in the past? Grab the existing copy from the database. - existing = db.prepare("SELECT mxc_url FROM file WHERE discord_url = ?").pluck().get(url) - if (typeof existing === "string") { - return existing + const existingFromDb = db.prepare("SELECT mxc_url FROM file WHERE discord_url = ?").pluck().get(url) + if (typeof existingFromDb === "string") { + return existingFromDb } // Download from Discord diff --git a/stdin.js b/stdin.js index ce612f58..a687c6c4 100644 --- a/stdin.js +++ b/stdin.js @@ -12,6 +12,7 @@ const createRoom = sync.require("./d2m/actions/create-room") const registerUser = sync.require("./d2m/actions/register-user") const mreq = sync.require("./matrix/mreq") const api = sync.require("./matrix/api") +const file = sync.require("./matrix/file") const sendEvent = sync.require("./m2d/actions/send-event") const eventDispatcher = sync.require("./d2m/event-dispatcher") const ks = sync.require("./matrix/kstate") diff --git a/test/data.js b/test/data.js index 6ed2f42f..a4d836db 100644 --- a/test/data.js +++ b/test/data.js @@ -98,6 +98,46 @@ module.exports = { } }, member: { + kumaccino: { + avatar: null, + communication_disabled_until: null, + flags: 0, + joined_at: "2015-11-11T09:55:40.321000+00:00", + nick: null, + pending: false, + premium_since: null, + roles: [ + "112767366235959296", "118924814567211009", + "199995902742626304", "204427286542417920", + "222168467627835392", "238028326281805825", + "259806643414499328", "265239342648131584", + "271173313575780353", "287733611912757249", + "225744901915148298", "305775031223320577", + "318243902521868288", "348651574924541953", + "349185088157777920", "378402925128712193", + "392141548932038658", "393912152173576203", + "482860581670486028", "495384759074160642", + "638988388740890635", "373336013109461013", + "530220455085473813", "454567553738473472", + "790724320824655873", "1040735082610167858", + "695946570482450442", "849737964090556488" + ], + user: { + id: "113340068197859328", + username: "kumaccino", + avatar: "b48302623a12bc7c59a71328f72ccb39", + discriminator: "0", + public_flags: 128, + flags: 128, + banner: null, + accent_color: 10206929, + global_name: "kumaccino", + avatar_decoration_data: null, + banner_color: "#9bbed1" + }, + mute: false, + deaf: false + }, sheep: { avatar: "38dd359aa12bcd52dd3164126c587f8c", communication_disabled_until: null,