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 если комната разрешает просмотр гостям, то появляется "список постов"
Можно получить отдельное событие через #id:homeserver.ru/!event_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 = []; let posts = [];
const table = document.querySelector("table"); const table = document.querySelector("table");
function getReactions(posts,p){ function getReactions(posts,p){
let reactions = []; 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"]); 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){ function printPost(post,roomId,noButton){
let body = DOMPurify.sanitize(post.content.formatted_body ?? post.content.body); let body = DOMPurify.sanitize(post.content.formatted_body ?? post.content.body);
body = body.split("\n").join("<br>"); 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>`; 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){ function loadPosts(roomId,start){
@ -41,10 +40,16 @@ if(!["m.room.message","m.reaction"].includes(c.type)) return;
if(c.redacted_because) return; if(c.redacted_because) return;
if(ignored_events.includes(c.event_id)) return; if(ignored_events.includes(c.event_id)) return;
if(c.type == "m.room.message"){ if(c.type == "m.room.message"){
if(c.content.formatted_body != undefined){ if(c.content.formatted_body != undefined){
c.content.body = ""; c.content.body = "";
if(c.content["m.new_content"]) c.content["m.new_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(c.content["m.new_content"]){
@ -53,19 +58,26 @@ if(c.type == "m.room.message"){
c.content = c.content["m.new_content"]; c.content = c.content["m.new_content"];
} }
posts.push(c); posts.push(c);
}); })
posts.forEach((p,i,a) => { posts.forEach((p,i,a) => {
printPost(p,roomId); printPost(p,roomId);
}); });
if(json.end) table.innerHTML += `<button class="button is-fullwidth" onclick="loadPosts('${roomId}','${json.end}')">Ещё</button>`; if(json.end) table.innerHTML += `<button class="button is-fullwidth" onclick="loadPosts('${roomId}','${json.end}')">Ещё</button>`;
}); })
} }
} }
window.onhashchange = () => { window.onhashchange = () => {
let hash = location.hash.slice(1); let hash = location.hash.slice(1);
if(hash.startsWith("!") && !hash.includes("/")){ if(hash.startsWith("!") && !hash.includes("/")){
return loadPosts(hash,undefined); 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("/")){ if(hash.includes("/")){
hash = hash.split("/"); hash = hash.split("/");
@ -81,8 +93,8 @@ table.innerHTML = `<tr><th>Контент</th></tr>`;
} }
}); });
}else{ }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", () => { window.addEventListener("load", () => {

View file

@ -3,18 +3,12 @@
<head> <head>
<meta charset="UTF-8"> <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <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"> <meta name="description" content="Blog powered by Matrix">
<title>Blog</title> <title>Blog</title>
</head> </head>
<body> <body>
<table class="table is-bordered is-fullwidth"> <table class="table is-bordered is-fullwidth"></table>
<tr>
<th>АААААААААААААААААААААААААААААААА</th>
</tr>
</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://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> <script src="blog.js"></script>
</body> </body>
</html> </html>