fix: three code review issues — leaveGroup duplicate, as any casts, federation ownership fallback
- Remove redundant `leaveGroup` API method from client.ts (duplicated `leave`); update MessageList.tsx WelcomeHeader to call `api.dm.leave` directly - Add optional `type` field to shared `Message` interface so `MessageWithUser` carries it; remove `(msg as any).type` casts in `isSameGroup` and the render branch in MessageList.tsx - Fix `processOwnershipTransferEvent` in federation.ts: replace `channel.ownerId` fallbacks (pre-update, old owner) with `event.ownership.newOwner.homeUserId` in the db update, dm_owner_updated broadcast, and both system message content payloads
This commit is contained in:
@@ -1965,7 +1965,7 @@ function processOwnershipTransferEvent(
|
||||
|
||||
db.update(schema.dmChannels)
|
||||
.set({
|
||||
ownerId: newOwnerLocal?.id ?? channel.ownerId,
|
||||
ownerId: newOwnerLocal?.id ?? null,
|
||||
ownerHomeUserId: event.ownership.newOwner.homeUserId,
|
||||
ownerHomeInstance: event.ownership.newOwner.homeInstance,
|
||||
})
|
||||
@@ -1975,7 +1975,7 @@ function processOwnershipTransferEvent(
|
||||
connectionManager.sendToDmMembers(channel.id, {
|
||||
type: 'dm_owner_updated',
|
||||
dmChannelId: channel.id,
|
||||
newOwnerId: newOwnerLocal?.id ?? channel.ownerId!,
|
||||
newOwnerId: newOwnerLocal?.id ?? event.ownership.newOwner.homeUserId,
|
||||
});
|
||||
|
||||
const prevOwnerLocal = event.ownership.previousOwner
|
||||
@@ -1991,7 +1991,7 @@ function processOwnershipTransferEvent(
|
||||
userId: prevOwnerId,
|
||||
content: JSON.stringify({
|
||||
event: 'owner_changed',
|
||||
newOwnerId: newOwnerLocal?.id ?? channel.ownerId,
|
||||
newOwnerId: newOwnerLocal?.id ?? event.ownership.newOwner.homeUserId,
|
||||
newOwnerDisplayName: newOwnerLocal?.displayName ?? newOwnerBaseName,
|
||||
}),
|
||||
type: 'system',
|
||||
@@ -2006,7 +2006,7 @@ function processOwnershipTransferEvent(
|
||||
userId: prevOwnerId,
|
||||
content: JSON.stringify({
|
||||
event: 'owner_changed',
|
||||
newOwnerId: newOwnerLocal?.id ?? channel.ownerId,
|
||||
newOwnerId: newOwnerLocal?.id ?? event.ownership.newOwner.homeUserId,
|
||||
newOwnerDisplayName: newOwnerLocal?.displayName ?? newOwnerBaseName,
|
||||
}),
|
||||
type: 'system',
|
||||
|
||||
@@ -193,6 +193,7 @@ export interface Message {
|
||||
userId: string;
|
||||
replyToId: string | null;
|
||||
content: string | null;
|
||||
type?: 'user' | 'system';
|
||||
editedAt: number | null;
|
||||
createdAt: number;
|
||||
}
|
||||
|
||||
@@ -145,7 +145,6 @@ export class BackspaceApiClient {
|
||||
deleteMessage: (id: string) => Promise<{ success: boolean }>;
|
||||
addMember: (dmChannelId: string, data: { userId: string }) => Promise<DmChannel>;
|
||||
leave: (dmChannelId: string) => Promise<{ success: boolean }>;
|
||||
leaveGroup: (dmChannelId: string) => Promise<{ success: boolean }>;
|
||||
};
|
||||
|
||||
readonly social: {
|
||||
@@ -506,8 +505,6 @@ export class BackspaceApiClient {
|
||||
request<DmChannel>('POST', `/dm/${dmChannelId}/members`, data),
|
||||
leave: (dmChannelId: string) =>
|
||||
request<{ success: boolean }>('DELETE', `/dm/${dmChannelId}/members`),
|
||||
leaveGroup: (dmChannelId: string) =>
|
||||
request<{ success: boolean }>('DELETE', `/dm/${dmChannelId}/members`),
|
||||
};
|
||||
|
||||
this.social = {
|
||||
|
||||
@@ -21,7 +21,7 @@ interface MessageListProps {
|
||||
}
|
||||
|
||||
function isSameGroup(prev: MessageWithUser, curr: MessageWithUser): boolean {
|
||||
if ((prev as any).type === 'system' || (curr as any).type === 'system') return false;
|
||||
if (prev.type === 'system' || curr.type === 'system') return false;
|
||||
if (prev.userId !== curr.userId) return false;
|
||||
const timeDiff = curr.createdAt - prev.createdAt;
|
||||
return timeDiff < 5 * 60 * 1000; // 5 minutes
|
||||
@@ -338,7 +338,7 @@ export function MessageList({ channelId, jumpToMessageId, onJumpComplete }: Mess
|
||||
<div className="flex-1 h-[1px] bg-border-hard" />
|
||||
</div>
|
||||
)}
|
||||
{(msg as any).type === 'system' ? (
|
||||
{msg.type === 'system' ? (
|
||||
<SystemMessage message={msg} />
|
||||
) : (
|
||||
<Message
|
||||
@@ -438,7 +438,7 @@ function WelcomeHeader({ channelId }: { channelId: string }) {
|
||||
|
||||
const handleLeaveGroup = async () => {
|
||||
try {
|
||||
await api.dm.leaveGroup(channelId);
|
||||
await api.dm.leave(channelId);
|
||||
navigate('/channels/@me');
|
||||
} catch (err) {
|
||||
console.error('Failed to leave group:', err);
|
||||
|
||||
Reference in New Issue
Block a user