统一聊天排序并支持公众号跳转小程序

This commit is contained in:
stu2not
2026-06-24 14:59:44 +08:00
parent 31804a78ff
commit e75a9015fa
16 changed files with 668 additions and 72 deletions

View File

@@ -122,6 +122,8 @@ interface ChildConversationItem {
last_message_preview?: string | null
last_message_at?: string | null
message_count: number
created_at: string
updated_at: string
}
interface ChildConversationListResponse {
@@ -307,9 +309,10 @@ function canSendParentConversation(parentUserId: number | null, context: Binding
return Boolean(parentUserId && parentUserId === context.currentUserId)
}
function getConversationRank(conversation: ChatConversation): number {
if (isParentChildConversation(conversation.conversationTypeName)) return 0
return 1
function compareConversationsByNewest(left: ChatConversation, right: ChatConversation): number {
const timeDiff = parseTime(right.sortAt) - parseTime(left.sortAt)
if (timeDiff !== 0) return timeDiff
return right.key.localeCompare(left.key)
}
async function getBindingContext(): Promise<BindingContext> {
@@ -385,6 +388,7 @@ function toImConversation(item: ChildConversationItem, context: BindingContext):
const parentUserId = isParentConversation ? parseNumericId(item.peer_id) : null
const canSend = isParentConversation ? canSendParentConversation(parentUserId, context) : false
const parentConversationName = getParentConversationName(parentUserId, item.peer_id, item.peer_name, context)
const sortAt = item.last_message_at || item.updated_at || item.created_at
return {
id: item.conversation_id,
@@ -400,8 +404,8 @@ function toImConversation(item: ChildConversationItem, context: BindingContext):
: '其他家长和孩子的留言记录'
: meta.description,
lastMessage: item.last_message_preview || (isParentConversation ? (canSend ? '还没有消息,点进去发送第一条' : '暂无留言记录') : '暂无消息'),
time: formatListTime(item.last_message_at),
sortAt: item.last_message_at || '',
time: formatListTime(sortAt),
sortAt,
conversationTypeName: item.conversation_type_name,
peerId: item.peer_id,
childId: context.childId,
@@ -496,11 +500,7 @@ export async function getConversations(): Promise<ChatConversation[]> {
}
}
return conversations.sort((left, right) => {
const rankDiff = getConversationRank(left) - getConversationRank(right)
if (rankDiff !== 0) return rankDiff
return parseTime(right.sortAt) - parseTime(left.sortAt)
})
return conversations.sort(compareConversationsByNewest)
}
export async function getMessages(

View File

@@ -0,0 +1,10 @@
import { request } from './api'
export interface WechatMpNotificationLink {
route: string
params: Record<string, string | number | null | undefined>
}
export function resolveWechatMpNotificationLink(token: string): Promise<WechatMpNotificationLink> {
return request<WechatMpNotificationLink>(`/banban/wechat-mp/notification-links/${encodeURIComponent(token)}`)
}