Skip to content

Commit

Permalink
feat: make completion fragments user-specific
Browse files Browse the repository at this point in the history
  • Loading branch information
ssube committed Dec 31, 2018
1 parent d829d65 commit f636374
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 16 deletions.
12 changes: 8 additions & 4 deletions src/entity/base/BaseCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,15 @@ export abstract class BaseCommand extends DataEntity<Array<string>> {
}

public getHeadOrNumber(key: string, defaultValue: number): number {
const value = Number(this.getHead(key));
if (isNaN(value)) {
return defaultValue;
if (this.has(key)) {
const value = Number(this.get(key));
if (isNaN(value)) {
return defaultValue;
} else {
return value;
}
} else {
return value;
return defaultValue;
}
}

Expand Down
3 changes: 1 addition & 2 deletions src/listener/ExpressListener.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@ import { Counter, Registry } from 'prom-client';
import { Connection, Repository } from 'typeorm';

import { BotServiceOptions } from 'src/BotService';
import { Token, JwtFields } from 'src/entity/auth/Token';
import { JwtFields, Token } from 'src/entity/auth/Token';
import { Context, ContextOptions } from 'src/entity/Context';
import { Message } from 'src/entity/Message';
import { NotInitializedError } from 'src/error/NotInitializedError';
import { Listener, ListenerData } from 'src/listener/Listener';
import { SessionListener } from 'src/listener/SessionListener';
import { ServiceModule } from 'src/module/ServiceModule';
Expand Down
11 changes: 1 addition & 10 deletions src/listener/SessionListener.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { isNil } from 'lodash';

import { BotServiceOptions } from 'src/BotService';
import { User } from 'src/entity/auth/User';
import { Message } from 'src/entity/Message';
Expand Down Expand Up @@ -40,13 +38,6 @@ export abstract class SessionListener<TData extends ListenerData> extends BaseLi

public async getSession(uid: string): Promise<Session | undefined> {
const now = this.clock.getSeconds();
const session = this.sessions.get(uid);

// session must have been created in the past and expire in the future
if (isNil(session) || session.createdAt.valueOf() >= now || session.expiresAt.valueOf() <= now) {
return;
} else {
return session;
}
return this.sessions.get(uid);
}
}
19 changes: 19 additions & 0 deletions src/migration/0001546283532-FragmentUser.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { MigrationInterface, QueryRunner, TableColumn } from 'typeorm';

import { TABLE_FRAGMENT } from 'src/entity/Fragment';

const COLUMN_USER = new TableColumn({
name: 'userId',
type: 'varchar',
});

export class FragmentUser0001546283532 implements MigrationInterface {
public async up(query: QueryRunner): Promise<void> {
await query.clearTable(TABLE_FRAGMENT);
await query.addColumn(TABLE_FRAGMENT, COLUMN_USER);
}

public async down(query: QueryRunner): Promise<void> {
await query.dropColumn(TABLE_FRAGMENT, COLUMN_USER);
}
}
2 changes: 2 additions & 0 deletions src/module/MigrationModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { CreateToken0001544317462 } from 'src/migration/0001544317462-CreateToke
import { KeywordCommand0001545509108 } from 'src/migration/0001545509108-KeywordCommand';
import { CreateTick0001546063195 } from 'src/migration/0001546063195-CreateTick';
import { Dates0001546236755 } from 'src/migration/0001546236755-Dates';
import { FragmentUser0001546283532 } from 'src/migration/0001546283532-FragmentUser';

export class MigrationModule extends Module {
public async configure(options: ModuleOptions): Promise<void> {
Expand All @@ -31,6 +32,7 @@ export class MigrationModule extends Module {
KeywordCommand0001545509108,
CreateTick0001546063195,
Dates0001546236755,
FragmentUser0001546283532,
]);
}
}

0 comments on commit f636374

Please sign in to comment.