Skip to content

Commit

Permalink
fix: rate operator
Browse files Browse the repository at this point in the history
  • Loading branch information
maxim vasin committed Jan 10, 2023
1 parent cb39496 commit 6649488
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 34 deletions.
54 changes: 27 additions & 27 deletions android/src/main/java/com/rnwebimchat/RnWebimChatModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -326,33 +326,33 @@ public void readMessages(final Promise promise) {
}


// @ReactMethod
// public void rateOperator(int rate, final Callback errorCallback, final Callback successCallback) {
// Operator operator = session.getStream().getCurrentOperator();
// if (operator != null) {
// session.getStream().rateOperator(operator.getId(), rate, new MessageStream.RateOperatorCallback() {
// @Override
// public void onSuccess() {
// successCallback.invoke(Arguments.createMap());
// }
//
// @Override
// public void onFailure(@NonNull WebimError<RateOperatorError> rateOperatorError) {
// WritableMap errorBody = Arguments.createMap();
// errorBody.putString("message", rateOperatorError.getErrorString());
// errorBody.putString("errorCode", rateOperatorError.getErrorType().name());
// errorBody.putString("errorType", "fatal");
// errorCallback.invoke(errorBody);
// }
// });
// } else {
// WritableMap errorBody = Arguments.createMap();
// errorBody.putString("message", "no operator");
// errorBody.putString("errorCode", MessageStream.RateOperatorCallback.RateOperatorError.OPERATOR_NOT_IN_CHAT.name());
// errorBody.putString("errorType", "common");
// errorCallback.invoke(errorBody);
// }
// }
@ReactMethod
public void rateOperator(int rate, final Promise promise) {
Operator operator = session.getStream().getCurrentOperator();
if (operator != null) {
session.getStream().rateOperator(operator.getId(), rate, new MessageStream.RateOperatorCallback() {
@Override
public void onSuccess() {
promise.resolve(Arguments.createMap());
}

@Override
public void onFailure(@NonNull WebimError<RateOperatorError> rateOperatorError) {
WritableMap errorBody = Arguments.createMap();
errorBody.putString("message", rateOperatorError.getErrorString());
errorBody.putString("errorCode", rateOperatorError.getErrorType().name());
errorBody.putString("errorType", "fatal");
promise.reject("Operator rate on failure", errorBody);
}
});
} else {
WritableMap errorBody = Arguments.createMap();
errorBody.putString("message", "no operator");
errorBody.putString("errorCode", MessageStream.RateOperatorCallback.RateOperatorError.OPERATOR_NOT_IN_CHAT.name());
errorBody.putString("errorType", "common");
promise.reject("Operator rate on failed", errorBody);
}
}

// @ReactMethod
// public void tryAttachFile(Callback failureCb, Callback successCb) {
Expand Down
14 changes: 7 additions & 7 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -123,13 +123,13 @@ export class RNWebim {
}

static rateOperator(rate: number) {
return new Promise((resolve, reject) => {
RnWebimChat.rateOperator(
rate,
(error: WebimNativeError) => reject(error),
resolve
);
});
return RnWebimChat.rateOperator(rate)
.catch((err: WebimNativeError) => {
throw err;
})
.then(() => {
return;
});
}

static tryAttachFile() {
Expand Down

0 comments on commit 6649488

Please sign in to comment.