Fix activity messages generation and display (#4469)

Signed-off-by: Kristina Fefelova <kristin.fefelova@gmail.com>
This commit is contained in:
Kristina
2024-01-29 18:54:21 +07:00
committed by GitHub
parent b78c4138a4
commit f94089b7dd
7 changed files with 75 additions and 50 deletions
@@ -21,6 +21,7 @@ import core, {
type Doc,
groupByArray,
type Hierarchy,
type Mixin,
type Ref,
SortingOrder,
type Timestamp
@@ -70,7 +71,13 @@ export async function getAttributeValues (client: Client, values: any[], attrCla
const docIds = docs.map(({ _id }) => _id)
const missedIds = values.filter((value) => !docIds.includes(value))
const removedDocs = await Promise.all(missedIds.map(async (value) => await buildRemovedDoc(client, value, attrClass)))
return [...docs, ...removedDocs].filter((doc) => !(doc == null))
const allDocs = [...docs, ...removedDocs].filter((doc) => !(doc == null))
if (allDocs.length > 0) {
return allDocs
}
return values
}
export function getCollectionAttribute (
@@ -94,6 +101,19 @@ export function getCollectionAttribute (
return undefined
}
async function getAttributePresenterSafe (
client: Client,
_class: Ref<Class<Doc>>,
attrKey: string,
mixin?: Ref<Mixin<Doc>>
): Promise<AttributeModel | undefined> {
try {
return await getAttributePresenter(client, _class, attrKey, { key: attrKey }, mixin)
} catch (e) {
console.error(e)
}
}
export async function getAttributeModel (
client: Client,
attributeUpdates: DocAttributeUpdates | undefined,
@@ -105,28 +125,24 @@ export async function getAttributeModel (
const hierarchy = client.getHierarchy()
try {
const { attrKey, attrClass, isMixin } = attributeUpdates
let attrObjectClass = objectClass
const { attrKey, attrClass, isMixin } = attributeUpdates
let attrObjectClass = objectClass
if (isMixin) {
const keyedAttribute = getFiltredKeys(hierarchy, attrClass, []).find(({ key }) => key === attrKey)
if (keyedAttribute === undefined) {
return undefined
}
attrObjectClass = keyedAttribute.attr.attributeOf
if (isMixin) {
const keyedAttribute = getFiltredKeys(hierarchy, attrClass, []).find(({ key }) => key === attrKey)
if (keyedAttribute === undefined) {
return undefined
}
return await getAttributePresenter(
client,
attrObjectClass,
attrKey,
{ key: attrKey },
view.mixin.ActivityAttributePresenter
)
} catch (e) {
// ignore error
attrObjectClass = keyedAttribute.attr.attributeOf
}
const model = await getAttributePresenterSafe(client, attrObjectClass, attrKey, view.mixin.ActivityAttributePresenter)
if (model !== undefined) {
return model
}
return await getAttributePresenterSafe(client, attrObjectClass, attrKey)
}
export function activityMessagesComparator (message1: ActivityMessage, message2: ActivityMessage): number {
@@ -26,16 +26,12 @@
export let viewlet: DocUpdateMessageViewlet | undefined
export let objectName: IntlString
export let collectionName: IntlString | undefined
export let objectClass: Ref<Class<Doc>>
export let collectionAttribute: Attribute<Collection<AttachedDoc>> | undefined = undefined
const client = getClient()
const hierarchy = client.getHierarchy()
const clazz = hierarchy.getClass(message.objectClass)
const objectPanel = hierarchy.classHierarchyMixin(objectClass, view.mixin.ObjectPanel)
const objectPresenter = hierarchy.classHierarchyMixin(objectClass, view.mixin.ObjectPresenter)
const isOwn = message.objectId === message.attachedTo
let valueMessages: DocUpdateMessage[] = []
@@ -71,8 +67,6 @@
{#each createMessages as valueMessage, index}
<DocUpdateMessageObjectValue
message={valueMessage}
{objectPresenter}
{objectPanel}
{viewlet}
withIcon={index === 0}
hasSeparator={createMessages.length > 1 && index !== createMessages.length - 1}
@@ -81,8 +75,6 @@
{#each removeMessages as valueMessage, index}
<DocUpdateMessageObjectValue
message={valueMessage}
{objectPresenter}
{objectPanel}
{viewlet}
withIcon={index === 0}
hasSeparator={removeMessages.length > 1 && index !== removeMessages.length - 1}
@@ -92,8 +84,6 @@
{#each valueMessages as valueMessage, index}
<DocUpdateMessageObjectValue
message={valueMessage}
{objectPresenter}
{objectPanel}
{viewlet}
hasSeparator={valueMessages.length > 1 && index !== valueMessages.length - 1}
/>
@@ -22,16 +22,18 @@
export let message: DisplayDocUpdateMessage
export let viewlet: DocUpdateMessageViewlet | undefined
export let objectPanel: ObjectPanel | undefined
export let objectPresenter: ObjectPresenter | undefined
export let withIcon: boolean = false
export let hasSeparator: boolean = false
const client = getClient()
const hierarchy = client.getHierarchy()
const objectQuery = createQuery()
let object: Doc | undefined = undefined
$: objectPanel = hierarchy.classHierarchyMixin(message.objectClass, view.mixin.ObjectPanel)
$: objectPresenter = hierarchy.classHierarchyMixin(message.objectClass, view.mixin.ObjectPresenter)
async function getValue (object: Doc): Promise<string | undefined> {
if (viewlet?.valueAttr) {
return (object as any)[viewlet.valueAttr]
@@ -83,7 +83,7 @@
.getModel()
.findAllSync(activity.class.DocUpdateMessageViewlet, { action: value.action, objectClass: value.objectClass })
$: void getAttributeModel(client, value.attributeUpdates, value.attachedToClass).then((model) => {
$: void getAttributeModel(client, value.attributeUpdates, value.objectClass).then((model) => {
attributeModel = model
})
@@ -197,14 +197,7 @@
</ShowMore>
{:else if value.action === 'create' || value.action === 'remove'}
<ShowMore>
<DocUpdateMessageContent
objectClass={value.objectClass}
message={value}
{viewlet}
{objectName}
{collectionName}
{collectionAttribute}
/>
<DocUpdateMessageContent message={value} {viewlet} {objectName} {collectionName} {collectionAttribute} />
</ShowMore>
{:else if value.attributeUpdates && attributeModel}
<DocUpdateMessageAttributes attributeUpdates={value.attributeUpdates} {attributeModel} {viewlet} />