add support for ephemeral events

This commit is contained in:
Robin Appelman 2020-12-05 18:07:14 +01:00
commit 21e919167c
3 changed files with 45 additions and 1 deletions

View file

@ -26,3 +26,14 @@ link <username> <password>
``` ```
If a steam guard (mobile or email) code is required, you will be asked for the code. If a steam guard (mobile or email) code is required, you will be asked for the code.
## Ephemeral events
To enable bridging ephemeral events from matrix to steam (typing notification, read markers and presence)
you'll need to enable the experimental support in synapse for pushing these events to the bridge by setting
```yaml
"de.sorunome.msc2409.push_ephemeral": true
```
in your registration file.

View file

@ -88,6 +88,9 @@ async function run() {
puppet.on("puppetDelete", steam.deletePuppet.bind(steam)); puppet.on("puppetDelete", steam.deletePuppet.bind(steam));
puppet.on("message", steam.handleMatrixMessage.bind(steam)); puppet.on("message", steam.handleMatrixMessage.bind(steam));
puppet.on("image", steam.handleMatrixImage.bind(steam)); puppet.on("image", steam.handleMatrixImage.bind(steam));
puppet.on("typing", steam.handleMatrixTyping.bind(steam));
puppet.on("read", steam.handleMatrixRead.bind(steam));
puppet.on("presence", steam.handleMatrixPresence.bind(steam));
puppet.setCreateUserHook(steam.createUser.bind(steam)); puppet.setCreateUserHook(steam.createUser.bind(steam));
puppet.setListUsersHook(steam.listUsers.bind(steam)); puppet.setListUsersHook(steam.listUsers.bind(steam));
puppet.setGetDmRoomIdHook(steam.getDmRoomId.bind(steam)); puppet.setGetDmRoomIdHook(steam.getDmRoomId.bind(steam));

View file

@ -9,7 +9,7 @@ import {
IRetList, IRetList,
Log, Log,
PuppetBridge, PuppetBridge,
Util, Util, ISendingUser, IPresenceEvent,
} from "mx-puppet-bridge"; } from "mx-puppet-bridge";
import * as SteamUser from "steam-user"; import * as SteamUser from "steam-user";
import * as SteamCommunity from "steamcommunity"; import * as SteamCommunity from "steamcommunity";
@ -495,4 +495,34 @@ export class Steam {
avatarUrl: chat_room_group.group_summary.chat_group_avatar_url, avatarUrl: chat_room_group.group_summary.chat_group_avatar_url,
}; };
} }
public handleMatrixTyping(room: IRemoteRoom, typing: boolean) {
const p = this.puppets[room.puppetId];
let steamId = this.getRoomSteamId(room);
if (steamId && typing) {
p.client.chat.sendFriendTyping(steamId);
}
}
public handleMatrixRead(room: IRemoteRoom, eventId: string) {
const p = this.puppets[room.puppetId];
let steamId = this.getRoomSteamId(room);
if (steamId) {
p.client.chat.ackFriendMessage(steamId, new Date());
} else {
let [groupId, chatId] = this.parseChatRoomId(room.roomId);
p.client.chat.ackChatMessage(groupId, chatId, new Date());
}
}
public handleMatrixPresence(puppetId, presence: IPresenceEvent) {
const p = this.puppets[puppetId];
if (presence.presence === "offline") {
p.client.setPersona(EPersonaState.Offline);
} else if (presence.presence === "online") {
p.client.setPersona(EPersonaState.Online);
} else if (presence.presence === "unavailable") {
p.client.setPersona(EPersonaState.Away);
}
}
} }