ejabberd - Comments for "Retrieve chat room history from a module" https://www.ejabberd.im/forum/28603/retrieve-chat-room-history-module en Why the select/6 function was https://www.ejabberd.im/forum/28603/retrieve-chat-room-history-module#comment-67755 <p>Why the select/6 function was not export by default in <strong>mod_mam</strong> module? Is there any benefits in use this function instead of access directly the database?</p> Mon, 15 Jan 2018 14:39:38 +0000 fernando-matos comment 67755 at https://www.ejabberd.im Solved and glad to have a https://www.ejabberd.im/forum/28603/retrieve-chat-room-history-module#comment-67201 <p>Solved and glad to have a working solution now.<br /> I have used your hints reported above and I have figured how can I use SELECT without altering the official tree or exporting other functions from these modules.<br /> I have detected the inner mod_mam_* used to deal with the db (mod_mam_sql in my case) and used it direcly from my code, I have reported details on this topic in the issues available on github as well (<noindex><a href="https://github.com/processone/ejabberd/issues/1383" rel="nofollow" >here</a></noindex>) and closed the problem.<br /> Code is helpful, thanks</p> Fri, 25 Nov 2016 08:58:17 +0000 andrea comment 67201 at https://www.ejabberd.im mod_mam has the function https://www.ejabberd.im/forum/28603/retrieve-chat-room-history-module#comment-67193 <p>mod_mam has the function select_and_send that searches in the database the matching messages and directly routes them to the corresponding user. Check what arguments are used inside it, and what is returned (you can add debug lines that print arguments and variables, then trigger that function using a Jabber client, and so you get internal details.</p> <p>First of all, export the select/5 function adding this line, recompile, reinstall and restart:</p> <pre> diff --git a/src/mod_mam.erl b/src/mod_mam.erl index f9ef104..cbb8ca6 100644 --- a/src/mod_mam.erl +++ b/src/mod_mam.erl @@ -33,6 +33,7 @@ %% API -export([start/2, stop/1, depends/2]). +-export([select/5]). -export([user_send_packet/4, user_send_packet_strip_tag/4, user_receive_packet/5, process_iq_v0_2/1, process_iq_v0_3/1, disco_sm_features/5, remove_user/2, remove_room/3, mod_opt_type/1, muc_process_iq/2, </pre><p> Then I can run this call:</p> <pre> mod_mam:select( &lt;&lt;"localhost"&gt;&gt;, {jid,&lt;&lt;"user1"&gt;&gt;,&lt;&lt;"localhost"&gt;&gt;,&lt;&lt;"tka1"&gt;&gt;,&lt;&lt;"user1"&gt;&gt;,&lt;&lt;"localhost"&gt;&gt;,&lt;&lt;"tka1"&gt;&gt;}, {jid,&lt;&lt;"user1"&gt;&gt;,&lt;&lt;"localhost"&gt;&gt;,&lt;&lt;"tka1"&gt;&gt;,&lt;&lt;"user1"&gt;&gt;,&lt;&lt;"localhost"&gt;&gt;,&lt;&lt;"tka1"&gt;&gt;}, {mam_query,&lt;&lt;"urn:xmpp:mam:1"&gt;&gt;,&lt;&lt;"f27"&gt;&gt;,undefined,undefined,undefined,undefined, {rsm_set,undefined,undefined,undefined,undefined,undefined,undefined,50}, undefined},chat). </pre><p>and I get this result:</p> <pre> {[{&lt;&lt;"1479721806878830"&gt;&gt;,1479721806878830, {forwarded,{delay,{1479,721806,878830}, {jid,&lt;&lt;&gt;&gt;,&lt;&lt;"localhost"&gt;&gt;,&lt;&lt;&gt;&gt;,&lt;&lt;&gt;&gt;,&lt;&lt;"localhost"&gt;&gt;,&lt;&lt;&gt;&gt;}, &lt;&lt;&gt;&gt;}, [{xmlel,&lt;&lt;"message"&gt;&gt;, [{&lt;&lt;"xml:lang"&gt;&gt;,&lt;&lt;"es"&gt;&gt;}, {&lt;&lt;"to"&gt;&gt;,&lt;&lt;"user2@localhost"&gt;&gt;}, {&lt;&lt;"from"&gt;&gt;,&lt;&lt;"user1@localhost/tka1"&gt;&gt;}, {&lt;&lt;"type"&gt;&gt;,&lt;&lt;"chat"&gt;&gt;}, {&lt;&lt;"id"&gt;&gt;,&lt;&lt;"255:457805"&gt;&gt;}, {&lt;&lt;"xmlns"&gt;&gt;,&lt;&lt;"jabber:client"&gt;&gt;}], [{xmlel,&lt;&lt;"body"&gt;&gt;,[],[{xmlcdata,&lt;&lt;"aaa"&gt;&gt;}]}]}]}}, {&lt;&lt;"1479721808024066"&gt;&gt;,1479721808024066, {forwarded,{delay,{1479,721808,24066}, {jid,&lt;&lt;&gt;&gt;,&lt;&lt;"localhost"&gt;&gt;,&lt;&lt;&gt;&gt;,&lt;&lt;&gt;&gt;,&lt;&lt;"localhost"&gt;&gt;,&lt;&lt;&gt;&gt;}, &lt;&lt;&gt;&gt;}, [{xmlel,&lt;&lt;"message"&gt;&gt;, [{&lt;&lt;"xml:lang"&gt;&gt;,&lt;&lt;"es"&gt;&gt;}, {&lt;&lt;"to"&gt;&gt;,&lt;&lt;"user2@localhost"&gt;&gt;}, {&lt;&lt;"from"&gt;&gt;,&lt;&lt;"user1@localhost/tka1"&gt;&gt;}, {&lt;&lt;"type"&gt;&gt;,&lt;&lt;"chat"&gt;&gt;}, {&lt;&lt;"id"&gt;&gt;,&lt;&lt;"256:336062"&gt;&gt;}, {&lt;&lt;"xmlns"&gt;&gt;,&lt;&lt;"jabber:client"&gt;&gt;}], [{xmlel,&lt;&lt;"body"&gt;&gt;,[],[{xmlcdata,&lt;&lt;"sss"&gt;&gt;}]}]}]}}], true,2} </pre> Mon, 21 Nov 2016 10:13:48 +0000 badlop comment 67193 at https://www.ejabberd.im