Skip to content
This repository has been archived by the owner on Nov 21, 2020. It is now read-only.

Commit

Permalink
feat(widget): show server time & online status
Browse files Browse the repository at this point in the history
  • Loading branch information
Buyantogtokh authored Aug 3, 2020
1 parent ccc028e commit 5d04366
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 6 deletions.
10 changes: 7 additions & 3 deletions src/__tests__/widgetQueries.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,20 +119,24 @@ describe('widgetQueries', () => {
const qry = `
query widgetsMessengerSupporters($integrationId: String!) {
widgetsMessengerSupporters(integrationId: $integrationId) {
_id
supporters {
_id
}
isOnline
serverTime
}
}
`;

try {
await graphqlRequest(qry, 'widgetsMessengerSupporters', { integrationId: '_id' });
} catch (e) {
expect(e.message).toBe('Integration not found');
expect(e[0].message).toBe('Integration not found');
}

const response = await graphqlRequest(qry, 'widgetsMessengerSupporters', { integrationId: integration._id });

expect(response.length).toBe(1);
expect(response.supporters.length).toBe(1);
});

test('widgetsTotalUnreadCount', async () => {
Expand Down
12 changes: 10 additions & 2 deletions src/data/resolvers/queries/widgets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,12 +147,20 @@ export default {
const integration = await Integrations.findOne({ _id: integrationId });

if (!integration) {
return [];
return {
supporters: [],
isOnline: false,
serverTime: new Date(),
};
}

const messengerData = integration.messengerData || { supporterIds: [] };

return Users.find({ _id: { $in: messengerData.supporterIds || [] } });
return {
supporters: await Users.find({ _id: { $in: messengerData.supporterIds || [] } }),
isOnline: await isMessengerOnline(integration),
serverTime: new Date(),
};
},

/**
Expand Down
8 changes: 7 additions & 1 deletion src/data/schema/widget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ export const types = `
text: String
}
type MessengerSupportersResponse {
supporters: [User]
isOnline: Boolean
serverTime: String
}
input FieldValueInput {
_id: String!
type: String
Expand All @@ -49,7 +55,7 @@ export const queries = `
widgetsMessages(conversationId: String): [ConversationMessage]
widgetsUnreadCount(conversationId: String): Int
widgetsTotalUnreadCount(integrationId: String!, customerId: String!): Int
widgetsMessengerSupporters(integrationId: String!): [User]
widgetsMessengerSupporters(integrationId: String!): MessengerSupportersResponse
widgetsKnowledgeBaseArticles(topicId: String!, searchString: String) : [KnowledgeBaseArticle]
widgetsKnowledgeBaseTopicDetail(_id: String!): KnowledgeBaseTopic
`;
Expand Down

0 comments on commit 5d04366

Please sign in to comment.