public override void Edit(TLMessageBase messageBase)
        {
            var message = messageBase as TLMessage;

            if (message != null)
            {
                HasEditDate = message.HasEditDate;
                EditDate    = message.EditDate;

                Message     = message.Message;
                HasEntities = message.HasEntities;
                Entities    = message.Entities;
                ReplyMarkup = message.ReplyMarkup;
                var webpageOld = Media as TLMessageMediaWebPage;
                var webpageNew = message.Media as TLMessageMediaWebPage;
                if ((webpageOld == null && webpageNew != null) || (webpageOld != null && webpageNew == null) || (webpageOld != null && webpageNew != null && webpageOld.WebPage.Id != webpageNew.WebPage.Id))
                {
                    Media = (TLMessageMediaBase)webpageNew ?? new TLMessageMediaEmpty();
                }

                var captionNew = message.Media as ITLMessageMediaCaption;
                var captionOld = Media as ITLMessageMediaCaption;
                if (captionOld != null && captionNew != null)
                {
                    captionOld.Caption = captionNew.Caption;
                }

                var invoiceNew = message.Media as TLMessageMediaInvoice;
                var invoiceOld = Media as TLMessageMediaInvoice;
                if (invoiceOld != null && invoiceNew != null)
                {
                    Media = invoiceNew;
                }
            }
        }
        public override TLObject FromStream(Stream input)
        {
            PrevMessage = GetObject <TLMessageBase>(input);
            NewMessage  = GetObject <TLMessageBase>(input);

            return(this);
        }
        public override TLObject FromBytes(byte[] bytes, ref int position)
        {
            bytes.ThrowExceptionIfIncorrect(ref position, Signature);

            Message = GetObject <TLMessageBase>(bytes, ref position);

            return(this);
        }
        public override bool IsGif()
        {
            var mediaDocument = Media as TLDecryptedMessageMediaDocument45;

            if (mediaDocument != null && TLString.Equals(mediaDocument.MimeType, new TLString("video/mp4"), StringComparison.OrdinalIgnoreCase))
            {
                return(TLMessageBase.IsGif(mediaDocument, mediaDocument.Size));
            }

            return(false);
        }
Esempio n. 5
0
        public override string GetFileName()
        {
            if (TLMessageBase.IsVideo(this))
            {
                return(string.Format("video{0}_{1}.{2}", Id, AccessHash, "mp4"));
            }
            if (TLMessageBase.IsVoice(this))
            {
                return(string.Format("audio{0}_{1}.{2}", Id, AccessHash, "mp3"));
            }

            return(string.Format("document{0}_{1}.{2}", Id, AccessHash, FileExt));
        }
Esempio n. 6
0
        public static bool IsChannelMessage(TLMessageBase message, out TLPeerChannel channel)
        {
            var isChannel = false;

            channel = null;

            var messageCommon = message as TLMessageCommonBase;

            if (messageCommon != null)
            {
                channel   = messageCommon.ToId as TLPeerChannel;
                isChannel = channel != null;
            }

            return(isChannel);
        }
Esempio n. 7
0
 public static TLPhoto GetPhoto(this TLMessageBase messageBase)
 {
     if (messageBase is TLMessage message)
     {
         if (message.Media is TLMessageMediaPhoto photoMedia)
         {
             return(photoMedia.Photo as TLPhoto);
         }
         else if (message.Media is TLMessageMediaWebPage webPageMedia && webPageMedia.WebPage is TLWebPage webPage)
         {
             return(webPage.Photo as TLPhoto);
         }
         else if (message.Media is TLMessageMediaGame gameMedia)
         {
             return(gameMedia.Game.Photo as TLPhoto);
         }
     }
Esempio n. 8
0
        public static int InsertMessageInOrder(IList <TLMessageBase> messages, TLMessageBase message)
        {
            var position = -1;

            if (messages.Count == 0)
            {
                position = 0;
            }

            for (var i = 0; i < messages.Count; i++)
            {
                if (messages[i].Index == 0)
                {
                    if (messages[i].DateIndex < message.DateIndex)
                    {
                        position = i;
                        break;
                    }

                    continue;
                }

                if (messages[i].Index == message.Index)
                {
                    position = -1;
                    break;
                }
                if (messages[i].Index < message.Index)
                {
                    position = i;
                    break;
                }
            }

            if (position != -1)
            {
                //message._isAnimated = position == 0;
                messages.Insert(position, message);
            }

            return(position);
        }
Esempio n. 9
0
        public override string GetFileName()
        {
            if (TLMessageBase.IsVideo(this))
            {
                return(string.Format("video{0}_{1}.{2}", Id, AccessHash, "mp4"));
            }
            if (TLMessageBase.IsVoice(this))
            {
                return(string.Format("audio{0}_{1}.{2}", Id, AccessHash, "mp3"));
            }

            var documentVersion = Version;

            if (documentVersion != null && documentVersion.Value > 0)
            {
                return(string.Format("document{0}_{1}.{2}", Id, documentVersion, FileExt));
            }

            return(string.Format("document{0}_{1}.{2}", Id, AccessHash, FileExt));
        }
Esempio n. 10
0
        public static int InsertMessageInOrder(IList <TLMessageBase> messages, TLMessageBase message)
        {
            int position = -1;

            if (messages.Count == 0)
            {
                position = 0;
            }

            for (int i = 0; i < messages.Count; i++)
            {
                if (messages[i].Id == 0)
                {
                    if (messages[i].Date < message.Date)
                    {
                        position = i;
                        break;
                    }
                }
                else
                {
                    if (messages[i].Id == message.Id)
                    {
                        position = -1;
                        break;
                    }
                    if (messages[i].Id < message.Id)
                    {
                        position = i;
                        break;
                    }
                }
            }

            if (position != -1)
            {
                messages.Insert(position, message);
            }

            return(position);
        }
Esempio n. 11
0
        // TODO: Secrets
        //public static TLPeerBase GetPeerFromMessage(TLDecryptedMessageBase message)
        //{
        //    TLPeerBase peer = null;
        //    var commonMessage = message;
        //    if (commonMessage != null)
        //    {
        //        if (commonMessage.ChatId != null)
        //        {
        //            peer = new TLPeerEncryptedChat{ Id = commonMessage.ChatId };
        //        }
        //    }
        //    else
        //    {
        //        WriteLine("Cannot get peer from non TLDecryptedMessage", LogSeverity.Error);
        //    }

        //    return peer;
        //}

        public static TLPeerBase GetPeerFromMessage(TLMessageBase message)
        {
            TLPeerBase peer          = null;
            var        commonMessage = message as TLMessageCommonBase;

            if (commonMessage != null)
            {
                if (commonMessage.ToId is TLPeerChannel)
                {
                    peer = commonMessage.ToId;
                }
                else if (commonMessage.ToId is TLPeerChat)
                {
                    peer = commonMessage.ToId;
                }
                else
                {
                    if (commonMessage.IsOut)
                    {
                        peer = commonMessage.ToId;
                    }
                    else
                    {
                        peer = new TLPeerUser {
                            Id = commonMessage.FromId.Value
                        };
                    }
                }
            }
            else
            {
                WriteLine("Cannot get peer from non TLMessage", LogSeverity.Error);
            }

            return(peer);
        }
Esempio n. 12
0
        public override string ToString()
        {
            if (Media is TLDecryptedMessageMediaEmpty)
            {
                return(string.Format("TLDecryptedMessage45 qts={0} in_seq_no={1} out_seq_no={2} flags=[{3}] date={4} delete_date={5} message={6}", Qts, InSeqNo, OutSeqNo, TLMessageBase.MessageFlagsString(Flags), Date, DeleteDate, Message));
            }

            return(string.Format("TLDecryptedMessage45 qts={0} in_seq_no={1} out_seq_no={2} flags=[{3}] date={4} delete_date={5} media={6}", Qts, InSeqNo, OutSeqNo, TLMessageBase.MessageFlagsString(Flags), Date, DeleteDate, Media));
        }
Esempio n. 13
0
 public virtual void Update(TLMessageBase message)
 {
     Id    = message.Id;
     State = message.State;
 }
Esempio n. 14
0
        public override TLObject FromBytes(byte[] bytes, ref int position)
        {
            bytes.ThrowExceptionIfIncorrect(ref position, Signature);

            Flags    = GetObject <TLInt>(bytes, ref position);
            Id       = GetObject <TLInt>(bytes, ref position);
            UserId   = GetObject <TLInt>(bytes, ref position);
            ChatId   = GetObject <TLInt>(bytes, ref position);
            Message  = GetObject <TLString>(bytes, ref position);
            Pts      = GetObject <TLInt>(bytes, ref position);
            PtsCount = GetObject <TLInt>(bytes, ref position);
            Date     = GetObject <TLInt>(bytes, ref position);

            if (IsSet(Flags, (int)MessageFlags.Fwd))
            {
                FwdFrom = GetObject <TLPeerBase>(bytes, ref position);
                FwdDate = GetObject <TLInt>(bytes, ref position);
            }
            if (IsSet(Flags, (int)MessageFlags.Reply))
            {
                ReplyToMsgId = GetObject <TLInt>(bytes, ref position);
            }
            if (IsSet(Flags, (int)MessageFlags.Entities))
            {
                Entities = GetObject <TLVector <TLMessageEntityBase> >(bytes, ref position);
            }



#if DEBUG
            var messageString = Message.ToString();
            var logString     = string.Format("TLUpdateShortChatMessage40 id={0} flags={1} user_id={2} message={3} pts={4} pts_count={5} date={6} fwd_from={7} fwd_date={8} reply_to_msg_id={9} entities={10}", Id, TLMessageBase.MessageFlagsString(Flags), UserId, messageString.Substring(0, Math.Min(messageString.Length, 5)), Pts, PtsCount, Date, FwdFrom, FwdDate, ReplyToMsgId, Entities);

            Logs.Log.Write(logString);
#endif

            return(this);
        }
Esempio n. 15
0
 public override string ToString()
 {
     return(string.Format("TLUpdatesShortSentMessage id={0} media={1} flags={2}", Id, Media, TLMessageBase.MessageFlagsString(Flags)));
 }
Esempio n. 16
0
        public override void Update(TLMessageBase message)
        {
            base.Update(message);
            var m = (TLMessage)message;

            FromId = m.FromId;
            ToId   = m.ToId;
            IsOut  = m.IsOut;
            if (IsUnread != IsUnread)
            {
                if (IsUnread)
                {
                    IsUnread = m.IsUnread;
                }
            }
            Date = m.Date;



            FwdFrom = m.FwdFrom;

            if (m.Views != null)
            {
                var currentViews = Views ?? 0;
                if (currentViews < m.Views)
                {
                    Views = m.Views;
                }
            }



            if (m.Entities != null)
            {
                Entities = m.Entities;
            }



            if (m.ReplyMarkup != null)
            {
                //var oldCustomFlags = ReplyMarkup != null ? ReplyMarkup.CustomFlags : null;
                ReplyMarkup = m.ReplyMarkup;
                //ReplyMarkup.CustomFlags = oldCustomFlags;
            }

            //if (m.CustomFlags != null)
            //{
            //    CustomFlags = m.CustomFlags;
            //}



            //FwdFromId = m.FwdFromId;
            //FwdDate = m.FwdDate;
            if (m.HasReplyToMsgId)
            {
                ReplyToMsgId = m.ReplyToMsgId;

                if (m.Reply != null)
                {
                    Reply = m.Reply;
                }
            }



            Message = m.Message;
            var oldMedia = Media;
            var newMedia = m.Media;

            if (oldMedia?.GetType() != newMedia?.GetType())
            {
                Media = m.Media;
            }
            else
            {
                var oldMediaDocument = oldMedia as TLMessageMediaDocument;
                var newMediaDocument = newMedia as TLMessageMediaDocument;
                if (oldMediaDocument != null && newMediaDocument != null)
                {
                    if (oldMediaDocument.Document == null || oldMediaDocument.Document.GetType() != newMediaDocument.Document.GetType())
                    {
                        Media = m.Media;
                        RaisePropertyChanged("Media");
                    }
                    else
                    {
                        var oldDocument = oldMediaDocument.Document as TLDocument;
                        var newDocument = newMediaDocument.Document as TLDocument;
                        if (oldDocument != null &&
                            newDocument != null &&
                            (oldDocument.Id != newDocument.Id ||
                             oldDocument.AccessHash != newDocument.AccessHash))
                        {
                            //var isoFileName = Media.IsoFileName;
#if WP8
                            var file = Media.File;
#endif
                            Media = m.Media;
                            RaisePropertyChanged("Media");
                            //Media.IsoFileName = isoFileName;
#if WP8
                            _media.File = file;
#endif
                        }
                    }

                    return;
                }

                //var oldMediaVideo = oldMedia as TLMessageMediaVideo;
                //var newMediaVideo = newMedia as TLMessageMediaVideo;
                //if (oldMediaVideo != null && newMediaVideo != null)
                //{
                //    if (oldMediaVideo.Video.GetType() != newMediaVideo.Video.GetType())
                //    {
                //        Media = m.Media;
                //    }
                //    else
                //    {
                //        var oldVideo = oldMediaVideo.Video as TLVideo;
                //        var newVideo = newMediaVideo.Video as TLVideo;
                //        if (oldVideo != null
                //            && newVideo != null
                //            && (oldVideo.Id.Value != newVideo.Id.Value
                //                || oldVideo.AccessHash.Value != newVideo.AccessHash.Value))
                //        {
                //            //var isoFileName = Media.IsoFileName;
                //            Media = m.Media;
                //            //Media.IsoFileName = isoFileName;
                //        }
                //    }

                //    return;
                //}

                //var oldMediaAudio = oldMedia as TLMessageMediaAudio;
                //var newMediaAudio = newMedia as TLMessageMediaAudio;
                //if (oldMediaAudio != null && newMediaAudio != null)
                //{
                //    if (oldMediaAudio.Audio.GetType() != newMediaAudio.Audio.GetType())
                //    {
                //        Media = m.Media;
                //    }
                //    else
                //    {
                //        var oldAudio = oldMediaAudio.Audio as TLAudio;
                //        var newAudio = newMediaAudio.Audio as TLAudio;
                //        if (oldAudio != null
                //            && newAudio != null
                //            && (oldAudio.Id.Value != newAudio.Id.Value
                //                || oldAudio.AccessHash.Value != newAudio.AccessHash.Value))
                //        {
                //            //var isoFileName = Media.IsoFileName;
                //            //var notListened = Media.NotListened;
                //            Media = m.Media;
                //            //Media.IsoFileName = isoFileName;
                //            //Media.NotListened = notListened;
                //        }
                //    }

                //    return;
                //}

                var oldMediaPhoto = oldMedia as TLMessageMediaPhoto;
                var newMediaPhoto = newMedia as TLMessageMediaPhoto;
                if (oldMediaPhoto == null || newMediaPhoto == null)
                {
                    Media = m.Media;
                }
                else
                {
                    var oldPhoto = oldMediaPhoto.Photo as TLPhoto;
                    var newPhoto = newMediaPhoto.Photo as TLPhoto;
                    if (oldPhoto == null || newPhoto == null)
                    {
                        Media = m.Media;
                    }
                    else
                    {
                        if (oldPhoto.AccessHash != newPhoto.AccessHash)
                        {
                            Media = m.Media;
                        }
                    }
                }
            }
        }
Esempio n. 17
0
        public static int InsertMessageInOrder(IList <TLMessageBase> messages, TLMessageBase message)
        {
            var position = -1;

            if (messages.Count == 0)
            {
                position = 0;
            }

            for (var i = messages.Count - 1; i >= 0; i--)
            {
                if (messages[i].Id == 0)
                {
                    if (messages[i].Date < message.Date)
                    {
                        position = i + 1;
                        break;
                    }

                    continue;
                }

                if (messages[i].Id == message.Id)
                {
                    position = -1;
                    break;
                }
                if (messages[i].Id < message.Id)
                {
                    position = i + 1;
                    break;
                }
            }

            if (position != -1)
            {
                messages.Insert(position, message);
            }

            return(position);

            //var position = -1;

            //if (messages.Count == 0)
            //{
            //    position = 0;
            //}

            //for (var i = 0; i < messages.Count; i++)
            //{
            //    if (messages[i].Id == 0)
            //    {
            //        if (messages[i].Date < message.Date)
            //        {
            //            position = i;
            //            break;
            //        }

            //        continue;
            //    }

            //    if (messages[i].Id == message.Id)
            //    {
            //        position = -1;
            //        break;
            //    }
            //    if (messages[i].Id < message.Id)
            //    {
            //        position = i;
            //        break;
            //    }
            //}

            //if (position != -1)
            //{
            //    //message._isAnimated = position == 0;
            //    messages.Insert(position, message);
            //}

            //return position;
        }
Esempio n. 18
0
 public virtual void Edit(TLMessageBase messageBase)
 {
 }