Skip to content

Commit

Permalink
[#1306] Fix contact metadata problem (#1349)
Browse files Browse the repository at this point in the history
* fix metadata for contact

* correct key

* linting
  • Loading branch information
AitorAlgorta authored Mar 23, 2021
1 parent d913165 commit 2936fd5
Show file tree
Hide file tree
Showing 13 changed files with 19 additions and 13 deletions.
1 change: 1 addition & 0 deletions frontend/ui/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ ts_web_library(
"@npm//@reduxjs/toolkit",
"@npm//reselect",
"@npm//typesafe-actions",
"@npm//camelcase-keys",
],
)

Expand Down
4 changes: 3 additions & 1 deletion frontend/ui/src/components/AiryWebsocket/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React, {useEffect, useState} from 'react';
import _, {connect, ConnectedProps} from 'react-redux';
import {WebSocketClient} from 'websocketclient';
import {Message, Channel, MetadataEvent} from 'httpclient';
import camelcaseKeys from 'camelcase-keys';

import {env} from '../../env';
import {StateModel} from '../../reducers';
Expand All @@ -28,7 +29,8 @@ const mapDispatchToProps = dispatch => ({
addMessages: (conversationId: string, messages: Message[]) => dispatch(addMessagesAction({conversationId, messages})),
onChannel: (channel: Channel) => dispatch(setChannelAction(channel)),
getConversationInfo: (conversationId: string) => dispatch(getConversationInfo(conversationId)),
onMetadata: (metadataEvent: MetadataEvent) => dispatch(setMetadataAction(metadataEvent)),
onMetadata: (metadataEvent: MetadataEvent) =>
dispatch(camelcaseKeys(setMetadataAction(metadataEvent), {deep: true, stopPaths: ['metadata.user_data']})),
});

const connector = connect(mapStateToProps, mapDispatchToProps);
Expand Down
7 changes: 5 additions & 2 deletions frontend/ui/src/reducers/data/conversations/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {ActionType, getType} from 'typesafe-actions';
import {combineReducers} from 'redux';
import {cloneDeep, sortBy, merge, pickBy, pick} from 'lodash-es';
import {cloneDeep, sortBy, merge, pickBy} from 'lodash-es';

import {Conversation, ConversationFilter, Message} from 'httpclient';

Expand Down Expand Up @@ -207,8 +207,11 @@ function allReducer(
...state.items[action.payload.identifier],
metadata: {
// Ensure that there is always a display name present
...pick(state.items[action.payload.identifier]?.metadata, 'contact.displayName'),
...(<MetadataEvent<ConversationMetadata>>action.payload).metadata,
contact: {
...state.items[action.payload.identifier]?.metadata.contact,
...(<MetadataEvent<ConversationMetadata>>action.payload).metadata.contact,
},
},
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ export default HttpClient.prototype.connectChatPluginChannel = async function (
) {
const response = await this.doFetchFromBackend('channels.chatplugin.connect', camelcaseKeys(requestPayload));

return camelcaseKeys(response, {deep: true, stopPaths: ['metadata.userData']});
return camelcaseKeys(response, {deep: true, stopPaths: ['metadata.user_data']});
};
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ export default HttpClient.prototype.connectFacebookChannel = async function (
image_url: requestPayload.imageUrl,
});

return camelcaseKeys(response, {deep: true, stopPaths: ['metadata.userData']});
return camelcaseKeys(response, {deep: true, stopPaths: ['metadata.user_data']});
};
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ export default HttpClient.prototype.connectTwilioSmsChannel = async function (
image_url: requestPayload.imageUrl,
});

return camelcaseKeys(response, {deep: true, stopPaths: ['metadata.userData']});
return camelcaseKeys(response, {deep: true, stopPaths: ['metadata.user_data']});
};
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ export default HttpClient.prototype.connectTwilioWhatsappChannel = async functio
image_url: requestPayload.imageUrl,
});

return camelcaseKeys(response, {deep: true, stopPaths: ['metadata.userData']});
return camelcaseKeys(response, {deep: true, stopPaths: ['metadata.user_data']});
};
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ export default HttpClient.prototype.exploreFacebookChannels = async function (
) {
const response = await this.doFetchFromBackend('facebook.channels.explore', requestPayload);

return camelcaseKeys(response.data, {deep: true, stopPaths: ['metadata.userData']});
return camelcaseKeys(response.data, {deep: true, stopPaths: ['metadata.user_data']});
};
2 changes: 1 addition & 1 deletion lib/typescript/httpclient/endpoints/getConversationInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ export default HttpClient.prototype.getConversationInfo = async function (conver
conversation_id: conversationId,
});

return camelcaseKeys(response, {deep: true, stopPaths: ['metadata.userData']});
return camelcaseKeys(response, {deep: true, stopPaths: ['metadata.user_data']});
};
2 changes: 1 addition & 1 deletion lib/typescript/httpclient/endpoints/listChannels.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ import {HttpClient} from '../client';
export default HttpClient.prototype.listChannels = async function () {
const response = await this.doFetchFromBackend('channels.list', {});

return camelcaseKeys(response.data, {deep: true, stopPaths: ['metadata.userData']});
return camelcaseKeys(response.data, {deep: true, stopPaths: ['metadata.user_data']});
};
2 changes: 1 addition & 1 deletion lib/typescript/httpclient/endpoints/listConversations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export default HttpClient.prototype.listConversations = async function (
const response: PaginatedPayload<any> = await this.doFetchFromBackend('conversations.list', conversationListRequest);

const conversationData = response.data.map(messagePayload => ({
...camelcaseKeys(messagePayload, {deep: true, stopPaths: ['metadata.userData']}),
...camelcaseKeys(messagePayload, {deep: true, stopPaths: ['metadata.user_data']}),
createdAt: new Date(messagePayload.created_at),
lastMessage: mapMessage(messagePayload.last_message),
}));
Expand Down
2 changes: 1 addition & 1 deletion lib/typescript/httpclient/endpoints/updateChannel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ export default HttpClient.prototype.updateChannel = async function (requestPaylo
}),
});

return camelcaseKeys(response, {deep: true, stopPaths: ['metadata.userData']});
return camelcaseKeys(response, {deep: true, stopPaths: ['metadata.user_data']});
};
2 changes: 1 addition & 1 deletion lib/typescript/websocketclient/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export class WebSocketClient {
const json: EventPayloadUnion = JSON.parse(body) as any;
switch (json.type) {
case 'channel':
this.callbackMap.onChannel?.(camelcaseKeys(json.payload, {deep: true, stopPaths: ['metadata.userData']}));
this.callbackMap.onChannel?.(camelcaseKeys(json.payload, {deep: true, stopPaths: ['metadata.user_data']}));
break;
case 'message':
this.callbackMap.onMessage?.(json.payload.conversation_id, json.payload.channel_id, {
Expand Down

0 comments on commit 2936fd5

Please sign in to comment.