( msg: MessageWithAuthorServerSettings, serverWithFlags: Pick<ServerWithFlags, 'flags'>, )
| 81 | const seedLookup = new Map(messages.map((a) => [a.authorId, getRandomId()])); |
| 82 | |
| 83 | const makeMessageWithAuthor = ( |
| 84 | msg: MessageWithAuthorServerSettings, |
| 85 | serverWithFlags: Pick<ServerWithFlags, 'flags'>, |
| 86 | ) => { |
| 87 | if (!msg.author || !msg.author.userServerSettings) { |
| 88 | return null; |
| 89 | } |
| 90 | const author = msg.author; |
| 91 | const seed = seedLookup.get(author.id) ?? getRandomId(); |
| 92 | const authorServerSettings = authorServerSettingsLookup.get( |
| 93 | getLookupKey({ |
| 94 | serverId: msg.serverId, |
| 95 | userId: author.id, |
| 96 | }), |
| 97 | ); |
| 98 | |
| 99 | const areAllServerMessagesPublic = |
| 100 | serverWithFlags.flags.considerAllMessagesPublic; |
| 101 | const hasUserGrantedConsent = |
| 102 | authorServerSettings?.flags.canPubliclyDisplayMessages ?? false; |
| 103 | const isMessagePublic = areAllServerMessagesPublic || hasUserGrantedConsent; |
| 104 | const publicAccount = zDiscordAccountPublic.parse(author); |
| 105 | const isAnonymous = |
| 106 | serverWithFlags.flags.anonymizeMessages && |
| 107 | !authorServerSettings?.flags.canPubliclyDisplayMessages; |
| 108 | return { |
| 109 | ...pick( |
| 110 | msg, |
| 111 | 'content', |
| 112 | 'id', |
| 113 | 'channelId', |
| 114 | 'serverId', |
| 115 | 'attachments', |
| 116 | 'parentChannelId', |
| 117 | 'embeds', |
| 118 | 'channelId', |
| 119 | 'childThreadId', |
| 120 | 'attachments', |
| 121 | 'embeds', |
| 122 | 'parentChannelId', |
| 123 | 'questionId', |
| 124 | ), |
| 125 | author: isAnonymous |
| 126 | ? anonymizeDiscordAccount(publicAccount, seed) |
| 127 | : publicAccount, |
| 128 | isAnonymous, |
| 129 | public: isMessagePublic, |
| 130 | }; |
| 131 | }; |
| 132 | |
| 133 | return messages |
| 134 | .map((msg) => { |
no test coverage detected