diff options
author | JoramWilander <jwawilander@gmail.com> | 2015-10-02 11:08:00 -0400 |
---|---|---|
committer | JoramWilander <jwawilander@gmail.com> | 2015-10-02 11:08:00 -0400 |
commit | 11903a38341eb55bb4c6f26ea141eccb90beabe2 (patch) | |
tree | 9988d9c39af2e29e94570af8552d8ce941200a60 | |
parent | f0c8019da468895a3da89809f63d272eaf26bb59 (diff) | |
download | chat-11903a38341eb55bb4c6f26ea141eccb90beabe2.tar.gz chat-11903a38341eb55bb4c6f26ea141eccb90beabe2.tar.bz2 chat-11903a38341eb55bb4c6f26ea141eccb90beabe2.zip |
Add ability to override username and icon for posts from incoming webhooks.
-rw-r--r-- | web/react/components/post.jsx | 7 | ||||
-rw-r--r-- | web/react/components/post_header.jsx | 13 | ||||
-rw-r--r-- | web/react/components/post_list.jsx | 15 | ||||
-rw-r--r-- | web/react/components/user_profile.jsx | 16 | ||||
-rw-r--r-- | web/web.go | 11 |
5 files changed, 54 insertions, 8 deletions
diff --git a/web/react/components/post.jsx b/web/react/components/post.jsx index 9127f00de..ba53054cd 100644 --- a/web/react/components/post.jsx +++ b/web/react/components/post.jsx @@ -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' /> diff --git a/web/react/components/post_header.jsx b/web/react/components/post_header.jsx index 9dc525e03..c2cadb742 100644 --- a/web/react/components/post_header.jsx +++ b/web/react/components/post_header.jsx @@ -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} diff --git a/web/react/components/post_list.jsx b/web/react/components/post_list.jsx index a31967257..0354d132c 100644 --- a/web/react/components/post_list.jsx +++ b/web/react/components/post_list.jsx @@ -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 diff --git a/web/react/components/user_profile.jsx b/web/react/components/user_profile.jsx index c5d028d31..ceb8f52a7 100644 --- a/web/react/components/user_profile.jsx +++ b/web/react/components/user_profile.jsx @@ -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 }; diff --git a/web/web.go b/web/web.go index bf985a5a0..564671285 100644 --- a/web/web.go +++ b/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 |