Suwatte

Progress sync

Report a reading position back to the site, sync the library, and use the correct shape for progress data.

Suwatte has no tracker of its own. A source gives it one. A source that reads a site with accounts can keep the list on that site current.

Five capabilities do this work. Write any of them, or none.

getContentProgress(id)

This method tells the app the position that the site holds. It returns ContentProgressData or null.

async getContentProgress(id: string): Promise<ContentProgressData | null> {
  const entry = await this.fetchListEntry(id);
  if (!entry) return null;

  return {
    readChapters: entry.readChapters,
    status: TrackStatus.READING,
    lastReadDate: entry.updatedAt,
  };
}

The fields

Field Use it when
readChapters The read chapters are not in one continuous block. Give a number[] or a Set<number>.
progress The person read each chapter up to one number. Give that number.
status The list status of the title.
lastReadDate The date of the last read.

The order of precedence

The app decides in this sequence:

  1. If readChapters is there and is not empty, the app uses it. It wins.
  2. If not, and progress is there, the app marks each chapter with a number value that is less than or equal to progress.

The sync only adds. The app does not use this data to mark a chapter as unread. A person who read a chapter keeps that state.

Two examples:

// The history has gaps.
return { readChapters: [1, 2, 5, 8], status: TrackStatus.READING };

// The person read each chapter up to 42.
return { progress: 42, status: TrackStatus.READING };

The progress events

Write any of these methods, and the app tells your source as a person reads:

Method When the app calls it
onChaptersMarked A person marks chapters as read or unread.
onChapterProgress The position in a chapter changes.
onPageRead A person reads a page.

onPageRead happens often. Collect the events and send them together. Do not make one request for each page.

Use these methods to send the position up:

async onChaptersMarked(contentId, chapterIds, completed) {
  if (!completed) return;
  await this.client.post("/list/progress", {
    id: contentId,
    chapter: Math.max(...chapterIds.map(this.chapterNumber)),
  });
}

The tracker form

getTrackEntryPage(id) returns a form. A person uses it to change the list entry: the status, the score and the progress.

async getTrackEntryPage(id: string): Promise<UIForm> {
  const entry = await this.fetchListEntry(id);
  return {
    sections: [
      {
        header: "Tracking",
        views: [
          {
            type: "picker",
            id: "status",
            title: "Status",
            currentValue: entry.status,
            options: [
              { id: "reading", title: "Reading" },
              { id: "completed", title: "Completed" },
              { id: "planning", title: "Planning" },
            ],
          },
          {
            type: "stepper",
            id: "progress",
            title: "Chapters read",
            currentValue: entry.progress,
            lowerBound: 0,
            step: 1,
          },
        ],
      },
    ],
  };
}

The app sends the result to onFormSubmitted.

Library Sync with a review

Write getLibrarySyncEntries, and Library Sync compares the library on the site with the library in Suwatte. The person sees each difference and selects the changes. Nothing changes before the person applies them.

The review shows these groups:

  • Titles that match a title in the library, by ID or by name.
  • Status changes in one direction, from the site or to the site.
  • Conflicts, where both sides changed.
  • Titles that are only on the site, and titles that are only in Suwatte.
  • Titles that a person removed on the site.

getLibrarySyncEntries()

Return the full library of the person. Do not change anything on the site.

async getLibrarySyncEntries(): Promise<LibrarySyncEntries> {
  const entries = await this.fetchWholeList();
  return {
    entries: entries.map((entry) => ({
      item: toItem(entry.series),
      status: toTrackStatus(entry.state),
      statusLabel: entry.stateName,
      otherIds: entry.series.anilistId ? [`anilist:${entry.series.anilistId}`] : [],
      otherTitles: entry.series.alternativeTitles,
    })),
  };
}
Field Necessary Notes
item Yes The title. The app uses its id as the ID on the site.
status No A TrackStatus. If the status on the site has no TrackStatus, do not set it. The app then does not change the flag of that title.
statusLabel No The name of the status on the site, such as “Considering”.
otherIds No The IDs of the title on other services, in the form that sources put in their endpoints, such as anilist:42. The app uses them to match titles.
otherTitles No Other names of the title. The app uses them to suggest matches.

If you leave entries out, set isComplete: false. An example is a setting that hides some titles. The app then does not think that a missing title was removed on the site.

applyLibrarySyncChanges(changes)

Write this method, and the person can send changes to the site. Without it, the review only brings statuses into Suwatte.

async applyLibrarySyncChanges(changes: LibrarySyncChange[]): Promise<LibrarySyncChangeResult> {
  const applied: string[] = [];
  const failed: { id: string; reason?: string }[] = [];
  for (const change of changes) {
    try {
      await this.writeStatus(change.id, change.status, {
        createIfMissing: change.create,
        private: change.isPrivate,
      });
      applied.push(change.id);
    } catch (error) {
      failed.push({ id: change.id, reason: String(error) });
    }
  }
  return { applied, failed };
}

Each change has these fields:

Field What it means
id The ID of the title on the site.
status The TrackStatus to write.
create Add the title to the list on the site if it is not there. If create is false and the title is not there, report a failure.
isPrivate Make a new entry private, if the site has private entries.

Report each id as applied or as failed. The app shows an error for each id that you do not report.

Do not delete entries on the site in this method. The app never asks you to delete one.

Library Sync and older versions of the app

Suwatte 7.2.1 build 13 and later use getLibrarySyncEntries instead of synchronizeLibrary. Keep synchronizeLibrary for older versions of the app. The two methods do not conflict.

Library Sync with a review needs toolchain 1.2.0.

Library sync without a review

synchronizeLibrary(since, added, removed) reconciles the whole library with the site. Older versions of the app use it.

async synchronizeLibrary(since, added, removed): Promise<LibrarySyncResponse> {
  await this.pushChanges(added, removed);
  const remote = await this.fetchListSince(since);
  return { full: remote.map(toItem) };
}

The app calls it on the interval in Settings → Sources → Source Updates → Library Sync Interval. Use since to get only what changed.

Three events tell you about the library as it changes:

  • onContentsAddedToLibrary(ids)
  • onContentsRemovedFromLibrary(ids)
  • onContentsReadingFlagChanged(ids, flag)

Declare your trackers

Declare the trackers that you know:

getConfiguration(): SourceConfiguration {
  return { endpoint: ["mal", "anilist"] };
}

The app matches these names against the endpoints map from getContent. The same values find Linked Titles in a library. This is the most useful thing that you can do for a person who reads from more than one source.

Incognito Mode

With Incognito Mode on, the app does not record progress. Do not try to go around it.