private async void MessageBox_Send(object sender, RoutedEventArgs e) { MessageUpsert mu = new MessageUpsert(); mu.Content = mbox.Text; // mu.Activity = new MessageActivity() { type = 3, party_id = "spotify:"+LocalModels.LocalState.CurrentUser.Id, session_id = Managers.GatewayManager.session }; await RESTCalls.CreateMessage(App.CurrentChannelId, mu); }
private async void SaveButton_Click(object sender, RoutedEventArgs e) { if (App.shareop != null) { if (shareContact != null) { if (shareContact.Id != null) { App.CurrentChannelId = shareContact.RemoteId; } } else { if (channelOption.SelectedItem != null) { App.CurrentChannelId = ((SimpleChannel)channelOption.SelectedItem).Id; } else { return; } } } ProgressViewer.Visibility = Visibility.Visible; RESTCalls.MessageUploadProgress += Session_MessageUploadProgress; FullUploadSize = 0; foreach (var file in attachements) { var props = await file.Value.GetBasicPropertiesAsync(); FullUploadSize = FullUploadSize + props.Size + 444; } FullUploadSize += Convert.ToUInt64(System.Text.Encoding.Unicode.GetByteCount(Editor.Text)); int attachCount = attachements.Count(); if (attachCount > 1) { FileNB.Visibility = Visibility.Visible; } string FileStr = App.GetString("/Dialogs/File"); for (int i = 0; i < attachCount; i++) { FileNB.Text = FileStr + " " + (i + 1) + "/" + attachCount; var file = attachements.ElementAt(i).Value; var props = await file.GetBasicPropertiesAsync(); //444 is an approximation of the http request overhead ulong overheadsize = 444; if (i == 0) { overheadsize += Convert.ToUInt64(System.Text.Encoding.Unicode.GetByteCount(Editor.Text)); } _fullBytesSentBuffer = _fullBytesSentBuffer + props.Size + overheadsize; _lockWaitState = false; progressBar.Value = 0; if (i == 0) { await RESTCalls.CreateMessage(App.CurrentChannelId, Editor.Text, file); } else { await RESTCalls.CreateMessage(App.CurrentChannelId, "", file); } } RESTCalls.MessageUploadProgress -= Session_MessageUploadProgress; if (App.shareop == null) { CloseButton_Click(null, null); } else { App.shareop.ReportCompleted(); } }
/// <summary> /// Send message post request /// </summary> private async void App_CreateMessageHandler(object sender, App.CreateMessageArgs e) { // TODO: Show pending message item till sent if (e.Message.Content.Length > 10000) // Too long { MessageDialog md = new MessageDialog("Sorry, but this message is way too long to be sent, even with Quarrel", "Over 10 000 characters?!"); await md.ShowAsync(); } else if (e.Message.Content.Length > 2000) // Too long for one message { // Show loading indicator MessagesLoading.Visibility = Visibility.Visible; //Split the message into <2000 char ones and send them individually IEnumerable <string> split = SplitToLines(e.Message.Content, 2000); int splitcount = split.Count(); if (splitcount < 10) { for (int i = 0; i < splitcount; i++) { // Get split message MessageUpsert splitmessage = new MessageUpsert { Content = split.ElementAt(i) }; if (i == splitcount) { splitmessage.file = e.Message.file; } // Send message Stopwatch sw = new Stopwatch(); sw.Start(); await RESTCalls.CreateMessage(e.ChannelId, splitmessage); sw.Stop(); //make sure to wait at least 500ms between each message if (sw.ElapsedMilliseconds < 500) { await Task.Delay(Convert.ToInt32(500 - sw.ElapsedMilliseconds)); } } } else { MessageDialog md = new MessageDialog("Sorry, but this message is way too long to be sent, even with Quarrel", "Wait, what?!"); await md.ShowAsync(); return; } // Hide loading indicator MessagesLoading.Visibility = Visibility.Collapsed; } else { //Just send the message await RESTCalls.CreateMessage(e.ChannelId, e.Message); } }