~singpolyma/biboumi

7f2127a7ea4c49fc1fbcd6cd6fb13e0265f4d841 — louiz’ 7 years ago 1090f3c
Add the archive ID to messages when they are sent to users

This makes us compatible with mam 6.0

fix #3249
M CHANGELOG.rst => CHANGELOG.rst +1 -0
@@ 10,6 10,7 @@ Version 5.0
   an IRC bouncer.
 - Use the udns library instead of c-ares, for asynchronous DNS resolution.
   It’s still fully optional.
 - Update MAM implementation to version 6.0 (namespace mam:2)

Version 4.1 - 2017-03-21
========================

M src/bridge/bridge.cpp => src/bridge/bridge.cpp +6 -5
@@ 254,15 254,16 @@ void Bridge::send_channel_message(const Iid& iid, const std::string& body)
      else
        irc->send_channel_message(iid.get_local(), line);

      std::string uuid;
#ifdef USE_DATABASE
      const auto xmpp_body = this->make_xmpp_body(line);
      if (this->record_history)
        Database::store_muc_message(this->get_bare_jid(), iid, std::chrono::system_clock::now(),
        uuid = Database::store_muc_message(this->get_bare_jid(), iid, std::chrono::system_clock::now(),
                                    std::get<0>(xmpp_body), irc->get_own_nick());
#endif
      for (const auto& resource: this->resources_in_chan[iid.to_tuple()])
        this->xmpp.send_muc_message(std::to_string(iid), irc->get_own_nick(),
                                    this->make_xmpp_body(line), this->user_jid + "/" + resource);
        this->xmpp.send_muc_message(std::to_string(iid), irc->get_own_nick(), this->make_xmpp_body(line),
                                    this->user_jid + "/" + resource, uuid);
    }
}



@@ 839,8 840,8 @@ void Bridge::send_message(const Iid& iid, const std::string& nick, const std::st
#endif
      for (const auto& resource: this->resources_in_chan[iid.to_tuple()])
        {
          this->xmpp.send_muc_message(std::to_string(iid), nick,
                                      this->make_xmpp_body(body, encoding), this->user_jid + "/" + resource);
          this->xmpp.send_muc_message(std::to_string(iid), nick, this->make_xmpp_body(body, encoding),
                                      this->user_jid + "/" + resource, {});

        }
    }

M src/database/database.cpp => src/database/database.cpp +9 -5
@@ 119,14 119,16 @@ db::IrcChannelOptions Database::get_irc_channel_options_with_server_and_global_d
  return coptions;
}

void Database::store_muc_message(const std::string& owner, const Iid& iid,
                                 Database::time_point date,
                                 const std::string& body,
                                 const std::string& nick)
std::string Database::store_muc_message(const std::string& owner, const Iid& iid,
                                        Database::time_point date,
                                        const std::string& body,
                                        const std::string& nick)
{
  db::MucLogLine line(*Database::db);

  line.uuid = Database::gen_uuid();
  auto uuid = Database::gen_uuid();

  line.uuid = uuid;
  line.owner = owner;
  line.ircChanName = iid.get_local();
  line.ircServerName = iid.get_server();


@@ 135,6 137,8 @@ void Database::store_muc_message(const std::string& owner, const Iid& iid,
  line.nick = nick;

  line.update();

  return uuid;
}

std::vector<db::MucLogLine> Database::get_muc_logs(const std::string& owner, const std::string& chan_name, const std::string& server,

M src/database/database.hpp => src/database/database.hpp +1 -1
@@ 50,7 50,7 @@ public:
                                                                                      const std::string& channel);
  static std::vector<db::MucLogLine> get_muc_logs(const std::string& owner, const std::string& chan_name, const std::string& server,
                                                  int limit=-1, const std::string& start="", const std::string& end="");
  static void store_muc_message(const std::string& owner, const Iid& iid,
  static std::string store_muc_message(const std::string& owner, const Iid& iid,
                                time_point date, const std::string& body, const std::string& nick);

  static void close();

M src/xmpp/xmpp_component.cpp => src/xmpp/xmpp_component.cpp +10 -1
@@ 380,7 380,7 @@ void XmppComponent::send_topic(const std::string& from, Xmpp::body&& topic, cons
  this->send_stanza(message);
}

void XmppComponent::send_muc_message(const std::string& muc_name, const std::string& nick, Xmpp::body&& xmpp_body, const std::string& jid_to)
void XmppComponent::send_muc_message(const std::string& muc_name, const std::string& nick, Xmpp::body&& xmpp_body, const std::string& jid_to, std::string uuid)
{
  Stanza message("message");
  message["to"] = jid_to;


@@ 402,6 402,15 @@ void XmppComponent::send_muc_message(const std::string& muc_name, const std::str
      // Pass the ownership of the pointer to this xmlnode
      html.add_child(std::move(std::get<1>(xmpp_body)));
    }

  if (!uuid.empty())
    {
      XmlSubNode stanza_id(message, "stanza-id");
      stanza_id["xmlns"] = STABLE_ID_NS;
      stanza_id["by"] = muc_name + "@" + this->served_hostname;
      stanza_id["id"] = std::move(uuid);
    }

  this->send_stanza(message);
}


M src/xmpp/xmpp_component.hpp => src/xmpp/xmpp_component.hpp +3 -1
@@ 33,6 33,7 @@
#define DATAFORM_NS      "jabber:x:data"
#define RSM_NS           "http://jabber.org/protocol/rsm"
#define MUC_TRAFFIC_NS   "http://jabber.org/protocol/muc#traffic"
#define STABLE_ID_NS     "urn:xmpp:sid:0"

/**
 * An XMPP component, communicating with an XMPP server using the protocole


@@ 134,7 135,8 @@ public:
  /**
   * Send a (non-private) message to the MUC
   */
  void send_muc_message(const std::string& muc_name, const std::string& nick, Xmpp::body&& body, const std::string& jid_to);
  void send_muc_message(const std::string& muc_name, const std::string& nick, Xmpp::body&& body, const std::string& jid_to,
                        std::string uuid);
  /**
   * Send a message, with a <delay/> element, part of a MUC history
   */

M tests/end_to_end/__main__.py => tests/end_to_end/__main__.py +6 -2
@@ 132,7 132,8 @@ def match(stanza, xpath):
                                            'rsm': 'http://jabber.org/protocol/rsm',
                                            'carbon': 'urn:xmpp:carbons:2',
                                            'hints': 'urn:xmpp:hints',
                                            'stanza': 'urn:ietf:params:xml:ns:xmpp-stanzas'})
                                            'stanza': 'urn:ietf:params:xml:ns:xmpp-stanzas',
                                            'stable_id': 'urn:xmpp:sid:0'})
    return matched




@@ 1483,7 1484,10 @@ if __name__ == '__main__':

                    # Send two channel messages
                    partial(send_stanza, "<message from='{jid_one}/{resource_one}' to='#foo%{irc_server_one}' type='groupchat'><body>coucou</body></message>"),
                    partial(expect_stanza, "/message[@from='#foo%{irc_server_one}/{nick_one}'][@to='{jid_one}/{resource_one}'][@type='groupchat']/body[text()='coucou']"),
                    partial(expect_stanza,
                            ("/message[@from='#foo%{irc_server_one}/{nick_one}'][@to='{jid_one}/{resource_one}'][@type='groupchat']/body[text()='coucou']",
                            "/message/stable_id:stanza-id[@by='#foo%{irc_server_one}'][@id]",)
                            ),

                    partial(send_stanza, "<message from='{jid_one}/{resource_one}' to='#foo%{irc_server_one}' type='groupchat'><body>coucou 2</body></message>"),
                    partial(expect_stanza, "/message[@from='#foo%{irc_server_one}/{nick_one}'][@to='{jid_one}/{resource_one}'][@type='groupchat']/body[text()='coucou 2']"),