hark: display chat mentions

This commit is contained in:
Liam Fitzgerald 2020-11-06 14:20:47 +10:00
parent fa3fe2b17d
commit dbda698a65
No known key found for this signature in database
GPG Key ID: D390E12C61D1CFFB
4 changed files with 22 additions and 10 deletions

View File

@ -31,8 +31,11 @@ export class HarkApi extends BaseApi<StoreState> {
});
}
setMentions(mentions: boolean) {
return this.graphHookAction({
async setMentions(mentions: boolean) {
await this.graphHookAction({
'set-mentions': mentions
});
return this.chatHookAction({
'set-mentions': mentions
});
}

View File

@ -209,7 +209,8 @@ function notifIdxEqual(a: NotifIndex, b: NotifIndex) {
a.group.description === b.group.description
);
} else if ("chat" in a && "chat" in b) {
return a.chat === b.chat;
return a.chat.chat === b.chat.chat &&
a.chat.mention === b.chat.mention;
}
return false;
}

View File

@ -18,7 +18,10 @@ export interface GroupNotifIndex {
description: string;
}
export type ChatNotifIndex = string;
export interface ChatNotifIndex {
chat: string;
mention: boolean;
}
export type NotifIndex =
| { graph: GraphNotifIndex }

View File

@ -1,5 +1,5 @@
import React, { useCallback } from "react";
import _ from 'lodash';
import _ from "lodash";
import { Link } from "react-router-dom";
import GlobalApi from "~/logic/api/global";
import {
@ -15,8 +15,12 @@ import { Header } from "./header";
import { pluralize } from "~/logic/lib/util";
import ChatMessage from "../chat/components/ChatMessage";
function describeNotification(lent: number) {
return `sent ${pluralize("message", lent !== 1)} in`;
function describeNotification(mention: boolean, lent: number) {
const msg = pluralize("message", lent !== 1);
if (mention) {
return `mentioned you in ${msg} in`;
}
return `sent ${msg} in`;
}
export function ChatNotification(props: {
@ -34,13 +38,14 @@ export function ChatNotification(props: {
const { index, contents, read, time, api, timebox } = props;
const authors = _.map(contents, "author");
const association = props.associations.chat[index];
const { chat, mention } = index;
const association = props.associations.chat[chat];
const groupPath = association["group-path"];
const appPath = association["app-path"];
const group = props.groups[groupPath];
const desc = describeNotification(contents.length);
const desc = describeNotification(mention, contents.length);
const groupContacts = props.contacts[groupPath];
const onClick = useCallback(() => {
@ -62,7 +67,7 @@ export function ChatNotification(props: {
time={time}
authors={authors}
moduleIcon="Chat"
channel={index}
channel={chat}
contacts={props.contacts}
group={groupPath}
description={desc}