Closed iitrsachin closed 7 years ago
You can try adding this line in mod_rest:
--- a/mod_rest/src/mod_rest.erl
+++ b/mod_rest/src/mod_rest.erl
@@ -147,6 +147,7 @@ ip_matches(ClientIp, AllowedValues) ->
AllowedValues).
post_request(Stanza, From, To) ->
+ mod_mam:user_send_packet({Stanza, #{jid => From}}),
case ejabberd_router:route(From, To, Stanza) of
ok -> {200, [], <<"Ok">>};
_ -> {500, [], <<"Error">>}
Thank you Badlop for the quick reply.
I have added extra mod_mam:user_send_packet call but I am getting following error:
CRASH REPORT Process <0.4657.0> with 0 neighbours crashed with reason: call to undefined function mod_mam:user_send_packet({{xmlel,<"message">>,[{<<"to">>,<<"user1@localhost">},{<"from">>,<<"user2@localhost">}],[{...}]},...})
I am using ejabberd 16.12 and ejabberd.yml configuration is modules: mod_rest: allowed_ips:
AND mod_mam.hrl file is -record(archivemsg, {us = {<<"">>, <<"">>} :: {binary(), binary()} | '$2', id = <<>> :: binary() | '', timestamp = p1_timecompat:timestamp() :: erlang:timestamp() | '' | '$1', peer = {<<"">>, <<"">>, <<"">>} :: ljid() | '_' | '$3' | undefined, barepeer = {<<"">>, <<"">>, <<"">>} :: ljid() | '' | '$3', packet = #xmlel{} :: xmlel() | message() | '_', nick = <<"">> :: binary(), type = chat :: chat | groupchat}).
-record(archive_prefs, {us = {<<"">>, <<"">>} :: {binary(), binary()}, default = never :: never | always | roster, always = [] :: [ljid()], never = [] :: [ljid()]}).
@badlop : Please do the needful.
As you didn't mention what ejabberd version you are using, I supposed you use the one that I prefer :P
I've installed 16.12, and updated the patch accordingly. I've committed it to github. Update and confirm that it works correctly.
Hi Badlop, Again thank you for your effort. Now, I am not getting the previous errors but it is inserting only one row in the archive table. I am using wget to send the message. Response of wget command is
wget http://localhost:5280/rest/ --server-response
--post-data '<message to="user1@localhost" from="user2@localhost"><body>Hello World</body></message>'
--2017-02-24 00:05:10-- http://localhost:5280/rest/
Resolving localhost (localhost)... 127.0.0.1
Connecting to localhost (localhost)|127.0.0.1|:5280... connected.
HTTP request sent, awaiting response...
HTTP/1.1 200 OK
Content-Type: text/html; charset=utf-8
Content-Length: 2
Length: 2 [text/html]
Saving to: ‘index.html.62’
2017-02-24 00:05:10 (129 KB/s) - ‘index.html.62’ saved [2/2]
And database row is:
select * from archive\G;
*************************** 1. row ***************************
username: user2
timestamp: 1487874910904709
peer: user1@localhost
bare_peer: user1@localhost
xml: <message to='user1@localhost' from='user2@localhost' xmlns='jabber:client'><body>Hello World</body></message>
txt: Hello World
id: 1
kind: chat
nick:
created_at: 2017-02-24 00:05:10
1 row in set (0.00 sec)
@badlop : Please guide me If I am doing something wrong.
That query sends a message from user2 to user1. It immediately stores in "archive" that user2 sent the message, as you have confirmed.
If user1 is logged in, then he receives the message, and it gets stored in "archive" table also for user1.
But, if user1 is not connected, the message is awaiting in user1's offline storage (if you have mod_offline enabled). When user1 logins, he will receive the offline message (will be deleted from the "offline" table), and it will be stored in "archive".
Oh, I missed that. Wao It's working now.
Thank you Badlop to supporting me.👍
I want some suggestions from you. I am the beginner in ejabberd and erlang so how should I learn these things in a very good way and please suggest some good books.
Thanks & Regards Sachin Sharma
On Fri, Feb 24, 2017 at 12:31 AM, badlop notifications@github.com wrote:
That query sends a message from user2 to user1. It immediately stores in "archive" that user2 sent the message, as you have confirmed.
If user1 is logged in, then he receives the message, and it gets stored in "archive" table also for user1.
But, if user1 is not connected, the message is awaiting in user1's offline storage (if you have mod_offline enabled). When user1 logins, he will receive the offline message (will be deleted from the "offline" table), and it will be stored in "archive".
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/processone/ejabberd-contrib/issues/196#issuecomment-282087193, or mute the thread https://github.com/notifications/unsubscribe-auth/ANPfG5YpTGTFK16pXMkNZdm33pSHksudks5rfdeXgaJpZM4MFjCu .
I want some suggestions from you. I am the beginner in ejabberd and erlang so how should I learn these things in a very good way and please suggest some good books.
The only way to learn ejabberd is by examples: take the module which is very close to your task and learn how it's written. However, I'm about to write some guide on ejabberd code. Regarding Erlang books: this one is great in my opinion as well as this one (freely available).
Hi Guys,
I am using mod_rest module and it is working fine for me but creating only one row in archive table of ejabberd database. Can I populate two rows for both sender and receiver in archive table.