public void UpdateThread(string threadId, InstaDirectInboxItem inboxItem) { try { var thread = Items.FirstOrDefault(x => x.Thread.ThreadId == threadId); if (thread != null) { thread.Thread.HasUnreadMessage = true; thread.Thread.Items.Add(inboxItem); thread.UpdateItem(inboxItem); } } catch { } }
private void PlayPauseButtonClick(object sender, RoutedEventArgs e) { try { if (sender is AppBarButton button && button != null) { if (button.DataContext is InstaDirectInboxItem directInboxItem && directInboxItem != null && directInboxItem.ItemType == InstaDirectThreadItemType.VoiceMedia && directInboxItem.VoiceMedia != null && directInboxItem.VoiceMedia?.Media?.Audio != null) { if (VoicePlayPauseButton == null) { VoicePlayPauseButton = button; } else if (VoicePlayPauseButton.Tag.ToString() != button.Tag.ToString()) { VoicePlayPauseButton.Content = Helper.PlayMaterialIcon; VoicePlayPauseButton = button; } if (button.Content.ToString() == Helper.PlayMaterialIcon)// play { if (CurrentDirectInboxItem == null) { CurrentDirectInboxItem = directInboxItem; ME.Source = new Uri(directInboxItem.VoiceMedia.Media.Audio.AudioSource); } else if (CurrentDirectInboxItem.ItemId != directInboxItem.ItemId) { CurrentDirectInboxItem = directInboxItem; ME.Source = new Uri(directInboxItem.VoiceMedia.Media.Audio.AudioSource); } else { ME.Play(); } button.Content = Helper.PauseMaterialIcon; } else { ME.Pause(); button.Content = Helper.PlayMaterialIcon; } } } } catch { } }
private static InstaActivityDto CreateActivityDto(InstaDirectInboxItem item, InstaUserShort user) { var activity = new InstaActivityDto { User = new InstaUserDto { Fullname = user.FullName, Username = user.UserName, ProfilePicture = user.ProfilePicture }, Timestamp = item.TimeStamp }; ActivityHandler.AddMediaToActivityBasedOnType(item, activity); return(activity); }
public void UpdateThread(string threadId, InstaDirectInboxItem inboxItem) { try { if (Helper.DontUseTimersAndOtherStuff) { return; } var thread = Items.FirstOrDefault(x => x.Thread.ThreadId == threadId); if (thread != null) { thread.Thread.HasUnreadMessage = true; thread.Thread.Items.Add(inboxItem); thread.UpdateItem(inboxItem); } } catch { } }
protected override void OnNavigatedTo(NavigationEventArgs e) { base.OnNavigatedTo(e); if (e.NavigationMode == NavigationMode.New) { GetType().RemovePageFromBackStack(); } try { if (e.Parameter != null && e.Parameter is object[] obj) { CurrentThread = obj[0] as InstaDirectInboxThread; InboxItem = obj[1] as InstaDirectInboxItem; } } catch { } }
public void GoFirst(string threadId, InstaDirectInboxItem inboxItem) { try { var item = Items.FirstOrDefault(x => x.Thread.ThreadId == threadId); if (item != null) { var findIndex = Items.IndexOf(item); if (findIndex != 0) { Items.Move(findIndex, 0); } UpdateThread(threadId, inboxItem); } else { RunLoadMore(true); } } catch { } }
public async void UploadSingleVoice(StorageFile File, string threadId) { ThreadId = threadId; UploadId = GenerateUploadId(); GUID = Guid.NewGuid().ToString(); WaveForm.Clear(); //try //{ // var deteils = await File.Properties.GetMusicPropertiesAsync(); // var count = deteils.Duration.TotalMilliseconds/* * 100*/; // for (int i = 0; i < count; i++) // WaveForm.Add($"0.{GetRnd()}"); //} //catch { } InstaDirectInboxItem directItem = new InstaDirectInboxItem { ItemType = InstaDirectThreadItemType.VoiceMedia, VoiceMedia = new InstaVoiceMedia { Media = new InstaVoice { Audio = new InstaAudio { AudioSource = File.Path, WaveformData = new float[] { } } } }, UserId = InstaApi.GetLoggedUser().LoggedInUser.Pk, TimeStamp = DateTime.UtcNow, SendingType = InstagramApiSharp.Enums.InstaDirectInboxItemSendingType.Pending, ItemId = GUID }; DirectItem = directItem; ThreadView.Current?.ThreadVM.Items.Add(directItem); var hashCode = Path.GetFileName(File.Path ?? $"C:\\{13.GenerateRandomStringStatic()}.jpg").GetHashCode(); var entityName = $"{UploadId}_0_{hashCode}"; var instaUri = GetMediaUploadUri(UploadId, hashCode); var device = InstaApi.GetCurrentDevice(); var httpRequestProcessor = InstaApi.HttpRequestProcessor; BackgroundUploader BGU = new BackgroundUploader(); var cookies = httpRequestProcessor.HttpHandler.CookieContainer.GetCookies(httpRequestProcessor.Client.BaseAddress); var strCookies = string.Empty; foreach (Cookie cook in cookies) { strCookies += $"{cook.Name}={cook.Value}; "; } // header haye asli in ha hastan faghat BGU.SetRequestHeader("Cookie", strCookies); var r = InstaApi.HttpHelper.GetDefaultRequest(HttpMethod.Post, instaUri, device); foreach (var item in r.Headers) { BGU.SetRequestHeader(item.Key, string.Join(" ", item.Value)); } var photoUploadParamsObj = new JObject { { "xsharing_user_ids", "[]" }, { "is_direct_voice", "1" }, { "upload_media_duration_ms", "0" }, { "upload_id", UploadId }, { "retry_context", GetRetryContext() }, { "media_type", "11" } }; var photoUploadParams = JsonConvert.SerializeObject(photoUploadParamsObj); var openedFile = await File.OpenAsync(FileAccessMode.Read); BGU.SetRequestHeader("X-Entity-Type", "audio/mp4"); BGU.SetRequestHeader("Offset", "0"); BGU.SetRequestHeader("X-Instagram-Rupload-Params", photoUploadParams); BGU.SetRequestHeader("X-Entity-Name", entityName); BGU.SetRequestHeader("X-Entity-Length", openedFile.AsStream().Length.ToString()); BGU.SetRequestHeader("X_FB_VIDEO_WATERFALL_ID", ExtensionHelper.GetThreadToken()); BGU.SetRequestHeader("Content-Transfer-Encoding", "binary"); BGU.SetRequestHeader("Content-Type", "application/octet-stream"); Debug.WriteLine("----------------------------------------Start upload----------------------------------"); //var uploadX = await BGU.CreateUploadAsync(instaUri, parts, "", UploadId); var upload = BGU.CreateUpload(instaUri, File); upload.Priority = BackgroundTransferPriority.High; await HandleUploadAsync(upload, true); }
private async Task <IResult <bool> > ConfigureVoiceAsync() { try { await Task.Delay(1500); Debug.WriteLine("----------------------------------------ConfigureVoiceAsync----------------------------------"); var instaUri = GetDIrectConfigureUri(); var retryContext = GetRetryContext(); var _user = InstaApi.GetLoggedUser(); var _deviceInfo = InstaApi.GetCurrentDevice(); var waves = string.Join(",", WaveForm); var token = ExtensionHelper.GetThreadToken(); var data = new Dictionary <string, string> { { "action", "send_item" }, { "client_context", token }, { "_csrftoken", _user.CsrfToken }, { "device_id", _deviceInfo.DeviceId }, { "mutation_token", token }, { "_uuid", _deviceInfo.DeviceGuid.ToString() }, { "waveform", $"[]" }, { "waveform_sampling_frequency_hz", "10" }, { "upload_id", UploadId }, { "thread_ids", $"[{ThreadId}]" } }; var _httpRequestProcessor = InstaApi.HttpRequestProcessor; var request = InstaApi.HttpHelper.GetDefaultRequest(HttpMethod.Post, instaUri, _deviceInfo, data); request.Headers.Add("retry_context", GetRetryContext()); var response = await _httpRequestProcessor.SendAsync(request); var json = await response.Content.ReadAsStringAsync(); try { var obj = JsonConvert.DeserializeObject <InstaDirectVoiceRespondResponse>(json); if (obj != null) { if (DirectItem != null) { DirectItem.SendingType = InstagramApiSharp.Enums.InstaDirectInboxItemSendingType.Sent; DirectItem.ItemId = obj.MessageMetadatas[0].ItemId; } //var res = ConvertersFabric.Instance.GetDirectVoiceRespondConverter(obj).Convert(); //Views.Main.MainView.Current?.MainVM.PostsGenerator.Items.Insert(0, new InstaPost //{ // Media = obj, // Type = InstagramApiSharp.Enums.InstaFeedsType.Media //}); //ShowNotify("Your photo uploaded successfully...", 3500); //NotificationHelper.ShowNotify(Caption?.Truncate(50), NotifyFile?.Path, "Media uploaded"); } } catch { } SendNotify(102); //RemoveThis(); return(Result.Success(true)); } catch (HttpRequestException httpException) { SendNotify(102); return(Result.Fail(httpException, false, ResponseType.NetworkProblem)); } catch (Exception exception) { SendNotify(102); return(Result.Fail <bool>(exception)); } finally { DirectItem = null; } }
public async void UploadSinglePhoto(StorageFile File, string threadId, string recipient, InstaInboxMedia mediaShare, InstaDirectInboxThread thread, InstaDirectInboxItem inboxItem) { Thread = thread; MediaShare = mediaShare; UploadId = GenerateUploadId(); ThreadId = threadId; Recipient = recipient; Item = inboxItem; var photoHashCode = Path.GetFileName(File.Path ?? $"C:\\{13.GenerateRandomStringStatic()}.jpg").GetHashCode(); var photoEntityName = $"{UploadId}_0_{photoHashCode}"; var instaUri = GetUploadPhotoUri(UploadId, photoHashCode); var device = InstaApi.GetCurrentDevice(); var httpRequestProcessor = InstaApi.HttpRequestProcessor; BackgroundUploader BGU = new BackgroundUploader(); var cookies = httpRequestProcessor.HttpHandler.CookieContainer.GetCookies(httpRequestProcessor.Client.BaseAddress); var strCookies = string.Empty; foreach (Cookie cook in cookies) { strCookies += $"{cook.Name}={cook.Value}; "; } // header haye asli in ha hastan faghat BGU.SetRequestHeader("Cookie", strCookies); var r = InstaApi.HttpHelper.GetDefaultRequest(HttpMethod.Post, instaUri, device); foreach (var item in r.Headers) { BGU.SetRequestHeader(item.Key, string.Join(" ", item.Value)); } //{ // "upload_id": "1595581225629", // "media_type": "1", // "retry_context": "{\"num_reupload\":0,\"num_step_auto_retry\":0,\"num_step_manual_retry\":0}", // "image_compression": "{\"lib_name\":\"moz\",\"lib_version\":\"3.1.m\",\"quality\":\"0\"}", // "xsharing_user_ids": "[\"1647718432\",\"1581245356\"]" //} var photoUploadParamsObj = new JObject { { "upload_id", UploadId }, { "media_type", "1" }, { "retry_context", GetRetryContext() }, { "image_compression", "{\"lib_name\":\"moz\",\"lib_version\":\"3.1.m\",\"quality\":\"0\"}" }, { "xsharing_user_ids", $"[{recipient ?? string.Empty}]" }, }; var photoUploadParams = JsonConvert.SerializeObject(photoUploadParamsObj); long fileLength = 0; using (var openedFile = await File.OpenAsync(FileAccessMode.Read)) fileLength = openedFile.AsStream().Length; BGU.SetRequestHeader("X_FB_PHOTO_WATERFALL_ID", Guid.NewGuid().ToString()); BGU.SetRequestHeader("X-Entity-Length", fileLength.ToString()); BGU.SetRequestHeader("X-Entity-Name", photoEntityName); BGU.SetRequestHeader("X-Instagram-Rupload-Params", photoUploadParams); BGU.SetRequestHeader("X-Entity-Type", "image/jpeg"); BGU.SetRequestHeader("Offset", "0"); BGU.SetRequestHeader("Content-Transfer-Encoding", "binary"); BGU.SetRequestHeader("Content-Type", "application/octet-stream"); // hatman bayad noe file ro moshakhas koni, mese in zirie> oun PHOTO mishe name // requestContent.Add(imageContent, "photo", $"pending_media_{ApiRequestMessage.GenerateUploadId()}.jpg"); // vase video nemikhad esmi bezari! //BackgroundTransferContentPart filePart = new BackgroundTransferContentPart(/*"photo"*/); //filePart.SetFile(File); //// chon binary hast: //filePart.SetHeader("Content-Transfer-Encoding", "binary"); //filePart.SetHeader("Content-Type", "application/octet-stream"); //var parts = new List<BackgroundTransferContentPart> //{ // filePart //}; Debug.WriteLine("----------------------------------------Start upload----------------------------------"); //var uploadX = await BGU.CreateUploadAsync(instaUri, parts, "", UploadId); var upload = BGU.CreateUpload(instaUri, File); upload.Priority = BackgroundTransferPriority.High; await HandleUploadAsync(upload, true); }
public static string Proccess(InstaDirectInboxItem item, InstaDirectInboxThread thread) { Constants.reqCount++; string cmd = item.Text.ToLower(); string q = "\""; if (cmd == "ping") { var now = DateTime.Now; var timetook = now.Subtract(item.TimeStamp); return($"Command sent at {item.TimeStamp.TimeOfDay} and recieved at {now.TimeOfDay.ToString("hh\\:mm\\:ss")}" + Environment.NewLine + $"API Latency: {(int)timetook.TotalMilliseconds}ms" + Environment.NewLine + $"TTP including latency: {(int)timetook.TotalMilliseconds * 2}ms"); } if (cmd == "like") { var posts = API.api.UserProcessor.GetUserMediaByIdAsync(item.UserId, PaginationParameters.Empty).Result.Value; if (posts.FirstOrDefault() == null) { return("You dont have any posts or you have not accepted the follow request."); } var like = API.api.MediaProcessor.LikeMediaAsync(posts.FirstOrDefault().Pk); return("NGL thats pretty desperate if your getting a bot to like your posts"); } if (cmd == "stats") { var uptime = DateTime.Now.Subtract(Constants.started); return($"Uptime: {uptime.Hours}h {uptime.Minutes}m {uptime.Seconds}s" + Environment.NewLine + $"Total requests served: {Constants.reqCount}"); } if (cmd.StartsWith("whois")) { var parts = cmd.Split(' '); if (parts.Length == 1) { return($"Please provide a user parameter. E.g. {q}whois ktechsys{q}"); } var profile = API.api.UserProcessor.GetUserInfoByUsernameAsync(parts[1]); if (profile.Result.Value == null) { return("User does not exist."); } var nl = Environment.NewLine; var data = profile.Result.Value; var json = new JavaScriptSerializer().Serialize(data); var requester = API.api.UserProcessor.GetUserInfoByIdAsync(item.UserId).Result.Value.Username; APIFunctions.sendDM(profile.Result.Value.Username, $"A whois lookup was requested on your account by user {requester}"); var ID = Pastebin(json, Constants.devkey).Split(new[] { ".com/" }, StringSplitOptions.None)[1]; var link = $"https://pastebin.com/raw/{ID}"; API.api.MessagingProcessor.SendDirectLinkAsync("Click the link below to view results", link, thread.ThreadId); return("Please be aware they have been informed of the lookup"); } if (cmd == "source") { API.api.MessagingProcessor.SendDirectLinkAsync("Click the link below to go to github", "https://github.com/NateKomodo/InstagramBot", thread.ThreadId); return(null); } if (cmd == "help") { return("Komosys help: " + Environment.NewLine + $"{q}ping{q} - gets message response times" + Environment.NewLine + $"{q}like{q} - likes your most recent post" + Environment.NewLine + $"{q}stats{q} - gets stats about current bot session" + Environment.NewLine + $"{q}whois <name>{q} - performs instagram lookup on a person" + Environment.NewLine + $"{q}source{q} - sends link to source code" + Environment.NewLine + $"{q}help{q} - displays this" + Environment.NewLine + "NOTE: Due to API response times, commands may take up to 5s to process"); } return($"Unknown command, type {q}help{q} for help"); }
public void UpdateItem(InstaDirectInboxItem last) { try { if (last == null) { return; } var pk = Helper.InstaApi.GetLoggedUser().LoggedInUser.Pk; var type = last.ItemType; var userId = last.UserId; var username = Thread.Users.FirstOrDefault(x => x.Pk == userId)?.UserName; var moreThanOnUser = Thread.Users?.Count > 1; var unreadMessageMoreThan1 = false; var converter = new Converters.DateTimeConverter(); var date = ""; if (last != null) { date = $" {Helper.MiddleDot} {converter.Convert(last?.TimeStamp)}"; } int ix = 0; if (Thread.HasUnreadMessage) { ix = 1; try { var user = Thread.Users.FirstOrDefault().UserName; var reversed = Thread.Items; reversed.Reverse(); if (Thread.LastSeenAt.LastOrDefault() != null) { var itemId = Thread.LastSeenAt.LastOrDefault().ItemId; var single = reversed.FirstOrDefault(a => a.ItemId == itemId); var index = reversed.IndexOf(single); if (index != -1) { ix = Thread.Items.Count - (index + 1); } txtFooter.Text = $"{ix} new messages{date}"; } //if (thread.LastActivity != thread.LastSeenAt.LastOrDefault().SeenTime) } catch { } unreadMessageMoreThan1 = ix > 1; HadNewMessages = true; } if (ix > 0) { NewMessageEllipse.Visibility = Visibility.Visible; } else { NewMessageEllipse.Visibility = Visibility.Collapsed; } if (!unreadMessageMoreThan1) { if (type == InstaDirectThreadItemType.ActionLog && last.ActionLog != null) { txtFooter.Text = last.ActionLog.Description.Truncate(45) + date; } else if (type == InstaDirectThreadItemType.AnimatedMedia && last.AnimatedMedia != null) { if (pk == userId) { txtFooter.Text = "You sent a gif".Truncate(45) + date; } else { if (moreThanOnUser) { txtFooter.Text = $"{username} sent you a gif".Truncate(45) + date; } else { txtFooter.Text = $"Sent you a gif".Truncate(45) + date; } } } else if (type == InstaDirectThreadItemType.FelixShare && last.FelixShareMedia != null) { if (pk == userId) { txtFooter.Text = "You shared a IGTV post".Truncate(45) + date; } else { if (moreThanOnUser) { txtFooter.Text = $"{username} shared you a IGTV post".Truncate(45) + date; } else { txtFooter.Text = "Shared you a IGTV post".Truncate(45) + date; } } } else if (type == InstaDirectThreadItemType.Hashtag && last.HashtagMedia != null) { if (pk == userId) { txtFooter.Text = "You shared a hashtag".Truncate(45) + date; } else { if (moreThanOnUser) { txtFooter.Text = $"{username} shared you a hashtag".Truncate(45) + date; } else { txtFooter.Text = "Shared you a hashtag".Truncate(45) + date; } } } else if (type == InstaDirectThreadItemType.Like && last.Text != null) { txtFooter.Text = last.Text.Truncate(45) + date; } else if (type == InstaDirectThreadItemType.Link && last.LinkMedia != null) { if (pk == userId) { txtFooter.Text = "You shared a link".Truncate(45) + date; } else { if (moreThanOnUser) { txtFooter.Text = $"{username} shared you a link".Truncate(45) + date; } else { txtFooter.Text = "Shared you a link".Truncate(45) + date; } } } else if (type == InstaDirectThreadItemType.Location && last.LocationMedia != null) { if (pk == userId) { txtFooter.Text = "You shared a location".Truncate(45) + date; } else { if (moreThanOnUser) { txtFooter.Text = $"{username} shared you a location".Truncate(45) + date; } else { txtFooter.Text = "Shared you a location".Truncate(45) + date; } } } else if (type == InstaDirectThreadItemType.Media && last.Media != null) { if (pk == userId) { txtFooter.Text = "You shared a post".Truncate(45) + date; } else { if (moreThanOnUser) { txtFooter.Text = $"{username} shared you a post".Truncate(45) + date; } else { txtFooter.Text = "Shared you a post".Truncate(45) + date; } } } else if (type == InstaDirectThreadItemType.MediaShare && last.MediaShare != null) { if (pk == userId) { txtFooter.Text = "You shared a post".Truncate(45) + date; } else { if (moreThanOnUser) { txtFooter.Text = $"{username} shared you a post".Truncate(45) + date; } else { txtFooter.Text = "Shared you a post".Truncate(45) + date; } } } else if (type == InstaDirectThreadItemType.Placeholder && last.Placeholder != null) { txtFooter.Text = last.Placeholder.Message.Truncate(45) + date; } else if (type == InstaDirectThreadItemType.Profile && last.ProfileMedia != null) { if (pk == userId) { txtFooter.Text = "You shared a profile".Truncate(45) + date; } else { if (moreThanOnUser) { txtFooter.Text = $"{username} shared you a profile".Truncate(45) + date; } else { txtFooter.Text = "Shared you a profile".Truncate(45) + date; } } } else if (type == InstaDirectThreadItemType.RavenMedia /* && last.RavenMedia != null*/) { if (pk == userId) { txtFooter.Text = "You shared a disappearing media".Truncate(45) + date; } else { if (moreThanOnUser) { txtFooter.Text = $"{username} shared you a disappearing media".Truncate(45) + date; } else { txtFooter.Text = "Shared you a disappearing media".Truncate(45) + date; } } } else if (type == InstaDirectThreadItemType.ReelShare && last.ReelShareMedia != null) { if (pk == userId) { txtFooter.Text = "You shared a story".Truncate(45) + date; } else { if (moreThanOnUser) { txtFooter.Text = $"{username} shared you a story".Truncate(45) + date; } else { txtFooter.Text = "Shared you a story".Truncate(45) + date; } } } else if (type == InstaDirectThreadItemType.StoryShare && last.StoryShare != null) { if (pk == userId) { txtFooter.Text = "You shared a story".Truncate(45) + date; } else { if (moreThanOnUser) { txtFooter.Text = $"{username} shared you a story".Truncate(45) + date; } else { txtFooter.Text = "Shared you a story".Truncate(45) + date; } } } else if (type == InstaDirectThreadItemType.Text && last.Text != null) { txtFooter.Text = last.Text.Replace("\r\n", "").Replace("\n", "").Replace("\r", "").Truncate(45) + date; } else if (type == InstaDirectThreadItemType.VideoCallEvent && last.VideoCallEvent != null) { txtFooter.Text = last.VideoCallEvent.Description.Truncate(45) + date; } else if (type == InstaDirectThreadItemType.VoiceMedia && last.VoiceMedia != null) { if (pk == userId) { txtFooter.Text = "You shared a voice".Truncate(45) + date; } else { if (moreThanOnUser) { txtFooter.Text = $"{username} shared you a voice".Truncate(45) + date; } else { txtFooter.Text = "Shared you a voice".Truncate(45) + date; } } } else if (type == InstaDirectThreadItemType.LiveViewerInvite && last.LiveViewerInvite != null) { txtFooter.Text = last.LiveViewerInvite.Text; } else { txtFooter.Text = date; } } } catch { } }
internal static void AddMediaToActivityBasedOnType(InstaDirectInboxItem item, InstaActivityDto activity) { switch (item.ItemType) { case InstaDirectThreadItemType.Text: case InstaDirectThreadItemType.Like: activity.Text = item.Text; break; case InstaDirectThreadItemType.MediaShare: activity.Urls.AddRange(item.MediaShare.Images.Select(i => i.Uri)); activity.Text = $"{item.MediaShare.Caption.Text} - {item.MediaShare.Title}"; break; case InstaDirectThreadItemType.Link: activity.Text = $"{item.LinkMedia.Text} - {item.LinkMedia.LinkContext.LinkTitle}"; activity.Text = item.LinkMedia.Text; activity.Urls.Add(item.LinkMedia.LinkContext.LinkImageUrl); activity.Urls.Add(item.LinkMedia.LinkContext.LinkUrl); break; case InstaDirectThreadItemType.Media: activity.Urls.AddRange(item.Media.Images.Select(i => i.Uri)); activity.Urls.AddRange(item.Media.Videos.Select(i => i.Uri)); break; case InstaDirectThreadItemType.StoryShare: activity.Text = $"{item.StoryShare.Title} - {item.StoryShare.Text} - {item.StoryShare.Message} - {item.StoryShare.Media.Title} - {item.StoryShare.Media.Caption.Text}"; activity.Urls.AddRange(item.StoryShare.Media.Images.Select(i => i.Uri)); break; case InstaDirectThreadItemType.RavenMedia: // ravenmedia if api version < 61 activity.Urls.AddRange(item.VisualMedia.Media.Images.Select(i => i.Uri)); activity.Urls.AddRange(item.VisualMedia.Media.Videos.Select(i => i.Uri)); break; case InstaDirectThreadItemType.ActionLog: activity.Text = item.ActionLog.Description; break; case InstaDirectThreadItemType.Profile: activity.Urls.Add(item.ProfileMedia.ProfilePicUrl); break; case InstaDirectThreadItemType.Placeholder: activity.Text = item.Placeholder.Message; break; case InstaDirectThreadItemType.Location: var lm = item.LocationMedia; activity.Text = $"{lm.ShortName}, {lm.City}, ({lm.X},{lm.Y})"; break; case InstaDirectThreadItemType.FelixShare: activity.Urls.AddRange(item.FelixShareMedia.Images.Select(i => i.Uri)); activity.Urls.AddRange(item.FelixShareMedia.Videos.Select(i => i.Uri)); activity.Text = $"{item.FelixShareMedia.Title} - {item.FelixShareMedia.Caption.Text}"; break; case InstaDirectThreadItemType.ReelShare: activity.Text = item.ReelShareMedia.Text; activity.Urls.AddRange(item.ReelShareMedia.Media.ImageList.Select(i => i.Uri)); activity.Urls.AddRange(item.ReelShareMedia.Media.VideoList.Select(i => i.Uri)); break; case InstaDirectThreadItemType.VoiceMedia: activity.Text = "VoiceMedia received, but not supported. Sorry."; break; case InstaDirectThreadItemType.AnimatedMedia: activity.Urls.Add(item.AnimatedMedia.Media.Url); break; case InstaDirectThreadItemType.Hashtag: //item.HashtagMedia.Media. activity.Text = $"{item.HashtagMedia.Name} - {item.HashtagMedia.Media.Title}"; activity.Urls.AddRange(item.HashtagMedia.Media.Images.Select(i => i.Uri)); activity.Urls.AddRange(item.HashtagMedia.Media.Videos.Select(i => i.Uri)); break; case InstaDirectThreadItemType.LiveViewerInvite: activity.Text = item.LiveViewerInvite.Text; activity.Urls.Add(item.LiveViewerInvite.Broadcast.CoverFrameUrl); activity.Urls.Add(item.LiveViewerInvite.Broadcast.DashAbrPlaybackUrl); activity.Urls.Add(item.LiveViewerInvite.Broadcast.DashPlaybackUrl); activity.Urls.Add(item.LiveViewerInvite.Broadcast.RtmpPlaybackUrl); break; } activity.Urls = activity.Urls.Distinct().ToList(); }
public void SetSeenFromRealtime(string threadId, InstaDirectInboxItem inboxItem) { try { if (ThreadView.Current != null && ThreadView.Current?.ThreadVM?.CurrentThread != null) { if (ThreadView.Current.ThreadVM.CurrentThread.ThreadId == threadId) { //var first = ThreadView.Current.ThreadVM.Items.FirstOrDefault(x => x.ItemId == inboxItem.ItemId); //var findIndex = ThreadView.Current.ThreadVM.Items.IndexOf(first); //if (findIndex != -1) { for (int i = 0; i < ThreadView.Current.ThreadVM.Items.Count; i++) { try { if (ThreadView.Current.ThreadVM.Items[i].SendingType != InstaDirectInboxItemSendingType.Seen && ThreadView.Current.ThreadVM.Items[i].UserId == CurrentUser.Pk) { ThreadView.Current.ThreadVM.Items[i].SendingType = InstaDirectInboxItemSendingType.Seen; } } catch { } } try { var first = ThreadView.Current.ThreadVM.CurrentThread.LastSeenAt.FirstOrDefault(x => x.PK != CurrentUser.Pk); if (first != null) { first.ItemId = inboxItem.ItemId; first.SeenTime = inboxItem.TimeStamp; } else { ThreadView.Current.ThreadVM.CurrentThread.LastSeenAt.Add(new InstaLastSeen { PK = ThreadView.Current.ThreadVM.CurrentThread.Users[0].Pk, ItemId = inboxItem.ItemId, SeenTime = inboxItem.TimeStamp }); } } catch { } try { var thread = Items.FirstOrDefault(x => x.Thread.ThreadId == threadId); if (thread != null) { var first = thread.Thread.LastSeenAt.FirstOrDefault(x => x.PK != CurrentUser.Pk); if (first != null) { first.ItemId = inboxItem.ItemId; first.SeenTime = inboxItem.TimeStamp; } else { thread.Thread.LastSeenAt.Add(new InstaLastSeen { PK = ThreadView.Current.ThreadVM.CurrentThread.Users[0].Pk, ItemId = inboxItem.ItemId, SeenTime = inboxItem.TimeStamp }); } } } catch { } } } } } catch { } }
public async void SetDirectItem(InstaDirectInboxThread thread, InstaDirectInboxItem item, ProgressVoice progressVoice, ToggleButton /*AppBarButton*/ button) { if (item == null) { return; } try { FasterModeButton.IsChecked = false; } catch { } try { if (CurrentDirectInboxItem != null) { if (CurrentDirectInboxItem.ItemId == item.ItemId) { try { Visibility = Visibility.Visible; } catch { } if (MainPage.Current.ME.CurrentState == MediaElementState.Paused) { Play(); } else { Pause(); } return; } } if (VoicePlayPauseButton != null) { VoicePlayPauseButton.Tag /*Content*/ = Helper.PlayMaterialIcon; } ProgressVoice = progressVoice; await Task.Delay(200); CurrentDirectInboxItem = item; VoicePlayPauseButton = button; var date = item.TimeStamp; var textDate = $"{date.ToString("MMM", CultureInfo.InvariantCulture)} {date.Day} at {date.ToString("hh:mm tt")}"; txtTime.Text = "00:00"; if (item.UserId == Helper.CurrentUser.Pk) { txtInfo.Text = $"You {textDate}"; } else { var user = thread.Users.FirstOrDefault(x => x.Pk == item.UserId); if (user == null) { txtInfo.Text = $"{textDate}"; } else { txtInfo.Text = $"{user.UserName} {textDate}"; } } } catch { } try { MainPage.Current.ME.PlaybackRate = 1.00; } catch { } try { MainPage.Current.ME.Source = new Uri(CurrentDirectInboxItem.VoiceMedia.Media.Audio.AudioSource); } catch { } try { Visibility = Visibility.Visible; } catch { } }
public Pair_Message_User(InstaDirectInboxItem item) { this.text = item.Text; this.user_id = item.UserId; }
private async Task OnPacketReceived(Packet msg) { if (!Running) { return; } var writer = _outboundWriter; try { switch (msg.PacketType) { case PacketType.CONNACK: this.Log("Received CONNACK"); await SubscribeForDM(); await RealtimeSub(); await PubSub(); if (SnapshotAt != null && SeqId <= 0) { await IrisSub(); } StartKeepAliveLoop(); break; case PacketType.PUBLISH: this.Log("Received PUBLISH"); var publishPacket = (PublishPacket)msg; if (publishPacket.Payload == null) { throw new Exception($"{nameof(RealtimeClient)}: Publish packet received but payload is null"); } if (publishPacket.QualityOfService == QualityOfService.AtLeastOnce) { await FbnsPacketEncoder.EncodePacket(PubAckPacket.InResponseTo(publishPacket), writer); } var payload = DecompressPayload(publishPacket.Payload); var json = await GetJsonFromThrift(payload); this.Log($"MQTT json: {json}"); if (string.IsNullOrEmpty(json)) { break; } try { Debug.WriteLine(""); Debug.WriteLine($"Unknown topic received:{msg.PacketType} : {publishPacket.TopicName} : {json}"); Debug.WriteLine(""); Debug.WriteLine(json); switch (publishPacket.TopicName) { case "150": break; case "133": // /ig_send_message_response try { Responses.AddItem(JsonConvert.DeserializeObject <InstaDirectRespondResponse>(json)); } catch { try { var o = JsonConvert.DeserializeObject <InstaDirectRespondV2Response>(json); Responses.AddItem(new InstaDirectRespondResponse { Action = o.Action, Message = o.Message, Status = o.Status, StatusCode = o.StatusCode, Payload = o.Payload[0] }); } catch { } } break; case "88": { var obj = JsonConvert.DeserializeObject <InstaRealtimeRespondResponse>(json); if (obj?.Data?.Length > 0) { var typing = new List <InstaRealtimeTypingEventArgs>(); var dm = new List <InstaDirectInboxItem>(); for (int i = 0; i < obj.Data.Length; i++) { var item = obj.Data[i]; if (item != null) { if (item.IsTyping) { var typingResponse = JsonConvert.DeserializeObject <InstaRealtimeTypingResponse>(item.Value); if (typingResponse != null) { try { var tr = new InstaRealtimeTypingEventArgs { SenderId = typingResponse.SenderId, ActivityStatus = typingResponse.ActivityStatus, RealtimeOp = item.Op, RealtimePath = item.Path, TimestampUnix = typingResponse.Timestamp, Timestamp = DateTimeHelper.FromUnixTimeMiliSeconds(typingResponse.Timestamp), Ttl = typingResponse.Ttl }; typing.Add(tr); } catch { } } } else if (item.IsThreadItem || item.IsThreadParticipants) { if (item.HasItemInValue) { var directItemResponse = JsonConvert.DeserializeObject <InstaDirectInboxItemResponse>(item.Value); if (directItemResponse != null) { try { var dI = ConvertersFabric.Instance.GetDirectThreadItemConverter(directItemResponse).Convert(); dI.RealtimeOp = item.Op; dI.RealtimePath = item.Path; dm.Add(dI); } catch { } } } else { var dI = new InstaDirectInboxItem { RealtimeOp = item.Op, RealtimePath = item.Path, ItemId = item.Value }; dm.Add(dI); } } } } if (typing.Count > 0) { OnTypingChanged(typing); } if (dm.Count > 0) { OnDirectItemChanged(dm); } } } break; } } catch { } break; case PacketType.PUBACK: this.Log("Received PUBACK"); break; case PacketType.PINGRESP: this.Log("Received PINGRESP"); break; default: Debug.WriteLine($"Unknown topic received:{msg.PacketType}"); break; } } catch (Exception e) { DebugLogger.LogExceptionX(e); } }