add more stubs to matrix implementation

This commit is contained in:
hippoz 2022-10-09 23:23:02 +03:00
parent 425406c88a
commit 7d0d29bb8b
No known key found for this signature in database
GPG key ID: 7C52899193467641

View file

@ -29,6 +29,19 @@ const roomToChannelId = (room?: any): number | null => {
return numberId;
};
const matrixUserProfile = (matrixUserId: string) => {
if (typeof matrixUserId !== "string") return null;
const parts = matrixUserId.split(":", 1);
if (parts.length !== 1) return null;
const suffixedId = parts[0];
if (!suffixedId.startsWith("@")) return null;
const username = suffixedId.substring(1, suffixedId.length);
if (!username || username.length < 3 || username.length > 32) return null;
return {
displayname: username
};
};
interface MatrixSyncCursors {
[channel_id: number]: number;
@ -408,10 +421,64 @@ router.get(
"/_matrix/client/r0/profile/:userId",
authenticateRoute(),
(req, res) => {
res.json({
displayname: req.user.username
});
res.json(matrixUserProfile(req.params.userId));
}
);
router.get(
"/_matrix/client/r0/profile/:userId/displayname",
authenticateRoute(),
(req, res) => {
res.json(matrixUserProfile(req.params.userId));
}
);
router.get(
"/_matrix/client/r0/thirdparty/protocols",
authenticateRoute(),
(req, res) => {
res.json({});
}
);
router.get(
"/_matrix/client/r0/rooms/:roomId/state/:eventType",
authenticateRoute(),
(req, res) => {
if (req.params.eventType === "m.room.topic") {
res.json({
topic: ""
});
} else if (req.params.eventType === "m.room.avatar") {
res.json({});
} else {
res.json({
errcode: "M_BAD_JSON",
error: "Unsupported eventType"
});
}
}
);
router.get(
"/_matrix/client/r0/account/3pid",
authenticateRoute(),
(req, res) => {
res.json({
threepids: []
});
}
)
router.use((req, res, next) => {
//console.log("[matrix debug] [404]");
//console.log(` -> method: ${req.method}`)
//console.log(` -> path: ${req.path}`);
//console.log(` -> body: ${JSON.stringify(req.body)}`);
res.status(404).json({
errcode: "M_NOT_FOUND",
error: "Resource or route not found"
});
});
export default router;