Expand all

mw.echo.api.EchoApi

Constructor

new mw.echo.api.EchoApi(config) #

A class defining Echo API instructions and network operations

Parameters:

Name Type Description
config Object

Configuration options

Source:
A class defining Echo API instructions and network operations

Methods

convertFiltersToAPIParams([filterObject]) → {Object} #

Convert the filter object to the relevant API parameters.

Parameters:

Name Type Attributes Description
filterObject Object optional

The filter object

Properties:
Name Type Attributes Description
continue string optional

A continue variable defining the offset to fetch notifications

readState string optional

Notification read state, 'all', 'read' or 'unread'

unreadFirst boolean optional

Fetch unread notifications first in the sorting order.

bundle boolean optional

Bundle local notifications

titles string | Array.<string> optional

Requested titles. To request notifications with no title, use null (standalone or as an array element).

Source:

Returns:

API parameter definitions to override

Type
Object
Convert the filter object to the relevant API parameters.

fetchFilteredNotifications(type, [source], [filters]) → {jQuery.Promise} #

Fetch notifications from a given source with given filters

Parameters:

Name Type Attributes Description
type string

Notification type to fetch: 'alert', 'message', or 'all'

source string optional

The source from which to fetch the notifications. If not given, the local notifications will be fetched.

filters Object optional

Filter values

Source:

Returns:

Promise that is resolved with all notifications for the requested types.

Type
jQuery.Promise
Fetch notifications from a given source with given filters

fetchNotificationGroups(sourceArray, type, bundle) → {jQuery.Promise} #

Fetch notifications from several sources

Parameters:

Name Type Description
sourceArray Array.<string>

An array of sources to fetch from the group

type string

Notification type

bundle boolean

Bundle local notifications

Source:

Returns:

A promise that resolves with an object that maps wiki names to an array of their items' API data objects.

Type
jQuery.Promise
Fetch notifications from several sources

fetchNotifications(type, [sources], [isForced], [filters]) → {jQuery.Promise} #

Fetch notifications from the server based on type

Parameters:

Name Type Attributes Description
type string

Notification type to fetch: 'alert', 'message', or 'all'

sources string | Array.<string> optional

The source from which to fetch the notifications. If not given, the local notifications will be fetched.

isForced boolean optional

Force a refresh on the fetch notifications promise

filters Object optional

Filter values

Source:

Returns:

Promise that is resolved with all notifications for the requested types.

Type
jQuery.Promise
Fetch notifications from the server based on type

fetchNotificationsFromRemoteSource(type, [source], [isForced], [filters]) → {jQuery.Promise} #

Fetch remote notifications from a given source. This skips the local fetching that is usually done and calls the remote wiki directly.

Parameters:

Name Type Attributes Description
type string

Notification type to fetch: 'alert', 'message', or 'all'

source string | Array.<string> optional

The source from which to fetch the notifications. If not given, the local notifications will be fetched.

isForced boolean optional

Force a refresh on the fetch notifications promise

filters Object optional

Filter values

Source:

Returns:

Promise that is resolved with all notifications for the requested types.

Type
jQuery.Promise
Fetch remote notifications from a given source.

fetchUnreadCount(source, type, [localOnly]) → {jQuery.Promise} #

Fetch the number of unread notifications for the given type in the given source.

Parameters:

Name Type Attributes Description
source string

Notifications source

type string

Notification type

localOnly boolean optional

Fetches only the count of local notifications, and ignores cross-wiki notifications.

Source:

Returns:

A promise that is resolved with the number of unread notifications for the given type and source.

Type
jQuery.Promise

Fetch the number of unread notifications for the given type in the given source.

fetchUnreadNotificationPages([sources]) → {jQuery.Promise} #

Fetch all pages with unread notifications in them per wiki

Parameters:

Name Type Attributes Default Description
sources Array.<string> optional
all

Requested sources

Source:

Returns:

Promise that is resolved with an object of pages with the number of unread notifications per wiki

Type
jQuery.Promise
Fetch all pages with unread notifications in them per wiki

getFetchNotificationPromise(source, type) → {jQuery.Promise} #

Get the fetch notifications promise active for the current source and type.

Parameters:

Name Type Description
source string

Notification source.

type string

Notification type

Source:

Returns:

Promise that is resolved when notifications are fetched from the API.

Type
jQuery.Promise
Get the fetch notifications promise active for the current source and type.

getLimit() → {number} #

Get the set limit for fetching notifications per request

Source:

Returns:

Limit of notifications per request

Type
number
Get the set limit for fetching notifications per request

isFetchingErrorState(source, type) → {boolean} #

Check whether the API promise for fetch notification is in an error state for the given source and notification type.

Parameters:

Name Type Description
source string

Notification source.

type string

Notification type

Source:

Returns:

The API response for fetching notification has resolved in an error state, or is rejected.

Type
boolean

Check whether the API promise for fetch notification is in an error state for the given source and notification type.

markAllRead(source, type) → {jQuery.Promise} #

Mark all notifications for a given type as read in the given source.

Parameters:

Name Type Description
source string

Symbolic name of notifications source

type string

Notifications type

Source:

Returns:

A promise that is resolved when the operation is complete, with the number of unread notifications still remaining for that type in the given source

Type
jQuery.Promise
Mark all notifications for a given type as read in the given source.

markItemsRead(itemIds, source, [isRead]) → {jQuery.Promise} #

Mark items as read in the API.

Parameters:

Name Type Attributes Description
itemIds Array.<string>

An array of item IDs to mark as read

source string

The source that these items belong to

isRead boolean optional

The read state of the item; true for marking the item as read, false for marking the item as unread

Source:

Returns:

A promise that is resolved when the operation is complete, with the number of unread notifications still remaining for that type in the given source

Type
jQuery.Promise
Mark items as read in the API.

queryAPI(params, [source]) → {jQuery.Promise} #

Send a general query to the API. This is mostly for dynamic actions where other extensions may set up API actions that are unique and unanticipated.

Parameters:

Name Type Attributes Default Description
params Object

API parameters

source string optional
'local'

Requested source to query

Source:

Returns:

Promise that is resolved when the action is complete

Type
jQuery.Promise
Send a general query to the API.

registerForeignSources(sources, [unreadOnly], [limit]) #

Register a set of foreign sources.

Parameters:

Name Type Attributes Default Description
sources Object

Object mapping source names to config objects

unreadOnly boolean optional
false

Fetch only unread notifications

limit number optional

Specific limit of notifications. Defaults to the default limit stated in the class.

Source:
Register a set of foreign sources.

registerLocalSources(sources) #

Register a set of local sources.

Parameters:

Name Type Description
sources Array.<string>

An array of source names

Source:
Register a set of local sources.

updateSeenTime([type], [source]) → {jQuery.Promise} #

Update the seenTime property for the given type. We only need to update this in a single source for the seenTime to be updated globally - but we will let the consumer of this method override the choice of which source to update.

Parameters:

Name Type Attributes Default Description
type string optional
'alert,message'

Notification type

source string optional
'local'

Notification source

Source:

Returns:

A promise that is resolved when the operation is complete.

Type
jQuery.Promise
Update the seenTime property for the given type.