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;
|
var profilePic = null;
|
||||||
if (!this.props.hideProfilePic) {
|
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 = (
|
profilePic = (
|
||||||
<div className='post-profile-img__container'>
|
<div className='post-profile-img__container'>
|
||||||
<img
|
<img
|
||||||
className='post-profile-img'
|
className='post-profile-img'
|
||||||
src={'/api/v1/users/' + post.user_id + '/image?time=' + timestamp}
|
src={src}
|
||||||
height='36'
|
height='36'
|
||||||
width='36'
|
width='36'
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -12,9 +12,20 @@ export default class PostHeader extends React.Component {
|
|||||||
render() {
|
render() {
|
||||||
var post = this.props.post;
|
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 (
|
return (
|
||||||
<ul className='post-header post-header-post'>
|
<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'>
|
<li className='post-info--hidden'>
|
||||||
<PostInfo
|
<PostInfo
|
||||||
post={post}
|
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);
|
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
|
// hide the profile pic if:
|
||||||
hideProfilePic = (prevPost.user_id === post.user_id) && !utils.isComment(prevPost) && !utils.isComment(post);
|
// 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
|
// 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() {
|
componentDidMount() {
|
||||||
UserStore.addChangeListener(this.onChange);
|
UserStore.addChangeListener(this.onChange);
|
||||||
$('#profile_' + this.uniqueId).popover({placement: 'right', container: 'body', trigger: 'hover', html: true, delay: {show: 200, hide: 100}});
|
if (!this.props.disablePopover) {
|
||||||
$('body').tooltip({selector: '[data-toggle=tooltip]', trigger: 'hover click'});
|
$('#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() {
|
componentWillUnmount() {
|
||||||
UserStore.removeChangeListener(this.onChange);
|
UserStore.removeChangeListener(this.onChange);
|
||||||
@@ -56,6 +58,10 @@ export default class UserProfile extends React.Component {
|
|||||||
name = this.props.overwriteName;
|
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" />';
|
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') {
|
if (!global.window.config.ShowEmailAddress === 'true') {
|
||||||
dataContent += '<div class="text-nowrap">Email not shared</div>';
|
dataContent += '<div class="text-nowrap">Email not shared</div>';
|
||||||
@@ -79,9 +85,11 @@ export default class UserProfile extends React.Component {
|
|||||||
|
|
||||||
UserProfile.defaultProps = {
|
UserProfile.defaultProps = {
|
||||||
userId: '',
|
userId: '',
|
||||||
overwriteName: ''
|
overwriteName: '',
|
||||||
|
disablePopover: false
|
||||||
};
|
};
|
||||||
UserProfile.propTypes = {
|
UserProfile.propTypes = {
|
||||||
userId: React.PropTypes.string,
|
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"]
|
channelName := props["channel"]
|
||||||
|
|
||||||
|
overrideUsername := props["username"]
|
||||||
|
overrideIconUrl := props["icon_url"]
|
||||||
|
|
||||||
var hook *model.IncomingWebhook
|
var hook *model.IncomingWebhook
|
||||||
if result := <-hchan; result.Err != nil {
|
if result := <-hchan; result.Err != nil {
|
||||||
c.Err = model.NewAppError("incomingWebhook", "Invalid webhook", "err="+result.Err.Message)
|
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}
|
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 {
|
if !c.HasPermissionsToChannel(pchan, "createIncomingHook") && channel.Type != model.CHANNEL_OPEN {
|
||||||
c.Err = model.NewAppError("incomingWebhook", "Inappropriate channel permissions", "")
|
c.Err = model.NewAppError("incomingWebhook", "Inappropriate channel permissions", "")
|
||||||
return
|
return
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user