Merge pull request #1224 from msgmaxim/fix-retrieve

Fix retrieving with pubkey object
pull/1227/head
Maxim Shishmarev 5 years ago committed by GitHub
commit 2f47690ead
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -151,13 +151,6 @@ async function handleRequestDetail(
envelope.senderIdentity = senderIdentity; envelope.senderIdentity = senderIdentity;
} }
// TODO: 'source' is almost certainly undefined here (sealed sender),
// so this check is not appropriate here
const blocked = await isBlocked(envelope.source);
if (blocked) {
return;
}
envelope.id = envelope.serverGuid || window.getGuid(); envelope.id = envelope.serverGuid || window.getGuid();
envelope.serverTimestamp = envelope.serverTimestamp envelope.serverTimestamp = envelope.serverTimestamp
? envelope.serverTimestamp.toNumber() ? envelope.serverTimestamp.toNumber()

@ -347,7 +347,7 @@ export async function storeOnNode(
export async function retrieveNextMessages( export async function retrieveNextMessages(
nodeData: Snode, nodeData: Snode,
lastHash: string, lastHash: string,
pubkey: PubKey pubkey: string
): Promise<Array<any>> { ): Promise<Array<any>> {
const params = { const params = {
pubKey: pubkey, pubKey: pubkey,

@ -56,11 +56,13 @@ export class SwarmPolling {
this.groupPubkeys.push(pubkey); this.groupPubkeys.push(pubkey);
} }
public addPubkey(pubkey: PubKey) { public addPubkey(pk: PubKey | string) {
const pubkey = PubKey.cast(pk);
this.pubkeys.push(pubkey); this.pubkeys.push(pubkey);
} }
public removePubkey(pubkey: PubKey) { public removePubkey(pk: PubKey | string) {
const pubkey = PubKey.cast(pk);
this.pubkeys = this.pubkeys.filter(key => !pubkey.isEqual(key)); this.pubkeys = this.pubkeys.filter(key => !pubkey.isEqual(key));
this.groupPubkeys = this.groupPubkeys.filter(key => !pubkey.isEqual(key)); this.groupPubkeys = this.groupPubkeys.filter(key => !pubkey.isEqual(key));
} }
@ -68,9 +70,9 @@ export class SwarmPolling {
protected async pollOnceForKey(pubkey: PubKey, isGroup: boolean) { protected async pollOnceForKey(pubkey: PubKey, isGroup: boolean) {
// NOTE: sometimes pubkey is string, sometimes it is object, so // NOTE: sometimes pubkey is string, sometimes it is object, so
// accept both until this is fixed: // accept both until this is fixed:
const pk = (pubkey.key ? pubkey.key : pubkey) as string; const pkStr = pubkey.key;
const snodes = await getSnodesFor(pk); const snodes = await getSnodesFor(pkStr);
// Select nodes for which we already have lastHashes // Select nodes for which we already have lastHashes
const alreadyPolled = snodes.filter( const alreadyPolled = snodes.filter(
@ -106,7 +108,7 @@ export class SwarmPolling {
const newMessages = await this.handleSeenMessages(messages); const newMessages = await this.handleSeenMessages(messages);
newMessages.forEach((m: Message) => { newMessages.forEach((m: Message) => {
const options = isGroup ? { conversationId: pk } : {}; const options = isGroup ? { conversationId: pkStr } : {};
processMessage(m.data, options); processMessage(m.data, options);
}); });
} }
@ -119,11 +121,11 @@ export class SwarmPolling {
): Promise<Array<any>> { ): Promise<Array<any>> {
const edkey = node.pubkey_ed25519; const edkey = node.pubkey_ed25519;
const pkStr = pubkey.key ? pubkey.key : pubkey; const pkStr = pubkey.key;
const prevHash = await this.getLastHash(edkey, pkStr as string); const prevHash = await this.getLastHash(edkey, pkStr);
const messages = await retrieveNextMessages(node, prevHash, pubkey); const messages = await retrieveNextMessages(node, prevHash, pkStr);
if (!messages.length) { if (!messages.length) {
return []; return [];
@ -197,7 +199,7 @@ export class SwarmPolling {
hash: string, hash: string,
expiration: number expiration: number
): Promise<void> { ): Promise<void> {
const pkStr = (pubkey.key ? pubkey.key : pubkey) as string; const pkStr = pubkey.key;
await Data.updateLastHash({ await Data.updateLastHash({
convoId: pkStr, convoId: pkStr,

Loading…
Cancel
Save