m->d typing
This commit is contained in:
@@ -0,0 +1,41 @@
|
|||||||
|
// @ts-check
|
||||||
|
|
||||||
|
const {discord} = require("../../passthrough")
|
||||||
|
|
||||||
|
/** @type {Set<string>} channel ids that are currently typing */
|
||||||
|
const isTyping = new Set()
|
||||||
|
/** @type {Map<string, NodeJS.Timeout>} channel id -> interval */
|
||||||
|
const intervals = new Map()
|
||||||
|
|
||||||
|
/** @param {string} channelID */
|
||||||
|
function startTyping(channelID) {
|
||||||
|
if (!isTyping.has(channelID)) {
|
||||||
|
// Start a new typing session
|
||||||
|
isTyping.add(channelID)
|
||||||
|
intervals.set(channelID, setInterval(refreshTyping, 8e3, channelID))
|
||||||
|
discord.snow.channel.startChannelTyping(channelID).catch(() => {})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @param {string} channelID */
|
||||||
|
function refreshTyping(channelID) {
|
||||||
|
if (isTyping.has(channelID)) {
|
||||||
|
// Continue typing session
|
||||||
|
discord.snow.channel.startChannelTyping(channelID).catch(() => {})
|
||||||
|
} else {
|
||||||
|
// End typing session
|
||||||
|
clearInterval(intervals.get(channelID))
|
||||||
|
intervals.delete(channelID)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @param {string} channelID */
|
||||||
|
function stopTyping(channelID) {
|
||||||
|
if (isTyping.has(channelID)) {
|
||||||
|
// Schedule typing session to end
|
||||||
|
isTyping.delete(channelID)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports.startTyping = startTyping
|
||||||
|
module.exports.stopTyping = stopTyping
|
||||||
@@ -36,6 +36,8 @@ const roomUpgrade = require("../matrix/room-upgrade")
|
|||||||
const retrigger = sync.require("../d2m/actions/retrigger")
|
const retrigger = sync.require("../d2m/actions/retrigger")
|
||||||
/** @type {import("../matrix/homeserver-status")} */
|
/** @type {import("../matrix/homeserver-status")} */
|
||||||
const homeserverStatus = sync.require("../matrix/homeserver-status")
|
const homeserverStatus = sync.require("../matrix/homeserver-status")
|
||||||
|
/** @type {import("./actions/typing")} */
|
||||||
|
const typing = sync.require("./actions/typing")
|
||||||
const {reg} = require("../matrix/read-registration")
|
const {reg} = require("../matrix/read-registration")
|
||||||
|
|
||||||
let lastReportedEvent = 0
|
let lastReportedEvent = 0
|
||||||
@@ -527,6 +529,20 @@ async event => {
|
|||||||
await createRoom.unbridgeChannel(channel, channel["guild_id"], "Encrypted rooms are not supported. This room was removed from the bridge.")
|
await createRoom.unbridgeChannel(channel, channel["guild_id"], "Encrypted rooms are not supported. This room was removed from the bridge.")
|
||||||
}))
|
}))
|
||||||
|
|
||||||
|
sync.addTemporaryListener(as, "ephemeral_type:m.typing", guard("m.typing",
|
||||||
|
/**
|
||||||
|
* @param {Ty.Event.Outer_M_Typing} event
|
||||||
|
*/
|
||||||
|
async event => {
|
||||||
|
const channelID = select("channel_room", "channel_id", {room_id: event.room_id}).pluck().get()
|
||||||
|
if (!channelID) return
|
||||||
|
if (event.content.user_ids.length) {
|
||||||
|
typing.startTyping(channelID)
|
||||||
|
} else {
|
||||||
|
typing.stopTyping(channelID)
|
||||||
|
}
|
||||||
|
}))
|
||||||
|
|
||||||
module.exports.stringifyErrorStack = stringifyErrorStack
|
module.exports.stringifyErrorStack = stringifyErrorStack
|
||||||
module.exports.cleanErrorStack = cleanErrorStack
|
module.exports.cleanErrorStack = cleanErrorStack
|
||||||
module.exports.sendError = sendError
|
module.exports.sendError = sendError
|
||||||
|
|||||||
@@ -17,6 +17,10 @@ function checkRegistration(reg) {
|
|||||||
assert(reg.ooye?.server_origin.match(/^https?:\/\//), "server origin must start with http or https")
|
assert(reg.ooye?.server_origin.match(/^https?:\/\//), "server origin must start with http or https")
|
||||||
assert.notEqual(reg.ooye?.server_origin.slice(-1), "/", "server origin must not end in slash")
|
assert.notEqual(reg.ooye?.server_origin.slice(-1), "/", "server origin must not end in slash")
|
||||||
assert.match(reg.url, /^https?:/, "url must start with http:// or https://")
|
assert.match(reg.url, /^https?:/, "url must start with http:// or https://")
|
||||||
|
if (!reg.receive_ephemeral) {
|
||||||
|
reg.receive_ephemeral = true
|
||||||
|
writeRegistration(reg)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* c8 ignore next 4 */
|
/* c8 ignore next 4 */
|
||||||
@@ -50,6 +54,7 @@ function getTemplateRegistration(serverName) {
|
|||||||
],
|
],
|
||||||
sender_localpart: `${namespace_prefix}bot`,
|
sender_localpart: `${namespace_prefix}bot`,
|
||||||
rate_limited: false,
|
rate_limited: false,
|
||||||
|
receive_ephemeral: true,
|
||||||
socket: 6693,
|
socket: 6693,
|
||||||
ooye: {
|
ooye: {
|
||||||
namespace_prefix,
|
namespace_prefix,
|
||||||
|
|||||||
Vendored
+10
@@ -18,6 +18,7 @@ export type AppServiceRegistrationConfig = {
|
|||||||
}
|
}
|
||||||
protocols: [string]
|
protocols: [string]
|
||||||
rate_limited: boolean
|
rate_limited: boolean
|
||||||
|
receive_ephemeral: boolean
|
||||||
socket?: string | number,
|
socket?: string | number,
|
||||||
ooye: {
|
ooye: {
|
||||||
namespace_prefix: string
|
namespace_prefix: string
|
||||||
@@ -59,6 +60,7 @@ export type InitialAppServiceRegistrationConfig = {
|
|||||||
}
|
}
|
||||||
protocols: [string]
|
protocols: [string]
|
||||||
rate_limited: boolean
|
rate_limited: boolean
|
||||||
|
receive_ephemeral: boolean
|
||||||
socket?: string | number,
|
socket?: string | number,
|
||||||
ooye: {
|
ooye: {
|
||||||
namespace_prefix: string
|
namespace_prefix: string
|
||||||
@@ -396,6 +398,14 @@ export namespace Event {
|
|||||||
rotation_period_ms?: number
|
rotation_period_ms?: number
|
||||||
rotation_period_msgs?: number
|
rotation_period_msgs?: number
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export type Outer_M_Typing = {
|
||||||
|
content: {
|
||||||
|
user_ids: string[]
|
||||||
|
}
|
||||||
|
room_id: string
|
||||||
|
type: "m.typing"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export namespace R {
|
export namespace R {
|
||||||
|
|||||||
Reference in New Issue
Block a user