Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Allow user to sort conversations #1080

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
6 changes: 6 additions & 0 deletions .changeset/nasty-feet-warn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@signalwire/core': minor
'@signalwire/js': minor
---

Allow user to sort conversations in ASC or DESC order. Default is DESC.
8 changes: 5 additions & 3 deletions internal/playground-js/src/fabric-http/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ import { SignalWire } from '@signalwire/js'

const searchInput = document.getElementById('searchInput')
const searchType = document.getElementById('searchType')
const conversationMessageInput = document.getElementById('new-conversation-message')
const conversationMessageInput = document.getElementById(
'new-conversation-message'
)
const sendMessageBtn = document.getElementById('send-message')

let client = null
Expand Down Expand Up @@ -162,7 +164,6 @@ const createAddressListItem = (address) => {
if (channelName != 'messaging') {
button.addEventListener('click', () => dialAddress(channelValue))
} else {

button.addEventListener('click', () => {
subscribeToNewMessages()
openMessageModal(address)
Expand Down Expand Up @@ -198,7 +199,7 @@ function updateAddressUI() {
addresses
.map(createAddressListItem)
.forEach((item) => addressUl.appendChild(item))
subscribeToNewMessages();
subscribeToNewMessages()
}

async function fetchAddresses() {
Expand Down Expand Up @@ -327,6 +328,7 @@ async function fetchHistories() {
try {
const historyData = await client.conversation.getConversations({
pageSize: 10,
sortOrder: 'ASC',
})
window.__historyData = historyData
updateHistoryUI()
Expand Down
4 changes: 4 additions & 0 deletions packages/core/src/types/callfabric.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ export interface FetchAddressResponse extends PaginatedResponse<Address> {}
/**
* Conversations
*/
export type SortOrder = 'ASC' | 'DESC'

export interface SendConversationMessageOptions {
text: string
addressId: string
Expand All @@ -76,6 +78,7 @@ export interface SendConversationMessageOptions {
}
export interface GetConversationsOptions {
pageSize?: number
sortOrder?: SortOrder
}

export interface Conversation {
Expand Down Expand Up @@ -126,6 +129,7 @@ export interface FetchConversationMessagesResponse
export interface GetConversationMessagesOptions {
addressId: string
pageSize?: number
sortOrder?: SortOrder
}

/**
Expand Down
10 changes: 8 additions & 2 deletions packages/js/src/fabric/Conversation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,16 @@ export class Conversation {

public async getConversations(options?: GetConversationsOptions) {
try {
const { pageSize } = options || {}
const { pageSize, sortOrder } = options || {}

const path = '/api/fabric/conversations'
const queryParams = new URLSearchParams()
if (pageSize) {
queryParams.append('page_size', pageSize.toString())
}
if (sortOrder) {
queryParams.append('sortOrder', sortOrder.toString())
}

const { body } = await this.httpClient.fetch<FetchConversationsResponse>(
makeQueryParamsUrls(path, queryParams)
Expand Down Expand Up @@ -109,13 +112,16 @@ export class Conversation {
options: GetConversationMessagesOptions
) {
try {
const { addressId, pageSize } = options || {}
const { addressId, pageSize, sortOrder } = options || {}

const path = `/api/fabric/conversations/${addressId}/messages`
const queryParams = new URLSearchParams()
if (pageSize) {
queryParams.append('page_size', pageSize.toString())
}
if (sortOrder) {
queryParams.append('sort_order', sortOrder.toString())
}

const { body } =
await this.httpClient.fetch<FetchConversationMessagesResponse>(
Expand Down
Loading