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

@ -88,6 +88,9 @@ async function run() {
puppet.on("puppetDelete", steam.deletePuppet.bind(steam));
puppet.on("message", steam.handleMatrixMessage.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.setListUsersHook(steam.listUsers.bind(steam));
puppet.setGetDmRoomIdHook(steam.getDmRoomId.bind(steam));

View file

@ -9,7 +9,7 @@ import {
IRetList,
Log,
PuppetBridge,
Util,
Util, ISendingUser, IPresenceEvent,
} from "mx-puppet-bridge";
import * as SteamUser from "steam-user";
import * as SteamCommunity from "steamcommunity";
@ -495,4 +495,34 @@ export class Steam {
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);
}
}
}