Blocking users proof of concept

This commit is contained in:
tezlm 2023-02-05 09:27:13 -08:00
parent 0000203596
commit 0000204863
Signed by: tezlm
GPG key ID: 649733FCD94AFBBA
3 changed files with 32 additions and 11 deletions

View file

@ -1,3 +1,10 @@
function shouldFilter(ev) {
const { ignored_users: ignored } = state.client.accountData.get("m.ignored_user_list");
return !ev.content["m.new_content"]
&& ev.type !== "m.reaction"
&& !ignored[ev.sender.id];
}
export default class Slice {
private foundStart = false;
private foundEnd = false;
@ -23,16 +30,14 @@ export default class Slice {
const endIdx = timeline.length - 1;
this.start = timeline[startIdx];
this.end = timeline[endIdx];
this.events = timeline.slice(startIdx, endIdx + 1)
.filter((ev) => !ev.content["m.new_content"] && ev.type !== "m.reaction");
this.events = timeline.slice(startIdx, endIdx + 1).filter(shouldFilter);
}
reslice() {
const { timeline, start, end } = this;
const startIdx = timeline.lastIndexOf(start);
const endIdx = timeline.lastIndexOf(end);
this.events = timeline.slice(startIdx, endIdx + 1)
.filter((ev) => !ev.content["m.new_content"] && ev.type !== "m.reaction");
this.events = timeline.slice(startIdx, endIdx + 1).filter(shouldFilter);
}
async backwards(count = 50) {
@ -54,8 +59,7 @@ export default class Slice {
this.start = timeline[newStart];
this.end = timeline[newEnd];
this.events = timeline.slice(newStart, newEnd + 1)
.filter((ev) => !ev.content["m.new_content"] && ev.type !== "m.reaction");
this.events = timeline.slice(newStart, newEnd + 1).filter(shouldFilter);
if (this.events.indexOf(undefined) >= 0) state.log.error("missing event!");
}
@ -78,8 +82,7 @@ export default class Slice {
this.start = timeline[newStart];
this.end = timeline[newEnd];
this.events = timeline.slice(newStart, newEnd + 1)
.filter((ev) => !ev.content["m.new_content"] && ev.type !== "m.reaction");
this.events = timeline.slice(newStart, newEnd + 1).filter(shouldFilter);
}
async jump(eventId, count = 50) {
@ -94,7 +97,6 @@ export default class Slice {
this.start = timeline[newStart];
this.end = timeline[newEnd];
this.events = timeline.slice(newStart, newEnd + 1)
.filter((ev) => !ev.content["m.new_content"] && ev.type !== "m.reaction");
this.events = timeline.slice(newStart, newEnd + 1).filter(shouldFilter);
}
}

View file

@ -4,7 +4,9 @@ import Avatar from "../../atoms/Avatar.svelte";
import { parseHtml } from "../../../util/html";
import { fastclick } from "../../../util/use";
export let room, eventId;
const { accountData } = state;
$: eventPromise = room.events.fetch(eventId);
$: ignored = $accountData.get("m.ignored_user_list");
</script>
<style>
.reply {
@ -114,6 +116,10 @@ $: eventPromise = room.events.fetch(eventId);
animation: dots 1s infinite;
}
.blocked ~ * { visibility: hidden; }
.reply:hover > * { visibility: visible; }
.reply:hover > .blocked { display: none; }
@keyframes dots {
0% { content: ""; }
25% { content: "."; }
@ -127,6 +133,11 @@ $: eventPromise = room.events.fetch(eventId);
</div>
{:then event}
<div class="reply">
{#if ignored.ignored_users[event.sender.id]}
<div class="blocked">
Sender blocked, hover to view
</div>
{/if}
<div class="avatar">
<Avatar user={event.sender} size={16} />
</div>

View file

@ -203,11 +203,19 @@ export function memberContext(member: Member): Array<ContextMenuOption> {
}
const menu = [];
const ignored = state.client.accountData.get("m.ignored_user_list");
menu.push(
{ label: "Profile", icon: "person", clicked: () => { state.popout.set({}); state.popup.set({ id: "user", userId: member.id }) } },
{ label: "Mention", icon: "notifications", clicked: () => { const { input } = state.roomState; input.set(get(input) + member.id); close() } },
{ label: "Message", icon: "message", clicked: todo },
{ label: "Block", icon: "block", clicked: todo },
{ label: ignored.ignored_users[member.id] ? "Unblock": "Block", icon: "block", clicked: () => {
if (ignored.ignored_users[member.id]) {
delete ignored.ignored_users[member.id];
} else {
ignored.ignored_users[member.id] = {};
}
state.client.accountData.put("m.ignored_user_list", ignored);
} },
null,
);