QuickBlox / quickblox-react-native-sdk

quickblox-react-native-sdk
Other
4 stars 1 forks source link

Getting [Error: base Forbidden. Need user.] when try to get ChatHistory QB.chat.getDialogMessages #55

Closed hiren-devstree closed 1 year ago

hiren-devstree commented 2 years ago

"react-native": "0.68.1", "quickblox-react-native-sdk": "^0.6.0-beta",

const data = {
            dialogId: props.route.params.dialogId,
            sort: {
                ascending: false,
                field: QB.chat.MESSAGES_SORT.FIELD.DATE_SENT
            },
            markAsRead: true
        };
export function* getChatHistory(action) {
  console.log("ACTION", action)
  const { data } = action
  console.log("DATA", data)
  const request = action.payload || {};
  console.log("REQUEST", request)
  console.log("QB CHAT", QB.chat.getDialogMessages)
  const response = yield call(QB.chat.getDialogMessages, data);
  console.log("RESPONSE", response)
  let chatArr = []
  if (response.messages) {
    const { messages } = response
    for (let i = 0; i < messages.length; i++) {
      let item = messages[i]
      if (item.attachments) {
        const { attachments } = item;
        const [attachment] = attachments;
        const contentGetFileUrlParams = { uid: attachment.id };
        item.attachments[0].url = yield call(QB.content.getPrivateURL, contentGetFileUrlParams)
        chatArr.push(item)
      } else {
        chatArr.push(item)
      }
    }
    yield put(UserActions.getChatHistorySuccess(chatArr));
  } else {
    yield put(UserActions.getChatHistoryFailure("Something Went Wrong.Please try again later", "ss"));
  }
}

[Error: base Forbidden. Need user.] ERROR The above error occurred in task getChatHistory created by takeLatest(GET_CHAT_HISTORY, getChatHistory) created by root Tasks cancelled due to error: takeLatest(GET_CHAT_HISTORY, getChatHistory)

ghost commented 2 years ago

Hello, please make sure that you created a user session before retrieving messages.