Skip to content
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,7 @@ Notes: web developers are advised to use [`~` (tilde range)](https://github.com/
- Fixed citation links are not properly matched against markdown links, in PR [#5614](https://github.com/microsoft/BotFramework-WebChat/pull/5614), by [@OEvgeny](https://github.com/OEvgeny)
- Fixed `botframework-webchat/decorator` import in legacy CommonJS environments, in [#5616](https://github.com/microsoft/BotFramework-WebChat/pull/5616), by [@OEvgeny](https://github.com/OEvgeny)
- Fixed `npm start` for efficiency and reliability, in PR [#5621](https://github.com/microsoft/BotFramework-WebChat/pull/5621) and [#5629](https://github.com/microsoft/BotFramework-WebChat/pull/5629), by [@compulim](https://github.com/compulim)
- Fixed activity sorting introduced in PR [#5622](https://github.com/microsoft/BotFramework-WebChat/pull/5622), part grouping, and livestreaming, by [@compulim](https://github.com/compulim) in PR [#XXX](https://github.com/microsoft/BotFramework-WebChat/pull/XXX)

### Removed

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
<!doctype html>
<html lang="en-US">
<head>
<link href="/assets/index.css" rel="stylesheet" type="text/css" />
</head>
<body>
<main id="webchat"></main>
<script type="importmap">
{
"imports": {
"botframework-webchat": "/__dist__/packages/bundle/static/botframework-webchat.js",
"react": "/__dist__/packages/bundle/static/react.js",
"react-dom": "/__dist__/packages/bundle/static/react-dom.js"
}
}
</script>
<script type="module">
import '/test-harness.mjs';
import '/test-page-object.mjs';

import { createDirectLine, createStoreWithOptions, renderWebChat } from 'botframework-webchat';
import { version } from 'react';

run(async function () {
const {
testHelpers: { createDirectLineEmulator }
} = window;

// TODO: This is for `createDirectLineEmulator` only, should find ways to eliminate this line.
window.WebChat = { createStoreWithOptions };

const { directLine, store } = createDirectLineEmulator();

renderWebChat({ directLine, store }, document.getElementById('webchat'));

await pageConditions.uiConnected();

await directLine.emulateIncomingActivity({
channelData: {
streamSequence: 1,
streamType: 'streaming'
},
from: { role: 'bot' },
id: 'a-00001',
text: 'a-00001: Stream 1 revision 1 at t = 0',
timestamp: new Date(0).toISOString(),
type: 'typing'
});

expect(pageElements.activityContents().map(({ textContent }) => textContent)).toEqual([
'a-00001: Stream 1 revision 1 at t = 0'
]);

await host.snapshot('local');

// A "Hello, World!" inserted between two thoughts.
await directLine.emulateIncomingActivity({
from: { role: 'bot' },
id: 'a-00002',
text: 'a-00002: Hello, World at t = 1',
timestamp: new Date(86_400_000).toISOString(),
type: 'message'
});

expect(pageElements.activityContents().map(({ textContent }) => textContent)).toEqual([
'a-00001: Stream 1 revision 1 at t = 0',
'a-00002: Hello, World at t = 1'
]);

await host.snapshot('local');

await directLine.emulateIncomingActivity({
channelData: {
streamId: 'a-00001',
streamSequence: 2,
streamType: 'streaming'
},
from: { role: 'bot' },
id: 'a-00003',
text: 'a-00003: Stream 1 revision 2 at t = 2',
timestamp: new Date(2 * 86_400_000).toISOString(),
type: 'typing'
});

expect(pageElements.activityContents().map(({ textContent }) => textContent)).toEqual([
'a-00003: Stream 1 revision 2 at t = 2',
'a-00002: Hello, World at t = 1'
]);

await host.snapshot('local');

await directLine.emulateIncomingActivity({
channelData: {
streamSequence: 1,
streamType: 'streaming'
},
from: { role: 'bot' },
id: 'a-00004',
text: 'a-00004: Stream 2 revision 1 at t = 3',
timestamp: new Date(3 * 86_400_000).toISOString(),
type: 'typing'
});

expect(pageElements.activityContents().map(({ textContent }) => textContent)).toEqual([
'a-00003: Stream 1 revision 2 at t = 2',
'a-00002: Hello, World at t = 1',
'a-00004: Stream 2 revision 1 at t = 3'
]);

await host.snapshot('local');

await directLine.emulateIncomingActivity({
channelData: {
streamId: 'a-00004',
streamSequence: 2,
streamType: 'streaming'
},
from: { role: 'bot' },
id: 'a-00005',
text: 'a-00005: Stream 2 revision 2 at t = 0',
timestamp: new Date(0).toISOString(),
type: 'typing'
});

expect(pageElements.activityContents().map(({ textContent }) => textContent)).toEqual([
'a-00003: Stream 1 revision 2 at t = 2',
'a-00002: Hello, World at t = 1',
'a-00005: Stream 2 revision 2 at t = 0'
]);

await host.snapshot('local');
});
</script>
</body>
</html>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
<!doctype html>
<html lang="en-US">
<head>
<link href="/assets/index.css" rel="stylesheet" type="text/css" />
</head>
<body>
<main id="webchat"></main>
<script type="importmap">
{
"imports": {
"botframework-webchat": "/__dist__/packages/bundle/static/botframework-webchat.js",
"react": "/__dist__/packages/bundle/static/react.js",
"react-dom": "/__dist__/packages/bundle/static/react-dom.js"
}
}
</script>
<script type="module">
import '/test-harness.mjs';
import '/test-page-object.mjs';

import { createDirectLine, createStoreWithOptions, renderWebChat } from 'botframework-webchat';
import { version } from 'react';

run(async function () {
const {
testHelpers: { createDirectLineEmulator }
} = window;

// TODO: This is for `createDirectLineEmulator` only, should find ways to eliminate this line.
window.WebChat = { createStoreWithOptions };

const { directLine, store } = createDirectLineEmulator();

renderWebChat({ directLine, store }, document.getElementById('webchat'));

await pageConditions.uiConnected();

await directLine.emulateIncomingActivity({
entities: [
{
'@context': 'https://schema.org',
'@id': '',
'@type': 'Message',
type: 'https://schema.org/Message',
isPartOf: { '@id': 'c-00001', '@type': 'HowTo' },
position: 1
}
],
from: { role: 'bot' },
id: 'a-00001',
text: 'a-00001: Chain 1 thought 1 at t = 0',
timestamp: new Date(0).toISOString(),
type: 'message'
});

expect(pageElements.activityContents().map(({ textContent }) => textContent)).toEqual([
'a-00001: Chain 1 thought 1 at t = 0'
]);

await host.snapshot('local');

// A "Hello, World!" inserted between two thoughts.
await directLine.emulateIncomingActivity({
from: { role: 'bot' },
id: 'a-00002',
text: 'a-00002: Hello, World at t = 1',
timestamp: new Date(86_400_000).toISOString(),
type: 'message'
});

expect(pageElements.activityContents().map(({ textContent }) => textContent)).toEqual([
'a-00001: Chain 1 thought 1 at t = 0',
'a-00002: Hello, World at t = 1'
]);

await host.snapshot('local');

// The second thought should be grouped with the first one.
await directLine.emulateIncomingActivity({
entities: [
{
'@context': 'https://schema.org',
'@id': '',
'@type': 'Message',
type: 'https://schema.org/Message',
isPartOf: { '@id': 'c-00001', '@type': 'HowTo' },
position: 2
}
],
from: { role: 'bot' },
id: 'a-00003',
text: 'a-00003: Chain 1 thought 2 at t = 2',
timestamp: new Date(2 * 86_400_000).toISOString(),
type: 'message'
});

expect(pageElements.activityContents().map(({ textContent }) => textContent)).toEqual([
'a-00001: Chain 1 thought 1 at t = 0',
'a-00003: Chain 1 thought 2 at t = 2',
'a-00002: Hello, World at t = 1'
]);

await host.snapshot('local');

await directLine.emulateIncomingActivity({
entities: [
{
'@context': 'https://schema.org',
'@id': '',
'@type': 'Message',
type: 'https://schema.org/Message',
isPartOf: { '@id': 'c-00002', '@type': 'HowTo' },
position: 1
}
],
from: { role: 'bot' },
id: 'a-00004',
text: 'a-00004: Chain 2 thought 1 at t = 3',
timestamp: new Date(3 * 86_400_000).toISOString(),
type: 'message'
});

expect(pageElements.activityContents().map(({ textContent }) => textContent)).toEqual([
'a-00001: Chain 1 thought 1 at t = 0',
'a-00003: Chain 1 thought 2 at t = 2',
'a-00002: Hello, World at t = 1',
'a-00004: Chain 2 thought 1 at t = 3'
]);

await host.snapshot('local');

await directLine.emulateIncomingActivity({
entities: [
{
'@context': 'https://schema.org',
'@id': '',
'@type': 'Message',
type: 'https://schema.org/Message',
isPartOf: { '@id': 'c-00002', '@type': 'HowTo' },
position: 2
}
],
from: { role: 'bot' },
id: 'a-00005',
text: 'a-00005: Chain 2 thought 2 at t = 0',
// Intentionally roll back the date.
// It should be grouped and not appear before "Hello, World!'
timestamp: new Date(0).toISOString(),
type: 'message'
});

expect(pageElements.activityContents().map(({ textContent }) => textContent)).toEqual([
'a-00001: Chain 1 thought 1 at t = 0',
'a-00003: Chain 1 thought 2 at t = 2',
'a-00002: Hello, World at t = 1',
'a-00004: Chain 2 thought 1 at t = 3',
'a-00005: Chain 2 thought 2 at t = 0'
]);

await host.snapshot('local');
});
</script>
</body>
</html>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
56 changes: 30 additions & 26 deletions packages/core/src/reducers/createActivitiesReducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,36 +165,40 @@ function upsertActivityWithSort(
// - If not available, it will fallback to `+new Date(timestamp)`
// - Outgoing activity will not have `timestamp` field

let indexToInsert = nextActivities.findIndex(activity => {
const { channelData = {} } = activity;
const currentEntityPosition = channelData['webchat:entity-position'];
const currentEntityPartOf = channelData['webchat:entity-part-of'];
let indexToInsert = -1;

const bothHavePosition = typeof currentEntityPosition === 'number' && typeof upsertingEntityPosition === 'number';
const bothArePartOf = typeof currentEntityPartOf === 'string' && currentEntityPartOf === upsertingPartOf;
if (typeof upsertingEntityPosition === 'number' && typeof upsertingPartOf === 'string') {
const activitiesOfSamePartGrouping = nextActivities.filter(
activity => activity.channelData['webchat:entity-part-of'] === upsertingPartOf
);

// For activities in the same creative work part, position is primary sort key
if (bothHavePosition && bothArePartOf) {
return currentEntityPosition > upsertingEntityPosition;
}

return false;
});
if (activitiesOfSamePartGrouping.length) {
const activityImmediateBeforeInsertion = activitiesOfSamePartGrouping.find(
activity => activity.channelData['webchat:entity-position'] > upsertingEntityPosition
);

if (!~indexToInsert) {
indexToInsert = nextActivities.findIndex(activity => {
const currentLivestreamingMetadata = getActivityLivestreamingMetadata(activity);

if (
upsertingLivestreamingMetadata &&
currentLivestreamingMetadata &&
upsertingLivestreamingMetadata.sessionId === currentLivestreamingMetadata.sessionId
) {
return currentLivestreamingMetadata.sequenceNumber > upsertingLivestreamingMetadata.sequenceNumber;
}
indexToInsert = activityImmediateBeforeInsertion
? nextActivities.indexOf(activityImmediateBeforeInsertion)
: nextActivities.indexOf(activitiesOfSamePartGrouping.at(-1)) + 1;
}
}

return false;
});
if (!~indexToInsert && upsertingLivestreamingMetadata) {
const upsertingLivestreamingSessionId = upsertingLivestreamingMetadata.sessionId;
const upsertingLivestreamingSequenceNumber = upsertingLivestreamingMetadata.sequenceNumber;
const activitiesOfSameLivestreamSession = nextActivities.filter(
activity => getActivityLivestreamingMetadata(activity)?.sessionId === upsertingLivestreamingSessionId
);

if (activitiesOfSameLivestreamSession.length) {
const activityImmediateBeforeInsertion = activitiesOfSameLivestreamSession.find(
activity => getActivityLivestreamingMetadata(activity).sequenceNumber > upsertingLivestreamingSequenceNumber
);

indexToInsert = activityImmediateBeforeInsertion
? nextActivities.indexOf(activityImmediateBeforeInsertion)
: nextActivities.indexOf(activitiesOfSameLivestreamSession.at(-1)) + 1;
}
}

// If the upserting activity does not have sequence ID or timestamp, always append it.
Expand Down
Loading