IRCQuery.cpp 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. /*
  2. * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include "IRCQuery.h"
  7. #include "IRCClient.h"
  8. #include <stdio.h>
  9. IRCQuery::IRCQuery(IRCClient& client, const String& name)
  10. : m_client(client)
  11. , m_name(name)
  12. , m_log(IRCLogBuffer::create())
  13. {
  14. m_window = m_client->aid_create_window(this, IRCWindow::Query, m_name);
  15. m_window->set_log_buffer(*m_log);
  16. }
  17. IRCQuery::~IRCQuery()
  18. {
  19. }
  20. NonnullRefPtr<IRCQuery> IRCQuery::create(IRCClient& client, const String& name)
  21. {
  22. return adopt_ref(*new IRCQuery(client, name));
  23. }
  24. void IRCQuery::add_message(char prefix, const String& name, const String& text, Color color)
  25. {
  26. log().add_message(prefix, name, text, color);
  27. window().did_add_message(name, text);
  28. }
  29. void IRCQuery::add_message(const String& text, Color color)
  30. {
  31. log().add_message(text, color);
  32. window().did_add_message();
  33. }
  34. void IRCQuery::say(const String& text)
  35. {
  36. m_client->send_privmsg(m_name, text);
  37. add_message(' ', m_client->nickname(), text);
  38. }