public void GetImportantHistoryAsync(TLInputChannelBase channel, TLPeerBase peer, bool sync, TLInt offsetId, TLInt addOffset, TLInt limit, TLInt maxId, TLInt minId, Action <TLMessagesBase> callback, Action <TLRPCError> faultCallback = null)
        {
            var obj = new TLGetImportantHistory {
                Channel = channel, OffsetId = offsetId, AddOffset = addOffset, Limit = limit, MaxId = maxId, MinId = minId
            };

            SendInformativeMessage("channels.getImportantHistory", obj, callback, faultCallback);
        }
예제 #2
0
        public void StopTracking(TLPeerBase peer)
        {
            var message = Items.FirstOrDefault(x => peer.Equals(x.Parent.ToPeer()));

            if (message != null)
            {
                Items.Remove(message);
                Update(message, null, true);
            }
        }
        private static string GetGameFullNameString(string fullName, int msgId, TLPeerBase toId, bool useActiveLinks)
        {
            if (!useActiveLinks)
            {
                return(fullName);
            }

            var channelIdString = toId is TLPeerChannel ? "&channel_id=" + toId.Id.Value : string.Empty;

            return('\a' + "tlg://?action=game&msg_id=" + msgId + channelIdString + '\b' + fullName + '\a');
        }
예제 #4
0
        //public IAsyncOperation<ContentDialogBaseResult> ShowAsync(TLStickerSet parameter)
        //{
        //    return ShowAsync(parameter, null);
        //}

        //public IAsyncOperation<ContentDialogBaseResult> ShowAsync(TLStickerSet parameter, ItemClickEventHandler callback)
        //{
        //    return ShowAsync(new TLInputStickerSetID { Id = parameter.Id, AccessHash = parameter.AccessHash }, callback);
        //}

        //public IAsyncOperation<ContentDialogBaseResult> ShowAsync(TLStickerSetCoveredBase parameter)
        //{
        //    return ShowAsync(parameter, null);
        //}

        //public IAsyncOperation<ContentDialogBaseResult> ShowAsync(TLStickerSetCoveredBase parameter, ItemClickEventHandler callback)
        //{
        //    return ShowAsync(new TLInputStickerSetID { Id = parameter.Set.Id, AccessHash = parameter.Set.AccessHash }, callback);
        //}

        //public IAsyncOperation<ContentDialogBaseResult> ShowAsync(TLInputStickerSetBase parameter)
        //{
        //    return ShowAsync(parameter, null);
        //}

        public IAsyncOperation <ContentDialogBaseResult> ShowAsync(TLPeerBase parameter)
        {
            //ViewModel.IsLoading = true;
            //ViewModel.StickerSet = new TLStickerSet();
            //ViewModel.Items.Clear();

            RoutedEventHandler handler = null;

            handler = new RoutedEventHandler(async(s, args) =>
            {
                Loaded -= handler;
                await ViewModel.OnNavigatedToAsync(parameter, NavigationMode.New, null);
            });

            Loaded += handler;
            return(ShowAsync());
        }
예제 #5
0
        private void UpdateListViewsSelectedItem(TLPeerBase peer)
        {
            if (peer == null)
            {
                _lastSelected = null;
                DialogsListView.SelectedItem = null;

                _lastSelected = null;
                UsersListView.SelectedItem = null;
                return;
            }

            var dialog = ViewModel.Dialogs.Items.FirstOrDefault(x => x.Peer.Equals(peer));

            if (dialog != null)
            {
                _lastSelected = dialog;
                DialogsListView.SelectedItem = dialog;
            }
            else
            {
                _lastSelected = null;
                DialogsListView.SelectedItem = null;
            }

            var user = ViewModel.Contacts.Items.FirstOrDefault(x => x.Id == peer.Id);

            if (user != null)
            {
                _lastSelected = user;
                UsersListView.SelectedItem = user;
            }
            else
            {
                _lastSelected = null;
                UsersListView.SelectedItem = null;
            }
        }
예제 #6
0
        // TODO: Encrypted public TLDecryptedMessageBase DecryptedMessage { get; protected set; }

        public TopMessageUpdatedEventArgs(TLPeerBase peer)
        {
            Peer = peer;
        }
예제 #7
0
        private void OnPushNotificationReceived(PushNotificationChannel sender, PushNotificationReceivedEventArgs args)
        {
            if (args.NotificationType == PushNotificationType.Raw)
            {
                if (JsonValue.TryParse(args.RawNotification.Content, out JsonValue node))
                {
                    var notification = node.GetObject();
                    var data         = notification.GetNamedObject("data");

                    if (data.ContainsKey("loc_key"))
                    {
                        var muted = data.GetNamedString("mute", "0") == "1";
                        if (muted)
                        {
                            return;
                        }

                        var custom = data.GetNamedObject("custom", null);
                        if (custom == null)
                        {
                            return;
                        }

                        TLPeerBase peer = null;
                        if (custom.ContainsKey("chat_id") && int.TryParse(custom.GetNamedString("chat_id"), out int chat_id))
                        {
                            peer = new TLPeerChat {
                                ChatId = chat_id
                            };
                        }
                        else if (custom.ContainsKey("channel_id") && int.TryParse(custom.GetNamedString("channel_id"), out int channel_id))
                        {
                            peer = new TLPeerChannel {
                                ChannelId = channel_id
                            };
                        }
                        else if (custom.ContainsKey("from_id") && int.TryParse(custom.GetNamedString("from_id"), out int from_id))
                        {
                            peer = new TLPeerUser {
                                UserId = from_id
                            };
                        }
                        else if (custom.ContainsKey("contact_id") && int.TryParse(custom.GetNamedString("contact_id"), out int contact_id))
                        {
                            peer = new TLPeerUser {
                                UserId = contact_id
                            };
                        }

                        if (peer == null)
                        {
                            return;
                        }

                        var service = WindowWrapper.Current().NavigationServices.GetByFrameId("Main");
                        if (service == null)
                        {
                            return;
                        }

                        Execute.BeginOnUIThread(() =>
                        {
                            if (service.Frame.Content is DialogPage page && peer.Equals(service.CurrentPageParam))
                            {
                                if (!page.ViewModel.IsActive || !App.IsActive || !App.IsVisible)
                                {
                                    return;
                                }

                                args.Cancel = true;
                            }
                        });
                    }
                }
            }
        }
예제 #8
0
        public override async Task OnNavigatedToAsync(object parameter, NavigationMode mode, IDictionary <string, object> state)
        {
            Task <MTProtoResponse <TLExportedChatInviteBase> > task = null;

            if (parameter is TLPeerChannel peerChannel)
            {
                _peer = peerChannel;

                var channel = CacheService.GetChat(peerChannel.ChannelId) as TLChannel;
                if (channel != null)
                {
                    Item = channel;

                    var full = CacheService.GetFullChat(channel.Id) as TLChannelFull;
                    if (full == null)
                    {
                        var response = await ProtoService.GetFullChannelAsync(channel.ToInputChannel());

                        if (response.IsSucceeded)
                        {
                            full = response.Result.FullChat as TLChannelFull;
                        }
                    }

                    if (full != null)
                    {
                        _exportedInvite = full.ExportedInvite;

                        if (full.ExportedInvite is TLChatInviteExported invite)
                        {
                            InviteLink = invite.Link;
                        }
                        else
                        {
                            task = ProtoService.ExportInviteAsync(channel.ToInputChannel());
                        }
                    }
                }
            }
            else if (parameter is TLPeerChat peerChat)
            {
                _peer = peerChat;

                var chat = CacheService.GetChat(peerChat.ChatId) as TLChat;
                if (chat != null)
                {
                    Item = chat;

                    var full = CacheService.GetFullChat(chat.Id) as TLChannelFull;
                    if (full == null)
                    {
                        var response = await ProtoService.GetFullChatAsync(chat.Id);

                        if (response.IsSucceeded)
                        {
                            full = response.Result.FullChat as TLChannelFull;
                        }
                    }

                    if (full != null)
                    {
                        _exportedInvite = full.ExportedInvite;

                        if (full.ExportedInvite is TLChatInviteExported invite)
                        {
                            InviteLink = invite.Link;
                        }
                        else
                        {
                            task = ProtoService.ExportChatInviteAsync(chat.Id);
                        }
                    }
                }
            }

            if (task != null)
            {
                var response = await task;
                if (response.IsSucceeded)
                {
                    _exportedInvite = response.Result;

                    var invite = response.Result as TLChatInviteExported;
                    if (invite != null && !string.IsNullOrEmpty(invite.Link))
                    {
                        InviteLink = invite.Link;
                    }
                }
                else
                {
                    Execute.ShowDebugMessage("channels.exportInvite error " + response.Error);
                }
            }
        }
예제 #9
0
        public string GetTypingString(TLPeerBase peer, IList <TypingUser> typingUsers)
        {
            if (peer is TLPeerUser)
            {
                var typingUser = typingUsers.FirstOrDefault();
                if (typingUser != null)
                {
                    var action = typingUser.Item2;
                    if (action is TLSendMessageUploadPhotoAction)
                    {
                        return(string.Format("{0}...", AppResources.SendingPhoto.ToLower(CultureInfo.InvariantCulture)));
                    }
                    if (action is TLSendMessageRecordAudioAction)
                    {
                        return(string.Format("{0}...", AppResources.RecordingAudio.ToLower(CultureInfo.InvariantCulture)));
                    }
                    if (action is TLSendMessageUploadAudioAction)
                    {
                        return(string.Format("{0}...", AppResources.RecordingAudio.ToLower(CultureInfo.InvariantCulture)));
                    }
                    if (action is TLSendMessageUploadDocumentAction)
                    {
                        return(string.Format("{0}...", AppResources.SendingFile.ToLower(CultureInfo.InvariantCulture)));
                    }
                    if (action is TLSendMessageRecordVideoAction)
                    {
                        return(string.Format("{0}...", AppResources.SendingVideo.ToLower(CultureInfo.InvariantCulture)));
                    }
                    if (action is TLSendMessageUploadVideoAction)
                    {
                        return(string.Format("{0}...", AppResources.SendingVideo.ToLower(CultureInfo.InvariantCulture)));
                    }
                }

                return(string.Format("{0}...", AppResources.Typing.ToLower(CultureInfo.InvariantCulture)));
            }

            if (typingUsers.Count == 1)
            {
                var userId = new TLInt(typingUsers[0].Item1);
                var user   = CacheService.GetUser(userId);
                if (user == null)
                {
                    var peerChat = peer as TLPeerChat;
                    if (peerChat != null)
                    {
                        MTProtoService.GetFullChatAsync(peerChat.Id, result => { }, error => { });
                    }

                    return(null);
                }

                var userName   = TLString.IsNullOrEmpty(user.FirstName) ? user.LastName : user.FirstName;
                var typingUser = typingUsers.FirstOrDefault();
                if (typingUser != null)
                {
                    var action = typingUser.Item2;
                    if (action is TLSendMessageUploadPhotoAction)
                    {
                        return(string.Format("{0} {1}...", userName, AppResources.IsSendingPhoto.ToLower(CultureInfo.InvariantCulture)));
                    }
                    if (action is TLSendMessageUploadAudioAction)
                    {
                        return(string.Format("{0} {1}...", userName, AppResources.IsRecordingAudio.ToLower(CultureInfo.InvariantCulture)));
                    }
                    if (action is TLSendMessageRecordAudioAction)
                    {
                        return(string.Format("{0} {1}...", userName, AppResources.IsRecordingAudio.ToLower(CultureInfo.InvariantCulture)));
                    }
                    if (action is TLSendMessageUploadDocumentAction)
                    {
                        return(string.Format("{0} {1}...", userName, AppResources.IsSendingFile.ToLower(CultureInfo.InvariantCulture)));
                    }
                    if (action is TLSendMessageRecordVideoAction)
                    {
                        return(string.Format("{0} {1}...", userName, AppResources.IsSendingVideo.ToLower(CultureInfo.InvariantCulture)));
                    }
                    if (action is TLSendMessageUploadVideoAction)
                    {
                        return(string.Format("{0} {1}...", userName, AppResources.IsSendingVideo.ToLower(CultureInfo.InvariantCulture)));
                    }
                }

                return(string.Format("{0} {1}...", userName, AppResources.IsTyping.ToLower(CultureInfo.InvariantCulture)));
            }

            if (typingUsers.Count <= 3)
            {
                var firstNames   = new List <string>(typingUsers.Count);
                var missingUsers = new List <TLInt>();
                foreach (var typingUser in typingUsers)
                {
                    var user = CacheService.GetUser(new TLInt(typingUser.Item1));
                    if (user != null)
                    {
                        var userName = TLString.IsNullOrEmpty(user.FirstName) ? user.LastName : user.FirstName;
                        firstNames.Add(userName.ToString());
                    }
                    else
                    {
                        missingUsers.Add(new TLInt(typingUser.Item1));
                    }
                }

                if (missingUsers.Count > 0)
                {
                    var peerChat = peer as TLPeerChat;
                    if (peerChat != null)
                    {
                        MTProtoService.GetFullChatAsync(peerChat.Id, result => { }, error => { });
                    }

                    return(null);
                }

                return(string.Format("{0} {1}...", string.Join(", ", firstNames),
                                     AppResources.AreTyping.ToLower(CultureInfo.InvariantCulture)));
            }

            return(string.Format("{0} {1}...", Language.Declension(
                                     typingUsers.Count,
                                     AppResources.CompanyNominativeSingular,
                                     AppResources.CompanyNominativePlural,
                                     AppResources.CompanyGenitiveSingular,
                                     AppResources.CompanyGenitivePlural).ToLower(CultureInfo.CurrentUICulture),
                                 AppResources.AreTyping.ToLower(CultureInfo.InvariantCulture)));
        }
예제 #10
0
        public static string GetTypingString(TLPeerBase peer, IList <Tuple <int, TLSendMessageActionBase> > typingUsers, Func <int?, TLUserBase> getUser, Action <TLPeerBase> getFullInfoAction)
        {
            if (peer is TLPeerUser)
            {
                var tuple = typingUsers.FirstOrDefault();
                if (tuple != null)
                {
                    var action = tuple.Item2;
                    switch (action)
                    {
                    //case TLSendMessageChooseContactAction chooseContact:
                    //    return "";
                    case TLSendMessageGamePlayAction gamePlay:
                        return(AppResources.PlayingGame);

                    //case TLSendMessageGeoLocationAction geoLocation:
                    //    return "";
                    case TLSendMessageRecordAudioAction recordAudio:
                        return(AppResources.RecordingVoiceMessage);

                    case TLSendMessageRecordRoundAction recordRound:
                        return(AppResources.RecordingVideoMessage);

                    case TLSendMessageRecordVideoAction recordVideo:
                        return(AppResources.RecordingVideo);

                    //case TLSendMessageTypingAction typing:
                    //    return AppResources.Typing;
                    case TLSendMessageUploadAudioAction uploadAudio:
                        return(AppResources.SendingAudio);

                    case TLSendMessageUploadDocumentAction uploadDocument:
                        return(AppResources.SendingFile);

                    case TLSendMessageUploadPhotoAction uploadPhoto:
                        return(AppResources.SendingPhoto);

                    case TLSendMessageUploadRoundAction uploadRound:
                        return(AppResources.SendingVideoMessage);

                    case TLSendMessageUploadVideoAction uploadVideo:
                        return(AppResources.SendingVideo);
                    }
                }

                return(AppResources.Typing);
            }

            if (typingUsers.Count == 1)
            {
                var user = getUser.Invoke(typingUsers[0].Item1) as TLUser;
                if (user == null)
                {
                    getFullInfoAction?.Invoke(peer);
                    return(null);
                }

                var userName = string.IsNullOrEmpty(user.FirstName) ? user.LastName : user.FirstName;

                var tuple = typingUsers.FirstOrDefault();
                if (tuple != null)
                {
                    var action = tuple.Item2;
                    switch (action)
                    {
                    //case TLSendMessageChooseContactAction chooseContact:
                    //    return "";
                    case TLSendMessageGamePlayAction gamePlay:
                        return(string.Format(AppResources.IsPlayingGame, userName));

                    //case TLSendMessageGeoLocationAction geoLocation:
                    //    return "";
                    case TLSendMessageRecordAudioAction recordAudio:
                        return(string.Format(AppResources.IsRecordingAudio, userName));

                    case TLSendMessageRecordRoundAction recordRound:
                        return(string.Format(AppResources.IsRecordingVideoMessage, userName));

                    case TLSendMessageRecordVideoAction recordVideo:
                        return(string.Format(AppResources.IsRecordingVideo, userName));

                    //case TLSendMessageTypingAction typing:
                    //    return string.Format(AppResources.IsTyping, userName);
                    case TLSendMessageUploadAudioAction uploadAudio:
                        return(string.Format(AppResources.IsSendingAudio, userName));

                    case TLSendMessageUploadDocumentAction uploadDocument:
                        return(string.Format(AppResources.IsSendingFile, userName));

                    case TLSendMessageUploadPhotoAction uploadPhoto:
                        return(string.Format(AppResources.IsSendingPhoto, userName));

                    case TLSendMessageUploadRoundAction uploadRound:
                        return(string.Format(AppResources.IsSendingVideoMessage, userName));

                    case TLSendMessageUploadVideoAction uploadVideo:
                        return(string.Format(AppResources.IsSendingVideo, userName));
                    }
                }

                return(string.Format(AppResources.IsTyping, userName));
            }
            else
            {
                if (typingUsers.Count > 3)
                {
                    return(string.Format(AppResources.AreTyping, Language.Declension(typingUsers.Count, AppResources.CompanyNominativeSingular, AppResources.CompanyNominativePlural, AppResources.CompanyGenitiveSingular, AppResources.CompanyGenitivePlural, null, null)));
                }

                var names   = new List <string>(typingUsers.Count);
                var missing = new List <int>();

                foreach (var current in typingUsers)
                {
                    var user = getUser.Invoke(current.Item1) as TLUser;
                    if (user != null)
                    {
                        names.Add(string.IsNullOrEmpty(user.FirstName) ? user.LastName : user.FirstName);
                    }
                    else
                    {
                        missing.Add(current.Item1);
                    }
                }

                if (missing.Count > 0)
                {
                    getFullInfoAction?.Invoke(peer);
                    return(null);
                }

                return(string.Format(AppResources.AreTyping, string.Join(", ", names)));
            }
        }
예제 #11
0
 public bool IsTracking(TLPeerBase peer)
 {
     return(Items.Any(x => x.Parent != null && peer.Equals(x.Parent.ToPeer())));
 }
예제 #12
0
        public override TLDialog this[long index]
        {
            get
            {
                if (TryGetValue(index, out TLDialog value))
                {
                    return(value);
                }

                Statement statement;
                Sqlite3.sqlite3_prepare_v2(_database, $"SELECT {_fields} FROM `Dialogs` WHERE `index` = {index}", out statement);

                TLDialog result = null;
                if (Sqlite3.sqlite3_step(statement) == SQLiteResult.Row)
                {
                    var flags = (TLDialog.Flag)Sqlite3.sqlite3_column_int(statement, 0);
                    var id    = Sqlite3.sqlite3_column_int64(statement, 1);

                    TLPeerBase peer = null;
                    if (((ulong)id & PeerIdTypeMask) == PeerIdUserShift)
                    {
                        peer = new TLPeerUser {
                            UserId = (int)(uint)((ulong)id & PeerIdMask)
                        };
                    }
                    else if (((ulong)id & PeerIdTypeMask) == PeerIdChatShift)
                    {
                        peer = new TLPeerChat {
                            ChatId = (int)(uint)((ulong)id & PeerIdMask)
                        };
                    }
                    else if (((ulong)id & PeerIdTypeMask) == PeerIdChannelShift)
                    {
                        peer = new TLPeerChannel {
                            ChannelId = (int)(uint)((ulong)id & PeerIdMask)
                        };
                    }

                    var top_message        = Sqlite3.sqlite3_column_int(statement, 3);
                    var read_inbox_max_id  = Sqlite3.sqlite3_column_int(statement, 4);
                    var read_outbox_max_id = Sqlite3.sqlite3_column_int(statement, 5);
                    var unread_count       = Sqlite3.sqlite3_column_int(statement, 6);

                    TLPeerNotifySettingsBase notifySettings;

                    var notifyType = Sqlite3.sqlite3_column_type(statement, 7);
                    if (notifyType == 1)
                    {
                        notifySettings = new TLPeerNotifySettings
                        {
                            Flags     = (TLPeerNotifySettings.Flag)Sqlite3.sqlite3_column_int(statement, 7),
                            MuteUntil = Sqlite3.sqlite3_column_int(statement, 8),
                            Sound     = Sqlite3.sqlite3_column_text(statement, 9)
                        };
                    }
                    else
                    {
                        notifySettings = new TLPeerNotifySettingsEmpty();
                    }

                    int?pts = null;
                    if (flags.HasFlag(TLDialog.Flag.Pts))
                    {
                        pts = Sqlite3.sqlite3_column_int(statement, 10);
                    }

                    //TLDraftMessageBase draft = null;
                    //if (flags.HasFlag(TLDialog.Flag.Draft))
                    //{
                    //    var draftFlags = (TLDraftMessage.Flag)Sqlite3.sqlite3_column_int(statement, 11);

                    //    int? replyToMsgId = null;
                    //    if (draftFlags.HasFlag(TLDraftMessage.Flag.ReplyToMsgId))
                    //    {
                    //        replyToMsgId = Sqlite3.sqlite3_column_int(statement, 12);
                    //    }

                    //    var message = Sqlite3.sqlite3_column_text(statement, 13);

                    //    TLVector<TLMessageEntityBase> entities = null;
                    //    if (draftFlags.HasFlag(TLDraftMessage.Flag.Entities))
                    //    {
                    //        entities = JsonConvert.DeserializeObject<TLVector<TLMessageEntityBase>>(Sqlite3.sqlite3_column_text(statement, 14), _settings);
                    //    }

                    //    draft = new TLDraftMessage
                    //    {
                    //        Flags = draftFlags,
                    //        ReplyToMsgId = replyToMsgId,
                    //        Message = message,
                    //        Entities = entities,
                    //        Date = Sqlite3.sqlite3_column_int(statement, 15)
                    //    };
                    //}

                    var message = JsonConvert.DeserializeObject <TLMessageBase>(Sqlite3.sqlite3_column_text(statement, 14), _settings);

                    result = new TLDialog
                    {
                        Flags           = flags,
                        Peer            = peer,
                        TopMessage      = top_message,
                        ReadInboxMaxId  = read_inbox_max_id,
                        ReadOutboxMaxId = read_outbox_max_id,
                        UnreadCount     = unread_count,
                        NotifySettings  = notifySettings,
                        Pts             = pts,
                        //Draft = draft
                        TopMessageItem = message
                    };

                    base[index] = result;
                }

                Sqlite3.sqlite3_finalize(statement);
                return(result);
            }
            set
            {
                base[index] = value;

                if (value is TLDialog dialog)
                {
                    Statement statement;
                    Sqlite3.sqlite3_prepare_v2(_database, $"INSERT OR REPLACE INTO `Dialogs` ({_fields}) VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)", out statement);

                    Sqlite3.sqlite3_bind_int(statement, 1, (int)dialog.Flags);

                    if (dialog.Peer is TLPeerUser peerUser)
                    {
                        Sqlite3.sqlite3_bind_int64(statement, 2, (long)(PeerIdUserShift | (ulong)(uint)peerUser.UserId));
                    }
                    else if (dialog.Peer is TLPeerChat peerChat)
                    {
                        Sqlite3.sqlite3_bind_int64(statement, 2, (long)(PeerIdChatShift | (ulong)(uint)peerChat.ChatId));
                    }
                    if (dialog.Peer is TLPeerChannel peerChannel)
                    {
                        Sqlite3.sqlite3_bind_int64(statement, 2, (long)(PeerIdChannelShift | (ulong)(uint)peerChannel.ChannelId));
                    }

                    Sqlite3.sqlite3_bind_int(statement, 3, dialog.Id);
                    Sqlite3.sqlite3_bind_int(statement, 4, dialog.TopMessage);
                    Sqlite3.sqlite3_bind_int(statement, 5, dialog.ReadInboxMaxId);
                    Sqlite3.sqlite3_bind_int(statement, 6, dialog.ReadOutboxMaxId);
                    Sqlite3.sqlite3_bind_int(statement, 7, dialog.UnreadCount);

                    if (dialog.NotifySettings is TLPeerNotifySettings notifySettings)
                    {
                        Sqlite3.sqlite3_bind_int(statement, 8, (int)notifySettings.Flags);
                        Sqlite3.sqlite3_bind_int(statement, 9, notifySettings.MuteUntil);
                        Sqlite3.sqlite3_bind_text(statement, 10, notifySettings.Sound, -1);
                    }
                    else
                    {
                        Sqlite3.sqlite3_bind_null(statement, 8);
                        Sqlite3.sqlite3_bind_null(statement, 9);
                        Sqlite3.sqlite3_bind_null(statement, 10);
                    }

                    if (dialog.HasPts && dialog.Pts.HasValue)
                    {
                        Sqlite3.sqlite3_bind_int(statement, 11, dialog.Pts.Value);
                    }
                    else
                    {
                        Sqlite3.sqlite3_bind_null(statement, 11);
                    }

                    //if (dialog.HasDraft && dialog.Draft is TLDraftMessage draft)
                    //{
                    //    Sqlite3.sqlite3_bind_int(statement, 12, (int)dialog.Flags);

                    //    if (draft.HasReplyToMsgId && draft.ReplyToMsgId.HasValue)
                    //    {
                    //        Sqlite3.sqlite3_bind_int(statement, 13, draft.ReplyToMsgId.Value);
                    //    }
                    //    else
                    //    {
                    //        Sqlite3.sqlite3_bind_null(statement, 13);
                    //    }

                    //    Sqlite3.sqlite3_bind_text(statement, 14, draft.Message, -1);

                    //    if (draft.HasEntities && draft.Entities != null)
                    //    {
                    //        Sqlite3.sqlite3_bind_text(statement, 15, JsonConvert.SerializeObject(draft.Entities, _settings), -1);
                    //    }
                    //    else
                    //    {
                    //        Sqlite3.sqlite3_bind_null(statement, 15);
                    //    }

                    //    Sqlite3.sqlite3_bind_int(statement, 16, draft.Date);
                    //}
                    //else
                    //{
                    //    Sqlite3.sqlite3_bind_null(statement, 12);
                    //    Sqlite3.sqlite3_bind_null(statement, 13);
                    //    Sqlite3.sqlite3_bind_null(statement, 14);
                    //    Sqlite3.sqlite3_bind_null(statement, 15);
                    //    Sqlite3.sqlite3_bind_null(statement, 16);
                    //}

                    Sqlite3.sqlite3_bind_text(statement, 15, JsonConvert.SerializeObject(dialog.TopMessageItem, _settings), -1);

                    Sqlite3.sqlite3_step(statement);
                    Sqlite3.sqlite3_reset(statement);

                    Sqlite3.sqlite3_finalize(statement);
                }
            }
        }
예제 #13
0
        public void Load()
        {
            Statement statement;

            Sqlite3.sqlite3_prepare_v2(_database, $"SELECT {_fields} FROM `Dialogs`", out statement);

            while (Sqlite3.sqlite3_step(statement) == SQLiteResult.Row)
            {
                var flags = (TLDialog.Flag)Sqlite3.sqlite3_column_int(statement, 0);
                var id    = Sqlite3.sqlite3_column_int64(statement, 1);

                TLPeerBase peer = null;
                if (((ulong)id & PeerIdTypeMask) == PeerIdUserShift)
                {
                    peer = new TLPeerUser {
                        UserId = (int)(uint)((ulong)id & PeerIdMask)
                    };
                }
                else if (((ulong)id & PeerIdTypeMask) == PeerIdChatShift)
                {
                    peer = new TLPeerChat {
                        ChatId = (int)(uint)((ulong)id & PeerIdMask)
                    };
                }
                else if (((ulong)id & PeerIdTypeMask) == PeerIdChannelShift)
                {
                    peer = new TLPeerChannel {
                        ChannelId = (int)(uint)((ulong)id & PeerIdMask)
                    };
                }

                var top_message        = Sqlite3.sqlite3_column_int(statement, 3);
                var read_inbox_max_id  = Sqlite3.sqlite3_column_int(statement, 4);
                var read_outbox_max_id = Sqlite3.sqlite3_column_int(statement, 5);
                var unread_count       = Sqlite3.sqlite3_column_int(statement, 6);

                TLPeerNotifySettingsBase notifySettings;

                var notifyType = Sqlite3.sqlite3_column_type(statement, 7);
                if (notifyType == 1)
                {
                    notifySettings = new TLPeerNotifySettings
                    {
                        Flags     = (TLPeerNotifySettings.Flag)Sqlite3.sqlite3_column_int(statement, 7),
                        MuteUntil = Sqlite3.sqlite3_column_int(statement, 8),
                        Sound     = Sqlite3.sqlite3_column_text(statement, 9)
                    };
                }
                else
                {
                    notifySettings = new TLPeerNotifySettingsEmpty();
                }

                int?pts = null;
                if (flags.HasFlag(TLDialog.Flag.Pts))
                {
                    pts = Sqlite3.sqlite3_column_int(statement, 10);
                }

                //TLDraftMessageBase draft = null;
                //if (flags.HasFlag(TLDialog.Flag.Draft))
                //{
                //    var draftFlags = (TLDraftMessage.Flag)Sqlite3.sqlite3_column_int(statement, 11);

                //    int? replyToMsgId = null;
                //    if (draftFlags.HasFlag(TLDraftMessage.Flag.ReplyToMsgId))
                //    {
                //        replyToMsgId = Sqlite3.sqlite3_column_int(statement, 12);
                //    }

                //    var message = Sqlite3.sqlite3_column_text(statement, 13);

                //    TLVector<TLMessageEntityBase> entities = null;
                //    if (draftFlags.HasFlag(TLDraftMessage.Flag.Entities))
                //    {
                //        entities = JsonConvert.DeserializeObject<TLVector<TLMessageEntityBase>>(Sqlite3.sqlite3_column_text(statement, 14), _settings);
                //    }

                //    draft = new TLDraftMessage
                //    {
                //        Flags = draftFlags,
                //        ReplyToMsgId = replyToMsgId,
                //        Message = message,
                //        Entities = entities,
                //        Date = Sqlite3.sqlite3_column_int(statement, 15)
                //    };
                //}

                var message = JsonConvert.DeserializeObject <TLMessageBase>(Sqlite3.sqlite3_column_text(statement, 14), _settings);

                var result = new TLDialog
                {
                    Flags           = flags,
                    Peer            = peer,
                    TopMessage      = top_message,
                    ReadInboxMaxId  = read_inbox_max_id,
                    ReadOutboxMaxId = read_outbox_max_id,
                    UnreadCount     = unread_count,
                    NotifySettings  = notifySettings,
                    Pts             = pts,
                    //Draft = draft
                    TopMessageItem = message
                };

                base[result.Id] = result;
            }

            Sqlite3.sqlite3_finalize(statement);
        }
예제 #14
0
        public static string GetTypingString(TLPeerBase peer, IList <Tuple <int, TLSendMessageActionBase> > typingUsers, Func <int?, TLUserBase> getUser, Action <TLPeerBase> getFullInfoAction)
        {
            if (peer is TLPeerUser)
            {
                var tuple = typingUsers.FirstOrDefault();
                if (tuple != null)
                {
                    var action = tuple.Item2;
                    switch (action)
                    {
                    //case TLSendMessageChooseContactAction chooseContact:
                    //    return "";
                    case TLSendMessageGamePlayAction gamePlay:
                        return(Strings.Android.SendingGame);

                    //case TLSendMessageGeoLocationAction geoLocation:
                    //    return "";
                    case TLSendMessageRecordAudioAction recordAudio:
                        return(Strings.Android.RecordingAudio);

                    case TLSendMessageRecordRoundAction recordRound:
                    case TLSendMessageUploadRoundAction uploadRound:
                        return(Strings.Android.RecordingRound);

                    //case TLSendMessageTypingAction typing:
                    //    return Strings.Android.Typing;
                    case TLSendMessageUploadAudioAction uploadAudio:
                        return(Strings.Android.SendingAudio);

                    case TLSendMessageUploadDocumentAction uploadDocument:
                        return(Strings.Android.SendingFile);

                    case TLSendMessageUploadPhotoAction uploadPhoto:
                        return(Strings.Android.SendingPhoto);

                    case TLSendMessageRecordVideoAction recordVideo:
                    case TLSendMessageUploadVideoAction uploadVideo:
                        return(Strings.Android.SendingVideoStatus);
                    }
                }

                return(Strings.Android.Typing);
            }

            if (typingUsers.Count == 1)
            {
                var user = getUser.Invoke(typingUsers[0].Item1) as TLUser;
                if (user == null)
                {
                    getFullInfoAction?.Invoke(peer);
                    return(null);
                }

                var userName = string.IsNullOrEmpty(user.FirstName) ? user.LastName : user.FirstName;

                var tuple = typingUsers.FirstOrDefault();
                if (tuple != null)
                {
                    var action = tuple.Item2;
                    switch (action)
                    {
                    //case TLSendMessageChooseContactAction chooseContact:
                    //    return "";
                    case TLSendMessageGamePlayAction gamePlay:
                        return(string.Format(Strings.Android.IsSendingGame, userName));

                    //case TLSendMessageGeoLocationAction geoLocation:
                    //    return "";
                    case TLSendMessageRecordAudioAction recordAudio:
                        return(string.Format(Strings.Android.IsRecordingAudio, userName));

                    case TLSendMessageRecordRoundAction recordRound:
                    case TLSendMessageUploadRoundAction uploadRound:
                        return(string.Format(Strings.Android.IsSendingVideo, userName));

                    //case TLSendMessageTypingAction typing:
                    //    return string.Format(Strings.Android.IsTyping, userName);
                    case TLSendMessageUploadAudioAction uploadAudio:
                        return(string.Format(Strings.Android.IsSendingAudio, userName));

                    case TLSendMessageUploadDocumentAction uploadDocument:
                        return(string.Format(Strings.Android.IsSendingFile, userName));

                    case TLSendMessageUploadPhotoAction uploadPhoto:
                        return(string.Format(Strings.Android.IsSendingPhoto, userName));

                    case TLSendMessageRecordVideoAction recordVideo:
                    case TLSendMessageUploadVideoAction uploadVideo:
                        return(string.Format(Strings.Android.IsSendingVideo, userName));
                    }
                }

                return(string.Format("{0} {1}", userName, Strings.Android.IsTyping));
            }
            else
            {
                var count = 0;
                var label = string.Empty;
                foreach (var pu in typingUsers)
                {
                    var user = getUser.Invoke(pu.Item1) as TLUser;
                    if (user == null)
                    {
                        getFullInfoAction?.Invoke(peer);
                    }

                    if (user != null)
                    {
                        if (label.Length > 0)
                        {
                            label += ", ";
                        }
                        label += string.IsNullOrEmpty(user.FirstName) ? user.LastName : user.FirstName;
                        count++;
                    }
                    if (count == 2)
                    {
                        break;
                    }
                }

                if (label.Length > 0)
                {
                    if (count == 1)
                    {
                        return(string.Format("{0} {1}", label, Strings.Android.IsTyping));
                    }
                    else
                    {
                        if (typingUsers.Count > 2)
                        {
                            return(string.Format("{0} {1}", label, LocaleHelper.Declension("AndMoreTyping", typingUsers.Count - 2)));
                        }
                        else
                        {
                            return(string.Format("{0} {1}", label, Strings.Android.AreTyping));
                        }
                    }
                }

                return(null);
            }
        }
예제 #15
0
        private TLDialog GetItemFromStatement(ref Statement statement)
        {
            var flags = (TLDialog.Flag)Sqlite3.sqlite3_column_int(statement, 0);
            var id    = Sqlite3.sqlite3_column_int64(statement, 1);

            TLPeerBase peer = null;

            if (((ulong)id & PeerIdTypeMask) == PeerIdUserShift)
            {
                peer = new TLPeerUser {
                    UserId = (int)(uint)((ulong)id & PeerIdMask)
                };
            }
            else if (((ulong)id & PeerIdTypeMask) == PeerIdChatShift)
            {
                peer = new TLPeerChat {
                    ChatId = (int)(uint)((ulong)id & PeerIdMask)
                };
            }
            else if (((ulong)id & PeerIdTypeMask) == PeerIdChannelShift)
            {
                peer = new TLPeerChannel {
                    ChannelId = (int)(uint)((ulong)id & PeerIdMask)
                };
            }

            var top_message        = Sqlite3.sqlite3_column_int(statement, 3);
            var read_inbox_max_id  = Sqlite3.sqlite3_column_int(statement, 4);
            var read_outbox_max_id = Sqlite3.sqlite3_column_int(statement, 5);
            var unread_count       = Sqlite3.sqlite3_column_int(statement, 6);

            TLPeerNotifySettingsBase notifySettings;

            var notifyType = Sqlite3.sqlite3_column_type(statement, 7);

            if (notifyType == 1)
            {
                notifySettings = new TLPeerNotifySettings
                {
                    Flags     = (TLPeerNotifySettings.Flag)Sqlite3.sqlite3_column_int(statement, 7),
                    MuteUntil = Sqlite3.sqlite3_column_int(statement, 8),
                    Sound     = Sqlite3.sqlite3_column_text(statement, 9)
                };
            }
            else
            {
                notifySettings = new TLPeerNotifySettingsEmpty();
            }

            int?pts = null;

            if (flags.HasFlag(TLDialog.Flag.Pts))
            {
                pts = Sqlite3.sqlite3_column_int(statement, 10);
            }

            TLDraftMessageBase draft = null;

            if (flags.HasFlag(TLDialog.Flag.Draft))
            {
                var draftFlags = (TLDraftMessage.Flag)Sqlite3.sqlite3_column_int(statement, 11);

                int?replyToMsgId = null;
                if (draftFlags.HasFlag(TLDraftMessage.Flag.ReplyToMsgId))
                {
                    replyToMsgId = Sqlite3.sqlite3_column_int(statement, 12);
                }

                var message = Sqlite3.sqlite3_column_text(statement, 13);

                TLVector <TLMessageEntityBase> entities = null;
                if (draftFlags.HasFlag(TLDraftMessage.Flag.Entities))
                {
                    entities = JsonConvert.DeserializeObject <TLVector <TLMessageEntityBase> >(Sqlite3.sqlite3_column_text(statement, 14), _settings);
                }

                draft = new TLDraftMessage
                {
                    Flags        = draftFlags,
                    ReplyToMsgId = replyToMsgId,
                    Message      = message,
                    Entities     = entities,
                    Date         = Sqlite3.sqlite3_column_int(statement, 15)
                };
            }

            return(new TLDialog
            {
                Flags = flags,
                Peer = peer,
                TopMessage = top_message,
                ReadInboxMaxId = read_inbox_max_id,
                ReadOutboxMaxId = read_outbox_max_id,
                UnreadCount = unread_count,
                NotifySettings = notifySettings,
                Pts = pts,
                Draft = draft
            });
        }
예제 #16
0
        public void Notify(TLMessageCommonBase messageCommon)
        {
            //if (this._stateService.SuppressNotifications)
            //{
            //    return;
            //}
            if (messageCommon.IsOut)
            {
                return;
            }

            if (!messageCommon.IsUnread)
            {
                return;
            }

            if (messageCommon is TLMessage message && message.IsSilent)
            {
                return;
            }

            TLUser from = null;

            if (messageCommon.FromId != null && messageCommon.FromId.Value >= 0)
            {
                from = CacheService.GetUser(messageCommon.FromId) as TLUser;
                if (from == null)
                {
                    return;
                }
            }

            try
            {
                TLObject   activeDialog = CheckActiveDialog();
                TLPeerBase toId         = messageCommon.ToId;
                var        fromId       = messageCommon.FromId;
                var        suppress     = false;
                TLDialog   dialog       = null;
                if (toId is TLPeerChat && activeDialog is TLChat && toId.Id == ((TLChat)activeDialog).Id)
                {
                    suppress = true;
                }
                if (toId is TLPeerChannel && activeDialog is TLChannel && toId.Id == ((TLChannel)activeDialog).Id)
                {
                    suppress = true;
                }
                else if (toId is TLPeerUser && activeDialog is TLUserBase && ((from != null && from.IsSelf) || fromId.Value == ((TLUserBase)activeDialog).Id))
                {
                    suppress = true;
                }

                if (!suppress)
                {
                    TLChatBase chat    = null;
                    TLUser     user    = null;
                    TLChannel  channel = null;
                    if (messageCommon.ToId is TLPeerChat)
                    {
                        chat   = CacheService.GetChat(messageCommon.ToId.Id);
                        dialog = CacheService.GetDialog(new TLPeerChat
                        {
                            Id = messageCommon.ToId.Id
                        });
                    }
                    else if (messageCommon.ToId is TLPeerChannel)
                    {
                        chat    = CacheService.GetChat(messageCommon.ToId.Id);
                        channel = (chat as TLChannel);
                        dialog  = CacheService.GetDialog(new TLPeerChannel {
                            ChannelId = messageCommon.ToId.Id
                        });
                    }
                    else if (messageCommon.IsOut)
                    {
                        user   = CacheService.GetUser(messageCommon.ToId.Id) as TLUser;
                        dialog = CacheService.GetDialog(new TLPeerUser {
                            UserId = messageCommon.ToId.Id
                        });
                    }
                    else
                    {
                        user   = CacheService.GetUser(messageCommon.FromId) as TLUser;
                        dialog = CacheService.GetDialog(new TLPeerUser {
                            UserId = messageCommon.FromId.Value
                        });
                    }

                    var now = TLUtils.DateToUniversalTimeTLInt(ProtoService.ClientTicksDelta, DateTime.Now);
                    if (chat != null)
                    {
                        var notifySettingsBase = CacheService.GetFullChat(chat.Id)?.NotifySettings;
                        if (notifySettingsBase == null)
                        {
                            notifySettingsBase = ((dialog != null) ? dialog.NotifySettings : null);
                        }

                        if (notifySettingsBase == null)
                        {
                            if (channel != null)
                            {
                                ProtoService.GetFullChannelAsync(channel.ToInputChannel(), chatFull =>
                                {
                                    //chat.NotifySettings = chatFull.FullChat.NotifySettings;
                                    if (dialog != null)
                                    {
                                        dialog.NotifySettings = chatFull.FullChat.NotifySettings;

                                        Execute.BeginOnUIThread(() =>
                                        {
                                            dialog.RaisePropertyChanged(() => dialog.NotifySettings);
                                            dialog.RaisePropertyChanged(() => dialog.Self);
                                        });
                                    }
                                }, null);
                            }
                            else
                            {
                                ProtoService.GetFullChatAsync(chat.Id, chatFull =>
                                {
                                    //chat.NotifySettings = chatFull.FullChat.NotifySettings;
                                    if (dialog != null)
                                    {
                                        dialog.NotifySettings = chatFull.FullChat.NotifySettings;

                                        Execute.BeginOnUIThread(() =>
                                        {
                                            dialog.RaisePropertyChanged(() => dialog.NotifySettings);
                                            dialog.RaisePropertyChanged(() => dialog.Self);
                                        });
                                    }
                                }, null);
                            }
                        }

                        var notifySettings = notifySettingsBase as TLPeerNotifySettings;
                        suppress = (notifySettings == null || notifySettings.MuteUntil > now);
                    }

                    if (user != null)
                    {
                        var notifySettingsBase = CacheService.GetFullUser(user.Id)?.NotifySettings;
                        if (notifySettingsBase == null)
                        {
                            notifySettingsBase = ((dialog != null) ? dialog.NotifySettings : null);
                        }

                        if (notifySettingsBase == null)
                        {
                            ProtoService.GetFullUserAsync(user.ToInputUser(), userFull =>
                            {
                                //user.NotifySettings = userFull.NotifySettings;
                                if (dialog != null)
                                {
                                    dialog.NotifySettings = userFull.NotifySettings;

                                    Execute.BeginOnUIThread(() =>
                                    {
                                        dialog.RaisePropertyChanged(() => dialog.NotifySettings);
                                        dialog.RaisePropertyChanged(() => dialog.Self);
                                    });
                                }
                            }, null);
                        }

                        var notifySettings = notifySettingsBase as TLPeerNotifySettings;
                        suppress = (notifySettings == null || notifySettings.MuteUntil > now || user.IsSelf);
                    }

                    if (!suppress)
                    {
                        if (dialog != null)
                        {
                            suppress = CheckLastNotificationTime(dialog, now);
                        }

                        if (!suppress)
                        {
                            if (ApplicationSettings.Current.InAppPreview)
                            {
                                // TODO
                            }

                            if (_lastNotificationTime.HasValue)
                            {
                                var totalSeconds = (DateTime.Now - _lastNotificationTime.Value).TotalSeconds;
                                if (totalSeconds > 0.0 && totalSeconds < 2.0)
                                {
                                    suppress = true;
                                }
                            }

                            _lastNotificationTime = DateTime.Now;

                            if (suppress)
                            {
                                Log.Write(string.Format("Cancel notification reason=[lastNotificationTime] msg_id={0} last_notification_time={1}, now={2}", messageCommon.Id, _lastNotificationTime, DateTime.Now), null);
                            }
                            else
                            {
                                if (ApplicationSettings.Current.InAppVibrate)
                                {
                                    _vibrationService.VibrateAsync();
                                }

                                if (ApplicationSettings.Current.InAppSounds)
                                {
                                    //if (_notificationPlayer == null)
                                    //{
                                    //    _notificationPlayer = new MediaPlayer();
                                    //    _notificationPlayer.Source = MediaSource.CreateFromUri(new Uri("ms-appx:///Assets/Sounds/Default.wav"));
                                    //}

                                    //_notificationPlayer.Pause();
                                    //_notificationPlayer.PlaybackSession.Position = TimeSpan.Zero;
                                    //_notificationPlayer.Play();



                                    //string text = "Sounds/Default.wav";
                                    //if (toId is TLPeerChat && !string.IsNullOrEmpty(s.GroupSound))
                                    //{
                                    //    text = "Sounds/" + s.GroupSound + ".wav";
                                    //}
                                    //else if (!string.IsNullOrEmpty(s.ContactSound))
                                    //{
                                    //    text = "Sounds/" + s.ContactSound + ".wav";
                                    //}
                                    //if (toId is TLPeerChat && chat != null && chat.NotifySettings is TLPeerNotifySettings)
                                    //{
                                    //    text = "Sounds/" + ((TLPeerNotifySettings)chat.NotifySettings).Sound.Value + ".wav";
                                    //}
                                    //else if (toId is TLPeerUser && user != null && user.NotifySettings is TLPeerNotifySettings)
                                    //{
                                    //    text = "Sounds/" + ((TLPeerNotifySettings)user.NotifySettings).Sound.Value + ".wav";
                                    //}
                                    //if (!Utils.XapContentFileExists(text))
                                    //{
                                    //    text = "Sounds/Default.wav";
                                    //}
                                    //System.IO.Stream stream = TitleContainer.OpenStream(text);
                                    //SoundEffect soundEffect = SoundEffect.FromStream(stream);
                                    //FrameworkDispatcher.Update();
                                    //soundEffect.Play();
                                }
                            }
                        }
                    }
                }
            }
            catch (System.Exception ex)
            {
                TLUtils.WriteLine(ex.ToString(), LogSeverity.Error);
            }
        }
예제 #17
0
        public TLMessage Get(TLPeerBase peer, TLInt fromId)
        {
            try
            {
                lock (_liveLocationsSyncRoot)
                {
                    for (var index = _messages.Count - 1; index >= 0; index--)
                    {
                        var messageBase = _messages[index];
                        var message     = messageBase as TLMessage48;
                        if (message != null &&
                            message.FromId.Value == fromId.Value)
                        {
                            var mediaGeoLive = message.Media as TLMessageMediaGeoLive;
                            if (mediaGeoLive != null)
                            {
                                mediaGeoLive.EditDate = message.EditDate;
                                mediaGeoLive.Date     = message.Date;
                                if (mediaGeoLive.Active)
                                {
                                    if (peer is TLPeerUser &&
                                        message.ToId is TLPeerUser &&
                                        !message.Out.Value &&
                                        peer.Id.Value == message.FromId.Value)
                                    {
                                        return(message);
                                    }

                                    if (peer is TLPeerUser &&
                                        message.ToId is TLPeerUser &&
                                        message.Out.Value &&
                                        peer.Id.Value == message.ToId.Id.Value)
                                    {
                                        return(message);
                                    }

                                    if (peer is TLPeerChat &&
                                        message.ToId is TLPeerChat &&
                                        peer.Id.Value == message.ToId.Id.Value)
                                    {
                                        return(message);
                                    }

                                    if (peer is TLPeerChannel &&
                                        message.ToId is TLPeerChannel &&
                                        peer.Id.Value == message.ToId.Id.Value)
                                    {
                                        return(message);
                                    }
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
            }

            return(null);
        }
예제 #18
0
        public static async Task <UserActivitySession> GenerateActivityAsync(TLPeerBase peer)
        {
            if (ApiInformation.IsApiContractPresent("Windows.Foundation.UniversalApiContract", 5))
            {
                var activity = await Channel.GetOrCreateUserActivityAsync("DialogActivity");

                var uri   = "tg://toast?";
                var title = string.Empty;
                var id    = 0;

                if (peer is TLPeerUser peerUser)
                {
                    var user = CacheService.GetUser(peerUser.UserId);
                    if (user == null)
                    {
                        return(null);
                    }

                    uri  += $"from_id={user.Id}";
                    title = user.FullName;
                    id    = user.Id;
                }
                else if (peer is TLPeerChat peerChat)
                {
                    var chat = (TLChat)CacheService.GetChat(peerChat.ChatId);
                    if (chat == null)
                    {
                        return(null);
                    }

                    uri  += $"chat_id={chat.Id}";
                    title = chat.Title;
                    id    = chat.Id;
                }
                else if (peer is TLPeerChannel peerChannel)
                {
                    var channel = (TLChannel)CacheService.GetChat(peerChannel.ChannelId);
                    if (channel == null)
                    {
                        return(null);
                    }

                    uri  += $"channel_id={channel.Id}";
                    title = channel.Title;
                    id    = channel.Id;
                }

                activity.ActivationUri = new Uri(uri);
                activity.VisualElements.DisplayText     = title;
                activity.VisualElements.BackgroundColor = BindConvert.Current.Bubble(id).Color;

                await activity.SaveAsync();

                var session = activity.CreateSession();

                _session?.Dispose();
                _session = session;

                return(session);
            }

            return(null);
        }