Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mark all as read for all chats in a scope #5964

Merged
merged 2 commits into from
Jun 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 22 additions & 3 deletions frontend/app/src/components/home/ChatList.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
chatIdentifiersEqual,
emptyCombinedUnreadCounts,
chatIdentifierToString,
type CombinedUnreadCounts,
} from "openchat-client";
import { afterUpdate, beforeUpdate, createEventDispatcher, getContext, tick } from "svelte";
import SearchResult from "./SearchResult.svelte";
Expand Down Expand Up @@ -102,12 +103,24 @@
}
}

$: canMarkAllRead = anythingUnread(unreadCounts);

$: {
if (view === "threads" && searchTerm !== "") {
view = "chats";
}
}

function anythingUnread(unread: CombinedUnreadCounts): boolean {
return (
unread.chats.muted +
unread.chats.unmuted +
unread.threads.muted +
unread.threads.unmuted >
0
);
}

function cancelPreview() {
if ($selectedCommunity) {
client.removeCommunity($selectedCommunity.id);
Expand Down Expand Up @@ -198,19 +211,25 @@
const scrollTop = view === "chats" ? chatsScrollTop : 0;
tick().then(() => (chatListElement.scrollTop = scrollTop));
}

function markAllRead() {
client.markAllReadForCurrentScope();
}
</script>

<!-- svelte-ignore missing-declaration -->
{#if user}
{#if $chatListScope.kind === "favourite"}
<FavouriteChatsHeader />
<FavouriteChatsHeader on:markAllRead={markAllRead} {canMarkAllRead} />
{:else if $chatListScope.kind === "group_chat"}
<GroupChatsHeader on:newGroup />
<GroupChatsHeader on:markAllRead={markAllRead} {canMarkAllRead} on:newGroup />
{:else if $chatListScope.kind === "direct_chat"}
<DirectChatsHeader />
<DirectChatsHeader on:markAllRead={markAllRead} {canMarkAllRead} />
{:else if $selectedCommunity && $chatListScope.kind === "community"}
<SelectedCommunityHeader
community={$selectedCommunity}
{canMarkAllRead}
on:markAllRead={markAllRead}
on:leaveCommunity
on:deleteCommunity
on:editCommunity
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<script lang="ts">
import MenuIcon from "../../MenuIcon.svelte";
import HoverIcon from "../../HoverIcon.svelte";
import CheckboxMultipleMarked from "svelte-material-icons/CheckboxMultipleMarked.svelte";
import AccountMultiple from "svelte-material-icons/AccountMultiple.svelte";
import AccountMultiplePlus from "svelte-material-icons/AccountMultiplePlus.svelte";
import PencilOutline from "svelte-material-icons/PencilOutline.svelte";
Expand All @@ -21,6 +22,7 @@
const client = getContext<OpenChat>("client");

export let community: CommunitySummary;
export let canMarkAllRead: boolean;

const dispatch = createEventDispatcher();

Expand Down Expand Up @@ -53,6 +55,10 @@
dispatch("communityDetails", community);
}

function markAllRead() {
dispatch("markAllRead");
}

function newChannel() {
canCreateChannel && dispatch("newChannel");
}
Expand Down Expand Up @@ -115,6 +121,13 @@
><Translatable resourceKey={i18nKey("communities.createChannel")} /></span>
</MenuItem>
{/if}
<MenuItem disabled={!canMarkAllRead} on:click={markAllRead}>
<CheckboxMultipleMarked
size={$iconSize}
color={"var(--icon-inverted-txt)"}
slot="icon" />
<span slot="text"><Translatable resourceKey={i18nKey("markAllRead")} /></span>
</MenuItem>
{#if member}
<MenuItem separator />
{#if canDelete}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,20 @@
<script lang="ts">
import Kebab from "svelte-material-icons/DotsVertical.svelte";
import CheckboxMultipleMarked from "svelte-material-icons/CheckboxMultipleMarked.svelte";
import MessageOutline from "svelte-material-icons/MessageOutline.svelte";
import SectionHeader from "../../SectionHeader.svelte";
import { iconSize } from "../../../stores/iconSize";
import Translatable from "../../Translatable.svelte";
import { i18nKey } from "../../../i18n/i18n";
import MenuIcon from "../../MenuIcon.svelte";
import HoverIcon from "../../HoverIcon.svelte";
import Menu from "../../Menu.svelte";
import MenuItem from "../../MenuItem.svelte";
import { createEventDispatcher } from "svelte";

const dispatch = createEventDispatcher();

export let canMarkAllRead: boolean;
</script>

<SectionHeader slim border={false}>
Expand All @@ -14,6 +25,29 @@
<div class="details">
<h4 class="name"><Translatable resourceKey={i18nKey("communities.directChats")} /></h4>
</div>
<span class="menu">
<MenuIcon position="bottom" align="end">
<span slot="icon">
<HoverIcon>
<Kebab size={$iconSize} color={"var(--icon-txt)"} />
</HoverIcon>
</span>
<span slot="menu">
<Menu>
<MenuItem
disabled={!canMarkAllRead}
on:click={() => dispatch("markAllRead")}>
<CheckboxMultipleMarked
size={$iconSize}
color={"var(--icon-inverted-txt)"}
slot="icon" />
<span slot="text"
><Translatable resourceKey={i18nKey("markAllRead")} /></span>
</MenuItem>
</Menu>
</span>
</MenuIcon>
</span>
</div>
</SectionHeader>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,20 @@
<script lang="ts">
import Kebab from "svelte-material-icons/DotsVertical.svelte";
import CheckboxMultipleMarked from "svelte-material-icons/CheckboxMultipleMarked.svelte";
import HeartOutline from "svelte-material-icons/HeartOutline.svelte";
import SectionHeader from "../../SectionHeader.svelte";
import { iconSize } from "../../../stores/iconSize";
import Translatable from "../../Translatable.svelte";
import { i18nKey } from "../../../i18n/i18n";
import MenuIcon from "../../MenuIcon.svelte";
import HoverIcon from "../../HoverIcon.svelte";
import Menu from "../../Menu.svelte";
import MenuItem from "../../MenuItem.svelte";
import { createEventDispatcher } from "svelte";

const dispatch = createEventDispatcher();

export let canMarkAllRead: boolean;
</script>

<SectionHeader slim border={false}>
Expand All @@ -14,6 +25,29 @@
<div class="details">
<h4 class="name"><Translatable resourceKey={i18nKey("communities.favourites")} /></h4>
</div>
<span class="menu">
<MenuIcon position="bottom" align="end">
<span slot="icon">
<HoverIcon>
<Kebab size={$iconSize} color={"var(--icon-txt)"} />
</HoverIcon>
</span>
<span slot="menu">
<Menu>
<MenuItem
disabled={!canMarkAllRead}
on:click={() => dispatch("markAllRead")}>
<CheckboxMultipleMarked
size={$iconSize}
color={"var(--icon-inverted-txt)"}
slot="icon" />
<span slot="text"
><Translatable resourceKey={i18nKey("markAllRead")} /></span>
</MenuItem>
</Menu>
</span>
</MenuIcon>
</span>
</div>
</SectionHeader>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import GroupChatsMenu from "./GroupChatsMenu.svelte";
import Translatable from "../../Translatable.svelte";
import { i18nKey } from "../../../i18n/i18n";

export let canMarkAllRead: boolean;
</script>

<SectionHeader slim border={false}>
Expand All @@ -19,7 +21,7 @@
</div>
</div>
<span class="menu">
<GroupChatsMenu on:newGroup />
<GroupChatsMenu {canMarkAllRead} on:markAllRead on:newGroup />
</span>
</SectionHeader>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<script lang="ts">
import MenuIcon from "../../MenuIcon.svelte";
import HoverIcon from "../../HoverIcon.svelte";
import CheckboxMultipleMarked from "svelte-material-icons/CheckboxMultipleMarked.svelte";
import AccountMultiplePlus from "svelte-material-icons/AccountMultiplePlus.svelte";
import Kebab from "svelte-material-icons/DotsVertical.svelte";
import Compass from "svelte-material-icons/CompassOutline.svelte";
Expand All @@ -16,6 +17,8 @@
const client = getContext<OpenChat>("client");
const dispatch = createEventDispatcher();

export let canMarkAllRead: boolean;

$: identityState = client.identityState;
$: anonUser = client.anonUser;
$: {
Expand Down Expand Up @@ -59,6 +62,13 @@
<Compass size={$iconSize} color={"var(--icon-inverted-txt)"} slot="icon" />
<span slot="text"><Translatable resourceKey={i18nKey("exploreGroups")} /></span>
</MenuItem>
<MenuItem disabled={!canMarkAllRead} on:click={() => dispatch("markAllRead")}>
<CheckboxMultipleMarked
size={$iconSize}
color={"var(--icon-inverted-txt)"}
slot="icon" />
<span slot="text"><Translatable resourceKey={i18nKey("markAllRead")} /></span>
</MenuItem>
</Menu>
</span>
</MenuIcon>
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
const client = getContext<OpenChat>("client");

export let community: CommunitySummary;
export let canMarkAllRead: boolean;

function showCommunityMembers() {
pushRightPanelHistory({ kind: "show_community_members" });
Expand Down Expand Up @@ -50,6 +51,8 @@
on:leaveCommunity
on:editCommunity
on:deleteCommunity
on:markAllRead
{canMarkAllRead}
{community} />
</span>
</SectionHeader>
Expand Down
2 changes: 1 addition & 1 deletion frontend/app/src/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -1409,4 +1409,4 @@
"yourChats": "Your chats",
"youreBlocked": "Sorry - you have been blocked from this group",
"yourRoleChanged": "{changedBy} changed your role from {oldRole} to {newRole}"
}
}
8 changes: 6 additions & 2 deletions frontend/app/src/styles/mixins.scss
Original file line number Diff line number Diff line change
Expand Up @@ -542,8 +542,12 @@ $shadow-level-3: 2px 6px 12px 0 rgba(25, 25, 25, 0.55);
display: flex;
}

.details h4 {
@include font(book, normal, fs-120);
.details {
flex: auto;

h4 {
@include font(book, normal, fs-120);
}
}
}

Expand Down
4 changes: 4 additions & 0 deletions frontend/openchat-client/src/openchat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3739,6 +3739,10 @@ export class OpenChat extends OpenChatAgentWorker {
messagesRead.markAllRead(chat);
}

markAllReadForCurrentScope() {
this._liveState.chatSummariesList.forEach((chat) => messagesRead.markAllRead(chat));
}

getDisplayDate = getDisplayDate;
isSocialVideoLink = isSocialVideoLink;
containsSocialVideoLink = containsSocialVideoLink;
Expand Down
Loading