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`, plus common others (`wikidatawiki` & `commonswiki`).
1. Give controller the ability to import notification history, which gathers up these wikis[x] Initial work - new database migration, makes the all the calls concurrentlysome code cleanup, and continues paging for each until pages have exhausted as indicated by `continue` in the response.removing legacy polling, For each responsecapturing additional notifications data into managed object, create a Core Data object and save on a background managed object contextfetching first page.
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[ ] Instantiate fully realized cell view model from RemoteNotification managed object properties.
3[ ] Refactor fetching first page operation into one import operation, and another refresh operation. Post NSNotifications for badging and app center status label to react to. If user changes their app preferred languages,Importing will need to continue paging until all pages have been exhausted as indicated by `continue` in response. detect which one would be new and never imported,Refresh operation will need to continue paging until the oldest object returned already exists in the database. and kick off the import process on that wiki projectUse a background managed object context for saving these notifications.
4[ ] Fetch additional unread notifications from non-app languages. Guard against steps 1First make fetch call with `notcrosswikisummary` param (see "API note" section below), 2 and 3then fetch unread notifications from executing multiple times back to backach new project from the `crosswikisummary` object. Only one import or refresh process should happen at a time.(TBD) Note we might need to filter these by recognized language types, Also guard againstso we aren't importing notifications from the import processing occurring unnecessarily for a project we have already importedrarer `notwikis` [[ https://www.mediawiki.org/wiki/Notifications/API | projects ]]. Persist which projects have been imported,) (Note: we do not need to fetch read history on these types of notifications. and only allow refreshing once they are imported.Otherwise that would complicate when exactly to trigger an import since any language with unread notifications could bubble up at any time.)
5. Allow steps in 1, 2[ ] Vend proper `NSFetchedResultsControllers` or `NSPredicates` for read/unread/all filtering, and 3 to continue importing or refreshing where they left off if the app gets terminated mid-processing.project inbox filtering, This might involve persisting continue identifiersand (future) notification types filtering.
6. Bulk delete these notifications from Core Data upon logout[ ] If user changes app preferred languages and adds one, as well as any persisted flags we need to keep track of like `continue` IDsdetect which ones are new and kick off import process on new languages.
7.[ ] If user changes app preferred languages and deletes one, clean out data in database housekeeper.
[ ] Importing and Refresh operations 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.
[ ] Allow import operation to continue importing where it left off if the app gets terminated mid-import. This might involve persisting continue identifiers.
[ ] Bulk delete all notifications from Core Data upon logout, as well as any other persisted data we needed to keep track of like `continue` IDs.
[ ] (optional) 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, we could 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. This is a nice-to-have, Pull any local unread notification that did **not** return from this fetch and flip to readconfirmed history doesn't need to be totally in sync at all times.
====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:====API note====
NotCrossWikiSummary call to make to gather additional unread notifications of interest.
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"
}
}
},
```