react-native-context-center
Version:
React native package for Impekable context center customer app
47 lines (40 loc) • 1.48 kB
JavaScript
import {NativeModules,NativeAppEventEmitter} from 'react-native';
const { CCClient } = NativeModules;
class ChatUser{
constructor(props) {
console.log('ChatUser:',props)
this.identity = props ? props.identity : '';
this.friendlyName = props ? props.friendlyName: '';
this.attributes = props ? props.attributes: '';
this.isOnline = props ? props.isOnline: '';
this.isNotifiable = props ? props.isNotifiable: '';
this.onUpdate = null;
this.enableEventHandler()
}
enableEventHandler(){
// event handlers
this._userInfoUpdateSubscription = NativeAppEventEmitter.addListener(
'chatClient:user:updated',
({ updated, user }) => {
console.log('_userInfoUpdateSubscription')
if (user.identity === this.identity) {
this.friendlyName = user.friendlyName;
this.attributes = user.attributes;
this.isOnline = user.isOnline;
this.isNotifiable = user.isNotifiable;
if (this.onUpdate) this.onUpdate(updated);
}
},
);
}
setAttributes(attributes) {
return CCClient.setUserAttributes(attributes);
}
setFriendlyName(friendlyName) {
return CCClient.setFriendlyName(friendlyName);
}
removeListeners() {
this._userInfoUpdateSubscription.remove();
}
}
export default ChatUser;