(inc, syncType)
| 571 | // the changes are pushed to the sync through there. |
| 572 | // |
| 573 | async sync(inc, syncType) { |
| 574 | let updated = false, follows = [] |
| 575 | // console.log(inc) |
| 576 | if ('follows' in inc) { |
| 577 | if ('index' in inc) |
| 578 | Object.assign(this.index, inc.index) |
| 579 | |
| 580 | let ids = Object.keys(inc.follows) |
| 581 | this.noteUpdate(ids, false) |
| 582 | for (let id of ids) { |
| 583 | try { |
| 584 | let incoming = inc.follows[id], current = this.findFeed(id, incoming.url), notify = false |
| 585 | if (incoming.deleted) { |
| 586 | if (current) { |
| 587 | delete this.all[id] |
| 588 | this.update({op: 'remove', path: `/all/${id}`}) |
| 589 | this.deleteFile(`/feeds/${id}.json`) |
| 590 | } |
| 591 | } else { |
| 592 | if (incoming.url) { |
| 593 | if (!(id.match && id.match(/-[0-9a-f]{1,8}$/))) { |
| 594 | id = urlToID(urlToNormal(incoming.url)) |
| 595 | } |
| 596 | if (!(id in this.follows)) |
| 597 | this.follows[id] = incoming |
| 598 | if (!current || current.editedAt < incoming.editedAt || !isValidFollow(current)) { |
| 599 | try { |
| 600 | incoming.id = id |
| 601 | await this.refresh(incoming, FETCH_SILENT) |
| 602 | if (syncType === SYNC_EXTERNAL) { |
| 603 | current = this.all[id] |
| 604 | notify = true |
| 605 | } |
| 606 | } catch {} |
| 607 | // catch(msg => console.log(`${incoming.url} is ${msg}`)) |
| 608 | updated = true |
| 609 | } else if (current.editedAt > incoming.editedAt) { |
| 610 | if (syncType !== SYNC_EXTERNAL) { |
| 611 | notify = true |
| 612 | } |
| 613 | } |
| 614 | |
| 615 | if (notify && current) { |
| 616 | follows.push(id) |
| 617 | this.notifyFollow(current) |
| 618 | } |
| 619 | } |
| 620 | } |
| 621 | } finally { |
| 622 | this.noteUpdate([id], true) |
| 623 | } |
| 624 | } |
| 625 | } |
| 626 | |
| 627 | if (syncType === SYNC_FULL) { |
| 628 | for (let id in this.all) { |
| 629 | if (!this.follows[id]) { |
| 630 | follows.push(id) |
nothing calls this directly
no test coverage detected