fix(moderation): neutral phrasing for paginated member events without prev_content
Fixes #82 Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01PPmy3tPq869XDW4njjVaKA
This commit is contained in:
@@ -63,8 +63,26 @@ function describeEvent(mx: ReturnType<typeof useMatrixClient>, ev: MatrixEvent):
|
||||
const prevMembership = prevContent.membership as string | undefined;
|
||||
const reason = content.reason as string | undefined;
|
||||
const targetName = getDisplayName(mx, stateKey);
|
||||
// getPrevContent() falls back to {} when unsigned.prev_content is missing,
|
||||
// which is common for state events fetched via back-pagination (homeservers
|
||||
// don't always include it in /messages). That makes prevMembership
|
||||
// indistinguishable from "no prior membership" (fresh join). Check the raw
|
||||
// unsigned field so we only apply the join/leave-transition assumptions
|
||||
// below to events where the SDK actually gave us prior state.
|
||||
const hasPrevContent = ev.getUnsigned().prev_content !== undefined;
|
||||
|
||||
if (membership === 'join') {
|
||||
if (!hasPrevContent) {
|
||||
return {
|
||||
text: (
|
||||
<>
|
||||
<strong>{targetName}</strong>'s membership changed to <strong>joined</strong>
|
||||
</>
|
||||
),
|
||||
iconSrc: Icons.User,
|
||||
filter: 'members',
|
||||
};
|
||||
}
|
||||
if (
|
||||
prevMembership === 'invite' ||
|
||||
prevMembership === 'knock' ||
|
||||
@@ -94,6 +112,17 @@ function describeEvent(mx: ReturnType<typeof useMatrixClient>, ev: MatrixEvent):
|
||||
}
|
||||
|
||||
if (membership === 'leave') {
|
||||
if (!hasPrevContent) {
|
||||
return {
|
||||
text: (
|
||||
<>
|
||||
<strong>{targetName}</strong>'s membership changed to <strong>left</strong>
|
||||
</>
|
||||
),
|
||||
iconSrc: Icons.User,
|
||||
filter: 'members',
|
||||
};
|
||||
}
|
||||
if (prevMembership === 'ban') {
|
||||
return {
|
||||
text: (
|
||||
|
||||
Reference in New Issue
Block a user