mirror of
https://github.com/chatmail/core.git
synced 2026-05-22 16:26:31 +03:00
fix: jsonrpc: typescript client: fix types of events in event emitter (#4373)
* fix: jsonrpc: typescript client: fix types of events in event emitter * add ts ignore to remove ts error (when building in ts5) doing the types right via casting is to complicated IMO and has no real benefit here.
This commit is contained in:
@@ -9,10 +9,13 @@
|
|||||||
- BREAKING: jsonrpc:
|
- BREAKING: jsonrpc:
|
||||||
- `get_chatlist_items_by_entries` now takes only chatids instead of `ChatListEntries`
|
- `get_chatlist_items_by_entries` now takes only chatids instead of `ChatListEntries`
|
||||||
- `get_chatlist_entries` now returns `Vec<u32>` of chatids instead of `ChatListEntries`
|
- `get_chatlist_entries` now returns `Vec<u32>` of chatids instead of `ChatListEntries`
|
||||||
|
- `Event`: `context_id` property is now called `contextId`
|
||||||
- JSON-RPC: add API to get reactions outside the message snapshot
|
- JSON-RPC: add API to get reactions outside the message snapshot
|
||||||
### Fixes
|
### Fixes
|
||||||
- Make the bots automatically accept group chat contact requests. #4377
|
- Make the bots automatically accept group chat contact requests. #4377
|
||||||
|
|
||||||
|
### Fixes
|
||||||
|
- jsonrpc: typescript client: fix types of events in event emitter
|
||||||
|
|
||||||
## [1.114.0] - 2023-04-24
|
## [1.114.0] - 2023-04-24
|
||||||
|
|
||||||
|
|||||||
@@ -1,33 +1,28 @@
|
|||||||
import * as T from "../generated/types.js";
|
import * as T from "../generated/types.js";
|
||||||
|
import { EventType } from "../generated/types.js";
|
||||||
import * as RPC from "../generated/jsonrpc.js";
|
import * as RPC from "../generated/jsonrpc.js";
|
||||||
import { RawClient } from "../generated/client.js";
|
import { RawClient } from "../generated/client.js";
|
||||||
import { WebsocketTransport, BaseTransport, Request } from "yerpc";
|
import { WebsocketTransport, BaseTransport, Request } from "yerpc";
|
||||||
import { TinyEmitter } from "@deltachat/tiny-emitter";
|
import { TinyEmitter } from "@deltachat/tiny-emitter";
|
||||||
|
|
||||||
type DCWireEvent<T extends Event> = {
|
type Events = { ALL: (accountId: number, event: EventType) => void } & {
|
||||||
event: T;
|
[Property in EventType["type"]]: (
|
||||||
contextId: number;
|
|
||||||
};
|
|
||||||
// export type Events = Record<
|
|
||||||
// Event["type"] | "ALL",
|
|
||||||
// (event: DeltaChatEvent<Event>) => void
|
|
||||||
// >;
|
|
||||||
|
|
||||||
type Events = { ALL: (accountId: number, event: Event) => void } & {
|
|
||||||
[Property in Event["type"]]: (
|
|
||||||
accountId: number,
|
accountId: number,
|
||||||
event: Extract<Event, { type: Property }>
|
event: Extract<EventType, { type: Property }>
|
||||||
) => void;
|
) => void;
|
||||||
};
|
};
|
||||||
|
|
||||||
type ContextEvents = { ALL: (event: Event) => void } & {
|
type ContextEvents = { ALL: (event: EventType) => void } & {
|
||||||
[Property in Event["type"]]: (
|
[Property in EventType["type"]]: (
|
||||||
event: Extract<Event, { type: Property }>
|
event: Extract<EventType, { type: Property }>
|
||||||
) => void;
|
) => void;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type DcEvent = Event;
|
export type DcEvent = EventType;
|
||||||
export type DcEventType<T extends Event["type"]> = Extract<Event, { type: T }>;
|
export type DcEventType<T extends EventType["type"]> = Extract<
|
||||||
|
EventType,
|
||||||
|
{ type: T }
|
||||||
|
>;
|
||||||
|
|
||||||
export class BaseDeltaChat<
|
export class BaseDeltaChat<
|
||||||
Transport extends BaseTransport<any>
|
Transport extends BaseTransport<any>
|
||||||
@@ -50,8 +45,9 @@ export class BaseDeltaChat<
|
|||||||
async eventLoop(): Promise<void> {
|
async eventLoop(): Promise<void> {
|
||||||
while (true) {
|
while (true) {
|
||||||
const event = await this.rpc.getNextEvent();
|
const event = await this.rpc.getNextEvent();
|
||||||
this.emit(event.event.type, event.contextId, event.event as any);
|
//@ts-ignore
|
||||||
this.emit("ALL", event.contextId, event.event as any);
|
this.emit(event.event.type, event.contextId, event.event);
|
||||||
|
this.emit("ALL", event.contextId, event.event);
|
||||||
|
|
||||||
if (this.contextEmitters[event.contextId]) {
|
if (this.contextEmitters[event.contextId]) {
|
||||||
this.contextEmitters[event.contextId].emit(
|
this.contextEmitters[event.contextId].emit(
|
||||||
|
|||||||
Reference in New Issue
Block a user