@bruch/max-client 0.1.2 → 0.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -120,8 +120,7 @@ function resolveEvent(
|
|
|
120
120
|
): { type: keyof EventMap; event: EventMap[keyof EventMap] } | null {
|
|
121
121
|
const payload = frame.payload as Record<string, unknown>;
|
|
122
122
|
if (frame.opcode === Opcode.NOTIF_MESSAGE || frame.opcode === Opcode.MSG_EDIT) {
|
|
123
|
-
const
|
|
124
|
-
const message = Message.fromPayload(messagePayload);
|
|
123
|
+
const message = Message.fromPayload(payload);
|
|
125
124
|
if (message.status === "REMOVED")
|
|
126
125
|
return { type: EventType.MESSAGE_DELETE, event: deleteFromMessage(message, payload) };
|
|
127
126
|
return {
|
package/src/types/models.ts
CHANGED
|
@@ -143,7 +143,15 @@ export class Message {
|
|
|
143
143
|
}
|
|
144
144
|
|
|
145
145
|
static fromPayload(value: unknown): Message {
|
|
146
|
-
|
|
146
|
+
const payload = asRecord(value, "message");
|
|
147
|
+
const nested = optionalRecord(payload.message);
|
|
148
|
+
if (!nested) return new Message(payload);
|
|
149
|
+
|
|
150
|
+
const normalized = { ...nested };
|
|
151
|
+
for (const field of ["chatId", "prevMessageId", "ttl", "unread", "mark"] as const) {
|
|
152
|
+
if (payload[field] !== undefined) normalized[field] = payload[field];
|
|
153
|
+
}
|
|
154
|
+
return new Message(normalized);
|
|
147
155
|
}
|
|
148
156
|
|
|
149
157
|
bind(actions: MessageActions): this {
|