public override TLObject FromBytes(byte[] bytes, ref int position) { bytes.ThrowExceptionIfIncorrect(ref position, Signature); Flags = GetObject <TLInt>(bytes, ref position); Id = GetObject <TLLong>(bytes, ref position); Url = GetObject <TLString>(bytes, ref position); DisplayUrl = GetObject <TLString>(bytes, ref position); if (IsSet(Flags, (int)WebPageFlags.Type)) { Type = GetObject <TLString>(bytes, ref position); } if (IsSet(Flags, (int)WebPageFlags.SiteName)) { SiteName = GetObject <TLString>(bytes, ref position); } if (IsSet(Flags, (int)WebPageFlags.Title)) { Title = GetObject <TLString>(bytes, ref position); } if (IsSet(Flags, (int)WebPageFlags.Description)) { Description = GetObject <TLString>(bytes, ref position); } if (IsSet(Flags, (int)WebPageFlags.Photo)) { Photo = GetObject <TLPhotoBase>(bytes, ref position); } if (IsSet(Flags, (int)WebPageFlags.Embed)) { EmbedUrl = GetObject <TLString>(bytes, ref position); EmbedType = GetObject <TLString>(bytes, ref position); } if (IsSet(Flags, (int)WebPageFlags.EmbedSize)) { EmbedWidth = GetObject <TLInt>(bytes, ref position); EmbedHeight = GetObject <TLInt>(bytes, ref position); } if (IsSet(Flags, (int)WebPageFlags.Duration)) { Duration = GetObject <TLInt>(bytes, ref position); } if (IsSet(Flags, (int)WebPageFlags.Author)) { Author = GetObject <TLString>(bytes, ref position); } if (IsSet(Flags, (int)WebPageFlags.Document)) { Document = GetObject <TLDocumentBase>(bytes, ref position); } return(this); }
public override TLObject FromStream(Stream input) { Flags = GetObject <TLInt>(input); Id = GetObject <TLLong>(input); Url = GetObject <TLString>(input); DisplayUrl = GetObject <TLString>(input); if (IsSet(Flags, (int)WebPageFlags.Type)) { Type = GetObject <TLString>(input); } if (IsSet(Flags, (int)WebPageFlags.SiteName)) { SiteName = GetObject <TLString>(input); } if (IsSet(Flags, (int)WebPageFlags.Title)) { Title = GetObject <TLString>(input); } if (IsSet(Flags, (int)WebPageFlags.Description)) { Description = GetObject <TLString>(input); } if (IsSet(Flags, (int)WebPageFlags.Photo)) { Photo = GetObject <TLPhotoBase>(input); } if (IsSet(Flags, (int)WebPageFlags.Embed)) { EmbedUrl = GetObject <TLString>(input); EmbedType = GetObject <TLString>(input); } if (IsSet(Flags, (int)WebPageFlags.EmbedSize)) { EmbedWidth = GetObject <TLInt>(input); EmbedHeight = GetObject <TLInt>(input); } if (IsSet(Flags, (int)WebPageFlags.Duration)) { Duration = GetObject <TLInt>(input); } if (IsSet(Flags, (int)WebPageFlags.Author)) { Author = GetObject <TLString>(input); } if (IsSet(Flags, (int)WebPageFlags.Document)) { Document = GetObject <TLDocumentBase>(input); } return(this); }
public void Handle(DownloadableItem item) { var document = item.Owner as TLDocument; if (document != null) { BeginOnUIThread(() => { var messages = Items; foreach (var m in messages) { var media = m.Media as TLMessageMediaDocument; if (media != null && TLDocumentBase.DocumentEquals(media.Document, document)) { media.NotifyOfPropertyChange(() => media.Document); break; } } }); } var message = item.Owner as TLMessage; if (message != null) { var mediaDocument1 = message.Media as TLMessageMediaDocument; if (mediaDocument1 == null) { return; } BeginOnUIThread(() => { foreach (var m in Items) { var mediaDocument2 = m.Media as TLMessageMediaDocument; if (mediaDocument2 != null && TLDocumentBase.DocumentEquals(mediaDocument1.Document, mediaDocument2.Document)) { m.Media.IsCanceled = false; m.Media.LastProgress = 0.0; m.Media.DownloadingProgress = 0.0; m.Media.NotifyOfPropertyChange(() => m.Media.Self); // update download icon for documents m.NotifyOfPropertyChange(() => m.Self); m.Media.IsoFileName = item.IsoFileName; } } }); } }
public void Handle(DownloadableItem item) { Execute.BeginOnUIThread(() => { var chatPhoto = item.Owner as TLChatPhoto; if (chatPhoto != null) { var channel = With as TLChannel; if (channel != null) { channel.NotifyOfPropertyChange(() => channel.Photo); //channel.NotifyOfPropertyChange(() => channel.ChatPhoto); } var serviceMessages = Items.OfType <TLMessageService>(); foreach (var serviceMessage in serviceMessages) { var editPhoto = serviceMessage.Action as TLMessageActionChatEditPhoto; if (editPhoto != null && editPhoto.Photo == chatPhoto) { editPhoto.NotifyOfPropertyChange(() => editPhoto.Photo); break; } } } var message = item.Owner as TLMessage; if (message != null) { var messages = Items.OfType <TLMessage>(); foreach (var m in messages) { var media = m.Media as TLMessageMediaVideo; if (media != null && m == item.Owner) { m.Media.IsCanceled = false; m.Media.LastProgress = 0.0; m.Media.DownloadingProgress = 0.0; m.NotifyOfPropertyChange(() => m.Self); m.Media.IsoFileName = item.IsoFileName; break; } var doc = m.Media as TLMessageMediaDocument; if (doc != null && m == item.Owner) { m.Media.IsCanceled = false; m.Media.LastProgress = 0.0; m.Media.DownloadingProgress = 0.0; m.Media.NotifyOfPropertyChange(() => m.Media.Self); // update download icon for documents m.NotifyOfPropertyChange(() => m.Self); m.Media.IsoFileName = item.IsoFileName; break; } var audioMedia = m.Media as TLMessageMediaAudio; if (audioMedia != null && m == item.Owner) { m.Media.IsCanceled = false; m.Media.LastProgress = 0.0; m.Media.DownloadingProgress = 0.0; m.Media.IsoFileName = item.IsoFileName; var a = audioMedia.Audio as TLAudio; if (a != null) { var fileName = a.GetFileName(); var wavFileName = Path.GetFileNameWithoutExtension(fileName) + ".wav"; #if WP8 var component = new WindowsPhoneRuntimeComponent(); var result = component.InitPlayer(ApplicationData.Current.LocalFolder.Path + "\\" + fileName); if (result == 1) { var buffer = new byte[16 * 1024]; var args = new int[3]; var pcmStream = new MemoryStream(); while (true) { component.FillBuffer(buffer, buffer.Length, args); var count = args[0]; var offset = args[1]; var endOfStream = args[2] == 1; pcmStream.Write(buffer, 0, count); if (endOfStream) { break; } } var wavStream = Wav.GetWavAsMemoryStream(pcmStream, 48000, 1, 16); using (var store = IsolatedStorageFile.GetUserStoreForApplication()) { using (var file = new IsolatedStorageFileStream(wavFileName, FileMode.OpenOrCreate, store)) { wavStream.Seek(0, SeekOrigin.Begin); wavStream.CopyTo(file); file.Flush(); } } } #endif } break; } } return; } var photo = item.Owner as TLPhoto; if (photo != null) { var isUpdated = false; var messages = Items.OfType <TLMessage>(); foreach (var m in messages) { var mediaPhoto = m.Media as TLMessageMediaPhoto; if (mediaPhoto != null && mediaPhoto.Photo == photo) { mediaPhoto.NotifyOfPropertyChange(() => mediaPhoto.Photo); mediaPhoto.NotifyOfPropertyChange(() => mediaPhoto.Self); isUpdated = true; break; } var mediaWebPage = m.Media as TLMessageMediaWebPage; if (mediaWebPage != null && mediaWebPage.Photo == photo) { mediaWebPage.NotifyOfPropertyChange(() => mediaWebPage.Photo); mediaWebPage.NotifyOfPropertyChange(() => mediaWebPage.Self); isUpdated = false; break; } } if (isUpdated) { return; } var serviceMessages = Items.OfType <TLMessageService>(); foreach (var serviceMessage in serviceMessages) { var editPhoto = serviceMessage.Action as TLMessageActionChatEditPhoto; if (editPhoto != null && editPhoto.Photo == photo) { editPhoto.NotifyOfPropertyChange(() => editPhoto.Photo); isUpdated = true; break; } } } var document = item.Owner as TLDocument; if (document != null) { var messages = Items.OfType <TLMessage>(); foreach (var m in messages) { var media = m.Media as TLMessageMediaDocument; if (media != null && TLDocumentBase.DocumentEquals(media.Document, document)) { media.NotifyOfPropertyChange(() => media.Document); break; } } } var video = item.Owner as TLVideo; if (video != null) { var messages = Items.OfType <TLMessage>(); foreach (var m in messages) { var media = m.Media as TLMessageMediaVideo; if (media != null && media.Video == video) { media.NotifyOfPropertyChange(() => media.Video); break; } } } var audio = item.Owner as TLAudio; if (audio != null) { var messages = Items.OfType <TLMessage>(); foreach (var m in messages) { var media = m.Media as TLMessageMediaAudio; if (media != null && media.Audio == audio) { media.NotifyOfPropertyChange(() => media.Audio); break; } } } var webPage = item.Owner as TLWebPage; if (webPage != null) { var messages = Items.OfType <TLMessage>(); foreach (var m in messages) { var media = m.Media as TLMessageMediaWebPage; if (media != null && media.WebPage == webPage) { media.NotifyOfPropertyChange(() => media.Photo); media.NotifyOfPropertyChange(() => media.Self); break; } } } }); }