forked from cadence/out-of-your-element
Comparison of all the stuff I did. #6
1 changed files with 5 additions and 3 deletions
|
|
@ -19,19 +19,21 @@ const userRegex = reg.namespaces.users.map(u => new RegExp(u.regex))
|
|||
*/
|
||||
async function threadToAnnouncement(parentRoomID, threadRoomID, creatorMxid, thread, di) {
|
||||
const branchedFromEventID = select("event_message", "event_id", {message_id: thread.id}).pluck().get()
|
||||
/** @type {{"m.mentions"?: any, "m.in_reply_to"?: any}} */
|
||||
/** @type {{"m.mentions"?: any, "m.relates_to"?: {event_id?: string, is_falling_back?: boolean, "m.in_reply_to"?: {event_id: string}, rel_type?: "m.replace"|"m.thread"}}} */
|
||||
const context = {}
|
||||
let suffix = "";
|
||||
if (branchedFromEventID) {
|
||||
// Need to figure out who sent that event...
|
||||
const event = await di.api.getEvent(parentRoomID, branchedFromEventID)
|
||||
context["m.relates_to"] = {"m.in_reply_to": {event_id: event.event_id}}
|
||||
suffix = "\n\n*[Note: You should talk there, rather than in this newly-created Matrix thread. Any messages sent here will be bridged as replies, which is probably not what you want.]*";
|
||||
context["m.relates_to"] = {"m.in_reply_to": {event_id: event.event_id}, is_falling_back:false, event_id: event.event_id, rel_type: "m.thread"}
|
||||
if (event.sender && !userRegex.some(rx => event.sender.match(rx))) context["m.mentions"] = {user_ids: [event.sender]}
|
||||
}
|
||||
|
||||
const msgtype = creatorMxid ? "m.emote" : "m.text"
|
||||
const template = creatorMxid ? "started a thread:" : "Thread started:"
|
||||
const via = await mxUtils.getViaServersQuery(threadRoomID, di.api)
|
||||
let body = `${template} ${thread.name} https://matrix.to/#/${threadRoomID}?${via.toString()}`
|
||||
let body = `${template} ${thread.name} https://matrix.to/#/${threadRoomID}?${via.toString()}${suffix}`
|
||||
|
||||
return {
|
||||
msgtype,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue