-
Notifications
You must be signed in to change notification settings - Fork 11.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[NEW] User Status Messages #12710
Closed
Closed
[NEW] User Status Messages #12710
Changes from 8 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
97b305f
User Status Messages
wreiske 50bb92b
Added statusMessage to users api
wreiske e61b031
Added rocket.chat message to status slash command
wreiske 83703b7
Added status message too long to slash command
wreiske 2138728
Added maxlength to status on profile and edit status modal
wreiske c593690
Added edit status from admin user UI
wreiske bf95e1a
Merge branch 'develop' into develop
wreiske 5952752
Merge branch 'develop' into develop
wreiske b47597d
Merge branch 'develop' into develop
wreiske 6fdb54b
setStatus and getStatus rest API
wreiske 8ecbe83
Fixed chimp test related to user status messages
wreiske ffa8e4d
Merge branch 'develop' into develop
wreiske 1bcaba2
Merge branch 'develop' into develop
wreiske 01df8a4
Merge branch 'develop' into develop
wreiske aca976a
Merge branch 'develop' into develop
wreiske File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { Meteor } from 'meteor/meteor'; | ||
import { Users, Subscriptions } from '../../../models'; | ||
import { Notifications } from '../../../notifications'; | ||
import { hasPermission } from '../../../authorization'; | ||
import { RateLimiter } from '../lib'; | ||
import s from 'underscore.string'; | ||
|
||
export const _setStatusMessage = function(userId, statusMessage) { | ||
statusMessage = s.trim(statusMessage); | ||
|
||
if (!userId) { | ||
return false; | ||
} | ||
|
||
if (statusMessage.length > 120) { | ||
throw new Meteor.Error('error-status-message-too-long', 'Status message too long.'); | ||
} | ||
|
||
const user = Users.findOneById(userId); | ||
|
||
// User already has desired statusMessage, return | ||
if (user.statusMessage === statusMessage) { | ||
return user; | ||
} | ||
|
||
// Set new statusMessage | ||
Users.setStatusMessage(user._id, statusMessage); | ||
user.statusMessage = statusMessage; | ||
|
||
Subscriptions.updateUserStatusMessage(user._id, statusMessage); | ||
|
||
Notifications.notifyLogged('Users:StatusMessageChanged', { | ||
_id: user._id, | ||
name: user.name, | ||
username: user.username, | ||
statusMessage: user.statusMessage, | ||
}); | ||
|
||
return true; | ||
}; | ||
|
||
export const setStatusMessage = RateLimiter.limitFunction(_setStatusMessage, 1, 60000, { | ||
0() { return !Meteor.userId() || !hasPermission(Meteor.userId(), 'edit-other-user-info'); }, // Administrators have permission to change others status, so don't limit those | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { Meteor } from 'meteor/meteor'; | ||
import { check } from 'meteor/check'; | ||
import { settings } from '../../../settings'; | ||
import { setStatusMessage } from '../functions'; | ||
import { RateLimiter } from '../lib'; | ||
|
||
Meteor.methods({ | ||
setStatusMessage(statusMessage) { | ||
|
||
check(statusMessage, String); | ||
|
||
if (!Meteor.userId()) { | ||
throw new Meteor.Error('error-invalid-user', 'Invalid user', { | ||
method: 'setStatusMessage', | ||
}); | ||
} | ||
|
||
if (!settings.get('Accounts_AllowUserStatusMessageChange')) { | ||
throw new Meteor.Error('error-not-allowed', 'Not allowed', { | ||
method: 'setStatusMessage', | ||
}); | ||
} | ||
|
||
if (!setStatusMessage(Meteor.userId(), statusMessage)) { | ||
throw new Meteor.Error('error-could-not-change-status-message', 'Could not change status message', { | ||
method: 'setStatusMessage', | ||
}); | ||
} | ||
|
||
return statusMessage; | ||
}, | ||
}); | ||
|
||
RateLimiter.limitMethod('setStatusMessage', 1, 1000, { | ||
userId: () => true, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
import '../lib/status'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { Meteor } from 'meteor/meteor'; | ||
|
||
if (Meteor.isClient) { | ||
module.exports = require('./client/index.js'); | ||
} | ||
if (Meteor.isServer) { | ||
module.exports = require('./server/index.js'); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import { Meteor } from 'meteor/meteor'; | ||
import { handleError, slashCommands } from '../../utils'; | ||
import { hasPermission } from '../../authorization'; | ||
import { TAPi18n } from 'meteor/tap:i18n'; | ||
import { Random } from 'meteor/random'; | ||
import { Notifications } from '../../notifications'; | ||
/* | ||
* Join is a named function that will replace /status commands | ||
* @param {Object} message - The message object | ||
*/ | ||
|
||
function Status(command, params, item) { | ||
if (command === 'status') { | ||
if ((Meteor.isClient && hasPermission('edit-other-user-info')) || (Meteor.isServer && hasPermission(Meteor.userId(), 'edit-other-user-info'))) { | ||
const user = Meteor.users.findOne(Meteor.userId()); | ||
Meteor.call('setStatusMessage', params, (err) => { | ||
if (err) { | ||
if (Meteor.isClient) { | ||
return handleError(err); | ||
} else { | ||
if (err.error === 'error-not-allowed') { | ||
Notifications.notifyUser(Meteor.userId(), 'message', { | ||
_id: Random.id(), | ||
rid: item.rid, | ||
ts: new Date, | ||
msg: TAPi18n.__('StatusMessage_Change_Disabled', null, user.language), | ||
}); | ||
} else if (err.error === 'error-status-message-too-long') { | ||
Notifications.notifyUser(Meteor.userId(), 'message', { | ||
_id: Random.id(), | ||
rid: item.rid, | ||
ts: new Date, | ||
msg: TAPi18n.__('StatusMessage_Too_Long', null, user.language), | ||
}); | ||
} | ||
throw err; | ||
} | ||
} else { | ||
Notifications.notifyUser(Meteor.userId(), 'message', { | ||
_id: Random.id(), | ||
rid: item.rid, | ||
ts: new Date, | ||
msg: TAPi18n.__('StatusMessage_Changed_Successfully', null, user.language), | ||
}); | ||
} | ||
}); | ||
} | ||
} | ||
} | ||
|
||
slashCommands.add('status', Status, { | ||
description: 'Slash_Status_Description', | ||
params: 'Slash_Status_Params', | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
import '../lib/status'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
would be really cool if like setAvatar this was a rest call. Imagining the ability to set status from music players, and many other much more practical integrations.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Like my smart toaster! "toast is done".
I'll get this coded up when I wake up unless someone else wants to give it a whack before then.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, pushed. @geekgonecrazy please take a look at the changes and let me know if I should change it.