summaryrefslogtreecommitdiffstats
path: root/web
diff options
context:
space:
mode:
authorFlorian Orben <florian.orben@gmail.com>2015-11-05 23:32:44 +0100
committerFlorian Orben <florian.orben@gmail.com>2015-11-05 23:33:21 +0100
commitb085bc2d56bdc98101b8cb50848aee248d42af28 (patch)
tree9e19e790ed53aa1fbaa4b5c0c5574e03ae801577 /web
parent4b6eb56415c2085bc9078836b70b833b1e01a60d (diff)
downloadchat-b085bc2d56bdc98101b8cb50848aee248d42af28.tar.gz
chat-b085bc2d56bdc98101b8cb50848aee248d42af28.tar.bz2
chat-b085bc2d56bdc98101b8cb50848aee248d42af28.zip
PLT-857: Support for Incoming Webhooks - Try #2
Diffstat (limited to 'web')
-rw-r--r--web/react/components/post_body.jsx15
-rw-r--r--web/react/components/post_body_additional_content.jsx56
-rw-r--r--web/sass-files/sass/partials/_post.scss4
-rw-r--r--web/web.go11
4 files changed, 74 insertions, 12 deletions
diff --git a/web/react/components/post_body.jsx b/web/react/components/post_body.jsx
index 4da13dace..5a157b792 100644
--- a/web/react/components/post_body.jsx
+++ b/web/react/components/post_body.jsx
@@ -7,7 +7,7 @@ const Utils = require('../utils/utils.jsx');
const Constants = require('../utils/constants.jsx');
const TextFormatting = require('../utils/text_formatting.jsx');
const twemoji = require('twemoji');
-const PostAttachmentList = require('./post_attachment_list.jsx');
+const PostBodyAdditionalContent = require('./post_body_additional_content.jsx');
export default class PostBody extends React.Component {
constructor(props) {
@@ -317,15 +317,6 @@ export default class PostBody extends React.Component {
);
}
- let postAttachments = '';
- if (post.attachments && post.attachments.length) {
- postAttachments = (
- <PostAttachmentList
- attachments={post.attachments}
- />
- );
- }
-
return (
<div className='post-body'>
{comment}
@@ -341,7 +332,9 @@ export default class PostBody extends React.Component {
dangerouslySetInnerHTML={{__html: TextFormatting.formatText(this.state.message)}}
/>
</div>
- {postAttachments}
+ <PostBodyAdditionalContent
+ post={post}
+ />
{fileAttachmentHolder}
{embed}
</div>
diff --git a/web/react/components/post_body_additional_content.jsx b/web/react/components/post_body_additional_content.jsx
new file mode 100644
index 000000000..8189ba2d3
--- /dev/null
+++ b/web/react/components/post_body_additional_content.jsx
@@ -0,0 +1,56 @@
+// Copyright (c) 2015 Mattermost, Inc. All Rights Reserved.
+// See License.txt for license information.
+
+const PostAttachmentList = require('./post_attachment_list.jsx');
+
+export default class PostBodyAdditionalContent extends React.Component {
+ constructor(props) {
+ super(props);
+
+ this.getSlackAttachment = this.getSlackAttachment.bind(this);
+ this.getComponent = this.getComponent.bind(this);
+ }
+
+ componentWillMount() {
+ this.setState({type: this.props.post.type, shouldRender: Boolean(this.props.post.type)});
+ }
+
+ getSlackAttachment() {
+ const attachments = this.props.post.props && this.props.post.props.attachments || [];
+ return (
+ <PostAttachmentList
+ key={'post_body_additional_content' + this.props.post.id}
+ attachments={attachments}
+ />
+ );
+ }
+
+ getComponent() {
+ switch (this.state.type) {
+ case 'slack_attachment':
+ return this.getSlackAttachment();
+ }
+ }
+
+ render() {
+ let content = [];
+
+ if (this.state.shouldRender) {
+ const component = this.getComponent();
+
+ if (component) {
+ content = component;
+ }
+ }
+
+ return (
+ <div>
+ {content}
+ </div>
+ );
+ }
+}
+
+PostBodyAdditionalContent.propTypes = {
+ post: React.PropTypes.object.isRequired
+}; \ No newline at end of file
diff --git a/web/sass-files/sass/partials/_post.scss b/web/sass-files/sass/partials/_post.scss
index db03a1578..b57c51242 100644
--- a/web/sass-files/sass/partials/_post.scss
+++ b/web/sass-files/sass/partials/_post.scss
@@ -668,6 +668,7 @@ body.ios {
}
.attachment__image {
max-width: 100%;
+ margin-bottom: 1em;
}
.attachment__thumb-container {
width: 20%;
@@ -682,5 +683,8 @@ body.ios {
.attachment___field-caption {
font-weight: 700;
}
+ .attachment___field p {
+ margin: 0;
+ }
}
} \ No newline at end of file
diff --git a/web/web.go b/web/web.go
index 51f6664b6..bd0154542 100644
--- a/web/web.go
+++ b/web/web.go
@@ -990,6 +990,15 @@ func incomingWebhook(c *api.Context, w http.ResponseWriter, r *http.Request) {
}
channelName := parsedRequest.ChannelName
+ webhookType := parsedRequest.Type
+
+ if parsedRequest.Attachments != nil {
+ if len(parsedRequest.Props) == 0 {
+ parsedRequest.Props = make(model.StringInterface)
+ }
+ parsedRequest.Props["attachments"] = parsedRequest.Attachments
+ webhookType = model.POST_SLACK_ATTACHMENT
+ }
var hook *model.IncomingWebhook
if result := <-hchan; result.Err != nil {
@@ -1039,7 +1048,7 @@ func incomingWebhook(c *api.Context, w http.ResponseWriter, r *http.Request) {
return
}
- if _, err := api.CreateWebhookPost(c, channel.Id, text, overrideUsername, overrideIconUrl); err != nil {
+ if _, err := api.CreateWebhookPost(c, channel.Id, text, overrideUsername, overrideIconUrl, parsedRequest.Props, webhookType); err != nil {
c.Err = err
return
}