private async Task GetUserSettings() { if (_getInProgress) { return; } _getInProgress = true; // FIXME: catch exception await TelegramSession.Instance.Established; try { PeerNotifySettings settings = await TelegramSession.Instance.Api.account_getNotifySettings( TL.inputNotifyPeer(TL.inputPeerContact(Id))); switch (settings.Constructor) { case Constructor.peerNotifySettings: UpdatePeerNotifySettings(settings as PeerNotifySettingsConstructor); break; case Constructor.peerNotifySettingsEmpty: logger.error("Unable to get USER settings: Constructor.peerNotifySettingsEmpty"); break; } } catch (MTProtoException ex) { logger.error("GetUserSettings Exception"); } _getInProgress = false; }
public static InputPeer PeerToInputPeer(Peer peer) { switch (peer.Constructor) { case Constructor.peerUser: // TODO: foreign and self cases return(TL.inputPeerContact(((PeerUserConstructor)peer).user_id)); case Constructor.peerChat: return(TL.inputPeerChat(((PeerChatConstructor)peer).chat_id)); default: throw new Exception("invalid constructor"); } }
private async Task UpdateUserSettings() { if (_updateInProgress) { return; } // LOCK ON THIS _updateInProgress = true; logger.debug("Synchronizing settings"); try { InputPeerNotifySettings newSettings = TL.inputPeerNotifySettings(peerNotifySettings.mute_until, peerNotifySettings.sound, peerNotifySettings.show_previews, peerNotifySettings.events_mask); // FIXME: catch exception, process BOOl error bool update = await TelegramSession.Instance.Api.account_updateNotifySettings(TL.inputNotifyPeer (TL.inputPeerContact(Id)), newSettings); logger.debug("Synchronized settings: " + update); } catch (MTProtoException ex) { logger.error("UpdateUserSettings Exception"); } // UNLOCK ON THIS _updateInProgress = false; }
private void OnDialogSelected(object sender, DialogModel model) { InputPeer inputPeer = null; if (!(model is DialogModelPlain)) { return; } DialogModelPlain dmp = (DialogModelPlain)model; if (fromMedia == 1) { MessageMedia media = MediaTransitionHelper.Instance.Media; InputMedia im = null; if (media.Constructor == Constructor.messageMediaPhoto) { MessageMediaPhotoConstructor mmpc = (MessageMediaPhotoConstructor)media; InputPhoto ip = TL.inputPhoto(((PhotoConstructor)mmpc.photo).id, ((PhotoConstructor)mmpc.photo).access_hash); im = TL.inputMediaPhoto(ip); } else if (media.Constructor == Constructor.messageMediaVideo) { MessageMediaVideoConstructor mmvc = (MessageMediaVideoConstructor)media; InputVideo iv = TL.inputVideo(((VideoConstructor)mmvc.video).id, ((VideoConstructor)mmvc.video).access_hash); im = TL.inputMediaVideo(iv); } else if (media.Constructor == Constructor.messageMediaGeo) { MessageMediaGeoConstructor mmgc = (MessageMediaGeoConstructor)media; GeoPointConstructor gpc = (GeoPointConstructor)mmgc.geo; InputGeoPoint point = TL.inputGeoPoint(gpc.lat, gpc.lng); im = TL.inputMediaGeoPoint(point); } if (im != null) { dmp.SendMedia(im); NavigationService.GoBack(); } return; } if (messageId.Count == 0) { logger.error("error forwarding, no messageId"); } Peer peer = model.Peer; if (model.IsChat) { inputPeer = TL.inputPeerChat(((PeerChatConstructor)peer).chat_id); } else { inputPeer = TL.inputPeerContact(((PeerUserConstructor)peer).user_id); } DoForwardMessages(inputPeer); int modelId = TelegramSession.Instance.Dialogs.Model.Dialogs.IndexOf(model); NavigationService.Navigate(new Uri("/UI/Pages/DialogPage.xaml?modelId=" + modelId, UriKind.Relative)); }