Skip to content

Commit c6bb69f

Browse files
committed
fix(Status): prioritize AuthOptions over currentUser
prevent currentUser warning when used with AuthOptions in node.
1 parent 6a43778 commit c6bb69f

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

src/status.js

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
11
const _ = require('underscore');
22
const AVRequest = require('./request').request;
3+
const { getSessionToken } = require('./utils');
34

45
module.exports = function(AV) {
5-
const getUser = (options = {}) => AV.User.currentAsync()
6-
.then(currUser => currUser || AV.User._fetchUserBySessionToken(options.sessionToken));
6+
const getUser = (options = {}) => {
7+
const sessionToken = getSessionToken(options);
8+
if (sessionToken) {
9+
return AV.User._fetchUserBySessionToken(getSessionToken(options));
10+
}
11+
return AV.User.currentAsync();
12+
};
713

814
const getUserPointer = options => getUser(options)
915
.then(currUser => AV.Object.createWithoutData('_User', currUser.id)._toPointer());
@@ -90,7 +96,7 @@ module.exports = function(AV) {
9096
* });
9197
*/
9298
send: function(options = {}){
93-
if(!options.sessionToken && !AV.User.current()) {
99+
if(!getSessionToken(options) && !AV.User.current()) {
94100
throw new Error('Please signin an user.');
95101
}
96102
if(!this.query){
@@ -146,7 +152,7 @@ module.exports = function(AV) {
146152
* });
147153
*/
148154
AV.Status.sendStatusToFollowers = function(status, options = {}) {
149-
if(!options.sessionToken && !AV.User.current()){
155+
if(!getSessionToken(options) && !AV.User.current()){
150156
throw new Error('Please signin an user.');
151157
}
152158
return getUserPointer(options).then(currUser => {
@@ -189,7 +195,7 @@ module.exports = function(AV) {
189195
* });
190196
*/
191197
AV.Status.sendPrivateStatus = function(status, target, options = {}) {
192-
if(!options.sessionToken && !AV.User.current()){
198+
if(!getSessionToken(options) && !AV.User.current()){
193199
throw new Error('Please signin an user.');
194200
}
195201
if(!target){
@@ -236,7 +242,7 @@ module.exports = function(AV) {
236242
*/
237243
AV.Status.countUnreadStatuses = function(owner, inboxType = 'default', options = {}){
238244
if (!_.isString(inboxType)) options = inboxType;
239-
if(!options.sessionToken && owner == null && !AV.User.current()) {
245+
if(!getSessionToken(options) && owner == null && !AV.User.current()) {
240246
throw new Error('Please signin an user or pass the owner objectId.');
241247
}
242248
return getUser(options).then(owner => {
@@ -263,7 +269,7 @@ module.exports = function(AV) {
263269
*/
264270
AV.Status.resetUnreadCount = function(owner, inboxType = 'default', options = {}){
265271
if (!_.isString(inboxType)) options = inboxType;
266-
if(!options.sessionToken && owner == null && !AV.User.current()) {
272+
if(!getSessionToken(options) && owner == null && !AV.User.current()) {
267273
throw new Error('Please signin an user or pass the owner objectId.');
268274
}
269275
return getUser(options).then(owner => {

0 commit comments

Comments
 (0)