Commit 11cb6b1f authored by Tim Kinnane's avatar Tim Kinnane

fix(roomid): Get direct message room ID from attribute

parent 1aeabf0f
This diff is collapsed.
......@@ -344,9 +344,10 @@ export function getRoomName (id: string): Promise<string> {
/**
* Get ID for a DM room by its recipient's name.
* Will create a DM (with the bot) if it doesn't exist already.
* @todo test why create resolves with object instead of simply ID
*/
export function getDirectMessageRoomId (username: string): Promise<string> {
return cacheCall('createDirectMessage', username)
return cacheCall('createDirectMessage', username).then((DM) => DM.rid)
}
/** Join the bot into a room by its name or ID */
......@@ -377,7 +378,7 @@ export function prepareMessage (content: string | IMessage, roomId?: string): Me
export function sendMessageByRoomId (content: string | string[] | IMessage, roomId: string): Promise<any> {
let messages: Message[] = []
if (Array.isArray(content)) {
content.forEach((msg) => messages.push(prepareMessage(msg, roomId)))
content.forEach((text) => messages.push(prepareMessage(text, roomId)))
} else {
messages.push(prepareMessage(content))
}
......@@ -393,6 +394,13 @@ export function sendMessageByRoom (content: string | string[] | IMessage, room:
return getRoomId(room).then((roomId) => sendMessageByRoomId(content, roomId))
}
/**
* Send a message to a user in a DM.
*/
export function sendDirectToUser (message: string | string[] | IMessage, username: string): Promise<any> {
return getDirectMessageRoomId(username).then((rid) => sendMessageByRoomId(message, rid))
}
/**
* Send a prepared message object (with pre-defined room ID).
* Usually prepared and called by sendMessageByRoomId or sendMessageByRoom.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment