1
0
mirror of https://github.com/matrix-org/matrix-js-sdk.git synced 2025-11-28 05:03:59 +03:00

Use /r0 or /unstable for all requests

This commit is contained in:
Daniel Wagner-Hall
2016-02-08 11:15:30 +00:00
parent 5ca4bc6b85
commit 02196416e4
3 changed files with 40 additions and 49 deletions

View File

@@ -154,7 +154,7 @@ function MatrixClient(opts) {
idBaseUrl: opts.idBaseUrl,
accessToken: opts.accessToken,
request: opts.request,
prefix: httpApi.PREFIX_V1,
prefix: httpApi.PREFIX_R0,
onlyData: true,
extraParams: opts.queryParams
};
@@ -342,7 +342,7 @@ MatrixClient.prototype.uploadKeys = function(maxKeys, deferred) {
};
var self = this;
this._http.authedRequestWithPrefix(
undefined, "POST", path, undefined, content, httpApi.PREFIX_V2_ALPHA
undefined, "POST", path, undefined, content, httpApi.PREFIX_UNSTABLE
).then(function(res) {
var keyLimit = Math.floor(maxOneTimeKeys / 2);
var keyCount = res.one_time_key_counts.curve25519 || 0;
@@ -408,7 +408,7 @@ MatrixClient.prototype.downloadKeys = function(userIds, forceDownload) {
var self = this;
this._http.authedRequestWithPrefix(
undefined, "POST", path, undefined, content,
httpApi.PREFIX_V2_ALPHA
httpApi.PREFIX_UNSTABLE
).then(function(res) {
for (var userId in res.device_keys) {
if (userId in notStored) {
@@ -514,7 +514,7 @@ MatrixClient.prototype.setRoomEncryption = function(roomId, config) {
var self = this;
this._http.authedRequestWithPrefix(
undefined, "POST", path, undefined, content,
httpApi.PREFIX_V2_ALPHA
httpApi.PREFIX_UNSTABLE
).done(function(res) {
var missing = {};
for (i = 0; i < devicesWithoutSession.length; ++i) {
@@ -750,8 +750,8 @@ MatrixClient.prototype.setRoomTag = function(roomId, tagName, metadata, callback
$roomId: roomId,
$tag: tagName,
});
return this._http.authedRequestWithPrefix(
callback, "PUT", path, undefined, metadata, httpApi.PREFIX_V2_ALPHA
return this._http.authedRequest(
callback, "PUT", path, undefined, metadata
);
};
@@ -768,8 +768,8 @@ MatrixClient.prototype.deleteRoomTag = function(roomId, tagName, callback) {
$roomId: roomId,
$tag: tagName,
});
return this._http.authedRequestWithPrefix(
callback, "DELETE", path, undefined, undefined, httpApi.PREFIX_V2_ALPHA
return this._http.authedRequest(
callback, "DELETE", path, undefined, undefined
);
};
@@ -785,8 +785,8 @@ MatrixClient.prototype.setAccountData = function(eventType, content, callback) {
$userId: this.credentials.userId,
$type: eventType,
});
return this._http.authedRequestWithPrefix(
callback, "PUT", path, undefined, content, httpApi.PREFIX_V2_ALPHA
return this._http.authedRequest(
callback, "PUT", path, undefined, content
);
};
@@ -805,8 +805,8 @@ MatrixClient.prototype.setRoomAccountData = function(roomId, eventType,
$roomId: roomId,
$type: eventType,
});
return this._http.authedRequestWithPrefix(
callback, "PUT", path, undefined, content, httpApi.PREFIX_V2_ALPHA
return this._http.authedRequest(
callback, "PUT", path, undefined, content
);
};
@@ -1389,8 +1389,8 @@ MatrixClient.prototype.sendReceipt = function(event, receiptType, callback) {
$receiptType: receiptType,
$eventId: event.getId()
});
var promise = this._http.authedRequestWithPrefix(
callback, "POST", path, undefined, {}, httpApi.PREFIX_V2_ALPHA
var promise = this._http.authedRequest(
callback, "POST", path, undefined, {}
);
var room = this.getRoom(event.getRoomId());
@@ -1834,8 +1834,8 @@ MatrixClient.prototype.mxcUrlToHttp =
*/
MatrixClient.prototype.getThreePids = function(callback) {
var path = "/account/3pid";
return this._http.authedRequestWithPrefix(
callback, "GET", path, undefined, undefined, httpApi.PREFIX_V2_ALPHA
return this._http.authedRequest(
callback, "GET", path, undefined, undefined
);
};
@@ -1852,8 +1852,8 @@ MatrixClient.prototype.addThreePid = function(creds, bind, callback) {
'threePidCreds': creds,
'bind': bind
};
return this._http.authedRequestWithPrefix(
callback, "POST", path, null, data, httpApi.PREFIX_V2_ALPHA
return this._http.authedRequest(
callback, "POST", path, null, data
);
};
@@ -1872,8 +1872,8 @@ MatrixClient.prototype.setPassword = function(authDict, newPassword, callback) {
'new_password': newPassword
};
return this._http.authedRequestWithPrefix(
callback, "POST", path, null, data, httpApi.PREFIX_V2_ALPHA
return this._http.authedRequest(
callback, "POST", path, null, data
);
};
@@ -2289,11 +2289,11 @@ MatrixClient.prototype.registerGuest = function(opts, callback) {
opts = opts || {};
opts.body = opts.body || {};
return this._http.requestWithPrefix(
return this._http.request(
callback, "POST", "/register", {
kind: "guest"
},
opts.body, httpApi.PREFIX_V2_ALPHA
opts.body
);
};
@@ -2365,9 +2365,9 @@ MatrixClient.prototype.register = function(username, password,
if (bindEmail !== undefined) { params.bind_email = bindEmail; }
if (guestAccessToken !== undefined) { params.guest_access_token = guestAccessToken; }
return this._http.requestWithPrefix(
return this._http.request(
callback, "POST", "/register", undefined,
params, httpApi.PREFIX_V2_ALPHA
params
);
};
@@ -2405,7 +2405,7 @@ MatrixClient.prototype.loginWithSAML2 = function(relayState, callback) {
MatrixClient.prototype.getCasLoginUrl = function(redirectUrl) {
return this._http.getUrl("/login/cas/redirect", {
"redirectUrl": redirectUrl
}, httpApi.PREFIX_V1);
}, httpApi.PREFIX_UNSTABLE);
};
/**
@@ -2792,8 +2792,8 @@ MatrixClient.prototype.createFilter = function(content) {
var path = utils.encodeUri("/user/$userId/filter", {
$userId: this.credentials.userId
});
return this._http.authedRequestWithPrefix(
undefined, "POST", path, undefined, content, httpApi.PREFIX_V2_ALPHA
return this._http.authedRequest(
undefined, "POST", path, undefined, content
).then(function(response) {
// persist the filter
var filter = Filter.fromJson(
@@ -2827,8 +2827,8 @@ MatrixClient.prototype.getFilter = function(userId, filterId, allowCached) {
$filterId: filterId
});
return this._http.authedRequestWithPrefix(
undefined, "GET", path, undefined, undefined, httpApi.PREFIX_V2_ALPHA
return this._http.authedRequest(
undefined, "GET", path, undefined, undefined
).then(function(response) {
// persist the filter
var filter = Filter.fromJson(

View File

@@ -28,26 +28,20 @@ TODO:
*/
/**
* A constant representing the URI path for version 1 of the Client-Server HTTP API.
* A constant representing the URI path for release 0 of the Client-Server HTTP API.
*/
module.exports.PREFIX_V1 = "/_matrix/client/api/v1";
module.exports.PREFIX_R0 = "/_matrix/client/r0";
/**
* A constant representing the URI path for version 2 alpha of the Client-Server
* HTTP API.
* A constant representing the URI path for as-yet unspecified Client-Server HTTP APIs.
*/
module.exports.PREFIX_V2_ALPHA = "/_matrix/client/v2_alpha";
module.exports.PREFIX_UNSTABLE = "/_matrix/client/unstable";
/**
* URI path for the identity API
*/
module.exports.PREFIX_IDENTITY_V1 = "/_matrix/identity/api/v1";
/**
* A constant representing the URI path for release 0 of the Client-Server HTTP API.
*/
module.exports.PREFIX_R0 = "/_matrix/client/r0";
/**
* Construct a MatrixHttpApi.
* @constructor
@@ -57,7 +51,7 @@ module.exports.PREFIX_R0 = "/_matrix/client/r0";
* @param {Function} opts.request Required. The function to call for HTTP
* requests. This function must look like function(opts, callback){ ... }.
* @param {string} opts.prefix Required. The matrix client prefix to use, e.g.
* '/_matrix/client/api/v1'. See PREFIX_V1 and PREFIX_V2_ALPHA for constants.
* '/_matrix/client/r0'. See PREFIX_R0 and PREFIX_UNSTABLE for constants.
* @param {bool} opts.onlyData True to return only the 'data' component of the
* response (e.g. the parsed HTTP body). If false, requests will return status
* codes and headers in addition to data. Default: false.

View File

@@ -27,7 +27,6 @@ var q = require("q");
var User = require("./models/user");
var Room = require("./models/room");
var utils = require("./utils");
var httpApi = require("./http-api");
var Filter = require("./filter");
var DEBUG = true;
@@ -143,9 +142,8 @@ SyncApi.prototype.syncLeftRooms = function() {
getFilterName(client.credentials.userId, "LEFT_ROOMS"), filter
).then(function(filterId) {
qps.filter = filterId;
return client._http.authedRequestWithPrefix(
undefined, "GET", "/sync", qps, undefined, httpApi.PREFIX_V2_ALPHA,
localTimeoutMs
return client._http.authedRequest(
undefined, "GET", "/sync", qps, undefined, localTimeoutMs
);
}).then(function(data) {
var leaveRooms = [];
@@ -265,11 +263,11 @@ SyncApi.prototype._peekPoll = function(roomId, token) {
var self = this;
// FIXME: gut wrenching; hard-coded timeout values
this.client._http.authedRequestWithPrefix(undefined, "GET", "/events", {
this.client._http.authedRequest(undefined, "GET", "/events", {
room_id: roomId,
timeout: 30 * 1000,
from: token
}, undefined, httpApi.PREFIX_V1, 50 * 1000).done(function(res) {
}, undefined, 50 * 1000).done(function(res) {
// strip out events which aren't for the given room_id (e.g presence)
var events = res.chunk.filter(function(e) {
return e.room_id === roomId;
@@ -379,9 +377,8 @@ SyncApi.prototype._sync = function(syncOptions, attempt) {
// normal timeout= plus buffer time
var clientSideTimeoutMs = this.opts.pollTimeout + BUFFER_PERIOD_MS;
this._currentSyncRequest = client._http.authedRequestWithPrefix(
undefined, "GET", "/sync", qps, undefined, httpApi.PREFIX_V2_ALPHA,
clientSideTimeoutMs
this._currentSyncRequest = client._http.authedRequest(
undefined, "GET", "/sync", qps, undefined, clientSideTimeoutMs
);
this._currentSyncRequest.done(function(data) {