23 lines
844 B
TypeScript
23 lines
844 B
TypeScript
import historyChatAvatar from "@/assets/img/chat-history-avatar.png";
|
|
import historyCloudAvatar from "@/assets/img/chat-history-cloud-avatar.png";
|
|
import historyDeviceAvatar from "@/assets/img/chat-history-device-avatar.png";
|
|
|
|
const CHAT_HISTORY_AVATARS = [
|
|
historyChatAvatar,
|
|
historyCloudAvatar,
|
|
historyDeviceAvatar,
|
|
] as const;
|
|
|
|
/**
|
|
* Conversations do not carry an avatar in persisted state. Derive one from
|
|
* the stable thread id, so each history row keeps its mark across refreshes
|
|
* while the list uses varied purple, green, and blue artwork.
|
|
*/
|
|
export function historyAvatarForThread(threadId: string): string {
|
|
let hash = 0;
|
|
for (let index = 0; index < threadId.length; index += 1) {
|
|
hash = (hash * 31 + threadId.charCodeAt(index)) | 0;
|
|
}
|
|
return CHAT_HISTORY_AVATARS[(hash >>> 0) % CHAT_HISTORY_AVATARS.length]!;
|
|
}
|