Commit 079f7646fd62a11c7e71deabb533b888890f1093
Combine mentions from markdown and files
Charles Lehner committed on 8/14/2016, 1:55:44 AMParent: 84d01396e7c8c55181da6c71061acdb78090dc4c
Files changed
modules/compose.js | changed |
modules/compose.js | ||
---|---|---|
@@ -46,17 +46,26 @@ | ||
46 | 46 | if(ev.keyCode === 13 && ev.ctrlKey) publish() |
47 | 47 | }) |
48 | 48 | |
49 | 49 | var files = [] |
50 | + var filesById = {} | |
50 | 51 | |
51 | 52 | function publish() { |
52 | 53 | publishBtn.disabled = true |
53 | 54 | var content |
54 | 55 | try { |
55 | 56 | content = JSON.parse(ta.value) |
56 | 57 | } catch (err) { |
57 | 58 | meta.text = ta.value |
58 | - meta.mentions = mentions(ta.value).concat(files) | |
59 | + meta.mentions = mentions(ta.value).map(function (mention) { | |
60 | + // merge markdown-detected mention with file info | |
61 | + var file = filesById[mention.link] | |
62 | + if (file) { | |
63 | + if (file.type) mention.type = file.type | |
64 | + if (file.size) mention.size = file.size | |
65 | + } | |
66 | + return mention | |
67 | + }) | |
59 | 68 | try { |
60 | 69 | meta = prepublish(meta) |
61 | 70 | } catch (err) { |
62 | 71 | publishBtn.disabled = false |
@@ -84,8 +93,9 @@ | ||
84 | 93 | //hidden until you focus the textarea |
85 | 94 | {style: {display: 'none'}}, |
86 | 95 | file_input(function (file) { |
87 | 96 | files.push(file) |
97 | + filesById[file.link] = file | |
88 | 98 | |
89 | 99 | var embed = file.type.indexOf('image/') === 0 ? '!' : '' |
90 | 100 | ta.value += embed + '['+file.name+']('+file.link+')' |
91 | 101 | console.log('added:', file) |
Built with git-ssb-web