/// <summary> /// Retrieves all chat messages within particular dialog. It's only possible to read chat messages in dialog if current user id is in occupants_ids field or if dialog's type=1(PUBLIC_GROUP). Server will return dialog's chat messages sorted ascending by date_sent field. /// All retrieved chat messages will be marked as read after request. /// </summary> /// <param name="dialogId">Dialog ID</param> /// <returns></returns> public async Task <HttpResponse <RetrieveMessagesResponse <T> > > GetMessagesAsync <T>(string dialogId) where T : Message { if (dialogId == null) { throw new ArgumentNullException("dialogId"); } var retrieveMessagesRequest = new RetrieveMessagesRequest(); var aggregator = new FilterAggregator(); aggregator.Filters.Add(new FieldFilter <string>(() => new Message().ChatDialogId, dialogId)); retrieveMessagesRequest.Filter = aggregator; return(await GetMessagesAsync <T>(retrieveMessagesRequest)); }
public async Task GetMessagesWithFiltersTest() { var responseDialogs = await this.client.ChatClient.GetDialogsAsync(); Assert.AreEqual(responseDialogs.StatusCode, HttpStatusCode.OK); var testDialog = responseDialogs.Result.Items.First(); var retrieveMessagesRequest = new RetrieveMessagesRequest(); var aggregator = new FilterAggregator(); aggregator.Filters.Add(new FieldFilter <string>(() => new Message().ChatDialogId, testDialog.Id)); retrieveMessagesRequest.Filter = aggregator; var responseMessages = await this.client.ChatClient.GetMessagesAsync((RetrieveMessagesRequest)retrieveMessagesRequest); Assert.AreEqual(responseMessages.StatusCode, HttpStatusCode.OK); }
public async Task <List <Message> > GetMessagesAsync(string dialogId) { var retrieveMessagesRequest = new RetrieveMessagesRequest(); var aggregator = new FilterAggregator(); aggregator.Filters.Add(new FieldFilter <string> (() => new Message().ChatDialogId, dialogId)); aggregator.Filters.Add(new SortFilter <long> (SortOperator.Desc, () => new Message().DateSent)); retrieveMessagesRequest.Filter = aggregator; var responseResult = await client.ChatClient.GetMessagesAsync(retrieveMessagesRequest); if (await HandleResponse(responseResult, HttpStatusCode.OK)) { return(responseResult.Result.Items.ToList()); } return(new List <Message>()); }
public async Task LoadMessages(string dialogId) { var retrieveMessagesRequest = new RetrieveMessagesRequest(); var aggregator = new FilterAggregator(); aggregator.Filters.Add(new FieldFilter<string>(() => new Message().ChatDialogId, dialogId)); aggregator.Filters.Add(new SortFilter<long>(SortOperator.Desc, () => new Message().DateSent)); retrieveMessagesRequest.Filter = aggregator; var quickbloxClient = ServiceLocator.Locator.Get<IQuickbloxClient>(); var response = await quickbloxClient.ChatClient.GetMessagesAsync(retrieveMessagesRequest); if (response.StatusCode == HttpStatusCode.OK) { Messages.Clear(); var messageList = new List<MessageViewModel>(); for (int i = response.Result.Items.Length - 1; i >= 0; i--) // doing it in reverse order because we requested them from server in descending order { var messageViewModel = await CreateMessageViewModelFromMessage(response.Result.Items[i]); await GenerateProperNotificationMessages(messageViewModel, response.Result.Items[i]); messageList.Add(messageViewModel); } InitializeMessagesFromList(messageList); } }
public async Task <List <MessageTable> > GetMessagesAsync(string dialogId) { List <MessageTable> messages = new List <MessageTable> (); var retrieveMessagesRequest = new RetrieveMessagesRequest(); var aggregator = new FilterAggregator(); aggregator.Filters.Add(new FieldFilter <string> (() => new Message().ChatDialogId, dialogId)); aggregator.Filters.Add(new SortFilter <long> (SortOperator.Desc, () => new Message().DateSent)); retrieveMessagesRequest.Filter = aggregator; var responseResult = await client.ChatClient.GetMessagesAsync(retrieveMessagesRequest); if (await HandleResponse(responseResult, HttpStatusCode.OK)) { foreach (var message in responseResult.Result.Items) { if (!string.IsNullOrWhiteSpace(message.MessageText)) { var chatMessage = new MessageTable(); chatMessage.Text = message.MessageText; chatMessage.DateSent = message.DateSent; chatMessage.SenderId = message.SenderId; chatMessage.MessageId = message.Id; if (message.RecipientId.HasValue) { chatMessage.RecepientId = message.RecipientId.Value; } chatMessage.DialogId = message.ChatDialogId; chatMessage.IsRead = message.Read == 1; messages.Add(chatMessage); } } } return(messages); }
public async Task<List<Message>> GetMessagesAsync(string dialogId) { var retrieveMessagesRequest = new RetrieveMessagesRequest (); var aggregator = new FilterAggregator (); aggregator.Filters.Add (new FieldFilter<string> (() => new Message ().ChatDialogId, dialogId)); aggregator.Filters.Add (new SortFilter<long> (SortOperator.Desc, () => new Message ().DateSent)); retrieveMessagesRequest.Filter = aggregator; var responseResult = await client.ChatClient.GetMessagesAsync (retrieveMessagesRequest); if (await HandleResponse (responseResult, HttpStatusCode.OK)) { return responseResult.Result.Items.ToList(); } return new List<Message>(); }
/// <summary> /// Retrieves all chat messages within particular dialog. It's only possible to read chat messages in dialog if current user id is in occupants_ids field or if dialog's type=1(PUBLIC_GROUP). Server will return dialog's chat messages sorted ascending by date_sent field. /// All retrieved chat messages will be marked as read after request. /// </summary> /// <param name="retrieveMessagesRequest">Get messages info</param> /// <returns></returns> public async Task <HttpResponse <RetrieveMessagesResponse <T> > > GetMessagesAsync <T>(RetrieveMessagesRequest retrieveMessagesRequest) where T : Message { if (retrieveMessagesRequest == null) { throw new ArgumentNullException("retrieveMessagesRequest"); } var headers = RequestHeadersBuilder.GetDefaultHeaders().GetHeaderWithQbToken(this.quickbloxClient.Token); return(await HttpService.GetAsync <RetrieveMessagesResponse <T>, RetrieveMessagesRequest>(this.quickbloxClient.ApiEndPoint, QuickbloxMethods.GetMessagesMethod, retrieveMessagesRequest, headers)); }