aboutsummaryrefslogtreecommitdiff
path: root/lib/serve.js
diff options
context:
space:
mode:
authorcel <cel@f/6sQ6d2CMxRUhLpspgGIulDxDCwYD7DzFzPNr7u5AU=.ed25519>2017-05-30 13:05:11 -1000
committercel <cel@f/6sQ6d2CMxRUhLpspgGIulDxDCwYD7DzFzPNr7u5AU=.ed25519>2017-05-30 13:05:11 -1000
commitc128fb17b25cb8adb9cb9e6c91cdc8e952e342a5 (patch)
treef59951c535d297cdff1ee75ebac976134d989a48 /lib/serve.js
parent584d7b9070f3c4ad05308c809e30b3ce0d1c5fce (diff)
downloadpatchfoo-c128fb17b25cb8adb9cb9e6c91cdc8e952e342a5.tar.gz
patchfoo-c128fb17b25cb8adb9cb9e6c91cdc8e952e342a5.zip
add built-in emoji as blobs
Diffstat (limited to 'lib/serve.js')
-rw-r--r--lib/serve.js49
1 files changed, 46 insertions, 3 deletions
diff --git a/lib/serve.js b/lib/serve.js
index b6a058a..1909bbc 100644
--- a/lib/serve.js
+++ b/lib/serve.js
@@ -19,6 +19,7 @@ var mime = require('mime-types')
var ident = require('pull-identify-filetype')
var htime = require('human-time')
var ph = require('pull-hyperscript')
+var emojis = require('emoji-named-characters')
module.exports = Serve
@@ -1970,7 +1971,18 @@ Serve.prototype.composer = function (opts, cb) {
.map(function (mention) { return mention.name })
.filter(uniques())
.map(function (name) {
- var id = formEmojiNames[name] || self.app.getReverseEmojiNameSync(name)
+ // 1. check emoji-image mapping for this message
+ var id = formEmojiNames[name]
+ if (id) return {name: name, id: id}
+ // 2. TODO: check user's preferred emoji-image mapping
+ // 3. check builtin emoji
+ var link = self.getBuiltinEmojiLink(name)
+ if (link) {
+ return {name: name, id: link.link}
+ blobs[id] = {type: link.type, size: link.size}
+ }
+ // 4. check recently seen emoji
+ id = self.app.getReverseEmojiNameSync(name)
return {name: name, id: id}
})
@@ -2054,8 +2066,17 @@ Serve.prototype.composer = function (opts, cb) {
.filter(function (mention) {
if (mention.emoji) {
mention.link = formEmojiNames[mention.name]
- || self.app.getReverseEmojiNameSync(mention.name)
- if (!mention.link) return false
+ if (!mention.link) {
+ var link = self.getBuiltinEmojiLink(mention.name)
+ if (link) {
+ mention.link = link.link
+ mention.size = link.size
+ mention.type = link.type
+ } else {
+ mention.link = self.app.getReverseEmojiNameSync(mention.name)
+ if (!mention.link) return false
+ }
+ }
}
var blob = blobs[mention.link]
if (blob) {
@@ -2172,6 +2193,28 @@ Serve.prototype.composer = function (opts, cb) {
}
+function hashBuf(buf) {
+ var hash = crypto.createHash('sha256')
+ hash.update(buf)
+ return '&' + hash.digest('base64') + '.sha256'
+}
+
+Serve.prototype.getBuiltinEmojiLink = function (name) {
+ if (!(name in emojis)) return
+ var file = path.join(emojiDir, name + '.png')
+ var fileBuf = fs.readFileSync(file)
+ var id = hashBuf(fileBuf)
+ // seed the builtin emoji
+ pull(pull.once(fileBuf), this.app.sbot.blobs.add(id, function (err) {
+ if (err) console.error('error adding builtin emoji as blob', err)
+ }))
+ return {
+ link: id,
+ type: 'image/png',
+ size: fileBuf.length,
+ }
+}
+
Serve.prototype.emojis = function (path) {
var self = this
pull(