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

[WIP]Replace authManager with IAuthenticationInformation #142

Closed
wants to merge 1 commit into from
Closed
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
6 changes: 3 additions & 3 deletions js/table/tablemanager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
} from "@poker/api-server";
import * as ko from "knockout";
import { DefaultApiProvider, IApiProvider } from "poker/api";
import { authManager } from "poker/authmanager";
import { authManager, AuthManager } from "poker/authmanager";
import { ICommandManager } from "poker/commandmanager";
import { TablePlaceModel } from "poker/table/tabpleplacemodel";
import * as signals from "signals";
Expand Down Expand Up @@ -341,7 +341,7 @@ export class TableManager {
}
}
public addTable(tableId: number, model: GameTableModel) {
const table = new TableView(tableId, model, this.apiProvider);
const table = new TableView(tableId, model, this.apiProvider, new AuthManager());
this.tables.push(table);
table.onMyTurn.add(this.onMyTurn, this);
table.onGamefinished.add(this.onGameFinished, this);
Expand Down Expand Up @@ -523,7 +523,7 @@ export class TableManager {
MaxPlayers: 10,
PotLimitType: 2,
};
return new TableView(0, nonExistingTableModel, this.apiProvider);
return new TableView(0, nonExistingTableModel, this.apiProvider, new AuthManager());
}
private onPlayerCardsDealed(tableId: number) {
const tableView = this.getTableById(tableId);
Expand Down
25 changes: 13 additions & 12 deletions js/table/tableview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import * as ko from "knockout";
import * as moment from "moment";
import { IApiProvider } from "poker/api";
import { authManager } from "poker/authmanager";
import { authManager, IAuthenticationInformation } from "poker/authmanager";
import { AccountManager } from "poker/services/accountManager";
import * as signals from "signals";
import { App } from "../app";
Expand Down Expand Up @@ -244,7 +244,7 @@ export class TableView {
private notificationHandleTimeout: number | null = null;
private notificationHandleInterval: number | null = null;
private displayingRebuyAddonNotification = false;

private authInformation: IAuthenticationInformation;
/**
* Indicates that Ante detected during current game.
*/
Expand All @@ -258,8 +258,9 @@ export class TableView {
* @param model View model.
* @param apiProvider API provider for performing operation.
*/
constructor(public tableId: number, public model: GameTableModel, private apiProvider: IApiProvider) {
constructor(public tableId: number, public model: GameTableModel, private apiProvider: IApiProvider, private authInfo: IAuthenticationInformation) {
const self = this;
this.authInformation = authInfo;
this.tableId = tableId;
this.tableName = ko.observable(model === null ? "0" : model.TableName);
this.connecting = ko.observable(true);
Expand Down Expand Up @@ -345,7 +346,7 @@ export class TableView {
}, this).extend({ notify: "always" });

this.myPlayer.subscribe(function (value) {
if (value !== null && authManager.loginId() === value.PlayerId()) {
if (value !== null && self.authInformation.loginId() === value.PlayerId()) {
value.needCardsOverlay(true);
}
});
Expand All @@ -364,9 +365,9 @@ export class TableView {
return (myself.Cards() !== null) && (myself.Cards().length !== 0);
}, this);

this.currentLogin = ko.observable(authManager.login());
this.currentLogin = ko.observable(self.authInformation.login());
authManager.registerAuthenticationChangedHandler(function (value) {
self.currentLogin(authManager.login());
self.currentLogin(self.authInformation.login());
});

this.timeLeft = ko.computed(function () {
Expand Down Expand Up @@ -1391,7 +1392,7 @@ export class TableView {
this.onGameStartedCore(gameId, players, actions, dealerSeat);
this.handHistory.onGameStarted(gameId, players, actions, dealerSeat, this.gameType());
});
const isInGame = players.some((player) => player.PlayerId === authManager.loginId());
const isInGame = players.some((player) => player.PlayerId === this.authInformation.loginId());
if (!isInGame) {
this.startDealCards();
}
Expand Down Expand Up @@ -1550,7 +1551,7 @@ export class TableView {
} else {
this.queue.pushCallback(() => {
if (!self.cardsReceived) {
if (playerId === authManager.loginId()) {
if (playerId === self.authInformation.loginId()) {
self.startDealCards();
this.queue.pushCallback(() => {
self.onPlayerCardsCore(playerId, cards);
Expand Down Expand Up @@ -2178,7 +2179,7 @@ export class TableView {
public toggleCards() {
const my = this.myPlayer();
if (!my) {
console.error(`Player ${authManager.loginId()} does not sit on the table ${this.tableId}.`);
console.error(`Player ${this.authInformation.loginId()} does not sit on the table ${this.tableId}.`);
return;
}

Expand Down Expand Up @@ -2641,7 +2642,7 @@ export class TableView {
this.actionBlock.updateAdditionalButtons();
}

if (nextPlayerId === authManager.loginId()) {
if (nextPlayerId === this.authInformation.loginId()) {
this.logGameEvent("Player turn approached");
this.tablePlaces.placesRefreshTrigger();
}
Expand Down Expand Up @@ -2737,7 +2738,7 @@ export class TableView {
this.lastRaise(this.bigBlind());

this.actionBlock.resetAutomaticAction();
if (players.some((player) => player.PlayerId === authManager.loginId())) {
if (players.some((player) => player.PlayerId === this.authInformation.loginId())) {
// Reset Wait BB status since player currently join the game.
this.actionBlock.resetWaitBB();
}
Expand Down Expand Up @@ -2884,7 +2885,7 @@ export class TableView {
if (p.PlayerId() === playerId) {
const saveMask = 16;
p.Status(status | (p.Status() & saveMask));
if (playerId === authManager.loginId()) {
if (playerId === self.authInformation.loginId()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Don’t add any new reference to self. Use this and change functions to arrow style

if (p.IsSitoutStatus()) {
self.actionBlock.processing(false);
}
Expand Down