void backgroundWorkerMessages_DoWork(object sender, DoWorkEventArgs e) { List <Message> messages = new List <Message>(); Tuple <List <Message>, ApiCallResponse> items; Tuple <List <Channel>, ApiCallResponse> channels = Channels.Subscriptions.getOfCurrentUser(this.accessToken); if (channels.Item2.success) { backgroundWorkerMessages.ReportProgress(20, channels.Item1); } else { return; } DateTime newestKnownDateTime = DateTime.MinValue; if (PrivateMessages.Count > 0) { newestKnownDateTime = PrivateMessages.Max(m => m.CreatedAt); } foreach (Channel channel in channels.Item1) { if (channel.type == "net.app.core.pm") { Messages.messageParameters parameter = new Messages.messageParameters(); parameter.include_annotations = true; items = Messages.getMessagesInChannel(this.accessToken, channel.id, parameters: parameter); if (items.Item2.success) { foreach (Message message in items.Item1) { if (message.created_at > newestKnownDateTime) { messages.Add(message); } } } } } foreach (Message message in messages) { if (!string.IsNullOrEmpty(message.text) && !message.is_deleted && !message.machine_only) { ApnItem item = new ApnItem(message, this); if (item != null) { item.isPrivateMessage = true; item.receivingAccount = this; backgroundWorkerMessages.ReportProgress(50, item); } } } backgroundWorkerMessages.ReportProgress(99, null); }
void backgroundWorkerMentions_DoWork(object sender, DoWorkEventArgs e) { Tuple <List <Post>, ApiCallResponse> items; ParametersMyStream parameter = new ParametersMyStream(); parameter.count = Properties.Settings.Default.TwitterItemsFetchInPast; if (Mentions.Count > 0) { parameter.since_id = Mentions.Max(i => i.Id).ToString(); } parameter.include_annotations = true; items = Posts.getMentionsOfUsernameOrId(this.accessToken, this.username, parameter); if (items.Item2.success) { foreach (Post post in items.Item1) { if (!post.machine_only && !string.IsNullOrEmpty(post.text) && !post.is_deleted) { ApnItem item = new ApnItem(post, this); if (item != null) { item.isMention = true; item.receivingAccount = this; backgroundWorkerMentions.ReportProgress(50, item); } } } backgroundWorkerMentions.ReportProgress(99, items.Item2); } }
public void channelsCallback(List <Message> messages, bool is_deleted = false) { if (messages != null) { foreach (Message message in messages) { if (message == null) { continue; } if (message.machine_only || string.IsNullOrEmpty(message.text)) { continue; } if (message.channel_id != "net.app.core.pm") { // PM for now continue; } if (!message.is_deleted) { ApnItem item = new ApnItem(message, this); item.receivingAccount = this; PrivateMessages.Add(item); } else { IEnumerable <ApnItem> existing_items = PrivateMessages.Where(item => item.Id.ToString() == message.id); if (existing_items != null) { if (existing_items.Count() > 0) { List <ApnItem> cache = new List <ApnItem>(); foreach (ApnItem item in existing_items) { cache.Add(item); } foreach (ApnItem item in cache) { PrivateMessages.Remove(item); } cache = null; } } } } } }
public void mentionsCallback(List <Post> posts, bool is_deleted = false) { if (posts != null) { foreach (Post post in posts) { if (post == null) { continue; } if (post.machine_only || string.IsNullOrEmpty(post.text)) { continue; } if (!post.is_deleted) { ApnItem item = new ApnItem(post, this); item.receivingAccount = this; Mentions.Add(item); AppController.Current.sendNotification("App.net " + username + " mentions", item.AuthorName, item.Text, item.Avatar, item); } else { IEnumerable <ApnItem> existing_items = Mentions.Where(item => item.Id.ToString() == post.id); if (existing_items != null) { if (existing_items.Count() > 0) { List <ApnItem> cache = new List <ApnItem>(); foreach (ApnItem item in existing_items) { cache.Add(item); } foreach (ApnItem item in cache) { Mentions.Remove(item); } cache = null; } } } } } }
public void unifiedCallback(List <Post> posts, bool is_deleted = false) { if (posts != null) { foreach (Post post in posts) { if (post == null) { continue; } if (post.machine_only || string.IsNullOrEmpty(post.text)) { continue; } if (!post.is_deleted) { ApnItem item = new ApnItem(post, this); item.receivingAccount = this; PersonalStream.Add(item); } else { IEnumerable <ApnItem> existing_items = PersonalStream.Where(item => item.Id.ToString() == post.id); if (existing_items != null) { if (existing_items.Count() > 0) { List <ApnItem> cache = new List <ApnItem>(); foreach (ApnItem item in existing_items) { cache.Add(item); } foreach (ApnItem item in cache) { PersonalStream.Remove(item); } cache = null; } } } } } }
void backgroundWorkerPersonalStream_ProgressChanged(object sender, ProgressChangedEventArgs e) { if (e != null) { switch (e.ProgressPercentage) { case 50: ApnItem item = e.UserState as ApnItem; if (item != null) { PersonalStream.Add(item); if (showNotifications) { AppController.Current.sendNotification("App.net " + username + " personal stream", item.AuthorName, item.Text, item.Avatar, item); } } break; case 99: ApiCallResponse apiCallResponse = e.UserState as ApiCallResponse; streamMarkerMyStreamUpdateComplete = true; if (apiCallResponse != null) { if (apiCallResponse.meta != null) { if (apiCallResponse.meta.marker != null) { storeMarkerIdMyStream = apiCallResponse.meta.marker.id; storeMarkerVersionMyStream = apiCallResponse.meta.marker.version; } } } if (PersonalStream.Count > 0) { InitialUpdateForPersonalStream = true; } streamMarkerMyStreamUpdateComplete = true; break; } } }
void backgroundWorkerMessages_ProgressChanged(object sender, ProgressChangedEventArgs e) { if (e != null) { switch (e.ProgressPercentage) { case 20: // Channel list KnownChannels = e.UserState as List <Channel>; if (KnownChannels != null) { foreach (Channel channel in KnownChannels) { if (KnownChannelIds.Contains(channel.id)) { KnownChannelIds.Add(channel.id); } } } break; case 50: ApnItem item = e.UserState as ApnItem; PrivateMessages.Add(item); // || true muss raus if (showNotifications) { AppController.Current.sendNotification("App.net " + username + " private messages", item.AuthorName, item.Text, item.Avatar, item); } break; case 99: streamMarkerPrivateMessagesUpdateComplete = true; InitialUpdateForMessages = true; break; } } }
/// <summary> /// Will return true if this filter would like the item to be displayed /// </summary> /// <param name="item">The item which shall be checked for filtering</param> /// <returns></returns> public bool ShallItemBeDisplayed(IItem item) { if (item == null || string.IsNullOrEmpty(FilterString)) { return(false); } #region Reposts and retweets detection bool isRepost = false; if (item.GetType() == typeof(TwitterItem)) { TwitterItem tempItem = item as TwitterItem; isRepost = tempItem.isRetweeted; } else if (item.GetType() == typeof(ApnItem)) { ApnItem tempItem = item as ApnItem; isRepost = tempItem.isReposted; } #endregion bool ItemShallBeDisplayed = true; if (IsExcludeFilter) { // was ein grausamer Code bzw. Kot if (FilterAuthor) { ItemShallBeDisplayed = !checkIfStringIsInText(item.AuthorName); } if (!ItemShallBeDisplayed) { return(ItemShallBeDisplayed); } if (FilterRetweeter) { ItemShallBeDisplayed = !isRepost; if (isRepost) { ItemShallBeDisplayed = !checkIfStringIsInText(item.AuthorName); } } if (!ItemShallBeDisplayed) { return(ItemShallBeDisplayed); } if (FilterText) { ItemShallBeDisplayed = !checkIfStringIsInText(item.Text); } if (!ItemShallBeDisplayed) { return(ItemShallBeDisplayed); } if (FilterClient) { ItemShallBeDisplayed = !checkIfStringIsInText(item.ClientName); } } else { ItemShallBeDisplayed = false; if (FilterAuthor) { ItemShallBeDisplayed = checkIfStringIsInText(item.AuthorName); } if (ItemShallBeDisplayed) { return(ItemShallBeDisplayed); } if (FilterRetweeter) { ItemShallBeDisplayed = !isRepost; if (isRepost) { ItemShallBeDisplayed = checkIfStringIsInText(item.AuthorName); } } if (ItemShallBeDisplayed) { return(ItemShallBeDisplayed); } if (FilterText) { ItemShallBeDisplayed = checkIfStringIsInText(item.Text); } if (ItemShallBeDisplayed) { return(ItemShallBeDisplayed); } if (FilterClient) { ItemShallBeDisplayed = checkIfStringIsInText(item.ClientName); } } return(ItemShallBeDisplayed); }