コード例 #1
0
        private async System.Threading.Tasks.Task import(JSONRequestEventArgs<SparklrLib.Objects.Responses.Beacon.Stream> args)
        {
            if (args.IsSuccessful)
            {
                SparklrLib.Objects.Responses.Beacon.Stream stream = args.Object;

                if (stream != null && stream.data != null)
                {
                    if (stream.notifications != null)
                    {
                        NewCount = stream.notifications.Count;

                        Notifications.Clear();
                        foreach (SparklrLib.Objects.Responses.Beacon.Notification n in stream.notifications)
                        {
                            Notifications.Add(new NotificationViewModel(n.id)
                            {
                                Message = n.body,
                                From = n.from
                            });
                        }
                    }

                    int count = stream.data.length;

                    List<ItemViewModel> newItems = new List<ItemViewModel>(Items);

                    foreach (var t in stream.data.timeline)
                    {
                        if (LastTime < t.time)
                        {
                            LastTime = t.time;
                        }
                        if (LastTime < t.modified)
                        {
                            LastTime = t.modified;
                        }

                        ItemViewModel existingitem = null;
                        existingitem = (from i in newItems where i.Id == t.id select i).FirstOrDefault();

                        if (existingitem == null)
                        {
                            ItemViewModel newItem = new ItemViewModel(t.id) { Message = t.message, CommentCount = (t.commentcount == null ? 0 : (int)t.commentcount), From = t.from.ToString(), OrderTime = t.modified > t.time ? t.modified : t.time };
                            if (!String.IsNullOrEmpty(t.meta))
                            {
                                newItem.ImageUrl = "http://d.sparklr.me/i/t" + t.meta;
                            }

                            JSONRequestEventArgs<SparklrLib.Objects.Responses.Work.Username[]> response = await App.Client.GetUsernamesAsync(new int[] { t.from });
                            if (response.IsSuccessful && response.Object[0] != null && !string.IsNullOrEmpty(response.Object[0].username))
                                newItem.From = response.Object[0].username;

                            newItems.Add(newItem);
                        }
                        else
                        {
                            existingitem.Message = t.message;
                            existingitem.CommentCount = (t.commentcount == null ? 0 : (int)t.commentcount);
                            existingitem.From = t.from.ToString();
                            existingitem.OrderTime = t.modified > t.time ? t.modified : t.time;

                            JSONRequestEventArgs<SparklrLib.Objects.Responses.Work.Username[]> response = await App.Client.GetUsernamesAsync(new int[] { t.from });

                            if (response.IsSuccessful && response.Object[0] != null && !string.IsNullOrEmpty(response.Object[0].username))
                                existingitem.From = response.Object[0].username;
                        }
                    }
                    newItems.Sort(itemComparison);
                    newItems.Reverse();

                    Items = new ObservableCollectionWithItemNotification<ItemViewModel>(newItems);
                    this.IsDataLoaded = true;
#if DEBUG
                    foreach (ItemViewModel i in Items)
                    {
                        if (i.ImageUrl != null)
                            App.logger.log(i.ImageUrl);
                    }
#endif
                }
            }
        }
コード例 #2
0
 public PostViewModel(ItemViewModel post)
 {
     this.Id = post.Id;
     Comments = new ObservableCollection<ItemViewModel>();
     MainPost = post;
 }