This commit is contained in:
Timothy Jaeryang Baek
2026-06-29 12:59:05 -05:00
parent 2c804b0ac4
commit 7ea7680f56
4 changed files with 69 additions and 31 deletions
+26 -8
View File
@@ -1365,19 +1365,37 @@ async def pin_channel_message(
await Messages.update_is_pinned_by_id(message_id, form_data.is_pinned, user.id, db=db)
message = await Messages.get_message_by_id(message_id, db=db)
message_user = await Users.get_user_by_id(message.user_id, db=db)
await publish_event(
request,
EVENTS.MESSAGE_PINNED if form_data.is_pinned else EVENTS.MESSAGE_UNPINNED,
actor=user,
subject_id=message_id, subject_type='message',
data={'channel_id': id},
)
return MessageUserResponse(
message_data = MessageUserResponse(
**{
**message.model_dump(),
'user': UserNameResponse(**message_user.model_dump()) if message_user else None,
}
)
await sio.emit(
'events:channel',
{
'channel_id': channel.id,
'message_id': message.id,
'data': {
'type': 'message:update',
'data': message_data.model_dump(),
},
'user': UserNameResponse(**user.model_dump()).model_dump(),
'channel': channel.model_dump(),
},
to=f'channel:{channel.id}',
)
await publish_event(
request,
EVENTS.MESSAGE_PINNED if form_data.is_pinned else EVENTS.MESSAGE_UNPINNED,
actor=user,
subject_id=message_id,
subject_type='message',
data={'channel_id': id},
)
return message_data
except Exception as e:
log.exception(e)
raise HTTPException(status_code=status.HTTP_400_BAD_REQUEST, detail=ERROR_MESSAGES.DEFAULT())
+25 -11
View File
@@ -76,6 +76,27 @@
);
};
const pinHandler = (
messageId: string,
pinned: boolean,
pinnedBy: string | null = pinned ? ($user?.id ?? null) : null,
pinnedAt: number | null = pinned ? Date.now() * 1000000 : null
) => {
if (messages) {
messages = messages.map((message) => {
if (message.id === messageId) {
return {
...message,
is_pinned: pinned,
pinned_by: pinnedBy,
pinned_at: pinnedAt
};
}
return message;
});
}
};
const initHandler = async () => {
if (currentId) {
updateLastReadAt(currentId);
@@ -305,17 +326,7 @@
<Pane defaultSize={50} minSize={50} class="h-full flex flex-col w-full relative">
<Navbar
{channel}
onPin={(messageId, pinned) => {
messages = messages.map((message) => {
if (message.id === messageId) {
return {
...message,
is_pinned: pinned
};
}
return message;
});
}}
onPin={pinHandler}
onUpdate={async () => {
channel = await getChannelById(localStorage.token, id).catch((error) => {
return null;
@@ -347,6 +358,7 @@
onThread={(id) => {
threadId = id;
}}
onPin={pinHandler}
onLoad={async () => {
const newMessages = await getChannelMessages(
localStorage.token,
@@ -406,6 +418,7 @@
<Thread
{threadId}
{channel}
onPin={pinHandler}
onClose={() => {
threadId = null;
}}
@@ -428,6 +441,7 @@
<Thread
{threadId}
{channel}
onPin={pinHandler}
onClose={() => {
threadId = null;
}}
+16 -12
View File
@@ -37,6 +37,7 @@
export let onLoad: Function = () => {};
export let onReply: Function = () => {};
export let onThread: Function = () => {};
export let onPin: Function = () => {};
let messagesLoading = false;
@@ -166,24 +167,27 @@
onReply(message);
}}
onPin={async (message) => {
const pinned = !message.is_pinned;
const pinnedBy = pinned ? ($user?.id ?? null) : null;
const pinnedAt = pinned ? Date.now() * 1000000 : null;
messages = messages.map((m) => {
if (m.id === message.id) {
m.is_pinned = !m.is_pinned;
m.pinned_by = !m.is_pinned ? null : $user?.id;
m.pinned_at = !m.is_pinned ? null : Date.now() * 1000000;
m.is_pinned = pinned;
m.pinned_by = pinnedBy;
m.pinned_at = pinnedAt;
}
return m;
});
const updatedMessage = await pinMessage(
localStorage.token,
message.channel_id,
message.id,
message.is_pinned
).catch((error) => {
toast.error(`${error}`);
return null;
});
onPin(message.id, pinned, pinnedBy, pinnedAt);
await pinMessage(localStorage.token, message.channel_id, message.id, pinned).catch(
(error) => {
toast.error(`${error}`);
return null;
}
);
}}
onThread={(id) => {
onThread(id);
+2
View File
@@ -18,6 +18,7 @@
export let channel = null;
export let onClose = () => {};
export let onPin = () => {};
let messages = null;
let top = false;
@@ -196,6 +197,7 @@
{messages}
{replyToMessage}
thread={true}
{onPin}
onReply={async (message) => {
replyToMessage = message;