feat(market): add Minha Intenções tab with panel, hook, and badge
- Introduced "Minhas Intenções" tab visible only to logged-in users. - Integrated MyPurchaseIntentionsPanel and useMyPurchaseIntentions hook. - Added tab badge showing count of pending intentions. - Extended session API to include user’s main character for downstream features.
This commit is contained in:
1 parent
f35fee944d
commit
7f42def478
55 files changed
+4906
-95
No files matched your search
@@ -0,0 +1,81 @@
|
||||
/**
|
||||
* Model Message - Representa uma mensagem em um chat
|
||||
*/
|
||||
|
||||
import mongoose, { Schema, model, models } from "mongoose";
|
||||
|
||||
export interface IMessage {
|
||||
chat_id: string; // Referência ao chat
|
||||
sender_id: number; // ID do remetente (PostgreSQL)
|
||||
content: string; // Conteúdo da mensagem (sanitizado)
|
||||
created_at: Date;
|
||||
read_at: Date | null; // Quando foi lida
|
||||
edited_at: Date | null; // Se foi editada
|
||||
deleted_at: Date | null; // Soft delete
|
||||
|
||||
// Metadados
|
||||
message_type: "text" | "system"; // System para mensagens automáticas
|
||||
metadata?: {
|
||||
listing_id?: number;
|
||||
action?: "listing_updated" | "listing_sold" | "price_changed";
|
||||
};
|
||||
}
|
||||
|
||||
const MessageSchema = new Schema<IMessage>(
|
||||
{
|
||||
chat_id: {
|
||||
type: String,
|
||||
required: true,
|
||||
index: true,
|
||||
},
|
||||
sender_id: {
|
||||
type: Number,
|
||||
required: true,
|
||||
index: true,
|
||||
},
|
||||
content: {
|
||||
type: String,
|
||||
required: true,
|
||||
maxlength: 1000,
|
||||
trim: true,
|
||||
},
|
||||
created_at: {
|
||||
type: Date,
|
||||
default: Date.now,
|
||||
index: true,
|
||||
},
|
||||
read_at: {
|
||||
type: Date,
|
||||
default: null,
|
||||
},
|
||||
edited_at: {
|
||||
type: Date,
|
||||
default: null,
|
||||
},
|
||||
deleted_at: {
|
||||
type: Date,
|
||||
default: null,
|
||||
},
|
||||
message_type: {
|
||||
type: String,
|
||||
enum: ["text", "system"],
|
||||
default: "text",
|
||||
},
|
||||
metadata: {
|
||||
type: Schema.Types.Mixed,
|
||||
default: null,
|
||||
},
|
||||
},
|
||||
{
|
||||
timestamps: false, // Usamos campos manuais
|
||||
collection: "messages",
|
||||
}
|
||||
);
|
||||
|
||||
// Índices compostos para queries eficientes
|
||||
MessageSchema.index({ chat_id: 1, created_at: -1 }); // Para buscar mensagens de um chat ordenadas
|
||||
MessageSchema.index({ chat_id: 1, sender_id: 1, created_at: -1 });
|
||||
MessageSchema.index({ sender_id: 1, created_at: -1 });
|
||||
|
||||
export const Message = models.Message || model<IMessage>("Message", MessageSchema);
|
||||
|
||||
Reference in new issue
Block a user