aliases, message author, get rid from bulma

This commit is contained in:
doesnm 2024-01-30 18:33:43 +03:00
parent 9da947d32e
commit 6c5bb9a6d1
3 changed files with 23 additions and 18 deletions

View file

@ -5,4 +5,3 @@
При переходе на #!id:homeserver.ru если комната разрешает просмотр гостям, то появляется "список постов"
Можно получить отдельное событие через #id:homeserver.ru/!event_id:homeserver.ru
[![Made with Bulma](https://bulma.io/images/made-with-bulma.png)](https://bulma.io)

30
blog.js
View file

@ -1,6 +1,5 @@
let posts = [];
const table = document.querySelector("table");
function getReactions(posts,p){
let reactions = [];
const preReactions = posts.filter(f => f.type == "m.reaction" && f.content["m.relates_to"].event_id == p.event_id).map(m => m.content["m.relates_to"]);
@ -23,8 +22,8 @@ function getReactions(posts,p){
}
function printPost(post,roomId,noButton){
let body = DOMPurify.sanitize(post.content.formatted_body ?? post.content.body);
body = body.split("\n").join("<br>");
table.innerHTML += `<tr><td>${body}${post.content.msgtype == "m.image" ? `<br><img src="https://matrix.org/_matrix/media/v3/download/${post.content.url.slice(6)}">` : ''}${!noButton ? `<a href="#${roomId}/${post.event_id}">Открыть</a>` : ''}</td></tr>`;
body = body.split("\n").join("<br>");
table.innerHTML += `<tr><td><b>${post.sender}</b><br>${body}${post.content.msgtype == "m.image" ? `<br><img src="https://matrix.org/_matrix/media/v3/download/${post.content.url.slice(6)}">` : ''}${!noButton ? `<br><a href="#${roomId}/${post.event_id}">Открыть</a>` : ''}</td></tr>`;
}
function loadPosts(roomId,start){
@ -41,11 +40,17 @@ if(!["m.room.message","m.reaction"].includes(c.type)) return;
if(c.redacted_because) return;
if(ignored_events.includes(c.event_id)) return;
if(c.type == "m.room.message"){
if(c.content.formatted_body != undefined){
c.content.body = "";
if(c.content["m.new_content"]) c.content["m.new_content"].body = "";
}
}
if(c.content.formatted_body != undefined){
c.content.body = "";
if(c.content["m.new_content"]) c.content["m.new_content"].body = "";
}
}
if(c.content["m.new_content"]){
if(ignored_events.includes(c.content["m.relates_to"].event_id)) return;
@ -53,19 +58,26 @@ if(c.type == "m.room.message"){
c.content = c.content["m.new_content"];
}
posts.push(c);
});
})
posts.forEach((p,i,a) => {
printPost(p,roomId);
});
if(json.end) table.innerHTML += `<button class="button is-fullwidth" onclick="loadPosts('${roomId}','${json.end}')">Ещё</button>`;
});
})
}
}
window.onhashchange = () => {
let hash = location.hash.slice(1);
if(hash.startsWith("!") && !hash.includes("/")){
return loadPosts(hash,undefined);
}else if(('#' + hash).match(/\#(.*)\:(\w*)\.(\w*)/gm)){
fetch(`https://matrix.org/_matrix/client/v3/directory/room/%23${hash.replace(":","%3A")}`).then(r => r.json()).then(json => {
if(!json.room_id){
table.innerHTML = `<tr><th>Ошибка!</th><tr><td>Алиас не найден</td></tr></tr>`;
}else{
loadPosts(json.room_id)
}
})
}
if(hash.includes("/")){
hash = hash.split("/");
@ -81,8 +93,8 @@ table.innerHTML = `<tr><th>Контент</th></tr>`;
}
});
}else{
//loadPosts("roomId");
table.innerHTML = "<tr><th>Добро пожаловать</th></tr><tr><td>Это блог работающий поверх децентрализованного мессенджера Matrix</td></tr>"
table.innerHTML = '<tr><th>Добро пожаловать</th></tr><tr><td>Это блог работающий поверх децентрализованного мессенджера Matrix</td></tr>'
}
};
window.addEventListener("load", () => {

View file

@ -3,18 +3,12 @@
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bulma@0.9.4/css/bulma.min.css">
<meta name="description" content="Blog powered by Matrix">
<title>Blog</title>
</head>
<body>
<table class="table is-bordered is-fullwidth">
<tr>
<th>АААААААААААААААААААААААААААААААА</th>
</tr>
</table>
<table class="table is-bordered is-fullwidth"></table>
<script src="https://cdnjs.cloudflare.com/ajax/libs/dompurify/3.0.6/purify.min.js" integrity="sha512-H+rglffZ6f5gF7UJgvH4Naa+fGCgjrHKMgoFOGmcPTRwR6oILo5R+gtzNrpDp7iMV3udbymBVjkeZGNz1Em4rQ==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<!-- <script src="https://code.jquery.com/jquery-3.7.1.min.js"></script> -->
<script src="blog.js"></script>
</body>
</html>