Skip to content

Commit ffe2368

Browse files
committed
feat: handle message positioning during part grouping
1 parent 8734cea commit ffe2368

4 files changed

Lines changed: 19 additions & 8 deletions

File tree

packages/api/src/providers/GroupActivities/private/createDefaultGroupActivitiesMiddleware.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* eslint-disable no-magic-numbers */
12
import { getOrgSchemaMessage, type GlobalScopePonyfill, type WebChatActivity } from 'botframework-webchat-core';
23

34
import type GroupActivitiesMiddleware from '../../../types/GroupActivitiesMiddleware';
@@ -99,9 +100,12 @@ export default function createDefaultGroupActivitiesMiddleware({
99100
part: bin(
100101
messages,
101102
([last], [current]) =>
102-
typeof last?.isPartOf?.[0]?.['@id'] === 'string' &&
103-
last.isPartOf[0]['@id'] === current?.isPartOf?.[0]?.['@id']
104-
).map(bin => bin.map(([, activity]) => activity))
103+
typeof last?.isPartOf?.['@id'] === 'string' && last.isPartOf['@id'] === current?.isPartOf?.['@id']
104+
).map(bin =>
105+
bin
106+
.toSorted(([m1], [m2]) => (m1.position < m2.position ? -1 : m1.position > m2.position ? 1 : 0))
107+
.map(([, activity]) => activity)
108+
)
105109
};
106110
}
107111
: undefined

packages/component/src/Middleware/ActivityGrouping/ui/PartGrouping/PartGrouping.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ function PartGrouping(props: PartGroupingProps) {
4444
[activities, lastActivity]
4545
);
4646

47-
const isGroup = activities.length > 1 || !!lastMessage?.isPartOf?.[0]?.['@id'];
47+
const isGroup = activities.length > 1 || !!lastMessage?.isPartOf?.['@id'];
4848

4949
return isGroup ? (
5050
<PartGroupingActivity activities={activities}>{children}</PartGroupingActivity>

packages/core/src/types/external/OrgSchema/CreativeWork.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { lazy, literal, object, parse, string, union, type ObjectEntries } from 'valibot';
1+
import { lazy, literal, number, object, parse, string, union, type ObjectEntries } from 'valibot';
22

33
import { definedTerm, type DefinedTerm } from './DefinedTerm';
44
import orgSchemaProperties from './private/orgSchemaProperties';
@@ -61,6 +61,13 @@ export type CreativeWork = Thing & {
6161
*/
6262
pattern?: DefinedTerm | undefined;
6363

64+
/**
65+
* The position of an item in a series or sequence of items.
66+
*
67+
* @see https://schema.org/position
68+
*/
69+
position?: number;
70+
6471
/**
6572
* The textual content of this CreativeWork.
6673
*
@@ -104,6 +111,7 @@ export const creativeWork = <TEntries extends ObjectEntries>(entries?: TEntries
104111
isBasedOn: orgSchemaProperty(lazy(() => creativeWork())),
105112
keywords: orgSchemaProperties(union([lazy(() => definedTerm()), string()])),
106113
pattern: orgSchemaProperty(lazy(() => definedTerm())),
114+
position: orgSchemaProperty(number()),
107115
text: orgSchemaProperty(string()),
108116
usageInfo: orgSchemaProperty(lazy(() => creativeWork())),
109117

packages/core/src/types/external/OrgSchema/Thing.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import { lazy, literal, looseObject, optional, parse, pipe, string, type ObjectE
44
import { action, type Action } from './Action';
55
import orgSchemaProperties from './private/orgSchemaProperties';
66
import orgSchemaProperty from './private/orgSchemaProperty';
7-
import type OneOrMany from '../../OneOrMany';
87
import { creativeWork, type CreativeWork } from './CreativeWork';
98

109
/**
@@ -66,7 +65,7 @@ export type Thing = {
6665
*
6766
* @see https://schema.org/isPartOf
6867
*/
69-
isPartOf?: OneOrMany<CreativeWork> | undefined;
68+
isPartOf?: CreativeWork | undefined;
7069
};
7170

7271
const thingEntries = {
@@ -80,7 +79,7 @@ const thingEntries = {
8079
name: orgSchemaProperty(string()),
8180
potentialAction: orgSchemaProperties(lazy(() => action())),
8281
url: orgSchemaProperty(string()),
83-
isPartOf: orgSchemaProperties(lazy(() => creativeWork()))
82+
isPartOf: orgSchemaProperty(lazy(() => creativeWork()))
8483
};
8584

8685
export const thing = <TEntries extends ObjectEntries>(entries?: TEntries | undefined) =>

0 commit comments

Comments
 (0)