Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove unused chat feature #346

Merged
merged 2 commits into from
Sep 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 1 addition & 52 deletions packages/docprovider/src/awareness.ts
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this expected to keep the IChatMessage interface and messageStreem ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not to my knowledge.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's remove them if they are not necessary anymore

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you approve this PR?

Copy link
Contributor

@brichet brichet Sep 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was expecting us to remove the remaining IChatMessage and messageStream before, since they are not used anymore.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah I didn't get that, thanks!

Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,16 @@
import { User } from '@jupyterlab/services';

import { IDisposable } from '@lumino/disposable';
import { IStream, Stream } from '@lumino/signaling';

import { IAwareness } from '@jupyter/ydoc';

import * as decoding from 'lib0/decoding';
import * as encoding from 'lib0/encoding';
import { WebsocketProvider } from 'y-websocket';

import { MessageType } from './utils';
import { IAwarenessProvider } from './tokens';

export interface IContent {
type: string;
body: string;
}

export interface IChatMessage {
sender: string;
timestamp: number;
content: IContent;
}

/**
* A class to provide Yjs synchronization over WebSocket.
*
Expand All @@ -36,7 +24,7 @@ export interface IChatMessage {
*/
export class WebSocketAwarenessProvider
extends WebsocketProvider
implements IAwarenessProvider, IDisposable
implements IDisposable
{
/**
* Construct a new WebSocketAwarenessProvider
Expand All @@ -55,33 +43,12 @@ export class WebSocketAwarenessProvider
.then(() => this._onUserChanged(this._user))
.catch(e => console.error(e));
this._user.userChanged.connect(this._onUserChanged, this);

this._messageStream = new Stream(this);

this.messageHandlers[MessageType.CHAT] = (
encoder,
decoder,
provider,
emitSynced,
messageType
) => {
const content = decoding.readVarString(decoder);
const data = JSON.parse(content) as IChatMessage;
this._messageStream.emit(data);
};
}

get isDisposed(): boolean {
return this._isDisposed;
}

/**
* A signal to subscribe for incoming messages.
*/
get messageStream(): IStream<this, IChatMessage> {
return this._messageStream;
}

dispose(): void {
if (this._isDisposed) {
return;
Expand All @@ -92,31 +59,13 @@ export class WebSocketAwarenessProvider
this.destroy();
}

/**
* Send a message to every collaborator.
*
* @param msg message
*/
sendMessage(msg: string): void {
const data: IContent = {
type: 'text',
body: msg
};
const encoder = encoding.createEncoder();
encoding.writeVarUint(encoder, MessageType.CHAT);
encoding.writeVarString(encoder, JSON.stringify(data));
this.ws!.send(encoding.toUint8Array(encoder));
}

private _onUserChanged(user: User.IManager): void {
this._awareness.setLocalStateField('user', user.identity);
}

private _isDisposed = false;
private _user: User.IManager;
private _awareness: IAwareness;

private _messageStream: Stream<this, IChatMessage>;
}

/**
Expand Down
20 changes: 0 additions & 20 deletions packages/docprovider/src/tokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@ import { DocumentChange, IAwareness, YDocument } from '@jupyter/ydoc';
import { Contents } from '@jupyterlab/services';

import { Token } from '@lumino/coreutils';
import { IStream } from '@lumino/signaling';

import { IChatMessage } from './awareness';

/**
* The collaborative drive.
Expand Down Expand Up @@ -56,20 +53,3 @@ export interface ISharedModelFactory extends Contents.ISharedFactory {
factory: SharedDocumentFactory
): void;
}

/**
* A provider interface for global awareness features.
*/
export interface IAwarenessProvider {
/**
* A signal to subscribe for incoming messages.
*/
readonly messageStream: IStream<this, IChatMessage>;

/**
* Send a message to every collaborator.
*
* @param msg message
*/
sendMessage(msg: string): void;
}
8 changes: 0 additions & 8 deletions packages/docprovider/src/utils.ts

This file was deleted.

Loading