You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

FeedbackSender.java 3.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /*
  2. * Copyright (c) 2006-2017 DMDirc Developers
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
  5. * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
  6. * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
  7. * permit persons to whom the Software is furnished to do so, subject to the following conditions:
  8. *
  9. * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
  10. * Software.
  11. *
  12. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  13. * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS
  14. * OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  15. * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  16. */
  17. package com.dmdirc.ui.core.feedback;
  18. import com.dmdirc.events.StatusBarMessageEvent;
  19. import com.dmdirc.events.eventbus.EventBus;
  20. import com.dmdirc.interfaces.config.AggregateConfigProvider;
  21. import com.dmdirc.ui.StatusMessage;
  22. import com.dmdirc.util.io.Downloader;
  23. import java.io.IOException;
  24. import java.util.HashMap;
  25. import java.util.List;
  26. import java.util.Map;
  27. /**
  28. * Sends feedback back to the developers.
  29. */
  30. public class FeedbackSender implements Runnable {
  31. private final Map<String, String> postData;
  32. private final EventBus eventBus;
  33. private final AggregateConfigProvider config;
  34. private final Downloader downloader;
  35. public FeedbackSender(
  36. final AggregateConfigProvider config,
  37. final Downloader downloader,
  38. final EventBus eventBus,
  39. final String name,
  40. final String email,
  41. final String feedback,
  42. final String version,
  43. final String serverInfo,
  44. final String dmdircInfo) {
  45. this.downloader = downloader;
  46. this.config = config;
  47. this.eventBus = eventBus;
  48. this.postData = new HashMap<>(6);
  49. if (!name.isEmpty()) {
  50. postData.put("name", name);
  51. }
  52. if (!email.isEmpty()) {
  53. postData.put("email", email);
  54. }
  55. if (!feedback.isEmpty()) {
  56. postData.put("feedback", feedback);
  57. }
  58. if (!version.isEmpty()) {
  59. postData.put("version", version);
  60. }
  61. if (!serverInfo.isEmpty()) {
  62. postData.put("serverInfo", serverInfo);
  63. }
  64. if (!dmdircInfo.isEmpty()) {
  65. postData.put("dmdircInfo", dmdircInfo);
  66. }
  67. }
  68. /**
  69. * Sends the error data to the server appending returned information to the global error
  70. * variable.
  71. *
  72. * @param postData Feedback data to send
  73. */
  74. private String sendData(final Map<String, String> postData) {
  75. try {
  76. final List<String> response = downloader.getPage(
  77. "https://feedback.dmdirc.com/dialog/", postData);
  78. if (response.isEmpty()) {
  79. return "Feedback failure: Unknown response from the server.";
  80. } else {
  81. return response.get(0);
  82. }
  83. } catch (IOException ex) {
  84. return "Feedback failure: " + ex.getMessage();
  85. }
  86. }
  87. @Override
  88. public void run() {
  89. eventBus.publishAsync(new StatusBarMessageEvent(
  90. new StatusMessage(sendData(postData), config)));
  91. }
  92. }