Ejemplo n.º 1
0
        private void SendVenue(TLMessageMediaVenue venue)
        {
            var chat = Chat as TLEncryptedChat;

            if (chat == null)
            {
                return;
            }

            var decryptedTuple = GetDecryptedMessageAndObject(TLString.Empty,
                                                              new TLDecryptedMessageMediaVenue
            {
                Lat      = ((TLGeoPoint)venue.Geo).Lat,
                Long     = ((TLGeoPoint)venue.Geo).Long,
                Title    = venue.Title,
                Address  = venue.Address,
                Provider = venue.Provider,
                VenueId  = venue.VenueId
            },
                                                              chat);

            BeginOnUIThread(() =>
            {
                InsertSendingMessage(decryptedTuple.Item1);
                RaiseScrollToBottom();
                NotifyOfPropertyChange(() => DescriptionVisibility);

                SendEncrypted(chat, decryptedTuple.Item2, MTProtoService, CacheService);
            });
        }
Ejemplo n.º 2
0
        public Task<bool> SendGeoPointAsync(TLMessageMediaVenue media)
        {
            var tsc = new TaskCompletionSource<bool>();
            var date = TLUtils.DateToUniversalTimeTLInt(ProtoService.ClientTicksDelta, DateTime.Now);

            var message = TLUtils.GetMessage(SettingsHelper.UserId, Peer.ToPeer(), TLMessageState.Sending, true, true, date, string.Empty, media, TLLong.Random(), null);

            if (Reply != null)
            {
                message.HasReplyToMsgId = true;
                message.ReplyToMsgId = Reply.Id;
                message.Reply = Reply;
                Reply = null;
            }

            var previousMessage = InsertSendingMessage(message);
            CacheService.SyncSendingMessage(message, previousMessage, async (m) =>
            {
                var inputMedia = media.ToInputMedia();

                var result = await ProtoService.SendMediaAsync(Peer, inputMedia, message);
                if (result.IsSucceeded)
                {
                    tsc.SetResult(true);
                }
                else
                {
                    tsc.SetResult(false);
                }
            });

            return tsc.Task;
        }
Ejemplo n.º 3
0
        public async Task <List <TLMessageMediaVenue> > GetVenuesAsync(double latitude, double longitute, string query = null)
        {
            var builder = new StringBuilder("https://api.foursquare.com/v2/venues/search/?");

            if (string.IsNullOrEmpty(query) == false)
            {
                builder.Append(string.Format("{0}={1}&", "query", WebUtility.UrlEncode(query)));
            }
            builder.Append(string.Format("{0}={1}&", "v", "20150326"));
            builder.Append(string.Format("{0}={1}&", "locale", "en"));
            builder.Append(string.Format("{0}={1}&", "limit", "25"));
            builder.Append(string.Format("{0}={1}&", "client_id", "BN3GWQF1OLMLKKQTFL0OADWD1X1WCDNISPPOT1EMMUYZTQV1"));
            builder.Append(string.Format("{0}={1}&", "client_secret", "WEEZHCKI040UVW2KWW5ZXFAZ0FMMHKQ4HQBWXVSX4WXWBWYN"));
            builder.Append(string.Format("{0}={1},{2}&", "ll", latitude.ToString(new CultureInfo("en-US")), longitute.ToString(new CultureInfo("en-US"))));

            var client  = new HttpClient();
            var request = new HttpRequestMessage(HttpMethod.Get, builder.ToString());

            var response = await client.SendAsync(request);

            if (response.IsSuccessStatusCode)
            {
                var content = await response.Content.ReadAsStringAsync();

                var json = await Task.Run(() => JsonConvert.DeserializeObject <FoursquareRootObject>(content));

                if (json?.response?.venues != null)
                {
                    var result = new List <TLMessageMediaVenue>();
                    foreach (var item in json.response.venues)
                    {
                        var venue = new TLMessageMediaVenue();
                        venue.VenueId  = item.id;
                        venue.Title    = item.name;
                        venue.Address  = item.location.address ?? item.location.city ?? item.location.country;
                        venue.Provider = "foursquare";
                        venue.Geo      = new TLGeoPoint {
                            Lat = item.location.lat, Long = item.location.lng
                        };

                        if (item.categories != null && item.categories.Count > 0)
                        {
                            var icon = item.categories[0].icon;
                            if (icon != null)
                            {
                                venue.VenueType = icon.prefix.Replace("https://ss3.4sqi.net/img/categories_v2/", string.Empty).TrimEnd('_');
                                //location.Icon = string.Format("https://ss3.4sqi.net/img/categories_v2/{0}_88.png");
                            }
                        }

                        result.Add(venue);
                    }

                    return(result);
                }
            }

            return(new List <TLMessageMediaVenue>());
        }
Ejemplo n.º 4
0
        public void AttachVenue(TLMessageMediaVenue venue)
        {
            if (venue == null)
            {
                return;
            }

            AttachAction.SafeInvoke(venue);
        }
Ejemplo n.º 5
0
        public void AttachVenue(TLMessageMediaVenue mediaVenue)
        {
            if (mediaVenue == null)
            {
                return;
            }

            CloseEditor(true);
            ContinueAction.SafeInvoke(mediaVenue);
        }
Ejemplo n.º 6
0
        public void AttachVenue(TLMessageMediaVenue venue)
        {
            if (venue == null)
            {
                return;
            }

            StateService.Venue = venue;
            _navigationService.GoBack();
        }
Ejemplo n.º 7
0
        private void SendVenue(TLMessageMediaVenue venue)
        {
            var message = GetMessage(TLString.Empty, venue);

            BeginOnUIThread(() =>
            {
                var previousMessage = InsertSendingMessage(message);
                IsEmptyDialog       = Items.Count == 0 && (_messages == null || _messages.Count == 0) && LazyItems.Count == 0;

                BeginOnThreadPool(() =>
                                  CacheService.SyncSendingMessage(
                                      message, previousMessage,
                                      SendVenueInternal));
            });
        }
        private void SendVenue(TLMessageMediaVenue venue)
        {
            var message = GetMessage(TLString.Empty, venue);

            BeginOnUIThread(() =>
            {
                var previousMessage = InsertSendingMessage(message);
                IsEmptyDialog       = Items.Count == 0 && LazyItems.Count == 0;

                BeginOnThreadPool(() =>
                                  CacheService.SyncSendingMessage(
                                      message, previousMessage,
                                      TLUtils.InputPeerToPeer(Peer, StateService.CurrentUserId),
                                      SendVenueInternal));
            });
        }
Ejemplo n.º 9
0
        public void Search(string inputText)
        {
            if (inputText == null)
            {
                return;
            }

            var text = inputText.Trim();

            Execute.BeginOnUIThread(TimeSpan.FromMilliseconds(300), () =>
            {
                if (!string.Equals(Text, text))
                {
                    return;
                }

                List <TLMessageMediaVenue> cachedResult;
                if (_cache.TryGetValue(text, out cachedResult))
                {
                    Items.Clear();
                    foreach (var venue in cachedResult)
                    {
                        Items.Add(venue);
                    }

                    IsWorking = false;
                    Status    = Items.Count > 0 ? string.Empty : AppResources.NoResults;

                    return;
                }

                Execute.BeginOnThreadPool(() =>
                {
                    var client = new WebClient();
                    client.DownloadStringCompleted += (sender, args) =>
                    {
                        if (args.Error != null)
                        {
                            BeginOnUIThread(() =>
                            {
                                Items.Clear();
                                IsWorking = false;
                                Status    = AppResources.NoResults;
                            });

                            return;
                        }

                        var venues     = new List <TLMessageMediaVenue>();
                        var serializer = new DataContractJsonSerializer(typeof(RootObject));
                        var rootObject = (RootObject)serializer.ReadObject(new MemoryStream(Encoding.UTF8.GetBytes(args.Result ?? "")));
                        if (rootObject != null &&
                            rootObject.response != null &&
                            rootObject.response.venues != null)
                        {
                            foreach (var venue in rootObject.response.venues)
                            {
                                if (venue.location == null)
                                {
                                    continue;
                                }

                                var mediaVenue = new TLMessageMediaVenue
                                {
                                    VenueId  = new TLString(venue.id),
                                    Title    = new TLString(venue.name),
                                    Address  = new TLString(venue.location.address ?? venue.location.city ?? venue.location.country),
                                    Provider = new TLString("foursquare"),
                                    Geo      = new TLGeoPoint {
                                        Lat = new TLDouble(venue.location.lat), Long = new TLDouble(venue.location.lng)
                                    }
                                };
                                venues.Add(mediaVenue);
                            }
                        }

                        BeginOnUIThread(() =>
                        {
                            _cache[text] = venues;

                            if (!string.Equals(Text, text))
                            {
                                return;
                            }

                            Items.Clear();
                            foreach (var venue in venues)
                            {
                                Items.Add(venue);
                            }

                            IsWorking = false;
                            Status    = Items.Count > 0 ? string.Empty : AppResources.NoResults;
                        });
                    };

                    IsWorking = true;
                    Status    = Items.Count > 0 ? string.Empty : AppResources.Loading;
                    client.DownloadStringAsync(Media.Foursquire.Utils.GetSearchVenueUrl(_location, text));
                });
            });
        }
Ejemplo n.º 10
0
        public void GetVenues(GeoCoordinate location)
        {
            var client = new WebClient();

            client.DownloadStringCompleted += (sender, args) =>
            {
                if (args.Error != null)
                {
                    Execute.BeginOnUIThread(() =>
                    {
                        Venues.Clear();
                        IsWorking = false;
                        Status    = AppResources.NoResults;
                    });

                    return;
                }

                var venues     = new List <TLMessageMediaVenue>();
                var serializer = new DataContractJsonSerializer(typeof(RootObject));
                var rootObject = (RootObject)serializer.ReadObject(new MemoryStream(Encoding.UTF8.GetBytes(args.Result ?? string.Empty)));
                if (rootObject != null &&
                    rootObject.response != null &&
                    rootObject.response.venues != null)
                {
                    foreach (var venue in rootObject.response.venues)
                    {
                        if (venue.location == null)
                        {
                            continue;
                        }

                        var mediaVenue = new TLMessageMediaVenue
                        {
                            VenueId  = new TLString(venue.id),
                            Title    = new TLString(venue.name),
                            Address  = new TLString(venue.location.address ?? venue.location.city ?? venue.location.country),
                            Provider = new TLString("foursquare"),
                            Geo      = new TLGeoPoint {
                                Lat = new TLDouble(venue.location.lat), Long = new TLDouble(venue.location.lng)
                            }
                        };

                        venues.Add(mediaVenue);
                    }
                }

                Execute.BeginOnUIThread(() =>
                {
                    Venues.Clear();
                    foreach (var venue in venues)
                    {
                        Venues.Add(venue);
                    }

                    IsWorking = false;
                    Status    = Venues.Count > 0 ? AppResources.NearbyPlaces : AppResources.NoResults;
                });
            };

            IsWorking = true;
            Status    = Venues.Count > 0 ? Status : AppResources.Loading;
            client.DownloadStringAsync(Foursquire.Utils.GetSearchVenueUrl(location));
        }