d->m bridge emojis in messages
This commit is contained in:
		
							parent
							
								
									94c4b6a262
								
							
						
					
					
						commit
						1657de4eef
					
				
					 5 changed files with 104 additions and 4 deletions
				
			
		| 
						 | 
				
			
			@ -41,8 +41,12 @@ function getDiscordParseCallbacks(message, useHTML) {
 | 
			
		|||
		/** @param {{animated: boolean, name: string, id: string, type: "discordEmoji"}} node */
 | 
			
		||||
		emoji: node => {
 | 
			
		||||
			if (useHTML) {
 | 
			
		||||
				// TODO: upload the emoji and actually use the right mxc!!
 | 
			
		||||
				return `<img src="mxc://cadence.moe/${node.id}" data-mx-emoticon alt=":${node.name}:" title=":${node.name}:" height="24">`
 | 
			
		||||
				const mxc = select("emoji", "mxc_url", "WHERE emoji_id = ?").pluck().get(node.id)
 | 
			
		||||
				if (mxc) {
 | 
			
		||||
					return `<img data-mx-emoticon height="32" src="${mxc}" title=":${node.name}:" alt=":${node.name}:">`
 | 
			
		||||
				} else {
 | 
			
		||||
					return `<img src="mxc://cadence.moe/${node.id}" data-mx-emoticon alt=":${node.name}:" title=":${node.name}:" height="24">`
 | 
			
		||||
				}
 | 
			
		||||
			} else {
 | 
			
		||||
				return `:${node.name}:`
 | 
			
		||||
			}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -379,3 +379,27 @@ test("message2event: thread start message reference", async t => {
 | 
			
		|||
		"m.mentions": {}
 | 
			
		||||
	}])
 | 
			
		||||
})
 | 
			
		||||
 | 
			
		||||
test("message2event: single large bridged emoji", async t => {
 | 
			
		||||
	const events = await messageToEvent(data.message.single_emoji, data.guild.general, {})
 | 
			
		||||
	t.deepEqual(events, [{
 | 
			
		||||
		$type: "m.room.message",
 | 
			
		||||
		"m.mentions": {},
 | 
			
		||||
		msgtype: "m.text",
 | 
			
		||||
		body: ":hippo:",
 | 
			
		||||
		format: "org.matrix.custom.html",
 | 
			
		||||
		formatted_body: '<img data-mx-emoticon height="32" src="mxc://cadence.moe/qWmbXeRspZRLPcjseyLmeyXC" title=":hippo:" alt=":hippo:">'
 | 
			
		||||
	}])
 | 
			
		||||
})
 | 
			
		||||
 | 
			
		||||
test("message2event: mid-message small bridged emoji", async t => {
 | 
			
		||||
	const events = await messageToEvent(data.message.surrounded_emoji, data.guild.general, {})
 | 
			
		||||
	t.deepEqual(events, [{
 | 
			
		||||
		$type: "m.room.message",
 | 
			
		||||
		"m.mentions": {},
 | 
			
		||||
		msgtype: "m.text",
 | 
			
		||||
		body: "h is for :hippo:!",
 | 
			
		||||
		format: "org.matrix.custom.html",
 | 
			
		||||
		formatted_body: 'h is for <img data-mx-emoticon height="32" src="mxc://cadence.moe/qWmbXeRspZRLPcjseyLmeyXC" title=":hippo:" alt=":hippo:">!'
 | 
			
		||||
	}])
 | 
			
		||||
})
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue