private bool SetForwardedMessagesTemplate(TLVector <TLMessage> messages) { Visibility = Visibility.Visible; if (ThumbRoot != null) { ThumbRoot.Visibility = Visibility.Collapsed; } TitleLabel.Text = string.Empty; ServiceLabel.Text = LocaleHelper.Declension("ForwardedMessageCount", messages.Count); MessageLabel.Text = string.Empty; var users = messages.Select(x => x.From).Distinct(new EqualityComparerDelegate <TLUser>((x, y) => x.Id == y.Id)).ToList(); if (users.Count > 2) { TitleLabel.Text = users[0].FullName + LocaleHelper.Declension("AndOther", users.Count); } else if (users.Count == 2) { TitleLabel.Text = $"{users[0].FullName}, {users[1].FullName}"; } else if (users.Count == 1) { TitleLabel.Text = users[0].FullName; } return(true); }
public object Convert(object value, Type targetType, object parameter, string language) { var count = System.Convert.ToInt32(value); if (count > 0) { return(LocaleHelper.Declension("Users", count)); } return(Strings.Android.EmpryUsersPlaceholder); }
public object Convert(object value, Type targetType, object parameter, string language) { var days = System.Convert.ToInt32(value); if (days >= 365) { return(LocaleHelper.Declension("Years", days / 365)); } return(LocaleHelper.Declension("Months", days / 30)); }
public object Convert(object value, Type targetType, object parameter, string language) { if (parameter is string format) { // TODO: declesion return(LocaleHelper.Declension(format, System.Convert.ToInt32(value))); } return(value); }
public object Convert(object value, Type targetType, object parameter, string language) { if (value is TLChannel channel) { if (channel.HasUsername && channel.HasParticipantsCount) { return(string.Format("{0}, {1}", channel.Username, LocaleHelper.Declension(channel.IsMegaGroup ? "Members" : "Subscribers", channel.ParticipantsCount ?? 0))); } else if (channel.HasUsername) { return(channel.Username); } } return(null); }
private async void AccountTTLExecute() { var dialog = new ContentDialog { Style = BootStrapper.Current.Resources["ModernContentDialogStyle"] as Style }; var stack = new StackPanel(); stack.Margin = new Thickness(12, 16, 12, 0); stack.Children.Add(new RadioButton { Tag = 30, Content = LocaleHelper.Declension("Months", 1) }); stack.Children.Add(new RadioButton { Tag = 90, Content = LocaleHelper.Declension("Months", 3) }); stack.Children.Add(new RadioButton { Tag = 180, Content = LocaleHelper.Declension("Months", 6) }); stack.Children.Add(new RadioButton { Tag = 365, Content = LocaleHelper.Declension("Years", 1) }); RadioButton GetSelectedPeriod(UIElementCollection periods, RadioButton defaultPeriod) { if (_accountTTL == 0) { return(stack.Children[2] as RadioButton); } RadioButton period = null; var max = 2147483647; foreach (RadioButton current in stack.Children) { var days = (int)current.Tag; int abs = Math.Abs(_accountTTL - days); if (abs < max) { max = abs; period = current; } } return(period ?? stack.Children[2] as RadioButton); }; var selected = GetSelectedPeriod(stack.Children, stack.Children[2] as RadioButton); if (selected != null) { selected.IsChecked = true; } dialog.Title = Strings.Android.DeleteAccountTitle; dialog.Content = stack; dialog.PrimaryButtonText = Strings.Android.OK; dialog.SecondaryButtonText = Strings.Android.Cancel; var confirm = await dialog.ShowQueuedAsync(); if (confirm == ContentDialogResult.Primary) { var days = 180; foreach (RadioButton current in stack.Children) { if (current.IsChecked == true) { days = (int)current.Tag; break; } } var response = await ProtoService.SetAccountTTLAsync(new TLAccountDaysTTL { Days = days }); if (response.IsSucceeded) { AccountTTL = days; } else { } } }
public override async Task <IList <TLMessageBase> > LoadDataAsync() { _viewModel.IsLoading = true; _hasMore = false; var maxId = Count > 0 ? _minEventId : 0; var response = await _protoService.GetAdminLogAsync(_inputChannel, null, null, null, maxId, 0, 50); if (response.IsSucceeded) { _viewModel.IsLoading = false; var result = new List <TLMessageBase>(); foreach (var item in response.Result.Events) { _minEventId = Math.Min(_minEventId, item.Id); if (item.Action is TLChannelAdminLogEventActionChangeTitle changeTitle) { result.Insert(0, GetServiceMessage(item)); } else if (item.Action is TLChannelAdminLogEventActionChangeAbout changeAbout) { var message = new TLMessage(); //message.Id = item.Id; message.FromId = item.UserId; message.ToId = _channel.ToPeer(); message.Date = item.Date; message.Message = changeAbout.NewValue; message.HasMedia = true; if (string.IsNullOrEmpty(changeAbout.PrevValue)) { message.Media = new TLMessageMediaEmpty(); } else { message.Media = new TLMessageMediaWebPage { WebPage = new TLWebPage { SiteName = Strings.Android.EventLogPreviousGroupDescription, Description = changeAbout.PrevValue, HasSiteName = true, HasDescription = true } }; } result.Insert(0, message); result.Insert(0, GetServiceMessage(item)); } else if (item.Action is TLChannelAdminLogEventActionChangeUsername changeUsername) { var message = new TLMessage(); //message.Id = item.Id; message.FromId = item.UserId; message.ToId = _channel.ToPeer(); message.Date = item.Date; message.Message = string.IsNullOrEmpty(changeUsername.NewValue) ? string.Empty : MeUrlPrefixConverter.Convert(changeUsername.NewValue); message.Entities = new TLVector <TLMessageEntityBase>(); message.HasMedia = true; message.HasEntities = true; message.Entities.Add(new TLMessageEntityUrl { Offset = 0, Length = message.Message.Length }); if (string.IsNullOrEmpty(changeUsername.PrevValue)) { message.Media = new TLMessageMediaEmpty(); } else { message.Media = new TLMessageMediaWebPage { WebPage = new TLWebPage { SiteName = Strings.Android.EventLogPreviousLink, Description = MeUrlPrefixConverter.Convert(changeUsername.PrevValue), HasSiteName = true, HasDescription = true } }; } result.Insert(0, message); result.Insert(0, GetServiceMessage(item)); } else if (item.Action is TLChannelAdminLogEventActionChangePhoto changePhoto) { result.Insert(0, GetServiceMessage(item)); } else if (item.Action is TLChannelAdminLogEventActionToggleInvites toggleInvites) { result.Insert(0, GetServiceMessage(item)); } else if (item.Action is TLChannelAdminLogEventActionToggleSignatures toggleSignatures) { result.Insert(0, GetServiceMessage(item)); } else if (item.Action is TLChannelAdminLogEventActionTogglePreHistoryHidden togglePreHistoryHidden) { result.Insert(0, GetServiceMessage(item)); } else if (item.Action is TLChannelAdminLogEventActionUpdatePinned updatePinned) { // Patch for view if (updatePinned.Message is TLMessageCommonBase messageCommon) { messageCommon.ReplyToMsgId = null; messageCommon.IsOut = false; messageCommon.IsPost = false; } if (!(updatePinned.Message is TLMessageEmpty)) { result.Insert(0, updatePinned.Message); } result.Insert(0, GetServiceMessage(item)); } else if (item.Action is TLChannelAdminLogEventActionEditMessage editMessage) { // TODO: the actual message if (editMessage.NewMessage is TLMessageCommonBase messageCommon) { messageCommon.ReplyToMsgId = editMessage.PrevMessage.Id; messageCommon.IsOut = false; messageCommon.IsPost = false; } if (editMessage.NewMessage is TLMessage message) { message.Reply = editMessage.PrevMessage; message.EditDate = null; message.HasEditDate = false; } result.Insert(0, editMessage.NewMessage); result.Insert(0, GetServiceMessage(item)); } else if (item.Action is TLChannelAdminLogEventActionDeleteMessage deleteMessage) { // Patch for view if (deleteMessage.Message is TLMessageCommonBase messageCommon) { messageCommon.ReplyToMsgId = null; messageCommon.IsOut = false; messageCommon.IsPost = false; } result.Insert(0, deleteMessage.Message); result.Insert(0, GetServiceMessage(item)); } else if (item.Action is TLChannelAdminLogEventActionParticipantJoin participantJoin) { result.Insert(0, GetServiceMessage(item)); } else if (item.Action is TLChannelAdminLogEventActionParticipantLeave participantLeave) { result.Insert(0, GetServiceMessage(item)); } else if (item.Action is TLChannelAdminLogEventActionParticipantInvite participantInvite) { result.Insert(0, GetServiceMessage(item)); } else if (item.Action is TLChannelAdminLogEventActionParticipantToggleBan participantToggleBan) { var message = new TLMessage(); //message.Id = item.Id; message.FromId = item.UserId; message.ToId = _channel.ToPeer(); message.Date = item.Date; //message.Message = from.ReadString(); message.Entities = new TLVector <TLMessageEntityBase>(); message.HasFromId = true; message.HasEntities = true; var whoUser = participantToggleBan.PrevParticipant.User; TLChannelBannedRights o = null; TLChannelBannedRights n = null; if (participantToggleBan.PrevParticipant is TLChannelParticipantBanned prevBanned) { o = prevBanned.BannedRights; } if (participantToggleBan.NewParticipant is TLChannelParticipantBanned newBanned) { n = newBanned.BannedRights; } if (_channel.IsMegaGroup && (n == null || !n.IsViewMessages || n != null && o != null && n.UntilDate != o.UntilDate)) { StringBuilder rights; String bannedDuration; if (n != null && !AdminLogHelper.IsBannedForever(n.UntilDate)) { bannedDuration = ""; int duration = n.UntilDate - item.Date; int days = duration / 60 / 60 / 24; duration -= days * 60 * 60 * 24; int hours = duration / 60 / 60; duration -= hours * 60 * 60; int minutes = duration / 60; int count = 0; for (int a = 0; a < 3; a++) { String addStr = null; if (a == 0) { if (days != 0) { addStr = LocaleHelper.Declension("Days", days); count++; } } else if (a == 1) { if (hours != 0) { addStr = LocaleHelper.Declension("Hours", hours); count++; } } else { if (minutes != 0) { addStr = LocaleHelper.Declension("Minutes", minutes); count++; } } if (addStr != null) { if (bannedDuration.Length > 0) { bannedDuration += ", "; } bannedDuration += addStr; } if (count == 2) { break; } } } else { bannedDuration = Strings.Android.UserRestrictionsUntilForever; } var str = Strings.Android.EventLogRestrictedUntil; rights = new StringBuilder(String.Format(str, GetUserName(whoUser, message.Entities, str.IndexOf("{0}")), bannedDuration)); var added = false; if (o == null) { o = new TLChannelBannedRights(); } if (n == null) { n = new TLChannelBannedRights(); } void AppendChange(bool value, string label) { if (!added) { rights.Append('\n'); added = true; } rights.Append('\n').Append(!value ? '+' : '-').Append(' '); rights.Append(label); } if (o.IsViewMessages != n.IsViewMessages) { AppendChange(n.IsViewMessages, Strings.Android.EventLogRestrictedReadMessages); } if (o.IsSendMessages != n.IsSendMessages) { AppendChange(n.IsSendMessages, Strings.Android.EventLogRestrictedSendMessages); } if (o.IsSendStickers != n.IsSendStickers || o.IsSendInline != n.IsSendInline || o.IsSendGifs != n.IsSendGifs || o.IsSendGames != n.IsSendGames) { AppendChange(n.IsSendStickers, Strings.Android.EventLogRestrictedSendStickers); } if (o.IsSendMedia != n.IsSendMedia) { AppendChange(n.IsSendMedia, Strings.Android.EventLogRestrictedSendMedia); } if (o.IsEmbedLinks != n.IsEmbedLinks) { AppendChange(n.IsEmbedLinks, Strings.Android.EventLogRestrictedSendEmbed); } message.Message = rights.ToString(); } else { String str; if (n != null && (o == null || n.IsViewMessages)) { str = Strings.Android.EventLogChannelRestricted; } else { str = Strings.Android.EventLogChannelUnrestricted; } message.Message = String.Format(str, GetUserName(whoUser, message.Entities, str.IndexOf("{0}"))); } result.Insert(0, message); } else if (item.Action is TLChannelAdminLogEventActionParticipantToggleAdmin participantToggleAdmin) { var message = new TLMessage(); //message.Id = item.Id; message.FromId = item.UserId; message.ToId = _channel.ToPeer(); message.Date = item.Date; //message.Message = from.ReadString(); message.Entities = new TLVector <TLMessageEntityBase>(); message.HasFromId = true; message.HasEntities = true; var whoUser = participantToggleAdmin.PrevParticipant.User; var str = Strings.Android.EventLogPromoted; var userName = GetUserName(whoUser, message.Entities, str.IndexOf("{0}")); var builder = new StringBuilder(string.Format(str, userName)); var added = false; TLChannelAdminRights o = null; TLChannelAdminRights n = null; if (participantToggleAdmin.PrevParticipant is TLChannelParticipantAdmin prevAdmin) { o = prevAdmin.AdminRights; } if (participantToggleAdmin.NewParticipant is TLChannelParticipantAdmin newAdmin) { n = newAdmin.AdminRights; } if (o == null) { o = new TLChannelAdminRights(); } if (n == null) { n = new TLChannelAdminRights(); } void AppendChange(bool value, string label) { if (!added) { builder.Append('\n'); added = true; } builder.Append('\n').Append(value ? '+' : '-').Append(' '); builder.Append(label); } if (o.IsChangeInfo != n.IsChangeInfo) { AppendChange(n.IsChangeInfo, _channel.IsMegaGroup ? Strings.Android.EventLogPromotedChangeGroupInfo : Strings.Android.EventLogPromotedChangeChannelInfo); } if (!_channel.IsMegaGroup) { if (o.IsPostMessages != n.IsPostMessages) { AppendChange(n.IsPostMessages, Strings.Android.EventLogPromotedPostMessages); } if (o.IsEditMessages != n.IsEditMessages) { AppendChange(n.IsEditMessages, Strings.Android.EventLogPromotedEditMessages); } } if (o.IsDeleteMessages != n.IsDeleteMessages) { AppendChange(n.IsDeleteMessages, Strings.Android.EventLogPromotedDeleteMessages); } if (o.IsAddAdmins != n.IsAddAdmins) { AppendChange(n.IsAddAdmins, Strings.Android.EventLogPromotedAddAdmins); } if (_channel.IsMegaGroup) { if (o.IsBanUsers != n.IsBanUsers) { AppendChange(n.IsBanUsers, Strings.Android.EventLogPromotedBanUsers); } } if (o.IsInviteUsers != n.IsInviteUsers) { AppendChange(n.IsInviteUsers, Strings.Android.EventLogPromotedAddUsers); } if (_channel.IsMegaGroup) { if (o.IsPinMessages != n.IsPinMessages) { AppendChange(n.IsPinMessages, Strings.Android.EventLogPromotedPinMessages); } } message.Message = builder.ToString(); result.Insert(0, message); } else if (item.Action is TLChannelAdminLogEventActionChangeStickerSet changeStickerSet) { result.Insert(0, GetServiceMessage(item)); } } if (response.Result.Events.Count < 50) { _hasMore = false; } return(result); } _viewModel.IsLoading = false; return(new TLMessageBase[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); } }
public string ConvertCount(int total, bool broadcast) { return(LocaleHelper.Declension(broadcast ? "Subscribers" : "Members", total)); }
public DeleteChannelMessageDialog(int count, string fullName) { this.InitializeComponent(); Title = Strings.Android.Message; PrimaryButtonText = Strings.Android.OK; SecondaryButtonText = Strings.Android.Cancel; Message.Text = string.Format(Strings.Android.AreYouSureDeleteMessages, LocaleHelper.Declension("Messages", count)); DeleteAllCheck.Content = string.Format(Strings.Android.DeleteAllFrom, fullName ?? string.Empty); }