Skip to content

Commit

Permalink
misc: fix some smart note issue (#946)
Browse files Browse the repository at this point in the history
* fix: ui issue with side widget

* feat: add more data in login status event

* fix: smart note init issue

* fix: typo issue
  • Loading branch information
embbnux authored Dec 19, 2024
1 parent 3edf6eb commit 04a7769
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 40 deletions.
6 changes: 4 additions & 2 deletions src/containers/AppView/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const MainContent = styled.div`
flex-direction: column;
flex: 1;
height: 100%;
max-width: 100%;
max-width: ${({ showSideDrawer }) => showSideDrawer ? '50%' : '100%'};
position: relative;
`;

Expand All @@ -40,7 +40,7 @@ const Content = styled.div`
function AppView(props) {
return (
<Root>
<MainContent>
<MainContent showSideDrawer={props.showSideDrawer}>
<DemoOnlyBanner
show={props.showDemoWarning}
onClose={props.dismissDemoWarning}
Expand Down Expand Up @@ -100,6 +100,7 @@ export default withPhone(connect((_, {
callingSettings,
appFeatures,
auth,
sideDrawerUI,
},
fromPopup,
}) => ({
Expand All @@ -117,6 +118,7 @@ export default withPhone(connect((_, {
(auth.loggedIn && callingSettings.callingMode === callingModes.webphone)
)
),
showSideDrawer: sideDrawerUI.show,
}), (_, {
phone: {
environment,
Expand Down
2 changes: 1 addition & 1 deletion src/lib/Adapter/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ class Adapter extends AdapterCore {
console.log(data.calls);
break;
case 'rc-login-status-notify':
console.log('rc-login-status-notify:', data.loggedIn, data.loginNumber, data.contractedCountryCode);
console.log('rc-login-status-notify:', data.loggedIn, data.loginNumber, data.contractedCountryCode, data.admin, data.features);
break;
case 'rc-calling-settings-notify':
console.log('rc-calling-settings-notify:', data.callWith, data.callingMode);
Expand Down
21 changes: 20 additions & 1 deletion src/modules/Adapter/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -561,13 +561,17 @@ export default class Adapter extends AdapterModuleCore {
return;
}
if (this._auth.loggedIn && (
!this._extensionInfo.ready || !this._accountInfo.ready
!this._extensionInfo.ready ||
!this._accountInfo.ready ||
!this._appFeatures.ready
)) {
return;
}
this._loggedIn = this._auth.loggedIn;
let loginNumber;
let contractedCountryCode;
let isAdmin = false;
let features = {};
if (this._loggedIn) {
const extensionNumber =
this._extensionInfo.extensionNumber && this._extensionInfo.extensionNumber !== '0'
Expand All @@ -580,12 +584,27 @@ export default class Adapter extends AdapterModuleCore {
this._accountInfo.serviceInfo &&
this._accountInfo.serviceInfo.contractedCountry &&
this._accountInfo.serviceInfo.contractedCountry.isoCode;
isAdmin = (
this._extensionInfo.info &&
this._extensionInfo.info.permissions &&
this._extensionInfo.info.permissions.admin &&
this._extensionInfo.info.permissions.admin.enabled
) || false;
features = {
sms: this._appFeatures.hasSMSSendingFeature,
meeting: this._appFeatures.hasMeetingsPermission,
glip: this._appFeatures.hasGlipPermission,
smartNote: this._appFeatures.hasSmartNotePermission,
call: this._appFeatures.isCallingEnabled,
};
}
this._postMessage({
type: 'rc-login-status-notify',
loggedIn: this._loggedIn,
loginNumber,
contractedCountryCode,
admin: isAdmin,
features,
});
}

Expand Down
100 changes: 64 additions & 36 deletions src/modules/SmartNotes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export class SmartNotes extends RcModuleV2 {
protected _smartNoteClient: any;
protected _smartNoteMFERemoteEntry: string;
protected _smartNoteIframeUri: string;
protected _webphoneHookAdded: boolean;

constructor(deps) {
super({
Expand All @@ -48,51 +49,67 @@ export class SmartNotes extends RcModuleV2 {
this._smartNoteClient = null;
this._smartNoteIframeUri = '';
this._smartNoteMFERemoteEntry = '';
this._webphoneHookAdded = false;
}

async onInitOnce() {
async onInit() {
if (!this.hasPermission) {
return;
}
this._deps.webphone.onCallStart((webphoneSession) => {
if (!this.showSmartNote) {
return;
}
if (!webphoneSession.partyData) {
return;
}
const phoneNumber =
webphoneSession.direction === callDirections.outbound ?
webphoneSession.to :
webphoneSession.from;
const feedbackName =
webphoneSession.direction === callDirections.outbound ?
webphoneSession.toUserName :
webphoneSession.fromUserName;
const contactMatches = this._deps.contactMatcher.dataMapping[phoneNumber];
this.setSession({
id: webphoneSession.partyData.sessionId,
status: 'Answered',
phoneNumber: phoneNumber,
contact: contactMatches && contactMatches.length > 0 ? contactMatches[0] : {
name: feedbackName,
},
direction: webphoneSession.direction,
startTime: new Date(webphoneSession.startTime).toISOString(),
});
});
this._deps.webphone.onCallEnd((webphoneSession) => {
if (!webphoneSession.partyData) {
return;
}
if (this.session?.id === webphoneSession.partyData.sessionId) {
if (this.clientInitialized) {
return;
}
if (!this._webphoneHookAdded) {
this._deps.webphone.onCallStart((webphoneSession) => {
if (!this.hasPermission) {
return;
}
if (!this.showSmartNote) {
return;
}
if (!webphoneSession.partyData) {
return;
}
const phoneNumber =
webphoneSession.direction === callDirections.outbound ?
webphoneSession.to :
webphoneSession.from;
const feedbackName =
webphoneSession.direction === callDirections.outbound ?
webphoneSession.toUserName :
webphoneSession.fromUserName;
const contactMatches = this._deps.contactMatcher.dataMapping[phoneNumber];
this.setSession({
id: webphoneSession.partyData.sessionId,
status: 'Disconnected',
status: 'Answered',
phoneNumber: phoneNumber,
contact: contactMatches && contactMatches.length > 0 ? contactMatches[0] : {
name: feedbackName,
},
direction: webphoneSession.direction,
startTime: new Date(webphoneSession.startTime).toISOString(),
});
}
});
});
this._deps.webphone.onCallEnd((webphoneSession) => {
if (!this.hasPermission) {
return;
}
if (!this.showSmartNote) {
return;
}
if (!webphoneSession.partyData) {
return;
}
if (this.session?.id === webphoneSession.partyData.sessionId) {
this.setSession({
id: webphoneSession.partyData.sessionId,
status: 'Disconnected',
direction: webphoneSession.direction,
});
}
});
this._webphoneHookAdded = true
}
try {
const plugins = await fetch('./plugins.json').then((res) => res.json());
const smartNotesRemoteEntry = plugins.smartNotesMFE;
Expand All @@ -113,6 +130,17 @@ export class SmartNotes extends RcModuleV2 {
}
}

onReset() {
this.clearStates()
}

@action
clearStates() {
this.callsQueryResults = [];
this.smartNoteTextStore = [];
this.session = null;
}

@state
session = null;

Expand Down

0 comments on commit 04a7769

Please sign in to comment.