/// <summary> /// Unlikes message, asynchronously. /// </summary> /// <param name="messageId">The message identifier.</param> /// <returns> /// The completion task. /// </returns> public async Task UnLikeMessageAsync(int messageId) { using (HttpResponseMessage response = await this.Client.DeleteAsync(YammerService.BuildRequest("messages/liked_by/current.json", "message_id", messageId.ToString()))) { response.EnsureSuccessStatusCode(); } }
/// <summary> /// Gets the thread, asynchronously. /// </summary> /// <param name="id">The identifier.</param> /// <returns> /// The thread task. /// </returns> public async Task <Thread> GetThreadAsync(int id) { using (HttpResponseMessage response = await this.Client.GetAsync(string.Concat("threads/", id, ".json"), HttpCompletionOption.ResponseContentRead)) { return(await YammerService.GetResponseContentAsync <Thread>(response)); } }
/// <summary> /// Likes the message, asynchronously. /// </summary> /// <param name="messageId">The message identifier.</param> /// <returns> /// The completion task. /// </returns> public async Task LikeMessageAsync(int messageId) { using (StringContent content = new StringContent(string.Empty)) using (HttpResponseMessage response = await this.Client.PostAsync(YammerService.BuildRequest("messages/liked_by/current.json", "message_id", messageId.ToString()), content)) { response.EnsureSuccessStatusCode(); } }
/// <summary> /// Gets the user groups, asynchronously. /// </summary> /// <returns> /// The groups task. /// </returns> public async Task <Group[]> GetUserGroupsAsync() { using (HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, "groups.json?mine=1")) { request.Headers.Add(CustomMessageHandler.CacheNameHeader, "my_groups.json"); request.Headers.Add(CustomMessageHandler.CacheMaxAgeHeader, TimeSpan.FromDays(1).ToString()); using (HttpResponseMessage response = await this.Client.SendAsync(request, HttpCompletionOption.ResponseContentRead)) { return(await YammerService.GetResponseContentAsync <Group[]>(response)); } } }
/// <summary> /// Posts the message, asynchronously. /// </summary> /// <param name="request">The request.</param> /// <returns> /// The message feed task. /// </returns> public async Task <MessageFeed> PostMessageAsync(PostRequest request) { request.ThrowIfNull(nameof(request)); User currentUser = await this.GetCurrentUserAsync(); string json = JsonConvert.SerializeObject(request); using (HttpContent content = new StringContent(json)) { content.Headers.ContentType = new MediaTypeHeaderValue("application/json"); using (HttpResponseMessage response = await this.Client.PostAsync(YammerService.BuildRequest("messages.json"), content)) { MessageFeed feed = await YammerService.GetResponseContentAsync <MessageFeed>(response); return(YammerService.ProcessMessages(currentUser, feed)); } } }
/// <summary> /// Gets the activity feed, asynchronously. /// </summary> /// <param name="olderThanId">The older than identifier.</param> /// <param name="newerThanId">The newer than identifier.</param> /// <param name="limit">The limit.</param> /// <returns> /// The activity feed task. /// </returns> private async Task <MessageFeed> GetMessagesAsync(string uri, Threaded?threaded, int olderThanId, int newerThanId, int limit) { List <string> parameters = new List <string>(3); if (threaded.HasValue) { parameters.Add("threaded"); parameters.Add(YammerService.ThreadedValues[threaded.Value]); } if (limit > 0) { parameters.Add("limit"); parameters.Add(limit.ToString()); } if (olderThanId > 0) { parameters.Add("older_than"); parameters.Add(olderThanId.ToString()); } if (newerThanId > 0) { parameters.Add("newer_than"); parameters.Add(newerThanId.ToString()); } // forces all loaded messages to be marked read parameters.Add("update_last_seen_message_id"); parameters.Add("true"); User currentUser = await this.GetCurrentUserAsync(); using (HttpResponseMessage response = await this.Client.GetAsync(YammerService.BuildRequest(uri, parameters.ToArray()), HttpCompletionOption.ResponseContentRead)) { MessageFeed feed = await YammerService.GetResponseContentAsync <MessageFeed>(response); return(YammerService.ProcessMessages(currentUser, feed)); } }
/// <summary> /// Gets the network, asynchronously. /// </summary> /// <returns> /// The network task. /// </returns> public async Task <Network[]> GetNetworkAsync() { using (HttpResponseMessage tokensResponse = await this.Client.GetAsync("oauth/tokens.json", HttpCompletionOption.ResponseContentRead)) using (HttpResponseMessage networksResponse = await this.Client.GetAsync("networks/current?exclude_own_messages_from_unseen=true&include_group_counts=true&inbox_supported_client=true&exclude_private_unread_thread_count=true", HttpCompletionOption.ResponseContentRead)) { NetworkToken[] tokens = await YammerService.GetResponseContentAsync <NetworkToken[]>(tokensResponse); Network[] networks = await YammerService.GetResponseContentAsync <Network[]>(networksResponse); Dictionary <int, NetworkToken> tokenLookup = tokens.ToDictionary(_ => _.NetworkId); foreach (Network network in networks) { NetworkToken token; if (tokenLookup.TryGetValue(network.Id, out token)) { network.Token = token; if (network.GroupCounts != null) { // some custom logic to derive the most frequently used group order + unseen counts network.GroupCounts.UnseenGroupThreadCountsLookup = new Dictionary <int, Tuple <int, int> >(); int index = 0; foreach (JProperty property in network.GroupCounts.UnseenGroupThreadCounts.Properties()) { network.GroupCounts.UnseenGroupThreadCountsLookup[int.Parse(property.Name)] = Tuple.Create(index++, (int)(long)((JValue)property.Value).Value); } } } if (network.IsPrimary && this.MessageHandler.ActiveNetwork == null) { this.SetActiveNetwork(network); } } return(networks); } }