コード例 #1
0
        private void ToServiceTemplate(TLDecryptedMessageService messageService)
        {
            _isChannelMessage    = false;
            FromLabel.Visibility = Visibility.Collapsed;
            Tile.Visibility      = Visibility.Collapsed;

            var serviceMessageToTextConverter = new DecryptedServiceMessageToTextConverter();

            InputMessage.Text = (string)serviceMessageToTextConverter.Convert(messageService.Self, null, null, null);

            DrawBubble(messageService);

            //var unreadMessagesAction = messageService.Action as TLDecryptedMessageActionUnreadMessages;
            //if (unreadMessagesAction != null)
            //{
            //    ToUnreadMessagesTemplate();
            //}
        }
コード例 #2
0
        public static string Convert(TLDecryptedMessageService serviceMessage)
        {
            var fromId           = serviceMessage.FromId;
            var fromUser         = IoC.Get <ICacheService>().GetUser(fromId);
            var fromUserFullName = fromUser != null ? fromUser.FullName : AppResources.User;

            var action = serviceMessage.Action;

            if (action != null && _actionsCache.ContainsKey(action.GetType()))
            {
                return(_actionsCache[action.GetType()](action, fromId.Value, fromUserFullName));
            }

#if DEBUG
            return(serviceMessage.GetType().Name);
#endif

            return(AppResources.MessageActionEmpty);
        }
コード例 #3
0
        public static TLDecryptedMessageService GetDecryptedServiceMessage(TLObject obj)
        {
            TLDecryptedMessageService message = null;

            var messageLayer17 = obj as TLDecryptedMessageLayer17;

            if (messageLayer17 != null)
            {
                message = messageLayer17.Message as TLDecryptedMessageService17;
            }

            var decryptedMessage = obj as TLDecryptedMessageService;

            if (decryptedMessage != null)
            {
                message = decryptedMessage;
            }

            return(message);
        }
コード例 #4
0
        public static Telegram.Api.WindowsPhone.Tuple <TLDecryptedMessageService, TLObject> GetDecryptedServiceMessageAndObject(TLDecryptedMessageActionBase action, TLEncryptedChat chat, TLInt currentUserId, ICacheService cacheService)
        {
            var mtProtoService = IoC.Get <IMTProtoService>();

            TLDecryptedMessageService decryptedMessage;
            TLObject decryptedObject;

            var randomId = TLLong.Random();

            var encryptedChat17 = chat as TLEncryptedChat17;

            if (encryptedChat17 != null && encryptedChat17.Layer.Value >= 17)
            {
                var cachedEncryptedChat17 = (TLEncryptedChat17)cacheService.GetEncryptedChat(encryptedChat17.Id);

                var inSeqNo  = TLUtils.GetInSeqNo(currentUserId, cachedEncryptedChat17);
                var outSeqNo = TLUtils.GetOutSeqNo(currentUserId, cachedEncryptedChat17);

                cachedEncryptedChat17.RawOutSeqNo = new TLInt(cachedEncryptedChat17.RawOutSeqNo.Value + 1);
                var decryptedMessage17 = new TLDecryptedMessageService17
                {
                    Action   = action,
                    RandomId = randomId,
                    //RandomBytes = TLString.Random(Telegram.Api.Constants.MinRandomBytesLength),

                    ChatId = chat.Id,
                    FromId = currentUserId,
                    Out    = new TLBool(true),
                    Unread = new TLBool(true),
                    Date   = TLUtils.DateToUniversalTimeTLInt(mtProtoService.ClientTicksDelta, DateTime.Now),
                    Status = MessageStatus.Sending,

                    TTL      = chat.MessageTTL ?? new TLInt(0),
                    InSeqNo  = inSeqNo,
                    OutSeqNo = outSeqNo
                };

                var decryptedMessageLayer17 = TLUtils.GetDecryptedMessageLayer(encryptedChat17.Layer, inSeqNo, outSeqNo, decryptedMessage17);

                decryptedMessage = decryptedMessage17;
                decryptedObject  = decryptedMessageLayer17;
            }
            else
            {
                var decryptedMessage8 = new TLDecryptedMessageService
                {
                    Action      = action,
                    RandomId    = randomId,
                    RandomBytes = TLString.Random(Telegram.Api.Constants.MinRandomBytesLength),

                    ChatId = chat.Id,
                    FromId = currentUserId,
                    Out    = new TLBool(true),
                    Unread = new TLBool(true),
                    Date   = TLUtils.DateToUniversalTimeTLInt(mtProtoService.ClientTicksDelta, DateTime.Now),
                    Status = MessageStatus.Sending,

                    TTL = chat.MessageTTL
                };

                decryptedMessage = decryptedMessage8;
                decryptedObject  = decryptedMessage;
            }

            return(new Telegram.Api.WindowsPhone.Tuple <TLDecryptedMessageService, TLObject>(decryptedMessage, decryptedObject));
        }
コード例 #5
0
        public static void CreateSecretChatCommon(TLUserBase user, TLDHConfig dhConfig, IMTProtoService mtProtoService, ICacheService cacheService, INavigationService navigationService, IStateService stateService, ITelegramEventAggregator eventAggregator)
        {
            if (user == null)
            {
                return;
            }

            var random   = new Random();
            var randomId = random.Next();

            mtProtoService.RequestEncryptionAsync(user.ToInputUser(), new TLInt(randomId), dhConfig.GA,
                                                  encryptedChat =>
            {
                var chatWaiting = encryptedChat as TLEncryptedChatWaiting;

                if (chatWaiting != null)
                {
                    var action   = new TLMessageActionChatCreate();
                    action.Title = TLString.Empty;
                    action.Users = new TLVector <TLInt> {
                        Items = new List <TLInt> {
                            user.Id
                        }
                    };

                    var dialog            = new TLDialog24();
                    dialog.ReadInboxMaxId = new TLInt(0);
                    dialog.With           = user;
                    dialog.Peer           = new TLPeerUser {
                        Id = user.Id
                    };

                    var topMessage    = new TLMessageService17();
                    topMessage.Date   = chatWaiting.Date;
                    topMessage.FromId = chatWaiting.AdminId;
                    topMessage.ToId   = new TLPeerUser {
                        Id = user.Id
                    };
                    topMessage.Out    = new TLBool(true);
                    topMessage.Action = action;
                    topMessage.SetUnread(new TLBool(false));

                    chatWaiting.A = dhConfig.A;
                    chatWaiting.P = dhConfig.P;
                    chatWaiting.G = dhConfig.G;
                }

                stateService.RemoveBackEntry = true;
                stateService.With            = chatWaiting;
                stateService.Participant     = user;

                Execute.BeginOnUIThread(() =>
                {
                    stateService.AnimateTitle = true;
                    navigationService.UriFor <SecretDialogDetailsViewModel>().Navigate();
                });


                //syncing chat and message
                cacheService.SyncEncryptedChat(chatWaiting, eventAggregator.Publish);

                var message = new TLDecryptedMessageService
                {
                    RandomId    = TLLong.Random(),
                    RandomBytes = new TLString(""),
                    ChatId      = chatWaiting.Id,
                    Action      = new TLDecryptedMessageActionEmpty(),
                    FromId      = new TLInt(stateService.CurrentUserId),
                    Date        = chatWaiting.Date,
                    Out         = new TLBool(false),
                    Unread      = new TLBool(false),
                    Status      = MessageStatus.Read
                };

                cacheService.SyncDecryptedMessage(message, chatWaiting, result => { });
            },
                                                  error =>
            {
                Execute.ShowDebugMessage("messages.requestEncryption error " + error);
            });
        }
コード例 #6
0
        public void CreateSecretChat()
        {
            var user = CurrentItem as TLUserBase;

            if (user == null)
            {
                return;
            }

            if (_a == null ||
                _g == null ||
                _p == null ||
                _ga == null)
            {
                IsWorking = true;
                NotifyOfPropertyChange(() => ProgressVisibility);
                _invokeDelayedUserAction = true;
                return;
            }

            IsWorking = false;
            NotifyOfPropertyChange(() => ProgressVisibility);

            var random   = new Random();
            var randomId = random.Next();

            MTProtoService.RequestEncryptionAsync(user.ToInputUser(), new TLInt(randomId), _ga,
                                                  encryptedChat =>
            {
                var chatWaiting = encryptedChat as TLEncryptedChatWaiting;
                if (chatWaiting == null)
                {
                    return;
                }

                chatWaiting.A = _a;
                chatWaiting.P = _p;
                chatWaiting.G = _g;

                StateService.With        = chatWaiting;
                StateService.Participant = user;

                Execute.BeginOnUIThread(() =>
                {
                    StateService.RemoveBackEntries = true;
                    NavigationService.UriFor <SecretDialogDetailsViewModel>().Navigate();
                });

                CacheService.SyncEncryptedChat(chatWaiting, result => EventAggregator.Publish(result));

                var message = new TLDecryptedMessageService
                {
                    RandomId    = TLLong.Random(),
                    RandomBytes = new TLString(""),
                    ChatId      = chatWaiting.Id,
                    Action      = new TLDecryptedMessageActionEmpty(),
                    FromId      = new TLInt(StateService.CurrentUserId),
                    Date        = chatWaiting.Date,
                    Out         = new TLBool(false),
                    Unread      = new TLBool(false),
                    Status      = MessageStatus.Read
                };

                CacheService.SyncDecryptedMessage(message, chatWaiting, result => { });
            },
                                                  error =>
            {
                Execute.ShowDebugMessage("messages.requestEncryption error: " + error);
            });
        }