fix: editing DM/GM channel header
This commit is contained in:
parent
752614217b
commit
cdbafea607
4 changed files with 25 additions and 12 deletions
|
|
@ -249,13 +249,14 @@ export async function createChannel(serverUrl: string, displayName: string, purp
|
|||
}
|
||||
}
|
||||
|
||||
export async function patchChannel(serverUrl: string, channelPatch: Partial<Channel> & {id: string}) {
|
||||
export async function patchChannel(serverUrl: string, channelId: string, channelPatch: ChannelPatch) {
|
||||
try {
|
||||
const client = NetworkManager.getClient(serverUrl);
|
||||
const {database, operator} = DatabaseManager.getServerDatabaseAndOperator(serverUrl);
|
||||
|
||||
const channelData = await client.patchChannel(channelPatch.id, channelPatch);
|
||||
const channelData = await client.patchChannel(channelId, channelPatch);
|
||||
const models = [];
|
||||
|
||||
const channelInfo = (await getChannelInfo(database, channelData.id));
|
||||
if (channelInfo && (channelInfo.purpose !== channelData.purpose || channelInfo.header !== channelData.header)) {
|
||||
channelInfo.prepareUpdate((v) => {
|
||||
|
|
@ -264,11 +265,16 @@ export async function patchChannel(serverUrl: string, channelPatch: Partial<Chan
|
|||
});
|
||||
models.push(channelInfo);
|
||||
}
|
||||
|
||||
const channel = await getChannelById(database, channelData.id);
|
||||
if (channel && (channel.displayName !== channelData.display_name || channel.type !== channelData.type)) {
|
||||
channel.prepareUpdate((v) => {
|
||||
v.displayName = channelData.display_name;
|
||||
// DM and GM display names cannot be patched and are formatted client-side; do not overwrite
|
||||
if (channelData.type !== General.DM_CHANNEL && channelData.type !== General.GM_CHANNEL) {
|
||||
v.displayName = channelData.display_name;
|
||||
}
|
||||
v.type = channelData.type;
|
||||
logInfo({channelData});
|
||||
});
|
||||
models.push(channel);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -128,7 +128,7 @@ const ClientChannels = <TBase extends Constructor<ClientBase>>(superclass: TBase
|
|||
);
|
||||
};
|
||||
|
||||
patchChannel = async (channelId: string, channelPatch: Partial<Channel>) => {
|
||||
patchChannel = async (channelId: string, channelPatch: ChannelPatch) => {
|
||||
this.analytics?.trackAPI('api_channels_patch', {channel_id: channelId});
|
||||
|
||||
return this.doFetch(
|
||||
|
|
|
|||
|
|
@ -202,16 +202,16 @@ const CreateOrEditChannel = ({
|
|||
return;
|
||||
}
|
||||
|
||||
const patchChannel = {
|
||||
id: channel.id,
|
||||
type: channel.type,
|
||||
display_name: isDirect(channel) ? channel.displayName : displayName,
|
||||
purpose: isDirect(channel) ? null : purpose,
|
||||
header: isDirect(channel) ? null : header,
|
||||
} as Channel;
|
||||
const patchChannel: ChannelPatch = {
|
||||
header,
|
||||
...!isDirect(channel) && {
|
||||
display_name: displayName,
|
||||
purpose,
|
||||
},
|
||||
};
|
||||
|
||||
setCanSave(false);
|
||||
const patchedChannel = await handlePatchChannel(serverUrl, patchChannel);
|
||||
const patchedChannel = await handlePatchChannel(serverUrl, channel.id, patchChannel);
|
||||
if (patchedChannel.error) {
|
||||
dispatch({
|
||||
type: RequestActions.FAILURE,
|
||||
|
|
|
|||
7
types/api/channels.d.ts
vendored
7
types/api/channels.d.ts
vendored
|
|
@ -44,6 +44,13 @@ type Channel = {
|
|||
group_constrained: boolean|null;
|
||||
shared: boolean;
|
||||
};
|
||||
type ChannelPatch = {
|
||||
name?: string;
|
||||
display_name?: string;
|
||||
header?: string;
|
||||
purpose?: string;
|
||||
group_constrained?: boolean|null;
|
||||
};
|
||||
type ChannelWithTeamData = Channel & {
|
||||
team_display_name: string;
|
||||
team_name: string;
|
||||
|
|
|
|||
Loading…
Reference in a new issue