[FIX] Custom status fixes (#14853)
* Fixes for status message text presence issues Added statusText to several api endpoints Changed statusMessage to statusText since that is what it is called everywhere * Fixed slash command for changing status * Fixed the "name is required" issue * Make sure the status is set blank if selecting a default status... we don't want an "online" status when someone is actually offline! * Fixes display of custom status on the room header * Changed the header of DM rooms to query the server for the user status text when it is not found on the internal collection * Changed Custom Status methods to check if the user is logged in * Improved code readability * Fix getting status list before logging inpull/14886/head
parent
0e95941d02
commit
24ebd2c434
@ -0,0 +1,19 @@ |
||||
import { Users } from '../../../models/server'; |
||||
|
||||
export const getStatusText = function(userId) { |
||||
if (!userId) { |
||||
return undefined; |
||||
} |
||||
|
||||
const fields = { |
||||
statusText: 1, |
||||
}; |
||||
|
||||
const options = { |
||||
fields, |
||||
limit: 1, |
||||
}; |
||||
|
||||
const data = Users.findOneById(userId, options); |
||||
return data && data.statusText; |
||||
}; |
@ -1,45 +0,0 @@ |
||||
import { Meteor } from 'meteor/meteor'; |
||||
import s from 'underscore.string'; |
||||
|
||||
import { Users } from '../../../models'; |
||||
import { Notifications } from '../../../notifications'; |
||||
import { hasPermission } from '../../../authorization'; |
||||
import { RateLimiter } from '../lib'; |
||||
|
||||
export const _setStatusMessage = function(userId, statusMessage) { |
||||
statusMessage = s.trim(statusMessage); |
||||
if (statusMessage.length > 120) { |
||||
statusMessage = statusMessage.substr(0, 120); |
||||
} |
||||
|
||||
if (!userId) { |
||||
return false; |
||||
} |
||||
|
||||
const user = Users.findOneById(userId); |
||||
|
||||
// User already has desired statusMessage, return
|
||||
if (user.statusText === statusMessage) { |
||||
return user; |
||||
} |
||||
|
||||
// Set new statusMessage
|
||||
Users.updateStatusText(user._id, statusMessage); |
||||
user.statusText = statusMessage; |
||||
|
||||
Notifications.notifyLogged('Users:StatusMessageChanged', { |
||||
_id: user._id, |
||||
name: user.name, |
||||
username: user.username, |
||||
statusText: user.statusText, |
||||
}); |
||||
|
||||
return true; |
||||
}; |
||||
|
||||
export const setStatusMessage = RateLimiter.limitFunction(_setStatusMessage, 1, 60000, { |
||||
0() { |
||||
// Administrators have permission to change others status, so don't limit those
|
||||
return !Meteor.userId() || !hasPermission(Meteor.userId(), 'edit-other-user-info'); |
||||
}, |
||||
}); |
@ -0,0 +1,53 @@ |
||||
import { Meteor } from 'meteor/meteor'; |
||||
import s from 'underscore.string'; |
||||
|
||||
import { Users } from '../../../models'; |
||||
import { Notifications } from '../../../notifications'; |
||||
import { hasPermission } from '../../../authorization'; |
||||
import { RateLimiter } from '../lib'; |
||||
|
||||
// mirror of object in /imports/startup/client/listenActiveUsers.js - keep updated
|
||||
const STATUS_MAP = { |
||||
offline: 0, |
||||
online: 1, |
||||
away: 2, |
||||
busy: 3, |
||||
}; |
||||
|
||||
export const _setStatusText = function(userId, statusText) { |
||||
statusText = s.trim(statusText); |
||||
if (statusText.length > 120) { |
||||
statusText = statusText.substr(0, 120); |
||||
} |
||||
|
||||
if (!userId) { |
||||
return false; |
||||
} |
||||
|
||||
const user = Users.findOneById(userId); |
||||
|
||||
// User already has desired statusText, return
|
||||
if (user.statusText === statusText) { |
||||
return user; |
||||
} |
||||
|
||||
// Set new statusText
|
||||
Users.updateStatusText(user._id, statusText); |
||||
user.statusText = statusText; |
||||
|
||||
Notifications.notifyLogged('user-status', [ |
||||
user._id, |
||||
user.username, |
||||
STATUS_MAP[user.status], |
||||
statusText, |
||||
]); |
||||
|
||||
return true; |
||||
}; |
||||
|
||||
export const setStatusText = RateLimiter.limitFunction(_setStatusText, 1, 60000, { |
||||
0() { |
||||
// Administrators have permission to change others status, so don't limit those
|
||||
return !Meteor.userId() || !hasPermission(Meteor.userId(), 'edit-other-user-info'); |
||||
}, |
||||
}); |
@ -0,0 +1,14 @@ |
||||
import { Meteor } from 'meteor/meteor'; |
||||
|
||||
import { getStatusText } from '../../../lib'; |
||||
|
||||
Meteor.methods({ |
||||
getUserStatusText(userId) { |
||||
const currentUserId = Meteor.userId(); |
||||
if (!currentUserId) { |
||||
throw new Meteor.Error('error-invalid-user', 'Invalid user', { method: 'getUserStatusText' }); |
||||
} |
||||
|
||||
return getStatusText(userId); |
||||
}, |
||||
}); |
Loading…
Reference in new issue