Skip to content

Commit

Permalink
MessagingSession prefetch supports sort for selecting which channels …
Browse files Browse the repository at this point in the history
…are prefetched (#2398)

* MessagingSession prefetch supports sort for selecting which channels are prefetched

* run build release and add tests to prefetch sort by

* Reset doc generating version and minor formatting fixs/capitalization changes to prefetch sort by

Co-authored-by: David Witherspoon <daviwith@amazon.com>
  • Loading branch information
dpwspoon and daviwith authored Aug 15, 2022
1 parent b7ed297 commit c00656d
Show file tree
Hide file tree
Showing 15 changed files with 1,788 additions and 1,453 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added

- Add support in `MessagingSession` to allow websocket connection for messaging service to select sort by for Prefetch.

### Removed

### Changed
Expand Down
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -252,10 +252,12 @@ const messagingSession = new DefaultMessagingSession(configuration, logger);
```
If you would like to enable prefetch feature when connecting to a messaging session, you can follow the code below.
Prefetch feature will send out CHANNEL_DETAILS event upon websocket connection, which includes information about channel,
channel messages, channel memberships etc.
channel messages, channel memberships etc. Prefetch sort order can be adjusted with `prefetchSortBy`, setting it to either
`unread` (default value if not set) or `lastMessageTimestamp`

```js
configuration.prefetchOn = PrefetchOn.Connect;
configuration.prefetchOn = Prefetch.Connect;
configuration.prefetchSortBy = PrefetchSortBy.Unread
```

## Building and testing
Expand Down
8 changes: 6 additions & 2 deletions demos/browser/app/messagingSession/messagingSession.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,12 @@ <h1 class="h3 mb-3 font-weight-normal">Messaging Session</h1>
<input type="text" id="sessionId" name="sessionId" class="form-control" placeholder="SessionId">
</div>
<div class="form-check" style="text-align: left;">
<input type="checkbox" id="prefetchOn" class="form-check-input">
<label for="prefetchOn" class="form-check-label">Connect with prefetch on</label>
<input type="radio" id="prefetchOff" name="prefetchSettings" value="off" checked>
<label for="prefetchOff">prefetch off</label><br>
<input type="radio" id="prefetchSortByUnread" name="prefetchSettings" value="unread">
<label for="prefetchSortByUnread">prefetch sorted by unread</label><br>
<input type="radio" id="prefetchSortByLastMessageTimestamp" name="prefetchSettings" value="last-message-timestamp">
<label for="prefetchSortByLastMessageTimestamp">prefetch sorted by last message timestamp</label><br>
</div>
<div class="row mt-3">
<div class="d-grid gap-2">
Expand Down
14 changes: 10 additions & 4 deletions demos/browser/app/messagingSession/messagingSession.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,15 @@ import {
Logger,
LogLevel,
Message,
MessagingSessionObserver,
MessagingSession,
MessagingSessionConfiguration,
MessagingSessionObserver,
PrefetchOn,
PrefetchSortBy,
Versioning,
} from 'amazon-chime-sdk-js';

import { ChimeSDKMessagingClient, GetMessagingSessionEndpointCommand } from '@aws-sdk/client-chime-sdk-messaging';
import {ChimeSDKMessagingClient, GetMessagingSessionEndpointCommand} from '@aws-sdk/client-chime-sdk-messaging';

export class DemoMessagingSessionApp implements MessagingSessionObserver {
static readonly BASE_URL: string = [
Expand Down Expand Up @@ -59,10 +60,15 @@ export class DemoMessagingSessionApp implements MessagingSessionObserver {
const endpoint = await chime.send(new GetMessagingSessionEndpointCommand());
this.userArn = (document.getElementById('userArn') as HTMLInputElement).value;
this.sessionId = (document.getElementById('sessionId') as HTMLInputElement).value;
this.prefetchOn = (document.getElementById('prefetchOn') as HTMLInputElement).checked;
this.prefetchSortByUnread = (document.getElementById('prefetchSortByUnread') as HTMLInputElement).checked;
this.prefetchSortByLastMessageTimestamp = (document.getElementById('prefetchSortByLastMessageTimestamp') as HTMLInputElement).checked;
this.configuration = new MessagingSessionConfiguration(this.userArn, this.sessionId, endpoint.Endpoint.Url, chime);
if (this.prefetchOn) {
if (this.prefetchSortByUnread) {
this.configuration.prefetchOn = PrefetchOn.Connect;
this.configuration.prefetchSortBy = PrefetchSortBy.Unread
} else if (this.prefetchSortByLastMessageTimestamp) {
this.configuration.prefetchOn = PrefetchOn.Connect;
this.configuration.prefetchSortBy = PrefetchSortBy.LastMessageTimestamp
}
this.session = new DefaultMessagingSession(this.configuration, this.logger);
this.session.addObserver(this);
Expand Down
Loading

0 comments on commit c00656d

Please sign in to comment.