public Dictionary <long, Recipients> BuildRecipients() { var channels = new List <ChannelInstance>(); var result = new Dictionary <long, Recipients>(); // Append recients per channel if (message.MessageFolder == Folders.SentItems || message.MessageFolder == Folders.Drafts) { // Use target channels channels.Add(ChannelsManager.GetChannelObject(message.TargetChannel.ChannelId)); } else { // Use source channel channels.Add(ChannelsManager.GetChannelObject(message.SourceChannel.ChannelId)); } foreach (var channel in channels) { var recipients = new Recipients(); recipients.To.AddRange(FilterByTargetChannel(message.To, channel)); recipients.CC.AddRange(FilterByTargetChannel(message.CC, channel)); recipients.BCC.AddRange(FilterByTargetChannel(message.BCC, channel)); if (!recipients.IsEmpty) { result.Add(channel.Configuration.ChannelId, recipients); } } return(result); }
protected override void ExecuteCore() { var config = ClientState.Current.DataService.SelectByKey <ChannelConfig>(configuration.ChannelId); if (notify && config.ChannelConnection == ChannelConnection.Connected) { // Remove configuration from server HttpServiceRequest.Post(CloudApi.ApiBaseUrl + "account/removechannel", String.Format("wrap_access_token={0}&key={1}", CloudApi.AccessToken, config.ChannelKey), true); } ClientState.Current.DataService.ExecuteNonQuery("DELETE FROM UserStatus WHERE SourceChannelId=" + config.ChannelConfigId); ClientState.Current.DataService.ExecuteNonQuery("DELETE FROM Profiles WHERE SourceChannelId=" + config.ChannelConfigId); ClientState.Current.DataService.ExecuteNonQuery("DELETE FROM Persons WHERE SourceChannelId=" + config.ChannelConfigId); ClientState.Current.DataService.ExecuteNonQuery("DELETE FROM Conversations WHERE ConversationIdentifier IN (SELECT ConversationIdentifier FROM Messages WHERE Messages.SourceChannelId=" + config.ChannelConfigId + " OR TargetChannelId=" + config.ChannelConfigId + ")"); ClientState.Current.DataService.ExecuteNonQuery("DELETE FROM Messages WHERE SourceChannelId=" + config.ChannelConfigId + " OR TargetChannelId=" + config.ChannelConfigId); ClientState.Current.DataService.ExecuteNonQuery("DELETE FROM Documents WHERE SourceChannelId=" + config.ChannelConfigId); ClientState.Current.DataService.ExecuteNonQuery("DELETE FROM DocumentVersions WHERE SourceChannelId=" + config.ChannelConfigId); ClientState.Current.DataService.Delete(config); mailbox.StatusUpdates.RemoveAll(u => u.SourceChannelId == config.ChannelConfigId || u.TargetChannelId == config.ChannelConfigId.ToString()); mailbox.Profiles.RemoveAll(p => p.SourceChannelId == config.ChannelConfigId); mailbox.Persons.RemoveAll(p => p.SourceChannelId == config.ChannelConfigId); // conversations are not deleted because well we don't care about then, will be gone on the next restart anyway mailbox.Messages.RemoveAll(m => m.SourceChannelId == config.ChannelConfigId || m.TargetChannelId == config.ChannelConfigId); mailbox.Documents.RemoveAll(d => d.SourceChannelId == config.ChannelConfigId || d.TargetChannelId == config.ChannelConfigId); mailbox.DocumentVersions.RemoveAll(d => d.SourceChannelId == config.ChannelConfigId || d.TargetChannelId == config.ChannelConfigId); // Delete channel from the ChannelsManager ChannelsManager.Remove(ChannelsManager.GetChannelObject(config.ChannelConfigId.Value)); EventBroker.Publish(AppEvents.RebuildToolbar); }
bool ContactsViewSourceFilter(object sender) { var person = (Person)sender; if (person.Profiles.Count == 0) { return(false); } if (Filter.ShowSoftContacts == false && person.IsSoft) { return(false); } if (!String.IsNullOrEmpty(Filter.SearchKeyword)) { return(person.Name.IndexOf(Filter.SearchKeyword, StringComparison.InvariantCultureIgnoreCase) > -1); } // Break out if source channel is not visible var channel = ChannelsManager.GetChannelObject(person.SourceChannelId); if (channel != null && !channel.IsVisible) { return(false); } return(true); }
void LoadChannelConfigs() { if (!configLoaded) { if (SourceChannelId > 0) { var channel = ChannelsManager.GetChannelObject(SourceChannelId); if (channel != null) { sourceChannelConfig = channel.Configuration; } } if (TargetChannelId > 0) { var channel = ChannelsManager.GetChannelObject(TargetChannelId); if (channel != null) { targetChannelConfig = channel.Configuration; } } configLoaded = true; } }
/// <summary> /// Filters the conversations view source. /// </summary> /// <param name="sender">The sender.</param> /// <returns></returns> public bool CalendarViewSourceFilter(object sender) { // Cast to an event Event calendarevent = (Event)sender; // Check if the event is set to an object if (calendarevent == null) { return(false); } // Break out if channel is not visible var channel = ChannelsManager.GetChannelObject(calendarevent.SourceChannelId); if (channel != null && !channel.IsVisible) { return(false); } // Determine the folder type and check it with the saved filter option switch (calendarevent.EventFolder) { case Folders.Inbox: return(Filter.Received); case Folders.Trash: return(Filter.Deleted); default: Logger.Debug("Event {0} has non recognized folder {1}, hiding event", LogSource.UI, calendarevent, calendarevent.EventFolder); return(true); } }
public static void ReplyAll(Message source, string text) { var recipients = new SourceAddressCollection(); recipients.AddRange(source.To); recipients.AddRange(source.CC); long channelid; // Remove receivers own address from list if (source.SourceChannelId != 0) { var channel = ChannelsManager.GetChannelObject(source.SourceChannelId); var sourceAddress = channel.InputChannel.GetSourceAddress(); if (recipients.Contains(sourceAddress)) { recipients.Remove(sourceAddress); } channelid = source.SourceChannelId; } else { var channel = ChannelsManager.GetChannelObject(source.TargetChannelId); var sourceAddress = channel.InputChannel.GetSourceAddress(); if (recipients.Contains(sourceAddress)) { recipients.Remove(sourceAddress); } channelid = source.TargetChannelId; } ClientState.Current.ViewController.MoveTo( PluginsManager.Current.GetPlugin <ConversationsPlugin>().NewItemView, new NewMessageDataHelper { SourceMessageId = source.MessageId, SelectedChannelId = channelid, Context = "Re: " + source.Context, To = source.From.ToList(), Cc = recipients, Body = MessageBodyGenerator.CreateBodyTextForReply(source, text), SuppressSignature = !String.IsNullOrEmpty(text) }); }
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { if (value == null) { return(null); } if (value != null) { var channel = ChannelsManager.GetChannelObject((long)value); return(channel.Configuration.DisplayName); } return(String.Empty); }
internal static void SendExecute(ChannelInstance sourceChannel, ExecutedRoutedEventArgs e) { var source = (ButtonBase)e.OriginalSource; var inreplyto = source.DataContext as UserStatus; // Reply to parent if that is available, othwerwise facebook replies // will break down. if (inreplyto != null && inreplyto.Parent != null) { inreplyto = inreplyto.Parent; } var channel = inreplyto == null ? sourceChannel : ChannelsManager.GetChannelObject(inreplyto.SourceChannel.ChannelId); Send(new[] { channel }, inreplyto == null ? null : inreplyto.ChannelStatusKey, e); }
public static IEnumerable <long> GetSavedSelection() { var setting = ClientState.Current.Context.GetSetting("/Settings/StatusUpdate/ChannelsSelection"); if (setting == null || String.IsNullOrEmpty(setting as string)) { yield break; } foreach (var channel in ((string)setting).Split(new[] { "," }, StringSplitOptions.RemoveEmptyEntries) .Select(s => Int64.Parse(s)) .Select(i => ChannelsManager.GetChannelObject(i)) .Where(c => c != null && c.Configuration.Charasteristics.SupportsStatusUpdates)) { yield return(channel.Configuration.ChannelId); } }
/// <summary> /// Called when [validation finished handler]. /// </summary> /// <param name="sender">The sender.</param> /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param> void OnValidationFinishedHandler(object sender, EventArgs e) { ChannelSetupControl control = sender as ChannelSetupControl; if (control.IsValidated) { if (control.InviteFriends) { // Send out viral var message = Messages.Next(); var config = control.ChannelConfiguration; var status = new UserStatus { Status = message, StatusType = StatusTypes.MyUpdate, SortDate = DateTime.Now, DateCreated = DateTime.Now, TargetChannelId = config.ChannelId.ToString() }; new BackgroundActionTask(delegate { var channel = ChannelsManager.GetChannelObject(config.ChannelId); ChannelContext.Current.ClientContext = new ChannelClientContext(ClientState.Current.Context, config); channel.StatusUpdatesChannel.UpdateMyStatus(status.DuckCopy <ChannelStatusUpdate>()); }).ExecuteAsync(); } var firstItem = (FrameworkElement)transitionContainer.Items[0]; var secondItem = (FrameworkElement)transitionContainer.Items[1]; TimeSpan duration = new TimeSpan(0, 0, 0); transitionContainer.RestDuration = new Duration(duration); transitionContainer.ApplyTransition(firstItem, secondItem); } OnPropertyChanged("HasConfiguredChannels"); }
public ChannelProfileControl(Person person, Profile profile, ChannelConfiguration channel) { InitializeComponent(); DataContext = this; Person = person; Profile = profile; Channel = channel; if (Channel.Charasteristics.SupportsStatusUpdates) { // Execute task to get latest status update for this user var task = new GetLastUserStatusTask(Channel, ChannelsManager.GetChannelObject(Channel.ChannelId).StatusUpdatesChannel, Profile.SourceAddress); task.FinishedSuccess += GetLastUserStatusTask_Finished; task.FinishedFailure += GetLastUserStatusTask_FinishedFailure; task.ExecuteAsync(); // Start loader animation ((Storyboard)FindResource("RunLoaderStoryboard")).Begin(); } }
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { if (value == null) { return(String.Empty); } if (value is IClientInputChannel) { IClientInputChannel channel = (IClientInputChannel)value; return(channel.GetSourceAddress().Address); } if (value is long) { IClientInputChannel channel = ChannelsManager.GetChannelObject((long)value).InputChannel; return(channel.GetSourceAddress().Address); } return(String.Empty); }
protected override void ExecuteCore() { var access = new ClientMessageAccess(message); var group = new ProgressGroup { Status = Strings.SendingMessage }; ProgressManager.Current.Register(group); var msg = message.DuckCopy <ChannelMessage>(); try { msg.BodyText = access.BodyText.ToStream(); msg.BodyHtml = access.BodyHtml.ToStream(); // Handle attachments foreach (var document in message.Documents) { var attachment = new ChannelAttachment { Filename = document.Filename, ContentType = document.ContentType, ContentStream = new MemoryStream() }; attachment.ContentStream = File.OpenRead( ClientState.Current.Storage.ResolvePhysicalFilename(".", document.StreamName)); msg.Attachments.Add(attachment); } Logger.Debug("Message has {0} attachments", LogSource.BackgroundTask, msg.Attachments.Count); var recipients = BuildRecipients(); try { group.SourceChannelId = message.TargetChannelId; var channel = ChannelsManager.GetChannelObject(message.TargetChannelId); // The messageid itself is not used by the send channel, so inject our friendlyrowkey into that field. // The field is added to the headers collection which in turn is used again to determine if its a sent // item that is allready in your inbox2 sent items folder. msg.MessageIdentifier = message.MessageKey; msg.ConversationId = message.ConversationIdentifier; // Filter only the recipients that belong to this channel msg.To = recipients[message.TargetChannelId].To; msg.CC = recipients[message.TargetChannelId].CC; msg.BCC = recipients[message.TargetChannelId].BCC; Logger.Debug("Sending message. Channel = {0}", LogSource.BackgroundTask, channel.Configuration.DisplayName); if (channel.Configuration.IsConnected) { SendCloudMessage(channel.Configuration, msg); } else { channel.OutputChannel.Send(msg); } Logger.Debug("Send was successfull. Channel = {0}", LogSource.BackgroundTask, channel.Configuration.DisplayName); } catch (Exception ex) { ClientState.Current.ShowMessage( new AppMessage(String.Concat(Strings.UnableToSendMessage, ", ", String.Format(Strings.ServerSaid, ex.Message))) { SourceChannelId = message.TargetChannelId }, MessageType.Error); throw; } EventBroker.Publish(AppEvents.SendMessageFinished); Thread.CurrentThread.ExecuteOnUIThread(() => ClientState.Current.ShowMessage( new AppMessage(Strings.MessageSentSuccessfully) { EntityId = message.MessageId.Value, EntityType = EntityType.Message }, MessageType.Success)); } finally { if (msg.BodyText != null) { msg.BodyText.Dispose(); } if (msg.BodyHtml != null) { msg.BodyHtml.Dispose(); } group.IsCompleted = true; // Close attachment streams foreach (var channelAttachment in msg.Attachments) { channelAttachment.ContentStream.Dispose(); channelAttachment.ContentStream = null; } } }
void Send_Executed(object sender, ExecutedRoutedEventArgs e) { ClientStats.LogEvent("Quick reply all send"); if (String.IsNullOrEmpty(QuickReplyAll.Text.Trim())) { return; } var newMessage = new Message(); #region Create message var channel = message.SourceChannelId == 0 ? ChannelsManager.GetDefaultChannel() : ChannelsManager.GetChannelObject(Message.SourceChannelId); var recipients = new SourceAddressCollection(); var sourceAddress = channel.InputChannel.GetSourceAddress(); recipients.Add(Message.From); recipients.AddRange(Message.To); // Remove our own address from recipient list if (recipients.Contains(sourceAddress)) { recipients.Remove(sourceAddress); } newMessage.InReplyTo = Message.MessageIdentifier; newMessage.ConversationIdentifier = Message.ConversationIdentifier; newMessage.Context = "Re: " + Message.Context; newMessage.From = channel.InputChannel.GetSourceAddress(); newMessage.TargetChannelId = channel.Configuration.ChannelId; newMessage.To.AddRange(recipients); newMessage.CC.AddRange(Message.CC); var access = new ClientMessageAccess(newMessage, null, MessageBodyGenerator.CreateBodyTextForReply(Message, QuickReplyAll.Text.Nl2Br())); newMessage.BodyHtmlStreamName = access.WriteBodyHtml(); newMessage.BodyPreview = access.GetBodyPreview(); newMessage.IsRead = true; newMessage.DateSent = DateTime.Now; newMessage.MessageFolder = Folders.SentItems; newMessage.DateSent = DateTime.Now; newMessage.DateCreated = DateTime.Now; #endregion #region Send message ClientState.Current.DataService.Save(newMessage); // Add message to mailbox EventBroker.Publish(AppEvents.MessageStored, newMessage); // Save command CommandQueue.Enqueue(AppCommands.SendMessage, newMessage); if (!NetworkInterface.GetIsNetworkAvailable()) { ClientState.Current.ShowMessage( new AppMessage(Strings.MessageWillBeSentLater) { EntityId = newMessage.MessageId.Value, EntityType = EntityType.Message }, MessageType.Success); } QuickReplyAll.Text = String.Empty; message.TrackAction(ActionType.ReplyForward); #endregion }
protected override void ExecuteCore() { var group = new ProgressGroup { Status = Strings.UpdatingStatus }; ProgressManager.Current.Register(group); try { foreach (var config in status.TargetChannels) { var channel = ChannelsManager.GetChannelObject(config.ChannelId); try { group.SourceChannelId = config.ChannelId; ChannelContext.Current.ClientContext = new ChannelClientContext(ClientState.Current.Context, config); Logger.Debug("Updating status. Channel = {0}", LogSource.BackgroundTask, config.DisplayName); if (config.IsConnected) { var data = String.Format("wrap_access_token={0}&channels={1}&inreplyto={2}&body={3}", CloudApi.AccessToken, config.ChannelKey, status.InReplyTo, HttpUtility.UrlEncode(status.Status)); HttpServiceRequest.Post(String.Concat(CloudApi.ApiBaseUrl, "send/statusupdate"), data, true); } else { channel.StatusUpdatesChannel.UpdateMyStatus(status.DuckCopy <ChannelStatusUpdate>()); } } catch (Exception ex) { ClientState.Current.ShowMessage( new AppMessage( String.Concat( String.Format(Strings.ErrorOccuredDuringStatusUpdate, channel.Configuration.DisplayName), String.Format(Strings.ServerSaid, ex.Message))) { SourceChannelId = config.ChannelId }, MessageType.Error); throw; } } Thread.CurrentThread.ExecuteOnUIThread(() => ClientState.Current.ShowMessage( new AppMessage(Strings.StatusUpdatedSuccessfully) { EntityId = status.StatusId, EntityType = EntityType.UserStatus }, MessageType.Success)); } finally { group.IsCompleted = true; } }