Simplify how last message is handled.

This commit is contained in:
Paul
2021-09-14 15:07:42 +01:00
parent 45c7cd0307
commit cc45b9e255
4 changed files with 12 additions and 25 deletions

View File

@@ -82,8 +82,9 @@ export const UserButton = observer((props: UserProps) => {
</div>
{
<div className={styles.subText}>
{channel?.last_message && alert ? (
(channel.last_message as { short: string }).short
{typeof channel?.last_message?.content === "string" &&
alert ? (
channel.last_message.content.slice(0, 32)
) : (
<UserStatus user={user} />
)}
@@ -162,8 +163,9 @@ export const ChannelButton = observer((props: ChannelProps) => {
<div>{channel.name}</div>
{channel.channel_type === "Group" && (
<div className={styles.subText}>
{channel.last_message && alert ? (
(channel.last_message as { short: string }).short
{typeof channel.last_message?.content === "string" &&
alert ? (
channel.last_message.content.slice(0, 32)
) : (
<Text
id="quantities.members"

View File

@@ -49,22 +49,7 @@ export function useUnreads({ channel, unreads }: UnreadProps) {
}
export function mapChannelWithUnread(channel: Channel, unreads: Unreads) {
let last_message_id;
if (
channel.channel_type === "DirectMessage" ||
channel.channel_type === "Group"
) {
last_message_id = (channel.last_message as { _id: string })?._id;
} else if (channel.channel_type === "TextChannel") {
last_message_id = channel.last_message as string;
} else {
return {
channel,
unread: undefined,
alertCount: undefined,
timestamp: channel._id,
};
}
const last_message_id = channel.last_message_id;
let unread: "mention" | "unread" | undefined;
let alertCount: undefined | number;