Published
Edited
Jun 12, 2019
2 forks
4 stars
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
ajaxMatches = (ajaxSearchResult.messages && ajaxSearchResult.messages.matches.map(match => ({...match, ajax:true}))) || []
Insert cell
exportSearchResult = (search && messages.filter(message => message.text && message.text.includes(search))) || []
Insert cell
combinedSearchResult = ajaxMatches.concat(exportSearchResult.filter(message => !ajaxMatches.find(match => match.ts == message.ts)))
Insert cell
d3 = require('d3')
Insert cell
axios = require('https://bundle.run/axios@0.19.0')
Insert cell
slack_zip = axios.get("https://gist.githubusercontent.com/stevekrouse/fd2e70db41849946d5077a494f04349f/raw/f6f92551de6ffe4743e40f29f987258279487cc6/foc-slack-export.zip", {responseType: 'blob'})
Insert cell
jszip = require("jszip@3.1.5/dist/jszip.min.js")
Insert cell
archive = jszip.loadAsync(slack_zip.data)
Insert cell
channelFiles = Object.keys(archive.files).filter(name => name.endsWith(".json"))
Insert cell
parse = file => {
return archive.file(file).async("text").then(JSON.parse).then(json => json.map(obj => ({...obj, channelName: file.split("/")[0]})))
}
Insert cell
parsedChannelFiles = Promise.all(channelFiles.map(parse))
Insert cell
messages = parsedChannelFiles.reduce((a,b) => a.concat(b), [])
Insert cell
users = archive.file("users.json").async("text").then(JSON.parse)
Insert cell
ts = queryParams.substring(4) - 0
Insert cell
findUser = userID => {
return users.find(user => user.id == userID)
}
Insert cell
renderMessage = message => {
return html`
<div class="message">
${displayTopLine(message.user, message.ts, message.username)}
<div>${renderMessageText(message.text)}</div>
</div>`
}
Insert cell
renderMessageText = messageText => md`${emoji.replace_colons(_.unescape(messageText)).replace(search, `<span style="background-color: #fcf5de">${search}</span>`).replace(/<@(.{9})>/g, (match, p1) => `<span style="background-color:#e8f5fa">@${findUser(p1).real_name}</span>`)}`
Insert cell
_ = require("lodash")
Insert cell
emojiJS = require("emoji-js")
Insert cell
emoji = {
let e = new emojiJS()
e.replace_mode = 'unified'
return e
}
Insert cell
displayTopLine = (user, ts, username) => `<div>
${findUser(user) ? `<img src="${findUser(user).profile.image_24}"></img>` : ``}
<b>${findUser(user) ? findUser(user).real_name : username}</b>
<a href="?ts=${ts}">
<span style="padding-left: 5px; font-size:12px;color:grey">
${new Date(ts * 1000).toLocaleString()}
</span>
</a>
</div>`
Insert cell
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more