Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get unread message via rest api for Rocket.chat #7775

Closed
ankit213 opened this issue Aug 17, 2017 · 9 comments · Fixed by #7793
Closed

Get unread message via rest api for Rocket.chat #7775

ankit213 opened this issue Aug 17, 2017 · 9 comments · Fixed by #7793

Comments

@ankit213
Copy link

ankit213 commented Aug 17, 2017

Description:

Hello I have used this https://rocket.chat/docs/developer-guides/rest-api/im/history for get unread message via rest API. Rocket.chat server version is 0.57.3 .

Example Call

  1. https://rcserver.rocket.chat/api/v1/im.history?roomId=ByehQjC44FwMeiLbX?&unreads=true
  2. https://rcserver.rocket.chat/api/v1/im.history?roomId=ByehQjC44FwMeiLbX?&unreads=”+true

Code

HttpClient client = new HttpClient();
client.BaseAddress = new Uri(Constants.CONST_SITEURL);
client.DefaultRequestHeaders.Accept.Add(
new MediaTypeWithQualityHeaderValue("application/json"));
client.DefaultRequestHeaders.Add("X-Auth-Token", authToken);
client.DefaultRequestHeaders.Add("X-User-Id", userRcId);
HttpResponseMessage msgHistory = client.GetAsync(Constants.CONST_CHATHISTORY + userDetail.RC_RoomID + "&count=20&unreads=true").Result;
     if (msgHistory.IsSuccessStatusCode)
         {
           using (HttpContent content = msgHistory.Content)
                   {
                      var result = content.ReadAsStringAsync();
                      value = JObject.Parse(result.Result);
                    }
           directChatWindow = JsonConvert.DeserializeObject<DirectChatWindowBO>(value.ToString());
         }

I have try to above link and code but it will not give any unread property in result

Example Result

{ "messages": [ { "_id": "7e6691fc-16sdfd3-ecbfsd8-317a-4076bb307e5dfsfd-4564", "rid": "CBsDHB7M8fsdfsdfN8G4X2BjsBDt5khnkenENacLN", "msg": "hittti", "ts": "2017-08-16T11:08:21.011Z", "u": { "_id": "CBsDHsdadsaB7M8N8G4X2Bj", "username": "xyz", "name": "xyz21" }, "mentions": [], "channels": [], "_updatedAt": "2017-08-16T11:08:21.013Z" }, { "_id": "eaf75056-bcxcvxcv40c-4a68-0128-c40503289d60", "rid": "CBsDHxcvB7M8cvxvxcvN8G4X2BjsBDt5kxcvhnkenENacLN", "msg": "hi", "ts": "2017-08-16T11:07:53.579Z", "u": { "_id": "CBsDHB7M8N8G4X2Bj", "username": "Abc", "name": "Abc123 " }, "mentions": [], "channels": [], "_updatedAt": "2017-08-16T11:07:53.583Z" }] }

Please help me out.
Thank You.

@MartinSchoeler
Copy link
Contributor

We aim to keep our Github issues for bugs and feature requests. This does not fit that criteria.
Please see our guidelines for support. If you feel like we are closing in error, please re-open and add additional details about the bug or feature request.

@graywolf336
Copy link
Contributor

Reopening as this is actually a bug with the current channels.history api endpoint, the value is never being returned to the clients.

@mbouchard
Copy link

I have the same problem with version 0.59.3. I can't find the total of unreal messages. All I see is the unreadNotLoaded property and its value is always 0. I can't see what has been done in 4f3c9d4 to fix the unread issue. Maybe I'm missing something?

@graywolf336
Copy link
Contributor

@mbouchard what's the full url you're calling?

@mbouchard
Copy link

I'm calling /api/v1/channels.history?roomName=general&unreads=true&oldest=2017-01-01. I think I don't really understand what the value of unreadNotLoaded means. I've been able to get something else than 0, but the value is not what I expect. I expect it to be the same as the number of unread messages I see in the Rocket.Chat app, but it's not the case. And if I use the count param, the value of unreadNotLoaded is changing, which I don't understand neither.

@rodrigok
Copy link
Member

rodrigok commented Dec 8, 2017

Hi @mbouchard , the unreadNotLoaded returns the amount of messages you have unread and server didn't returned on that request. It's not the total amount.

To get the total amount we verify if the unreadNotLoaded is greater then 0 the unread count will be the unreadNotLoaded + request.count, if not we need to check the subscription.ls property, that is a timestamp, sort the messages by ts and then count the messages where ts is greater than subscription.ls. That is the current way to do it.

@shreekarade
Copy link

shreekarade commented Feb 9, 2018

@mbouchard graywolf336 I'm calling "/api/v1/im.history?roomId=MLtBizp6jZT6w5LmqXrJK2GRbJBPPKSYPm&unreads=true", but it return unreadNotLoaded = 0; Which is not right. Please help me ASAP.

@mbouchard
Copy link

@shreekarade I never managed to get the correct number of unread messages with that method and I didn't have any time left to achieve it.

@Jamirkhan50
Copy link

Hi Team,
We have any plan to get unread messages for particular USERS

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants