Skip to content

Commit

Permalink
yoyoyo
Browse files Browse the repository at this point in the history
  • Loading branch information
Trevor Johnston committed Nov 18, 2016
1 parent 96b39f7 commit 7200c5d
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 21 deletions.
4 changes: 2 additions & 2 deletions src/cca/model/server.ts
Expand Up @@ -13,6 +13,6 @@ export type AccessCode = string;

export interface ServerRepository {
addServer(code: AccessCode): Promise<Server>
// Fetch the list of servers from storage.
getSavedServers(): Promise<Server[]>;
// Fetches the list of servers known to this repository.
getServers(): Promise<Server[]>;
}
18 changes: 7 additions & 11 deletions src/cca/scripts/uproxy_server.ts
Expand Up @@ -38,12 +38,10 @@ export class UproxyServer implements Server {
}

// Name by which servers are saved to storage.
const SERVERS_STORAGE_KEY = 'saved-servers';
const SERVERS_STORAGE_KEY = 'servers';

// Type of the object placed, in serialised form, in storage.
interface SavedServers {
servers: { [id: string]: SavedServer }
}
type SavedServers = { [id: string]: SavedServer };

// A server as saved to storage.
interface SavedServer {
Expand All @@ -52,30 +50,28 @@ interface SavedServer {

// Maintains a persisted set of servers and liases with the core.
export class UproxyServerRepository implements ServerRepository {
// core must already be logged into social networks.
constructor(
private storage: Storage,
// Must already be logged into social networks.
private core: CoreConnector,
private vpnDevice: VpnDevice) { }

public getSavedServers() {
const servers = this.loadServers().servers;
public getServers() {
const servers = this.loadServers();
return Promise.all(Object.keys(servers).map((host) => {
return this.notifyCoreOfServer(servers[host].cloudTokens);
}));
}

private loadServers(): SavedServers {
return JSON.parse(this.storage.getItem(SERVERS_STORAGE_KEY)) || {
servers: {}
};
return JSON.parse(this.storage.getItem(SERVERS_STORAGE_KEY)) || {};
}

// Saves a server to storage, merging it with any already found there.
// Returns true if the server was not already in storage.
private saveServer(cloudTokens: cloud_social_provider.Invite) {
const savedServers = this.loadServers();
savedServers.servers[cloudTokens.host] = {
savedServers[cloudTokens.host] = {
cloudTokens: cloudTokens
};
this.storage.setItem(SERVERS_STORAGE_KEY, JSON.stringify(savedServers));
Expand Down
10 changes: 5 additions & 5 deletions src/cca/ui_components/server_list.ts
Expand Up @@ -55,9 +55,9 @@ export class ServerListPage {
private addButton: HTMLButtonElement;
private entryList: HTMLDivElement;

// Hostnames of servers currently displayed.
// Servers currently shown, indexed by hostname.
// Used to prevent listing servers more than once.
private activeServerIds: String[] = [];
private activeServerIds = new Set<String>();

// Parameters:
// - root: Where to attach the ServerListPage to
Expand All @@ -73,7 +73,7 @@ export class ServerListPage {
this.pressAddServer();
});

servers.getSavedServers().then((restoredServers) => {
servers.getServers().then((restoredServers) => {
restoredServers.forEach((server) => {
this.addServer(server);
});
Expand All @@ -92,11 +92,11 @@ export class ServerListPage {
}

private addServer(server: Server) {
if (this.activeServerIds.indexOf(server.getIpAddress()) > -1) {
if (this.activeServerIds.has(server.getIpAddress())) {
return;
}
this.activeServerIds.push(server.getIpAddress());

this.activeServerIds.add(server.getIpAddress());
const entryElement = this.root.ownerDocument.createElement('div');
this.entryList.appendChild(entryElement);
return new ServerEntryComponent(entryElement, server);
Expand Down
4 changes: 2 additions & 2 deletions src/generic_core/social.ts
Expand Up @@ -82,10 +82,10 @@ export function initializeNetworks() :void {
*/
export function getNetwork(networkName :string, userId :string) :social.Network {
if (!(networkName in networks)) {
throw new Error('unknown network ' + networkName);
throw new Error('unknown network ${networkName}');
}
if (!(userId in networks[networkName])) {
throw new Error(userId + ' is not logged into network ' + networkName);
throw new Error('${userId} is not logged into network ${networkName}');
}
return networks[networkName][userId];
}
Expand Down
3 changes: 2 additions & 1 deletion tsconfig.json
Expand Up @@ -9,8 +9,9 @@
"lib": [
"dom",
"es5",
"es2015.promise",
"es2015.collection",
"es2015.iterable",
"es2015.promise",
"scripthost"
]
},
Expand Down

0 comments on commit 7200c5d

Please sign in to comment.