Skip to content

Commit

Permalink
Add auto message ACK & Fix connected list diff patcher object hash & …
Browse files Browse the repository at this point in the history
…Publish v1.3.0
  • Loading branch information
7PH committed Apr 29, 2024
1 parent d8660d2 commit 6d65054
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 5 deletions.
36 changes: 35 additions & 1 deletion app/api/SkyChatClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ const defaultUser: SanitizedUser = {
},
};

export type SkyChatOptions = {
autoMessageAck: boolean;
};

export type SkyChatClientState = {
websocketReadyState: number;
user: SanitizedUser;
Expand Down Expand Up @@ -147,9 +151,16 @@ export class SkyChatClient extends EventEmitter {
};
private _playerLastUpdate: Date | null = null;

constructor(public readonly url: string) {
private autoMessageAck: boolean;

constructor(
public readonly url: string,
options: SkyChatOptions,
) {
super();

this.autoMessageAck = options.autoMessageAck ?? false;

// Auth & Config
this.on('config', this._onConfig.bind(this));
this.on('sticker-list', this._onStickerList.bind(this));
Expand All @@ -159,6 +170,9 @@ export class SkyChatClient extends EventEmitter {
this.on('connected-list', this._onConnectedList.bind(this));
this.on('connected-list-patch', this._onConnectedListPatch.bind(this));

// Messages
this.on('message', this._onMessage.bind(this));

// Room
this.on('room-list', this._onRoomList.bind(this));
this.on('join-room', this._onCurrentRoomId.bind(this));
Expand Down Expand Up @@ -295,6 +309,19 @@ export class SkyChatClient extends EventEmitter {
this._generateRoomConnectedUsersAndPlayerChannelUsers());
}

private _onMessage(message: SanitizedMessage) {
if (!this.autoMessageAck) {
return;
}
if (this._user.id === 0) {
return;
}
if (message.id === 0) {
return;
}
this.notifySeenMessage(message.id);
}

private _onRoomList(rooms: Array<SanitizedRoom>) {
this._rooms = rooms;
this.emit('update', this.state);
Expand Down Expand Up @@ -471,6 +498,13 @@ export class SkyChatClient extends EventEmitter {
this.emit('update', this.state);
}

/**
* Set whether the client should be considered focused or not
*/
setAutoMessageAck(autoMessageAck: boolean) {
this.autoMessageAck = autoMessageAck;
}

/**
* Send a last message seen notification
* @param messageId
Expand Down
2 changes: 1 addition & 1 deletion app/server/plugins/core/global/ConnectedListPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export class ConnectedListPlugin extends GlobalPlugin {

this.lastConnectedList = this.getConnectedList();
this.diffPatcher = jsondiffpatch.create({
objectHash: (obj: any) => (obj as SanitizedSession).identifier,
objectHash: (obj: any, index?: number | undefined) => (obj as SanitizedSession)?.identifier ?? obj.id ?? index,
});
setInterval(this.sync.bind(this), ConnectedListPlugin.SYNC_DELAY);
}
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "skychat",
"private": false,
"version": "1.2.2",
"version": "1.3.0",
"description": "Future-proof virtual cinema platform",
"types": "build/api/index.d.ts",
"main": "build/api/index.js",
Expand Down

0 comments on commit 6d65054

Please sign in to comment.