public async Task LookupFriendshipAsync(IUserModel user)
        {
            IFriendshipModel model = StorageService.GetCachedFriendship(user.ScreenName);

            if (model == null)
            {
                var option = Const.GetDictionary();
                option.Add(Const.USER_ID, user.Id);
                var friendships = await tokens.Friendships.LookupAsync(option);

                if (friendships != null && friendships.Count != 0)
                {
                    model = new FriendshipModel(friendships[0]);
                }
            }
            if (model == null)
            {
                return;
            }

            var connections = model.Connections.Select(c => c.ToLower()).ToList();

            user.IsFollowing  = connections.Contains(Const.FOLLOWING);
            user.IsFollowedBy = connections.Contains(Const.FOLLOWED_BY);

            StorageService.AddOrUpdateCachedFriendship(model);
        }
Ejemplo n.º 2
0
 public void AddOrUpdateCachedFriendship(IFriendshipModel friendship)
 {
     lock (locker)
     {
         var entity = context.CachedFriendships.FirstOrDefault(u => u.Id == friendship.ScreenName);
         if (entity == null)
         {
             entity = new CachedFriendship {
                 Id = friendship.ScreenName
             };
             context.CachedFriendships.InsertOnSubmit(entity);
         }
         entity.Data = SerializeObject(friendship);
         context.SubmitChanges();
     }
 }