1
0
mirror of https://github.com/matrix-org/matrix-js-sdk.git synced 2026-01-03 23:22:30 +03:00

Cleanup jsdoc. Allow extra query params to be set on requests (for ASes).

This commit is contained in:
Kegan Dougal
2015-07-28 10:57:05 +01:00
parent 14a7ff3e04
commit 9993e5dbed
5 changed files with 43 additions and 19 deletions

View File

@@ -54,14 +54,13 @@ var OLM_ALGORITHM = "m.olm.v1.curve25519-aes-sha2";
* @param {Object} opts.scheduler Optional. The scheduler to use. If not
* specified, this client will not retry requests on failure. This client
* will supply its own processing function to
* @param {Object} opts.queryParams Optional. Extra query parameters to append
* to all requests with this client. Useful for application services which require
* <code>?user_id=</code>.
* {@link module:scheduler~MatrixScheduler#setProcessFunction}.
*/
function MatrixClient(opts) {
utils.checkObjectHasKeys(opts, ["baseUrl", "request"]);
utils.checkObjectHasNoAdditionalKeys(opts, [
"baseUrl", "idBaseUrl", "request", "accessToken", "userId", "store",
"scheduler", "sessionStore", "deviceId"
]);
this.store = opts.store || new StubStore();
this.sessionStore = opts.sessionStore || null;
@@ -123,7 +122,8 @@ function MatrixClient(opts) {
accessToken: opts.accessToken,
request: opts.request,
prefix: httpApi.PREFIX_V1,
onlyData: true
onlyData: true,
extraParams: opts.queryParams
};
this.credentials = {
userId: (opts.userId || null)

View File

@@ -43,6 +43,8 @@ module.exports.PREFIX_IDENTITY_V1 = "/_matrix/identity/api/v1";
* codes and headers in addition to data. Default: false.
* @param {string} opts.accessToken The access_token to send with requests. Can be
* null to not send an access token.
* @param {Object} opts.extraParams Optional. Extra query parameters to send on
* requests.
*/
module.exports.MatrixHttpApi = function MatrixHttpApi(opts) {
utils.checkObjectHasKeys(opts, ["baseUrl", "request", "prefix"]);
@@ -363,6 +365,15 @@ module.exports.MatrixHttpApi.prototype = {
"Expected callback to be a function but got " + typeof callback
);
}
if (!queryParams) {
queryParams = {};
}
if (this.opts.extraParams) {
for (var key in this.opts.extraParams) {
if (!this.opts.extraParams.hasOwnProperty(key)) { continue; }
queryParams[key] = this.opts.extraParams[key];
}
}
var defer = q.defer();
this.opts.request(
{

View File

@@ -6,7 +6,7 @@ module.exports.MatrixEvent = require("./models/event").MatrixEvent;
module.exports.EventStatus = require("./models/event").EventStatus;
/** The {@link module:store/memory.MatrixInMemoryStore|MatrixInMemoryStore} class. */
module.exports.MatrixInMemoryStore = require("./store/memory").MatrixInMemoryStore;
/** The {@link module:store/webstorage.WebStorageStore|WebStorageStore} class. */
/** The {@link module:store/webstorage~WebStorageStore|WebStorageStore} class. */
module.exports.WebStorageStore = require("./store/webstorage");
/** The {@link module:http-api.MatrixHttpApi|MatrixHttpApi} class. */
module.exports.MatrixHttpApi = require("./http-api").MatrixHttpApi;
@@ -24,10 +24,10 @@ module.exports.RoomState = require("./models/room-state");
module.exports.User = require("./models/user");
/** The {@link module:scheduler~MatrixScheduler|MatrixScheduler} class. */
module.exports.MatrixScheduler = require("./scheduler");
/** The {@link module:store/session/webstorage.WebStorageSessionStore|
* ebStorageSessionStore} class */
/** The {@link module:store/session/webstorage~WebStorageSessionStore|
* WebStorageSessionStore} class */
module.exports.WebStorageSessionStore = require("./store/session/webstorage");
/** */
/** True if crypto libraries are being used on this client. */
module.exports.CRYPTO_ENABLED = require("./client").CRYPTO_ENABLED;
/**
@@ -59,12 +59,15 @@ module.exports.request = function(r) {
* @param {(Object|string)} opts The configuration options for this client. If
* this is a string, it is assumed to be the base URL. These configuration
* options will be passed directly to {@link module:client~MatrixClient}.
* @param {string} opts.baseUrl The base URL to the client-server HTTP API.
* @param {string} opts.accessToken Optional. The access_token for this user.
* @param {string} opts.userId Optional. The user ID for this user.
* @param {Object} opts.store Set to {@link module:store/memory.MatrixInMemoryStore}.
* @param {Object} opts.scheduler Set to {@link module:scheduler~MatrixScheduler}.
* @param {Object} opts.store If not set, defaults to
* {@link module:store/memory.MatrixInMemoryStore}.
* @param {Object} opts.scheduler If not set, defaults to
* {@link module:scheduler~MatrixScheduler}.
* @param {requestFunction} opts.request If not set, defaults to the function
* supplied to {@link request} which defaults to the request module from NPM.
* @return {MatrixClient} A new matrix client.
* @see {@link module:client~MatrixClient} for the full list of options for
* <code>opts</code>.
*/
module.exports.createClient = function(opts) {
if (typeof opts === "string") {
@@ -72,9 +75,9 @@ module.exports.createClient = function(opts) {
"baseUrl": opts
};
}
opts.request = request;
opts.store = new module.exports.MatrixInMemoryStore();
opts.scheduler = new module.exports.MatrixScheduler();
opts.request = opts.request || request;
opts.store = opts.store || new module.exports.MatrixInMemoryStore();
opts.scheduler = opts.scheduler || new module.exports.MatrixScheduler();
return new module.exports.MatrixClient(opts);
};

View File

@@ -1,9 +1,13 @@
/**
* @module pushprocessor
*/
/**
* Construct a Push Processor.
* @constructor
* @param {Object} client The Matrix client object to use
*/
module.exports = function(client) {
function PushProcessor(client) {
var escapeRegExp = function(string) {
return string.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
};
@@ -237,5 +241,7 @@ module.exports = function(client) {
this.actionsForEvent = function(ev) {
return pushActionsForEventAndRulesets(ev, client.pushRules);
};
};
}
/** The PushProcessor class. */
module.exports = PushProcessor;

View File

@@ -1,5 +1,9 @@
"use strict";
/**
* @module store/session/webstorage
*/
var utils = require("../../utils");
var DEBUG = false; // set true to enable console logging.