Skip to content

Commit

Permalink
Add Rest prefix to Channel, Presence class names
Browse files Browse the repository at this point in the history
Groundwork for removing the Realtime versions’ inheritance.
  • Loading branch information
lawrence-forooghian committed Nov 9, 2023
1 parent 29007a0 commit 871e0cc
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 25 deletions.
8 changes: 4 additions & 4 deletions src/common/lib/client/realtimechannel.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import ProtocolMessage from '../types/protocolmessage';
import EventEmitter from '../util/eventemitter';
import * as Utils from '../util/utils';
import Channel from './channel';
import RestChannel from './restchannel';
import Logger from '../util/logger';
import RealtimePresence from './realtimepresence';
import Message, { CipherOptions } from '../types/message';
Expand Down Expand Up @@ -48,7 +48,7 @@ function validateChannelOptions(options?: API.Types.ChannelOptions) {
}
}

class RealtimeChannel extends Channel {
class RealtimeChannel extends RestChannel {
realtime: BaseRealtime;
private _realtimePresence: RealtimePresence | null;
get presence(): RealtimePresence {
Expand Down Expand Up @@ -156,7 +156,7 @@ class RealtimeChannel extends Channel {
_callback(err);
return;
}
Channel.prototype.setOptions.call(this, options);
RestChannel.prototype.setOptions.call(this, options);
if (this._decodingContext) this._decodingContext.channelOptions = this.channelOptions;
if (this._shouldReattachToSetOptions(options)) {
/* This does not just do _attach(true, null, callback) because that would put us
Expand Down Expand Up @@ -900,7 +900,7 @@ class RealtimeChannel extends Channel {
params.from_serial = this.properties.attachSerial;
}

Channel.prototype._history.call(this, params, callback);
RestChannel.prototype._history.call(this, params, callback);
} as any;

whenState = ((state: string, listener: ErrCallback) => {
Expand Down
6 changes: 3 additions & 3 deletions src/common/lib/client/realtimepresence.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as Utils from '../util/utils';
import Presence from './presence';
import RestPresence from './restpresence';
import EventEmitter from '../util/eventemitter';
import Logger from '../util/logger';
import PresenceMessage, { fromValues as presenceMessageFromValues } from '../types/presencemessage';
Expand Down Expand Up @@ -78,7 +78,7 @@ function newerThan(item: PresenceMessage, existing: PresenceMessage) {
}
}

class RealtimePresence extends Presence {
class RealtimePresence extends RestPresence {
channel: RealtimeChannel;
pendingPresence: { presence: PresenceMessage; callback: ErrCallback }[];
syncComplete: boolean;
Expand Down Expand Up @@ -319,7 +319,7 @@ class RealtimePresence extends Presence {
}
}

Presence.prototype._history.call(this, params, callback);
RestPresence.prototype._history.call(this, params, callback);
}

setPresence(presenceSet: PresenceMessage[], isSync: boolean, syncChannelSerial?: string): void {
Expand Down
6 changes: 3 additions & 3 deletions src/common/lib/client/rest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import Logger, { LoggerOptions } from '../util/logger';
import Defaults from '../util/defaults';
import Push from './push';
import PaginatedResource, { HttpPaginatedResponse, PaginatedResult } from './paginatedresource';
import Channel from './channel';
import RestChannel from './restchannel';
import ErrorInfo from '../types/errorinfo';
import Stats from '../types/stats';
import HttpMethods from '../../constants/HttpMethods';
Expand Down Expand Up @@ -324,7 +324,7 @@ export class Rest {

class Channels {
client: BaseClient;
all: Record<string, Channel>;
all: Record<string, RestChannel>;

constructor(client: BaseClient) {
this.client = client;
Expand All @@ -335,7 +335,7 @@ class Channels {
name = String(name);
let channel = this.all[name];
if (!channel) {
this.all[name] = channel = new Channel(this.client, name, channelOptions);
this.all[name] = channel = new RestChannel(this.client, name, channelOptions);
} else if (channelOptions) {
channel.setOptions(channelOptions);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as Utils from '../util/utils';
import EventEmitter from '../util/eventemitter';
import Logger from '../util/logger';
import Presence from './presence';
import RestPresence from './restpresence';
import Message, { CipherOptions } from '../types/message';
import ErrorInfo from '../types/errorinfo';
import PaginatedResource, { PaginatedResult } from './paginatedresource';
Expand Down Expand Up @@ -46,23 +46,23 @@ function normaliseChannelOptions(Crypto: IUntypedCryptoStatic | null, options?:
return channelOptions;
}

class Channel extends EventEmitter {
class RestChannel extends EventEmitter {
client: BaseClient;
name: string;
basePath: string;
private _presence: Presence;
get presence(): Presence {
private _presence: RestPresence;
get presence(): RestPresence {
return this._presence;
}
channelOptions: ChannelOptions;

constructor(client: BaseClient, name: string, channelOptions?: ChannelOptions) {
super();
Logger.logAction(Logger.LOG_MINOR, 'Channel()', 'started; name = ' + name);
Logger.logAction(Logger.LOG_MINOR, 'RestChannel()', 'started; name = ' + name);
this.client = client;
this.name = name;
this.basePath = '/channels/' + encodeURIComponent(name);
this._presence = new Presence(this);
this._presence = new RestPresence(this);
this.channelOptions = normaliseChannelOptions(client._Crypto ?? null, channelOptions);
}

Expand All @@ -74,7 +74,7 @@ class Channel extends EventEmitter {
params: RestHistoryParams | null,
callback: PaginatedResultCallback<Message>
): Promise<PaginatedResult<Message>> | void {
Logger.logAction(Logger.LOG_MICRO, 'Channel.history()', 'channel = ' + this.name);
Logger.logAction(Logger.LOG_MICRO, 'RestChannel.history()', 'channel = ' + this.name);
/* params and callback are optional; see if params contains the callback */
if (callback === undefined) {
if (typeof params == 'function') {
Expand Down Expand Up @@ -200,4 +200,4 @@ class Channel extends EventEmitter {
}
}

export default Channel;
export default RestChannel;
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,22 @@ import PaginatedResource, { PaginatedResult } from './paginatedresource';
import PresenceMessage from '../types/presencemessage';
import { CipherOptions } from '../types/message';
import { PaginatedResultCallback } from '../../types/utils';
import Channel from './channel';
import RestChannel from './restchannel';
import RealtimeChannel from './realtimechannel';
import Defaults from '../util/defaults';

class Presence extends EventEmitter {
channel: RealtimeChannel | Channel;
class RestPresence extends EventEmitter {
channel: RealtimeChannel | RestChannel;
basePath: string;

constructor(channel: RealtimeChannel | Channel) {
constructor(channel: RealtimeChannel | RestChannel) {
super();
this.channel = channel;
this.basePath = channel.basePath + '/presence';
}

get(params: any, callback: PaginatedResultCallback<PresenceMessage>): void | Promise<PresenceMessage> {
Logger.logAction(Logger.LOG_MICRO, 'Presence.get()', 'channel = ' + this.channel.name);
Logger.logAction(Logger.LOG_MICRO, 'RestPresence.get()', 'channel = ' + this.channel.name);
/* params and callback are optional; see if params contains the callback */
if (callback === undefined) {
if (typeof params == 'function') {
Expand Down Expand Up @@ -52,7 +52,7 @@ class Presence extends EventEmitter {
params: any,
callback: PaginatedResultCallback<PresenceMessage>
): void | Promise<PaginatedResult<PresenceMessage>> {
Logger.logAction(Logger.LOG_MICRO, 'Presence.history()', 'channel = ' + this.channel.name);
Logger.logAction(Logger.LOG_MICRO, 'RestPresence.history()', 'channel = ' + this.channel.name);
return this._history(params, callback);
}

Expand Down Expand Up @@ -93,4 +93,4 @@ class Presence extends EventEmitter {
}
}

export default Presence;
export default RestPresence;

0 comments on commit 871e0cc

Please sign in to comment.