This subtask is for developing the underlying notification data and the methods for importing and refreshing that data. There will be nothing to QA against it until we build UI utilizing this data, so this task can move to PM signoff once development is complete.
The API call to fetch data is here: https://en.wikipedia.org/w/api.php?action=query&meta=notifications¬wikis=enwiki¬limit=max¬prop=count|list¬format=model
We must make the corresponding call (change subdomain and notwikis param) for each of the user's app languages, plus common others like `wikidatawiki`, `commonswiki`.
1. Give controller the ability to import notification history, which gathers up these wikis, makes the all the calls concurrently, and continues paging for each until pages have exhausted as indicated by `continue` in the response. For each response, create a Core Data object and save on a background managed object context.
2. Also give controller the ability to refresh this data. Fetch this data again, continuing to page until the oldest object returned already exists in the database. That indicates we have gathered all new information thus can stop the refresh.
3. If user changes their app preferred languages, detect which one would be new and never imported, and kick off the import process on that wiki project.
4. Guard against steps 1, 2 and 3 from executing multiple times back to back. Only one import or refresh process should happen at a time. Also guard against the import processing occurring unnecessarily for a project we have already imported. Persist which projects have been imported, and only allow refreshing once they are imported.
5. Allow steps in 1, 2, and 3 to continue importing or refreshing where they left off if the app gets terminated mid-processing. This might involve persisting continue identifiers.
6. Bulk delete these notifications from Core Data upon logout, as well as any persisted flags we need to keep track of like `continue` IDs.
7. Add separate ability sync read and unread flags periodically. There's a chance someone could flip a read flag for a notification deep in history that we have already imported, and thus may not touch again in the refresh step. For this step, only fetch unread notifications from each project, be sure unread flag is updated in the database. Pull any local unread notification that did **not** return from this fetch and flip to read.
Other useful links:
Notifications API documentation: //www.mediawiki.org/wiki/Notifications/API
Original spike findings: https://phabricator.wikimedia.org/T284239
**Sidenote**: We also might need to consider making an initial call to gather additional wikis of interest here:
https://{primary language subdomain}.wikipedia.org/w/api.php?action=query&meta=notifications¬wikis={primary language wiki}¬limit=1¬crosswikisummary=1
The summary object has an ID of -1 and will return an object of foreign wikis that contain unread notifications.
Example summary object:
```
{
"wiki": "enwiki",
"id": -1,
"type": "foreign",
"category": "other",
"section": "all",
"timestamp": {
"utciso8601": "2021-07-21T17:17:38Z",
"utcunix": 1626887858,
"unix": "1626887858",
"utcmw": "20210721171738",
"mw": "20210721171738",
"date": "21 July"
},
"agent": {
"id": 35904678,
"name": "TSevener (WMF)"
},
"targetpages": [],
"*": {
"header": "More notifications from 2 other wikis",
"compactHeader": "More notifications from 2 other wikis",
"body": "MediaWiki and Test Wikipedia",
"icon": "global",
"links": {
"primary": [],
"secondary": []
},
"iconUrl": "/w/extensions/Echo/modules/icons/global-progressive.svg"
},
"count": 2,
"sources": {
"mediawikiwiki": {
"title": "MediaWiki",
"url": "https://www.mediawiki.org/w/api.php",
"base": "https://www.mediawiki.org/wiki/$1",
"ts": "2021-07-21T17:17:38Z"
},
"testwiki": {
"title": "Test Wikipedia",
"url": "https://test.wikipedia.org/w/api.php",
"base": "https://test.wikipedia.org/wiki/$1",
"ts": "2021-07-19T16:28:52Z"
}
}
},
```