protected virtual void ViewExecute() { TLMessageCommonBase messageCommon = null; if (_selectedItem is GalleryMessageItem messageItem) { messageCommon = messageItem.Message; } else if (_selectedItem is GalleryMessageServiceItem serviceItem) { messageCommon = serviceItem.Message; } if (messageCommon == null) { return; } NavigationService.GoBack(); var service = WindowWrapper.Current().NavigationServices.GetByFrameId("Main"); if (service != null) { service.NavigateToDialog(messageCommon.Parent, messageCommon.Id); } }
private string GetLaunch(TLMessageCommonBase custom) { var launch = string.Empty; if (custom.Id > 0) { launch += string.Format(CultureInfo.InvariantCulture, "msg_id={0}&", custom.Id); } if (custom.Parent is TLChat chat) { launch += string.Format(CultureInfo.InvariantCulture, "chat_id={0}", chat.Id); } else if (custom.Parent is TLChannel channel) { launch += string.Format(CultureInfo.InvariantCulture, "channel_id={0}&access_hash={1}", channel.Id, channel.AccessHash ?? 0); } else if (custom.Parent is TLUser user) { launch += string.Format(CultureInfo.InvariantCulture, "from_id={0}&access_hash={1}", user.Id, user.AccessHash ?? 0); } //launch += L"Action="; //launch += loc_key->Data(); return(launch); }
private string GetLaunch(TLMessageCommonBase custom) { return(GetLaunch(custom?.Parent)); //launch += L"Action="; //launch += loc_key->Data(); }
private string GetPicture(TLMessageCommonBase custom, string group) { TLFileLocation location = null; if (custom.Parent is TLUser user && user.Photo is TLUserProfilePhoto userPhoto) { location = userPhoto.PhotoSmall as TLFileLocation; }
public void Notify(TLMessageCommonBase commonMessage) { var caption = commonMessage.Parent.DisplayName; var content = GetFromLabel(commonMessage) + GetBriefLabel(commonMessage, true); var sound = ""; var launch = GetLaunch(commonMessage); var tag = GetTag(commonMessage); var group = GetGroup(commonMessage); var picture = GetPicture(commonMessage, group); var date = BindConvert.Current.DateTime(commonMessage.Date).ToString("o"); var loc_key = commonMessage.Parent is TLChannel channel && channel.IsBroadcast ? "CHANNEL" : string.Empty; NotificationTask.UpdateToast(caption, content, sound, launch, tag, group, picture, date, loc_key); }
private static bool IsReadMessage(TLMessageCommonBase messageCommon, Dictionary <int, TLUpdateReadHistoryOutbox> readChatOutbox, Dictionary <int, TLUpdateReadHistoryInbox> readChatInbox, Dictionary <int, TLUpdateReadHistoryOutbox> readUserOutbox, Dictionary <int, TLUpdateReadHistoryInbox> readUserInbox, Dictionary <int, TLUpdateReadChannelOutbox> readChannelOutbox, Dictionary <int, TLUpdateReadChannelInbox> readChannelInbox) { if (messageCommon.ToId is TLPeerChat) { if (messageCommon.IsOut) { if (readChatOutbox.TryGetValue(messageCommon.ToId.Id, out TLUpdateReadHistoryOutbox update) && update.MaxId >= messageCommon.Id) { return(true); } } else if (readChatInbox.TryGetValue(messageCommon.ToId.Id, out TLUpdateReadHistoryInbox update) && update.MaxId >= messageCommon.Id) { return(true); } } else if (messageCommon.ToId is TLPeerUser) { if (messageCommon.IsOut) { if (readUserOutbox.TryGetValue(messageCommon.ToId.Id, out TLUpdateReadHistoryOutbox update) && update.MaxId >= messageCommon.Id) { return(true); } } else if (readUserInbox.TryGetValue(messageCommon.FromId ?? 0, out TLUpdateReadHistoryInbox update) && update.MaxId >= messageCommon.Id) { return(true); } } else if (messageCommon.ToId is TLPeerChannel) { if (messageCommon.IsOut) { if (readChannelOutbox.TryGetValue(messageCommon.ToId.Id, out TLUpdateReadChannelOutbox update) && update.MaxId >= messageCommon.Id) { return(true); } } else if (readChannelInbox.TryGetValue(messageCommon.ToId.Id, out TLUpdateReadChannelInbox update) && update.MaxId >= messageCommon.Id) { return(true); } } return(false); }
private string GetGroup(TLMessageCommonBase custom) { if (custom.Parent is TLChat chat) { return(string.Format(CultureInfo.InvariantCulture, "c{0}", chat.Id)); } else if (custom.Parent is TLChannel channel) { return(string.Format(CultureInfo.InvariantCulture, "c{0}", channel.Id)); } else if (custom.Parent is TLUser user) { return(string.Format(CultureInfo.InvariantCulture, "u{0}", user.Id)); } return(null); }
private Visibility MessageDelete_Loaded(TLMessageCommonBase messageCommon) { if (messageCommon.Parent is TLChannel channel) { if (messageCommon.Id == 1 && messageCommon.ToId is TLPeerChannel) { return(Visibility.Collapsed); } if (!messageCommon.IsOut && !channel.IsCreator && !channel.HasAdminRights || (channel.AdminRights != null && !channel.AdminRights.IsDeleteMessages)) { return(Visibility.Collapsed); } } return(Visibility.Visible); }
private static async void Hyperlink_Navigate(TLMessageCommonBase message, string currentId) { if (currentId.StartsWith("tg-user://")) { var navigationService = WindowWrapper.Current().NavigationServices.GetByFrameId("Main"); if (navigationService != null) { navigationService.Navigate(typeof(UserDetailsPage), new TLPeerUser { UserId = int.Parse(currentId.Replace("tg-user://", string.Empty)) }); } } else if (currentId.StartsWith("tg-message://")) { var navigationService = WindowWrapper.Current().NavigationServices.GetByFrameId("Main"); if (navigationService != null && navigationService.Content is DialogPage dialogPage) { dialogPage.ViewModel.MessageOpenReplyCommand.Execute(message); } } else if (currentId.StartsWith("tg-stickers://")) { var split = currentId.Replace("tg-stickers://", string.Empty).Split('?'); TLInputStickerSetBase input; if (split.Length > 1) { input = new TLInputStickerSetID { Id = long.Parse(split[0]), AccessHash = long.Parse(split[1]) }; } else { input = new TLInputStickerSetShortName { ShortName = split[0] }; } await StickerSetView.Current.ShowAsync(input); } }
private static void Hyperlink_Navigate(TLMessageCommonBase message, string currentId) { if (currentId.StartsWith("tg-user://")) { var navigationService = WindowWrapper.Current().NavigationServices.GetByFrameId("Main"); if (navigationService != null) { navigationService.Navigate(typeof(UserDetailsPage), new TLPeerUser { UserId = int.Parse(currentId.Replace("tg-user://", string.Empty)) }); } } else if (currentId.StartsWith("tg-message://")) { var navigationService = WindowWrapper.Current().NavigationServices.GetByFrameId("Main"); if (navigationService != null && navigationService.Content is DialogPage dialogPage) { dialogPage.ViewModel.MessageOpenReplyCommand.Execute(message); } } }
public void Handle(TLMessageCommonBase commonMessage) { Execute.BeginOnUIThread(() => Notify(commonMessage)); }
private static Paragraph ReplaceLinks(TLMessageCommonBase message, string text, string[] users = null, string[] identifiers = null, bool useActiveLinks = true) { var paragraph = new Paragraph(); if (users == null) { paragraph.Inlines.Add(new Run { Text = text }); return(paragraph); } if (!useActiveLinks) { paragraph.Inlines.Add(new Run { Text = string.Format(text, users) }); return(paragraph); } var regex = new Regex("({[0-9]?})"); var matches = regex.Matches(text); if (matches.Count > 0) { var lastIndex = 0; for (int i = 0; i < matches.Count; i++) { var match = matches[i]; if (match.Index - lastIndex > 0) { paragraph.Inlines.Add(new Run { Text = text.Substring(lastIndex, match.Index - lastIndex) }); } lastIndex = match.Index + match.Length; if (users?.Length > i && identifiers?.Length > i) { var currentId = identifiers[i]; if (currentId.Equals("tg-bold://")) { paragraph.Inlines.Add(new Run { Text = users[i], FontWeight = FontWeights.SemiBold }); } else { var hyperlink = new Hyperlink(); hyperlink.Click += (s, args) => Hyperlink_Navigate(message, currentId); hyperlink.UnderlineStyle = UnderlineStyle.None; hyperlink.Foreground = new SolidColorBrush(Colors.White); hyperlink.Inlines.Add(new Run { Text = users[i], FontWeight = FontWeights.SemiBold }); paragraph.Inlines.Add(hyperlink); } } else if (users?.Length > i) { paragraph.Inlines.Add(new Run { Text = users[i] }); } } if (lastIndex < text.Length) { paragraph.Inlines.Add(new Run { Text = text.Substring(lastIndex, text.Length - lastIndex) }); } } else { paragraph.Inlines.Add(new Run { Text = text }); } return(paragraph); }
private Visibility MessageForward_Loaded(TLMessageCommonBase messageCommon) { return(Visibility.Visible); }
private Visibility MessageSelect_Loaded(TLMessageCommonBase messageCommon) { return(ViewModel.SelectionMode == ListViewSelectionMode.None ? Visibility.Visible : Visibility.Collapsed); }
private string GetTag(TLMessageCommonBase custom) { return(custom.Id.ToString(CultureInfo.InvariantCulture)); }
public void Handle(TLMessageCommonBase messageCommon) { Execute.BeginOnUIThread(() => Notify(messageCommon)); }
private string GetPicture(TLMessageCommonBase custom, string group) { return(GetPicture(custom?.Parent, group)); }
private string GetGroup(TLMessageCommonBase custom) { return(GetGroup(custom?.Parent)); }
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); } }