Skip to content

Commit

Permalink
feat(line): support audio, video, file and more elements
Browse files Browse the repository at this point in the history
  • Loading branch information
shigma committed Jul 16, 2023
1 parent b714a2e commit 960938c
Showing 1 changed file with 11 additions and 24 deletions.
35 changes: 11 additions & 24 deletions adapters/mail/src/message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,40 +39,21 @@ export class MailMessageEncoder extends MessageEncoder<MailBot> {
const { type, attrs, children } = element
if (type === 'text') {
this.buffer += attrs.content
} else if (type === 'b' || type === 'strong') {
this.buffer += '<b>'
} else if (['b', 'strong', 'i', 'em', 'u', 'ins', 's', 'del', 'p', 'code', 'li', 'ul', 'ol', 'blockquote'].includes(type)) {
this.buffer += `<${type}>`
await this.render(children)
this.buffer += '</b>'
} else if (type === 'i' || type === 'em') {
this.buffer += '<i>'
await this.render(children)
this.buffer += '</i>'
} else if (type === 'u' || type === 'ins') {
this.buffer += '<u>'
await this.render(children)
this.buffer += '</u>'
} else if (type === 's' || type === 'del') {
this.buffer += '<s>'
await this.render(children)
this.buffer += '</s>'
} else if (type === 'code') {
this.buffer += '<code>'
await this.render(children)
this.buffer += '</code>'
this.buffer += `</${type}>`
} else if (type === 'a') {
this.buffer += `<a href=${attrs.href}>`
await this.render(children)
this.buffer += `</a>`
} else if (type === 'p') {
await this.render(children)
this.buffer += `\n`
} else if (type === 'at') {
if (attrs.id) {
this.buffer += `<a href="mailto:${attrs.id}">@${attrs.id}</a>`
}
} else if (type === 'sharp' && attrs.id) {
this.buffer += ` #${attrs.id} `
} else if (type === 'image' && attrs.url) {
} else if (['image', 'audio', 'video', 'file'].includes(type) && attrs.url) {
let url: string
if (attrs.url.match(/^https?:/)) {
url = attrs.url
Expand All @@ -87,7 +68,13 @@ export class MailMessageEncoder extends MessageEncoder<MailBot> {
})
url = `cid:${cid}`
}
this.buffer += `<img src="${url}"/>`
if (type === 'image') {
this.buffer += `<img src="${url}" />`
} else if (type === 'audio') {
this.buffer += `<audio src="${url}" controls />`
} else if (type === 'video') {
this.buffer += `<video src="${url}" controls />`
}
} else if (type === 'quote') {
this.reply = attrs.id
} else if (type === 'message') {
Expand Down

0 comments on commit 960938c

Please sign in to comment.