Add ability to override username and icon for posts from incoming webhooks.
Этот коммит содержится в:
@@ -158,11 +158,16 @@ export default class Post extends React.Component {
|
||||
|
||||
var profilePic = null;
|
||||
if (!this.props.hideProfilePic) {
|
||||
let src = '/api/v1/users/' + post.user_id + '/image?time=' + timestamp;
|
||||
if (post.props && post.props.override_icon_url) {
|
||||
src = post.props.override_icon_url;
|
||||
}
|
||||
|
||||
profilePic = (
|
||||
<div className='post-profile-img__container'>
|
||||
<img
|
||||
className='post-profile-img'
|
||||
src={'/api/v1/users/' + post.user_id + '/image?time=' + timestamp}
|
||||
src={src}
|
||||
height='36'
|
||||
width='36'
|
||||
/>
|
||||
|
||||
@@ -12,9 +12,20 @@ export default class PostHeader extends React.Component {
|
||||
render() {
|
||||
var post = this.props.post;
|
||||
|
||||
let userProfile = <UserProfile userId={post.user_id} />;
|
||||
if (post.props && post.props.override_username) {
|
||||
userProfile = (
|
||||
<UserProfile
|
||||
userId={post.user_id}
|
||||
overwriteName={post.props.override_username}
|
||||
disablePopover={true}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<ul className='post-header post-header-post'>
|
||||
<li className='post-header-col post-header__name'><strong><UserProfile userId={post.user_id} /></strong></li>
|
||||
<li className='post-header-col post-header__name'><strong>{userProfile}</strong></li>
|
||||
<li className='post-info--hidden'>
|
||||
<PostInfo
|
||||
post={post}
|
||||
|
||||
@@ -516,8 +516,19 @@ export default class PostList extends React.Component {
|
||||
|
||||
sameRoot = utils.isComment(post) && (prevPost.id === post.root_id || prevPost.root_id === post.root_id);
|
||||
|
||||
// we only hide the profile pic if the previous post is not a comment, the current post is not a comment, and the previous post was made by the same user as the current post
|
||||
hideProfilePic = (prevPost.user_id === post.user_id) && !utils.isComment(prevPost) && !utils.isComment(post);
|
||||
// hide the profile pic if:
|
||||
// the previous post was made by the same user as the current post,
|
||||
// the previous post is not a comment,
|
||||
// the current post is not a comment,
|
||||
// the current profile pic is not overridden
|
||||
// and the previous profile pic is not overridden
|
||||
if ((prevPost.user_id === post.user_id) &&
|
||||
!utils.isComment(prevPost) &&
|
||||
!utils.isComment(post) &&
|
||||
(!post.props || !post.props.override_icon_url) &&
|
||||
(!prevPost.props || !prevPost.props.override_icon_url)) {
|
||||
hideProfilePic = true;
|
||||
}
|
||||
}
|
||||
|
||||
// check if it's the last comment in a consecutive string of comments on the same post
|
||||
|
||||
@@ -31,8 +31,10 @@ export default class UserProfile extends React.Component {
|
||||
}
|
||||
componentDidMount() {
|
||||
UserStore.addChangeListener(this.onChange);
|
||||
$('#profile_' + this.uniqueId).popover({placement: 'right', container: 'body', trigger: 'hover', html: true, delay: {show: 200, hide: 100}});
|
||||
$('body').tooltip({selector: '[data-toggle=tooltip]', trigger: 'hover click'});
|
||||
if (!this.props.disablePopover) {
|
||||
$('#profile_' + this.uniqueId).popover({placement: 'right', container: 'body', trigger: 'hover', html: true, delay: {show: 200, hide: 100}});
|
||||
$('body').tooltip({selector: '[data-toggle=tooltip]', trigger: 'hover click'});
|
||||
}
|
||||
}
|
||||
componentWillUnmount() {
|
||||
UserStore.removeChangeListener(this.onChange);
|
||||
@@ -56,6 +58,10 @@ export default class UserProfile extends React.Component {
|
||||
name = this.props.overwriteName;
|
||||
}
|
||||
|
||||
if (this.props.disablePopover) {
|
||||
return <div>{name}</div>;
|
||||
}
|
||||
|
||||
var dataContent = '<img class="user-popover__image" src="/api/v1/users/' + this.state.profile.id + '/image?time=' + this.state.profile.update_at + '" height="128" width="128" />';
|
||||
if (!global.window.config.ShowEmailAddress === 'true') {
|
||||
dataContent += '<div class="text-nowrap">Email not shared</div>';
|
||||
@@ -79,9 +85,11 @@ export default class UserProfile extends React.Component {
|
||||
|
||||
UserProfile.defaultProps = {
|
||||
userId: '',
|
||||
overwriteName: ''
|
||||
overwriteName: '',
|
||||
disablePopover: false
|
||||
};
|
||||
UserProfile.propTypes = {
|
||||
userId: React.PropTypes.string,
|
||||
overwriteName: React.PropTypes.string
|
||||
overwriteName: React.PropTypes.string,
|
||||
disablePopover: React.PropTypes.bool
|
||||
};
|
||||
|
||||
11
web/web.go
11
web/web.go
@@ -865,6 +865,9 @@ func incomingWebhook(c *api.Context, w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
channelName := props["channel"]
|
||||
|
||||
overrideUsername := props["username"]
|
||||
overrideIconUrl := props["icon_url"]
|
||||
|
||||
var hook *model.IncomingWebhook
|
||||
if result := <-hchan; result.Err != nil {
|
||||
c.Err = model.NewAppError("incomingWebhook", "Invalid webhook", "err="+result.Err.Message)
|
||||
@@ -911,6 +914,14 @@ func incomingWebhook(c *api.Context, w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
post := &model.Post{UserId: hook.UserId, ChannelId: channel.Id, Message: text}
|
||||
|
||||
if len(overrideUsername) != 0 {
|
||||
post.AddProp("override_username", overrideUsername)
|
||||
}
|
||||
|
||||
if len(overrideIconUrl) != 0 {
|
||||
post.AddProp("override_icon_url", overrideIconUrl)
|
||||
}
|
||||
|
||||
if !c.HasPermissionsToChannel(pchan, "createIncomingHook") && channel.Type != model.CHANNEL_OPEN {
|
||||
c.Err = model.NewAppError("incomingWebhook", "Inappropriate channel permissions", "")
|
||||
return
|
||||
|
||||
Ссылка в новой задаче
Block a user