Compare commits
3 commits
db2c038f40
...
b3ef973568
| Author | SHA1 | Date | |
|---|---|---|---|
| b3ef973568 | |||
| 7229206d09 | |||
| b7fa7c3e2d |
4 changed files with 15 additions and 3 deletions
|
|
@ -103,6 +103,7 @@ async function memberToStateContent(pkMessage, author) {
|
|||
// We prefer to use the member's avatar URL data since the image upload can be cached across channels,
|
||||
// unlike the userAvatar URL which is unique per channel, due to the webhook ID being in the URL.
|
||||
const avatar = pkMessage.member.avatar_url || pkMessage.member.webhook_avatar_url || pkMessage.system.avatar_url || file.userAvatar(author)
|
||||
const color = pkMessage.member.color ?? pkMessage.system.color
|
||||
|
||||
const content = {
|
||||
displayname: author.username,
|
||||
|
|
@ -110,6 +111,12 @@ async function memberToStateContent(pkMessage, author) {
|
|||
"moe.cadence.ooye.pk_member": pkMessage.member
|
||||
}
|
||||
if (avatar) content.avatar_url = await file.uploadDiscordFileToMxc(avatar)
|
||||
if (color) {
|
||||
content["eu.she-a.color"] = {
|
||||
on_dark: `#${color}`,
|
||||
on_light: `#${color}`
|
||||
}
|
||||
}
|
||||
|
||||
return content
|
||||
}
|
||||
|
|
|
|||
|
|
@ -194,7 +194,9 @@ function memberToPowerLevel(user, member, guild, channel) {
|
|||
* @param {number} powerLevel
|
||||
*/
|
||||
function _hashProfileContent(content, powerLevel) {
|
||||
const unsignedHash = hasher.h64(`${content.displayname}\u0000${content.avatar_url}\u0000${powerLevel}`)
|
||||
let toHash = `${content.displayname}\u0000${content.avatar_url}\u0000${powerLevel}`
|
||||
if (content["eu.she-a.color"]?.on_dark) toHash += `\u0000${content["eu.she-a.color"].on_dark}`
|
||||
const unsignedHash = hasher.h64(toHash)
|
||||
const signedHash = unsignedHash - 0x8000000000000000n // shifting down to signed 64-bit range
|
||||
return signedHash
|
||||
}
|
||||
|
|
@ -243,6 +245,7 @@ async function syncUser(user, member, channel, guild, roomID, interactionMetadat
|
|||
async function _sendSyncUser(roomID, mxid, content, powerLevel, options) {
|
||||
const currentHash = _hashProfileContent(content, powerLevel ?? 0)
|
||||
const existingHash = select("sim_member", "hashed_profile_content", {room_id: roomID, mxid}).safeIntegers().pluck().get()
|
||||
console.log(roomID, mxid, existingHash, currentHash)
|
||||
// only do the actual sync if the hash has changed since we last looked
|
||||
const hashHasChanged = existingHash !== currentHash
|
||||
// always okay to add new data. for overwriting, restrict based on options.allowOverwrite, if present
|
||||
|
|
|
|||
|
|
@ -641,8 +641,7 @@ async function messageToEvent(message, guild, options = {}, di) {
|
|||
html = "* " + html
|
||||
}
|
||||
|
||||
const flags = message.flags || 0
|
||||
if (flags & DiscordTypes.MessageFlags.IsCrosspost) {
|
||||
if (((message.flags || 0) & DiscordTypes.MessageFlags.IsCrosspost) && message.author?.username) {
|
||||
body = `[↷ ${message.author.username}]\n` + body
|
||||
html = `↷ <strong>${message.author.username}</strong><br>` + html
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,6 +16,9 @@ block body
|
|||
|
||||
- let value = !select("opt_out", "user_id", {user_id: session.data.userID}).pluck().get()
|
||||
|
||||
noscript
|
||||
.s-notice.s-notice__danger.mb16 You must enable JavaScript to use this form. Please do that now!
|
||||
|
||||
#opt-in-msg(hx-swap-oob="true")
|
||||
if msg
|
||||
.s-notice.s-notice__info.mb16= msg
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue