much more functioning
This commit is contained in:
parent
d1a78e057b
commit
cde18a28b3
@ -56,7 +56,9 @@ export class AutoVerifier<T> {
|
||||
for (let trustedElement of trustedResult) {
|
||||
let primaryElement = primaryResult.find(primaryElement => primaryElement.id === trustedElement.id);
|
||||
if (primaryElement) {
|
||||
changes.updated.push({ oldDataPoint: primaryElement, newDataPoint: trustedElement });
|
||||
if (!primaryElement.equals(trustedElement)) {
|
||||
changes.updated.push({ oldDataPoint: primaryElement, newDataPoint: trustedElement });
|
||||
}
|
||||
} else {
|
||||
changes.added.push(trustedElement);
|
||||
}
|
||||
@ -133,10 +135,10 @@ export class AutoVerifier<T> {
|
||||
// You CAN safely call this while another fetch is going on! How convenient
|
||||
unverify(): void {
|
||||
if (this.primaryPromise) {
|
||||
this.primaryPromise.catch((e) => { console.warn('caught unverified promise', e); });
|
||||
this.primaryPromise.catch((e) => { console.warn('caught unverified primary promise', e); });
|
||||
}
|
||||
if (this.trustedPromise) {
|
||||
this.trustedPromise.catch((e) => { console.warn('caught unverified promise', e); });
|
||||
this.trustedPromise.catch((e) => { console.warn('caught unverified trusted promise', e); });
|
||||
}
|
||||
this.primaryPromise = null;
|
||||
this.trustedPromise = null;
|
||||
@ -150,9 +152,6 @@ export class AutoVerifier<T> {
|
||||
return await new Promise<T | null>(async (resolve: (result: T | null) => void, reject: (error: Error) => void) => {
|
||||
let resolved = false;
|
||||
try {
|
||||
let origTrustedStatus = this.trustedStatus;
|
||||
let origTrustedPromise = this.trustedPromise;
|
||||
|
||||
if (this.primaryPromise === null) {
|
||||
this.primaryPromise = this.primaryFunc();
|
||||
}
|
||||
|
@ -151,8 +151,8 @@ export class Message implements WithEquals<Message> {
|
||||
|
||||
return new Message(
|
||||
dataMessage.id,
|
||||
{ id: dataMessage.member_id },
|
||||
{ id: dataMessage.channel_id },
|
||||
{ id: dataMessage.member_id },
|
||||
new Date(dataMessage.sent_dtg),
|
||||
dataMessage.text ?? null,
|
||||
dataMessage.resource_id ?? null,
|
||||
@ -179,7 +179,7 @@ export class Message implements WithEquals<Message> {
|
||||
this.id === other.id &&
|
||||
this.member.id === other.member.id &&
|
||||
this.channel.id === other.channel.id &&
|
||||
this.sent === other.sent &&
|
||||
this.sent.getTime() === other.sent.getTime() &&
|
||||
this.resourceId === other.resourceId &&
|
||||
this.resourceName === other.resourceName &&
|
||||
this.resourceWidth === other.resourceWidth &&
|
||||
|
@ -1,3 +1,8 @@
|
||||
import * as electronRemote from '@electron/remote';
|
||||
const electronConsole = electronRemote.getGlobal('console') as Console;
|
||||
import Logger from '../../logger/logger';
|
||||
const LOG = Logger.create(__filename, electronConsole);
|
||||
|
||||
import { Changes, Channel, GuildMetadata, Member, Message, Resource, Token } from './data-types';
|
||||
import { AsyncFetchable, Fetchable, Lackable, Conflictable } from './guild-types';
|
||||
import { AutoVerifier, AutoVerifierChangesType } from './auto-verifier';
|
||||
|
@ -278,13 +278,31 @@ export default class CombinedGuild extends EventEmitter<Connectable & Conflictab
|
||||
return await this.fetchable.fetchChannels();
|
||||
}
|
||||
async fetchMessagesRecent(channelId: string, number: number): Promise<Message[]> {
|
||||
return await this.fetchable.fetchMessagesRecent(channelId, number);
|
||||
let members = await this.grabRAMMembersMap();
|
||||
let channels = await this.grabRAMChannelsMap();
|
||||
let messages = await this.fetchable.fetchMessagesRecent(channelId, number);
|
||||
for (let message of messages) {
|
||||
message.fill(members, channels);
|
||||
}
|
||||
return messages;
|
||||
}
|
||||
async fetchMessagesBefore(channelId: string, messageId: string, number: number): Promise<Message[]> {
|
||||
return await this.fetchable.fetchMessagesBefore(channelId, messageId, number);
|
||||
let members = await this.grabRAMMembersMap();
|
||||
let channels = await this.grabRAMChannelsMap();
|
||||
let messages = await this.fetchable.fetchMessagesBefore(channelId, messageId, number);
|
||||
for (let message of messages) {
|
||||
message.fill(members, channels);
|
||||
}
|
||||
return messages;
|
||||
}
|
||||
async fetchMessagesAfter(channelId: string, messageId: string, number: number): Promise<Message[]> {
|
||||
return await this.fetchable.fetchMessagesAfter(channelId, messageId, number);
|
||||
let members = await this.grabRAMMembersMap();
|
||||
let channels = await this.grabRAMChannelsMap();
|
||||
let messages = await this.fetchable.fetchMessagesAfter(channelId, messageId, number);
|
||||
for (let message of messages) {
|
||||
message.fill(members, channels);
|
||||
}
|
||||
return messages;
|
||||
}
|
||||
async fetchResource(resourceId: string): Promise<Resource> {
|
||||
return await this.fetchable.fetchResource(resourceId);
|
||||
|
@ -1,3 +1,8 @@
|
||||
import * as electronRemote from '@electron/remote';
|
||||
const electronConsole = electronRemote.getGlobal('console') as Console;
|
||||
import Logger from '../../logger/logger';
|
||||
const LOG = Logger.create(__filename, electronConsole);
|
||||
|
||||
import { AsyncFetchable, AsyncLackable } from "./guild-types";
|
||||
import { Channel, GuildMetadata, Member, Message, Resource, Token } from "./data-types";
|
||||
|
||||
@ -13,8 +18,7 @@ export default class PersonalDBGuild implements AsyncFetchable, AsyncLackable {
|
||||
// Fetched Methods
|
||||
|
||||
async fetchMetadata(): Promise<GuildMetadata | null> {
|
||||
// TODO
|
||||
return null;
|
||||
return this.db.fetchGuild(this.guildId);
|
||||
}
|
||||
|
||||
async fetchMembers(): Promise<Member[] | null> {
|
||||
@ -48,47 +52,60 @@ export default class PersonalDBGuild implements AsyncFetchable, AsyncLackable {
|
||||
// Lacking Methods (resolving differences)
|
||||
|
||||
async handleMetadataChanged(changedMetaData: GuildMetadata): Promise<void> {
|
||||
LOG.debug('personal metadata changed', { changedMetaData });
|
||||
(async () => { await this.db.updateGuildName(this.guildId, changedMetaData.name); })();
|
||||
(async () => { await this.db.updateGuildIcon(this.guildId, changedMetaData.iconResourceId); })();
|
||||
}
|
||||
|
||||
async handleMembersAdded(addedMembers: Member[]): Promise<void> {
|
||||
LOG.debug(addedMembers.length + ' personal members added');
|
||||
await this.db.addMembers(this.guildId, addedMembers);
|
||||
}
|
||||
async handleMembersChanged(changedMembers: Member[]): Promise<void> {
|
||||
LOG.debug(changedMembers.length + ' personal members changed');
|
||||
await this.db.updateMembers(this.guildId, changedMembers);
|
||||
}
|
||||
async handleMembersDeleted(deletedMembers: Member[]): Promise<void> {
|
||||
LOG.debug(deletedMembers.length + ' personal members deleted');
|
||||
await this.db.deleteMembers(this.guildId, deletedMembers);
|
||||
}
|
||||
|
||||
async handleChannelsAdded(addedChannels: Channel[]): Promise<void> {
|
||||
LOG.debug(addedChannels.length + ' personal channels added');
|
||||
await this.db.addChannels(this.guildId, addedChannels);
|
||||
}
|
||||
async handleChannelsChanged(changedChannels: Channel[]): Promise<void> {
|
||||
LOG.debug(changedChannels.length + ' personal channels changed');
|
||||
await this.db.updateChannels(this.guildId, changedChannels);
|
||||
}
|
||||
async handleChannelsDeleted(deletedChannels: Channel[]): Promise<void> {
|
||||
LOG.debug(deletedChannels.length + ' personal channels deleted');
|
||||
await this.db.deleteChannels(this.guildId, deletedChannels);
|
||||
}
|
||||
|
||||
async handleMessagesAdded(addedMessages: Message[]): Promise<void> {
|
||||
LOG.debug(addedMessages.length + ' personal messages added');
|
||||
await this.db.addMessages(this.guildId, addedMessages);
|
||||
}
|
||||
async handleMessagesChanged(changedMessages: Message[]): Promise<void> {
|
||||
LOG.debug(changedMessages.length + ' personal messages changed');
|
||||
await this.db.updateMessages(this.guildId, changedMessages);
|
||||
}
|
||||
async handleMessagesDeleted(deletedMessages: Message[]): Promise<void> {
|
||||
LOG.debug(deletedMessages.length + ' personal messages deleted');
|
||||
await this.db.deleteMessages(this.guildId, deletedMessages);
|
||||
}
|
||||
|
||||
async handleResourceAdded(addedResource: Resource): Promise<void> {
|
||||
//LOG.debug('personal resoprces added', { addedResource });
|
||||
await this.db.addResources(this.guildId, [ addedResource ]);
|
||||
}
|
||||
async handleResourceChanged(changedResource: Resource): Promise<void> {
|
||||
//LOG.debug('personal resoprces changed', { changedResource });
|
||||
await this.db.updateResources(this.guildId, [ changedResource ]);
|
||||
}
|
||||
async handleResourceDeleted(deletedResource: Resource): Promise<void> {
|
||||
//LOG.debug('personal resoprces deleted', { deletedResource });
|
||||
await this.db.deleteResources(this.guildId, [ deletedResource ]);
|
||||
}
|
||||
|
||||
|
@ -237,7 +237,7 @@ export default class Logger {
|
||||
// Use the source map to create a typescript version of the stack
|
||||
// This will be printed asynchronously because SourceMapConsumer
|
||||
} else {
|
||||
let s = util.inspect(data, { colors: true, depth: 2 });
|
||||
let s = util.inspect(data, { colors: true, depth: 5 });
|
||||
s = s.split('\n').map(o => `${prefix}$ ${o}`).join('\n');
|
||||
out += s;
|
||||
}
|
||||
|
@ -60,8 +60,7 @@ export default class DB {
|
||||
static async getMemberInfo(publicKey: crypto.KeyObject): Promise<any> {
|
||||
let der = publicKey.export({ type: 'spki', format: 'der' });
|
||||
|
||||
let der_start = der.subarray(0, 10);
|
||||
LOG.silly(`searching for public key (der starts with ${LOG.inspect(der_start)})`);
|
||||
LOG.silly(`searching for public key (der hash: ${LOG.inspect(crypto.createHash('sha256').update(der).digest().toString('hex'))})`);
|
||||
|
||||
let result = await db.query('SELECT "id" AS member_id, "guild_id" FROM "members" WHERE "public_key"=$1', [ der ]);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user