Display correct info in hover preview (#5597)
This commit is contained in:
@@ -1,8 +1,7 @@
|
||||
import { differenceInMinutes, formatDistanceToNowStrict } from "date-fns";
|
||||
import { t } from "i18next";
|
||||
import { head, orderBy } from "lodash";
|
||||
import { dateLocale } from "@shared/utils/date";
|
||||
import { Document, User } from "@server/models";
|
||||
import { Document, User, View } from "@server/models";
|
||||
import { opts } from "@server/utils/i18n";
|
||||
|
||||
export const presentLastOnlineInfoFor = (user: User) => {
|
||||
@@ -26,8 +25,17 @@ export const presentLastOnlineInfoFor = (user: User) => {
|
||||
return info;
|
||||
};
|
||||
|
||||
export const presentLastViewedInfoFor = (user: User, document: Document) => {
|
||||
const lastView = head(orderBy(document.views, ["updatedAt"], ["desc"]));
|
||||
export const presentLastViewedInfoFor = async (
|
||||
user: User,
|
||||
document: Document
|
||||
) => {
|
||||
const lastView = await View.findOne({
|
||||
where: {
|
||||
userId: user.id,
|
||||
documentId: document.id,
|
||||
},
|
||||
order: [["updatedAt", "DESC"]],
|
||||
});
|
||||
const lastViewedAt = lastView ? lastView.updatedAt : undefined;
|
||||
const locale = dateLocale(user.language);
|
||||
|
||||
|
||||
@@ -2,16 +2,17 @@ import { Unfurl, UnfurlType } from "@shared/types";
|
||||
import { Document, User } from "@server/models";
|
||||
import { presentLastOnlineInfoFor, presentLastViewedInfoFor } from "./common";
|
||||
|
||||
function presentMention(
|
||||
async function presentMention(
|
||||
user: User,
|
||||
document: Document
|
||||
): Unfurl<UnfurlType.Mention> {
|
||||
): Promise<Unfurl<UnfurlType.Mention>> {
|
||||
const lastOnlineInfo = presentLastOnlineInfoFor(user);
|
||||
const lastViewedInfo = await presentLastViewedInfoFor(user, document);
|
||||
|
||||
return {
|
||||
type: UnfurlType.Mention,
|
||||
title: user.name,
|
||||
description: `${presentLastOnlineInfoFor(
|
||||
user
|
||||
)} • ${presentLastViewedInfoFor(user, document)}`,
|
||||
description: `${lastOnlineInfo} • ${lastViewedInfo}`,
|
||||
thumbnailUrl: user.avatarUrl,
|
||||
meta: {
|
||||
id: user.id,
|
||||
|
||||
@@ -42,7 +42,7 @@ router.post(
|
||||
authorize(actor, "read", user);
|
||||
authorize(actor, "read", document);
|
||||
|
||||
ctx.body = presentMention(user, document);
|
||||
ctx.body = await presentMention(user, document);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user