consider membership change with reason change (#1441)
This commit is contained in:
parent
bffd27ae5b
commit
60b5b5d312
4 changed files with 10 additions and 4 deletions
|
@ -3,6 +3,7 @@ import { IconSrc, Icons } from 'folds';
|
||||||
import { MatrixEvent } from 'matrix-js-sdk';
|
import { MatrixEvent } from 'matrix-js-sdk';
|
||||||
import { IMemberContent, Membership } from '../../types/matrix/room';
|
import { IMemberContent, Membership } from '../../types/matrix/room';
|
||||||
import { getMxIdLocalPart } from '../utils/matrix';
|
import { getMxIdLocalPart } from '../utils/matrix';
|
||||||
|
import { isMembershipChanged } from '../utils/room';
|
||||||
|
|
||||||
export type ParsedResult = {
|
export type ParsedResult = {
|
||||||
icon: IconSrc;
|
icon: IconSrc;
|
||||||
|
@ -27,7 +28,7 @@ export const useMemberEventParser = (): MemberEventParser => {
|
||||||
const senderName = getMxIdLocalPart(senderId);
|
const senderName = getMxIdLocalPart(senderId);
|
||||||
const userName = content.displayname || getMxIdLocalPart(userId);
|
const userName = content.displayname || getMxIdLocalPart(userId);
|
||||||
|
|
||||||
if (content.membership !== prevContent.membership) {
|
if (isMembershipChanged(mEvent)) {
|
||||||
if (content.membership === Membership.Invite) {
|
if (content.membership === Membership.Invite) {
|
||||||
if (prevContent.membership === Membership.Knock) {
|
if (prevContent.membership === Membership.Knock) {
|
||||||
return {
|
return {
|
||||||
|
|
|
@ -4,6 +4,7 @@ import { useEffect, useState } from 'react';
|
||||||
import { settingsAtom } from '../state/settings';
|
import { settingsAtom } from '../state/settings';
|
||||||
import { useSetting } from '../state/hooks/settings';
|
import { useSetting } from '../state/hooks/settings';
|
||||||
import { MessageEvent, StateEvent } from '../../types/matrix/room';
|
import { MessageEvent, StateEvent } from '../../types/matrix/room';
|
||||||
|
import { isMembershipChanged } from '../utils/room';
|
||||||
|
|
||||||
export const useRoomLatestRenderedEvent = (room: Room) => {
|
export const useRoomLatestRenderedEvent = (room: Room) => {
|
||||||
const [hideMembershipEvents] = useSetting(settingsAtom, 'hideMembershipEvents');
|
const [hideMembershipEvents] = useSetting(settingsAtom, 'hideMembershipEvents');
|
||||||
|
@ -20,7 +21,7 @@ export const useRoomLatestRenderedEvent = (room: Room) => {
|
||||||
if (!evt) continue;
|
if (!evt) continue;
|
||||||
if (evt.isRelation()) continue;
|
if (evt.isRelation()) continue;
|
||||||
if (evt.getType() === StateEvent.RoomMember) {
|
if (evt.getType() === StateEvent.RoomMember) {
|
||||||
const membershipChanged = evt.getContent().membership !== evt.getPrevContent().membership;
|
const membershipChanged = isMembershipChanged(evt);
|
||||||
if (membershipChanged && hideMembershipEvents) continue;
|
if (membershipChanged && hideMembershipEvents) continue;
|
||||||
if (!membershipChanged && hideNickAvatarEvents) continue;
|
if (!membershipChanged && hideNickAvatarEvents) continue;
|
||||||
return evt;
|
return evt;
|
||||||
|
|
|
@ -83,6 +83,7 @@ import {
|
||||||
decryptAllTimelineEvent,
|
decryptAllTimelineEvent,
|
||||||
getMemberDisplayName,
|
getMemberDisplayName,
|
||||||
getReactionContent,
|
getReactionContent,
|
||||||
|
isMembershipChanged,
|
||||||
} from '../../utils/room';
|
} from '../../utils/room';
|
||||||
import { useSetting } from '../../state/hooks/settings';
|
import { useSetting } from '../../state/hooks/settings';
|
||||||
import { settingsAtom } from '../../state/settings';
|
import { settingsAtom } from '../../state/settings';
|
||||||
|
@ -1311,8 +1312,7 @@ export function RoomTimeline({ room, eventId, roomInputRef, editor }: RoomTimeli
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
renderRoomMember: (mEventId, mEvent, item) => {
|
renderRoomMember: (mEventId, mEvent, item) => {
|
||||||
const membershipChanged =
|
const membershipChanged = isMembershipChanged(mEvent);
|
||||||
mEvent.getContent().membership !== mEvent.getPrevContent().membership;
|
|
||||||
if (membershipChanged && hideMembershipEvents) return null;
|
if (membershipChanged && hideMembershipEvents) return null;
|
||||||
if (!membershipChanged && hideNickAvatarEvents) return null;
|
if (!membershipChanged && hideNickAvatarEvents) return null;
|
||||||
|
|
||||||
|
|
|
@ -278,6 +278,10 @@ export const getMemberAvatarMxc = (room: Room, userId: string): string | undefin
|
||||||
return member?.getMxcAvatarUrl();
|
return member?.getMxcAvatarUrl();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const isMembershipChanged = (mEvent: MatrixEvent): boolean =>
|
||||||
|
mEvent.getContent().membership !== mEvent.getPrevContent().membership ||
|
||||||
|
mEvent.getContent().reason !== mEvent.getPrevContent().reason;
|
||||||
|
|
||||||
export const decryptAllTimelineEvent = async (mx: MatrixClient, timeline: EventTimeline) => {
|
export const decryptAllTimelineEvent = async (mx: MatrixClient, timeline: EventTimeline) => {
|
||||||
const crypto = mx.getCrypto();
|
const crypto = mx.getCrypto();
|
||||||
if (!crypto) return;
|
if (!crypto) return;
|
||||||
|
|
Loading…
Reference in a new issue