Skip to content
This repository has been archived by the owner on Apr 19, 2022. It is now read-only.

Commit

Permalink
add support for ephemeral events
Browse files Browse the repository at this point in the history
  • Loading branch information
Sorunome committed Mar 2, 2021
1 parent 291bbc2 commit 46d4a71
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,8 @@ async function run() {
puppet.on("removeReaction", slack.handleMatrixRemoveReaction.bind(slack));
puppet.on("image", slack.handleMatrixImage.bind(slack));
puppet.on("file", slack.handleMatrixFile.bind(slack));
puppet.on("presence", slack.handleMatrixPresence.bind(slack));
puppet.on("typing", slack.handleMatrixTyping.bind(slack));
puppet.setCreateUserHook(slack.createUser.bind(slack));
puppet.setCreateRoomHook(slack.createRoom.bind(slack));
puppet.setCreateGroupHook(slack.createGroup.bind(slack));
Expand Down
41 changes: 41 additions & 0 deletions src/slack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
IStringFormatterVars,
MessageDeduplicator,
ISendingUser,
IPresenceEvent,
} from "mx-puppet-bridge";
import {
SlackMessageParser, ISlackMessageParserOpts, MatrixMessageParser, IMatrixMessageParserOpts,
Expand Down Expand Up @@ -790,6 +791,46 @@ export class App {
}
}

public async handleMatrixPresence(
puppetId: number,
presence: IPresenceEvent,
asUser: ISendingUser | null,
event: any,
) {
const p = this.puppets[puppetId];
if (!p || asUser) {
return;
}
if (presence.statusMsg) {
await p.client.setStatus(presence.statusMsg);
}
await p.client.setPresence({
online: "auto",
offline: "away",
unavailable: "away",
}[presence.presence] as "auto" | "away");
}

public async handleMatrixTyping(
room: IRemoteRoom,
typing: boolean,
asUser: ISendingUser | null,
event: any,
) {
const p = this.puppets[room.puppetId];
if (!p || asUser) {
return;
}
const chan = p.client.getChannel(room.roomId);
if (!chan) {
log.warn(`Room ${room.roomId} not found!`);
return;
}
if (typing) {
await chan.sendTyping();
}
}

public async createRoom(room: IRemoteRoom): Promise<IRemoteRoom | null> {
const p = this.puppets[room.puppetId];
if (!p) {
Expand Down

0 comments on commit 46d4a71

Please sign in to comment.