public static TLKeyboardButtonGame GetKeyboardButtonGame(TLMessageService message) { var reply = message.Reply as TLMessage31; if (reply != null) { if (reply.ReplyMarkup != null) { var replyKeyboardMarkup = reply.ReplyMarkup as TLReplyInlineMarkup; if (replyKeyboardMarkup != null) { foreach (var row in replyKeyboardMarkup.Rows) { foreach (var button in row.Buttons) { var keyboardButtonGame = button as TLKeyboardButtonGame; if (keyboardButtonGame != null) { return(keyboardButtonGame); } } } } } } return(null); }
private void UpdateSeparatorOnInsert(TLMessageBase item, TLMessageBase previous, int index) { if (item != null && previous != null) { if ((item is TLMessageService itemService && itemService.Action is TLMessageActionAdminLogEvent) || (previous is TLMessageService previousService && previousService.Action is TLMessageActionAdminLogEvent)) { return; } if (item.Id == previous.Id) { return; } var itemDate = Utils.UnixTimestampToDateTime(item.Date); var previousDate = Utils.UnixTimestampToDateTime(previous.Date); if (previousDate.Date != itemDate.Date) { var timestamp = (int)Utils.DateTimeToUnixTimestamp(previousDate.Date); var service = new TLMessageService { Date = timestamp, FromId = SettingsHelper.UserId, HasFromId = true, Action = new TLMessageActionDate { Date = timestamp } }; base.InsertItem(index + 1, service); } } }
public static Paragraph Convert(TLMessageService serviceMessage, bool useActiveLinks) { var fromId = serviceMessage.FromId; var user = InMemoryCacheService.Current.GetUser(fromId ?? 0); var userFullName = user != null ? user.FullName : AppResources.UserNominativeSingular; var action = serviceMessage.Action; if (serviceMessage.ToId is TLPeerChannel) { var channel = InMemoryCacheService.Current.GetChat(serviceMessage.ToId.Id) as TLChannel; if (action is TLMessageActionAdminLogEvent eventAction && _actionsCache.TryGetValue(eventAction.Event.Action.GetType(), out Func <TLMessageService, TLChannelAdminLogEventActionBase, int, string, bool, Paragraph> func)) { return(func.Invoke(serviceMessage, eventAction.Event.Action, fromId.Value, userFullName, useActiveLinks)); } } if (action is TLMessageActionDate dateAction) { return(ReplaceLinks(serviceMessage, DateTimeToFormatConverter.ConvertDayGrouping(Utils.UnixTimestampToDateTime(dateAction.Date)))); } var paragraph = new Paragraph(); paragraph.Inlines.Add(new Run { Text = AppResources.MessageActionEmpty }); return(paragraph); }
private string ConvertTitle(TLMessageService message) { if (message.Action is TLMessageActionPhoneCall phoneCallAction) { var outgoing = message.IsOut; var missed = phoneCallAction.Reason is TLPhoneCallDiscardReasonMissed || phoneCallAction.Reason is TLPhoneCallDiscardReasonBusy; return(missed ? (outgoing ? Strings.Android.CallMessageOutgoingMissed : Strings.Android.CallMessageIncomingMissed) : (outgoing ? Strings.Android.CallMessageOutgoing : Strings.Android.CallMessageIncoming)); } return(string.Empty); }
private string ConvertTitle(TLMessageService message) { if (message.Action is TLMessageActionPhoneCall phoneCallAction) { var loader = ResourceLoader.GetForCurrentView("Resources"); var outgoing = message.IsOut; var missed = phoneCallAction.Reason is TLPhoneCallDiscardReasonMissed || phoneCallAction.Reason is TLPhoneCallDiscardReasonBusy; return(loader.GetString(missed ? (outgoing ? "CallCanceled" : "CallMissed") : (outgoing ? "CallOutgoing" : "CallIncoming"))); } return(string.Empty); }
protected string ConvertReason(TLMessageService message) { if (message.Action is TLMessageActionPhoneCall phoneCallAction) { var outgoing = message.IsOut; var missed = phoneCallAction.Reason is TLPhoneCallDiscardReasonMissed || phoneCallAction.Reason is TLPhoneCallDiscardReasonBusy; VisualStateManager.GoToState(_layoutRoot, missed ? "Missed" : "Default", false); return(outgoing ? "\uE60B\u00A0" : "\uE60C\u00A0"); } return(string.Empty); }
private TLMessageService GetServiceMessage(TLChannelAdminLogEvent item) { var message = new TLMessageService(); //message.Id = item.Id; message.FromId = item.UserId; message.ToId = _channel.ToPeer(); message.Date = item.Date; message.Action = new TLMessageActionAdminLogEvent { Event = item }; return(message); }
public static string Convert(TLMessageService serviceMessage) { var paragraph = Convert(serviceMessage, false); if (paragraph != null && paragraph.Inlines.Count > 0) { var run = paragraph.Inlines[0] as Run; if (run != null) { return(run.Text); } } return(AppResources.MessageActionEmpty); }
private bool SetServiceTextTemplate(TLMessageService message, string title) { Visibility = Visibility.Visible; if (ThumbRoot != null) { ThumbRoot.Visibility = Visibility.Collapsed; } TitleLabel.Text = GetFromLabel(message, title); ServiceLabel.Text = string.Empty; MessageLabel.Text = ServiceHelper.Convert(message); return(true); }
public static string Convert(TLMessageService serviceMessage, bool useActiveLinks = false) { TLInt fromId = new TLInt(0); //serviceMessage.FromId; TLUserBase fromUser = null; //IoC.Get<ICacheService>().GetUser(fromId); string fromUserFullName = null; //fromUser != null ? fromUser.FullName : AppResources.User; var action = serviceMessage.Action; if (action != null && _actionsCache.ContainsKey(action.GetType())) { return(_actionsCache[action.GetType()](action, fromId.Value, fromUserFullName, useActiveLinks)); } return(null); }
public static TLGame GetGame(TLMessageService message) { var reply = message.Reply as TLMessage31; if (reply != null) { var mediaGame = reply.Media as TLMessageMediaGame; if (mediaGame != null) { return(mediaGame.Game); } } return(null); }
private string GetFromLabel(TLMessageService message, string title) { if (!string.IsNullOrWhiteSpace(title)) { return(Title); } if (message.IsPost && (message.ToId is TLPeerChat || message.ToId is TLPeerChannel)) { return(message.Parent?.DisplayName ?? string.Empty); } else { return(message.From?.FullName ?? string.Empty); } }
private bool SetServicePhotoTemplate(TLMessageService message, string title) { Visibility = Visibility.Visible; FindName(nameof(ThumbRoot)); if (ThumbRoot != null) { ThumbRoot.Visibility = Visibility.Visible; } TitleLabel.Text = GetFromLabel(message, title); ServiceLabel.Text = string.Empty; MessageLabel.Text = ServiceHelper.Convert(message); var action = message.Action as TLMessageActionChatEditPhoto; if (action != null) { ThumbRoot.CornerRadius = ThumbEllipse.CornerRadius = default(CornerRadius); ThumbImage.ImageSource = (ImageSource)DefaultPhotoConverter.Convert(action.Photo, true); } return(true); }
public void ExportMessageService(TLMessageService message) { }
public override void ExportMessageService(TLMessageService message) { m_sAuthor = GetAuthor(message.from_id); m_sHeader = String.Format(c_sMessageHeader, m_sAuthor, Date.TLConvertTxt(message.date)); string sMessage = ""; if (message.action.GetType() == typeof(TLMessageActionChannelCreate)) { sMessage = "ChannelCreate"; } else if (message.action.GetType() == typeof(TLMessageActionChannelMigrateFrom)) { sMessage = "ChannelMigrateFrom"; } else if (message.action.GetType() == typeof(TLMessageActionChatAddUser)) { sMessage = "ChatAddUser"; } else if (message.action.GetType() == typeof(TLMessageActionChatCreate)) { sMessage = "ChatCreate"; } else if (message.action.GetType() == typeof(TLMessageActionChatDeletePhoto)) { sMessage = "ChatDeletePhoto"; } else if (message.action.GetType() == typeof(TLMessageActionChatDeleteUser)) { sMessage = "ChatDeleteUser"; } else if (message.action.GetType() == typeof(TLMessageActionChatEditPhoto)) { sMessage = "ChatEditPhoto"; } else if (message.action.GetType() == typeof(TLMessageActionChatEditTitle)) { sMessage = "ChatEditTitle"; } else if (message.action.GetType() == typeof(TLMessageActionChatJoinedByLink)) { sMessage = "ChatJoinedByLink"; } else if (message.action.GetType() == typeof(TLMessageActionChatMigrateTo)) { sMessage = "ChatMigrateTo"; } else if (message.action.GetType() == typeof(TLMessageActionEmpty)) { sMessage = "Empty"; } else if (message.action.GetType() == typeof(TLMessageActionGameScore)) { sMessage = "GameScore"; } else if (message.action.GetType() == typeof(TLMessageActionHistoryClear)) { sMessage = "HistoryClear"; } else if (message.action.GetType() == typeof(TLMessageActionPinMessage)) { sMessage = "PinMessage"; } else { throw new TLCoreException("Unknown message service"); } Prepend(sMessage); Prepend(m_sHeader); }
public static string Convert(TLMessageService serviceMessage, bool useActiveLinks = false) { var fromId = serviceMessage.FromId; var fromUser = IoC.Get <ICacheService>().GetUser(fromId); var fromUserFullName = fromUser != null ? fromUser.FullName : AppResources.User; //var stateService = IoC.Get<IStateService>(); //if (fromId.Value == stateService.CurrentUserId) //{ // fromUserFullName = AppResources.You; //} var action = serviceMessage.Action; if (serviceMessage.ToId is TLPeerChannel) { //var channel = IoC.Get<ICacheService>().GetChat(serviceMessage.ToId.Id) as TLChannel; var isMegaGroup = false;// channel != null && channel.IsMegaGroup; var actionChannelCreate = action as TLMessageActionChannelCreate; if (actionChannelCreate != null) { return(isMegaGroup ? string.Format(AppResources.MessageActionChatCreate, GetUserFullNameString(fromUserFullName, fromId.Value, useActiveLinks), ((TLMessageActionChannelCreate)action).Title) : string.Format(AppResources.MessageActionChannelCreate, GetUserFullNameString(fromUserFullName, fromId.Value, useActiveLinks), ((TLMessageActionChannelCreate)action).Title)); } var actionChatEditPhoto = action as TLMessageActionChatEditPhoto; if (actionChatEditPhoto != null) { return(isMegaGroup ? AppResources.MessageActionChatEditPhoto : AppResources.MessageActionChannelEditPhoto); } var actionChatDeletePhoto = action as TLMessageActionChatDeletePhoto; if (actionChatDeletePhoto != null) { return(isMegaGroup ? AppResources.MessageActionChatDeletePhoto : AppResources.MessageActionChannelDeletePhoto); } var actionChantEditTitle = action as TLMessageActionChatEditTitle; if (actionChantEditTitle != null) { return(isMegaGroup ? string.Format(AppResources.MessageActionChatEditTitle, actionChantEditTitle.Title) : string.Format(AppResources.MessageActionChannelEditTitle, actionChantEditTitle.Title)); } } if (action != null && _actionsCache.ContainsKey(action.GetType())) { return(_actionsCache[action.GetType()](action, fromId.Value, fromUserFullName, useActiveLinks)); } #if DEBUG return(action != null?action.GetType().Name : AppResources.MessageActionEmpty); #endif return(AppResources.MessageActionEmpty); }
public ChatPhotosViewModel(IMTProtoService protoService, ICacheService cacheService, TLChatFullBase chatFull, TLChatBase chat, TLMessageService serviceMessage) : base(protoService, cacheService, null) { _peer = chat.ToInputPeer(); _lastMaxId = serviceMessage.Id; if (serviceMessage.Action is TLMessageActionChatEditPhoto editPhotoAction) { Items = new MvxObservableCollection <GalleryItem> { new GalleryPhotoItem(editPhotoAction.Photo as TLPhoto, chat) }; SelectedItem = Items[0]; FirstItem = Items[0]; } Initialize(serviceMessage.Id); }
public static string Convert(TLMessageService serviceMessage, bool useActiveLinks = false, bool noName = false) { var fromId = serviceMessage.FromId; var fromUser = IoC.Get <ICacheService>().GetUser(fromId); var fromUserFullName = fromUser != null ? fromUser.FullName2 : AppResources.User; //var stateService = IoC.Get<IStateService>(); //if (fromId.Value == stateService.CurrentUserId) //{ // fromUserFullName = AppResources.You; //} var action = serviceMessage.Action; if (serviceMessage.ToId is TLPeerChannel) { var channel = IoC.Get <ICacheService>().GetChat(serviceMessage.ToId.Id) as TLChannel; var isMegaGroup = channel != null && channel.IsMegaGroup; var actionPinMessage = action as TLMessageActionPinMessage; if (actionPinMessage != null) { var serviceMessage49 = serviceMessage as TLMessageService49; if (serviceMessage49 != null) { var replyToMsgId = serviceMessage49.ReplyToMsgId; if (replyToMsgId != null && channel != null) { var reply = IoC.Get <ICacheService>().GetMessage(serviceMessage49.ReplyToMsgId, channel.Id) as TLMessage; if (reply != null) { if (!isMegaGroup && fromUser == null) { useActiveLinks = false; fromUserFullName = channel.FullName; } var mediaGame = reply.Media as TLMessageMediaGame; if (mediaGame != null) { return(string.Format(AppResources.MessageActionPinGame, GetUserFullNameString(fromUserFullName, fromId.Value, useActiveLinks, noName))); } var text = reply.Message.ToString(); if (text.Length > 0) { if (text.Length > 20) { return(string.Format(AppResources.MessageActionPinText, GetUserFullNameString(fromUserFullName, fromId.Value, useActiveLinks, noName), text.Substring(0, 20).Replace("\r\n", "\n").Replace("\n", " ") + "...")); } return(string.Format(AppResources.MessageActionPinText, GetUserFullNameString(fromUserFullName, fromId.Value, useActiveLinks, noName), text)); } var mediaPhoto = reply.Media as TLMessageMediaPhoto; if (mediaPhoto != null) { return(string.Format(AppResources.MessageActionPinPhoto, GetUserFullNameString(fromUserFullName, fromId.Value, useActiveLinks, noName))); } var mediaDocument = reply.Media as TLMessageMediaDocument; if (mediaDocument != null) { if (TLMessageBase.IsSticker(mediaDocument.Document)) { return(string.Format(AppResources.MessageActionPinSticker, GetUserFullNameString(fromUserFullName, fromId.Value, useActiveLinks, noName))); } if (TLMessageBase.IsVoice(mediaDocument.Document)) { return(string.Format(AppResources.MessageActionPinVoiceMessage, GetUserFullNameString(fromUserFullName, fromId.Value, useActiveLinks, noName))); } if (TLMessageBase.IsMusic(mediaDocument.Document)) { return(string.Format(AppResources.MessageActionPinTrack, GetUserFullNameString(fromUserFullName, fromId.Value, useActiveLinks, noName))); } if (TLMessageBase.IsVideo(mediaDocument.Document)) { return(string.Format(AppResources.MessageActionPinVideo, GetUserFullNameString(fromUserFullName, fromId.Value, useActiveLinks, noName))); } if (TLMessageBase.IsGif(mediaDocument.Document)) { return(string.Format(AppResources.MessageActionPinGif, GetUserFullNameString(fromUserFullName, fromId.Value, useActiveLinks, noName))); } return(string.Format(AppResources.MessageActionPinFile, GetUserFullNameString(fromUserFullName, fromId.Value, useActiveLinks, noName))); } var mediaContact = reply.Media as TLMessageMediaContact; if (mediaContact != null) { return(string.Format(AppResources.MessageActionPinContact, GetUserFullNameString(fromUserFullName, fromId.Value, useActiveLinks, noName))); } var mediaGeoLive = reply.Media as TLMessageMediaGeoLive; if (mediaGeoLive != null) { return(string.Format(AppResources.MessageActionPinGeoLive, GetUserFullNameString(fromUserFullName, fromId.Value, useActiveLinks, noName))); } var mediaGeo = reply.Media as TLMessageMediaGeo; if (mediaGeo != null) { return(string.Format(AppResources.MessageActionPinMap, GetUserFullNameString(fromUserFullName, fromId.Value, useActiveLinks, noName))); } var mediaAudio = reply.Media as TLMessageMediaAudio; if (mediaAudio != null) { return(string.Format(AppResources.MessageActionPinVoiceMessage, GetUserFullNameString(fromUserFullName, fromId.Value, useActiveLinks, noName))); } var mediaVideo = reply.Media as TLMessageMediaVideo; if (mediaVideo != null) { return(string.Format(AppResources.MessageActionPinVideo, GetUserFullNameString(fromUserFullName, fromId.Value, useActiveLinks, noName))); } } } return(string.Format(AppResources.MessageActionPinMessage, GetUserFullNameString(fromUserFullName, fromId.Value, useActiveLinks, noName))); } } var actionChatAddUser41 = action as TLMessageActionChatAddUser41; if (actionChatAddUser41 != null) { var users = ((TLMessageActionChatAddUser41)action).Users; var userFullName = new List <string>(); foreach (var userId in users) { var user = IoC.Get <ICacheService>().GetUser(userId); if (user != null) { userFullName.Add(GetUserFullName(user, useActiveLinks, noName)); } } if (users.Count == 1 && users[0].Value == fromId.Value) { if (fromId.Value == IoC.Get <IStateService>().CurrentUserId) { return(AppResources.MessageActionChatJoinSelf); } return(string.Format(AppResources.MessageActionChatJoin, GetUserFullNameString(fromUserFullName, fromId.Value, useActiveLinks, noName), string.Join(", ", userFullName))); } return(string.Format(AppResources.MessageActionChatAddUser, GetUserFullNameString(fromUserFullName, fromId.Value, useActiveLinks, noName), string.Join(", ", userFullName))); } var actionChannelCreate = action as TLMessageActionChannelCreate; if (actionChannelCreate != null) { return(isMegaGroup ? string.Format(AppResources.MessageActionChatCreate, GetUserFullNameString(fromUserFullName, fromId.Value, useActiveLinks, noName), ((TLMessageActionChannelCreate)action).Title) : string.Format(AppResources.MessageActionChannelCreate, GetUserFullNameString(fromUserFullName, fromId.Value, useActiveLinks, noName), ((TLMessageActionChannelCreate)action).Title)); } var actionChatEditPhoto = action as TLMessageActionChatEditPhoto; if (actionChatEditPhoto != null) { return(isMegaGroup ? string.Format(AppResources.MessageActionChatEditPhoto, GetUserFullNameString(fromUserFullName, fromId.Value, useActiveLinks, noName)) : AppResources.MessageActionChannelEditPhoto); } var actionChatDeletePhoto = action as TLMessageActionChatDeletePhoto; if (actionChatDeletePhoto != null) { return(isMegaGroup ? string.Format(AppResources.MessageActionChatDeletePhoto, GetUserFullNameString(fromUserFullName, fromId.Value, useActiveLinks, noName)) : AppResources.MessageActionChannelDeletePhoto); } var actionChantEditTitle = action as TLMessageActionChatEditTitle; if (actionChantEditTitle != null) { return(isMegaGroup ? string.Format(AppResources.MessageActionChatEditTitle, GetUserFullNameString(fromUserFullName, fromId.Value, useActiveLinks, noName), actionChantEditTitle.Title) : string.Format(AppResources.MessageActionChannelEditTitle, actionChantEditTitle.Title)); } } if (action != null && _actionsCache.ContainsKey(action.GetType())) { return(_actionsCache[action.GetType()](serviceMessage, action, fromId.Value, fromUserFullName, useActiveLinks, noName)); } #if DEBUG return(string.Format("{0} msg_id={1}", action != null ? action.ToString() : AppResources.MessageActionEmpty, serviceMessage.Id)); #endif return(AppResources.MessageActionEmpty); }