ejabberd - Comments for "mod_admin_extra" https://www.ejabberd.im/node/3267 en Patch committed with changes https://www.ejabberd.im/node/3267#comment-53730 <p>I've committed your patch with some changes: the command names are send_message_chat and send_message_headline.</p> Mon, 10 Nov 2008 10:43:01 +0000 mfoss comment 53730 at https://www.ejabberd.im Patch. For interested :-) https://www.ejabberd.im/node/3267#comment-53721 <p>Hi!</p> <p>Thanks for Your advice! It helped!<br /> I've created a small patch, leaving functionality for headline messages as <code>send_headline</code>, and changed <code>send_message</code> syntax, removing 'Subject'-field.<br /> I really do not know, how it corresponds to XMPP and other standards, but I found such a function useful for me. Maybe I'm not alone :-)))<br /> So, patch was created for ejabberd-modules SVN version 815.<br /> It's a pity, but simple copying of code doesn't work :-)) because of text transformations while posting so, You have 2 ways:<br /> 1) see the changes, and make them manually<br /> or<br /> 2) download it from<br /> <noindex><a href="http://rapidshare.com/files/161264241/mod_admin_extra_send_message.patch.html" title="http://rapidshare.com/files/161264241/mod_admin_extra_send_message.patch.html" rel="nofollow" >http://rapidshare.com/files/161264241/mod_admin_extra_send_message.patch...</a></noindex><br /> or<br /> <noindex><a href="http://www.megaupload.com/?d=N2D3CJ9J" title="http://www.megaupload.com/?d=N2D3CJ9J" rel="nofollow" >http://www.megaupload.com/?d=N2D3CJ9J</a></noindex><br /> filesize: 5234 bytes<br /> md5: e732d580274029182f13a076628bf3d7)</p> <div class="codeblock"><code>--- mod_admin_extra.erl Thu Nov&nbsp; 6 12:53:49 2008<br />+++ /home/misc/trunk/src/mod_admin_extra.erl Thu Nov&nbsp; 6 13:24:28 2008<br />@@ -71,7 +71,8 @@<br /> srg_user_add/4,<br /> srg_user_del/4,<br /> %% Stanza<br />- send_message/4,<br />+ send_headline/4,<br />+ send_message/3,<br /> %% Stats<br /> stats/1, stats/2<br /> ]).<br />@@ -380,13 +381,19 @@<br /> args = [{user, string}, {host, string}, {group, string}, {grouphost, string}],<br /> result = {res, rescode}},<br />-&nbsp;&nbsp;&nbsp;&nbsp; #ejabberd_commands{name = send_message, tags = [stanza],<br />+&nbsp;&nbsp;&nbsp;&nbsp; #ejabberd_commands{name = send_headline, tags = [stanza],<br /> desc = &quot;Send a headline message to a local or remote bare of full JID&quot;,<br />- module = ?MODULE, function = send_message,<br />+ module = ?MODULE, function = send_headline,<br /> args = [{from, string}, {to, string},<br /> {subject, string}, {body, string}],<br /> result = {res, rescode}},<br />+&nbsp;&nbsp;&nbsp;&nbsp; #ejabberd_commands{name = send_message, tags = [stanza],<br />+ desc = &quot;Send a chat message to a local or remote bare of full JID&quot;,<br />+ module = ?MODULE, function = send_message,<br />+ args = [{from, string}, {to, string}, {body, string}],<br />+ result = {res, rescode}},<br />+<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; #ejabberd_commands{name = stats, tags = [stats],<br /> desc = &quot;Get statistical value: registeredusers onlineusers onlineusersnode uptimeseconds&quot;,<br /> module = ?MODULE, function = stats,<br />@@ -1007,49 +1014,92 @@<br /> %%% Stanza<br /> %%%<br />-%% @doc Send a message to a Jabber account.<br />+%% @doc Send a (headline) message to a Jabber account.<br /> %% If a resource was specified in the JID,<br />-%% the message is sent only to that specific resource.<br />+%% the (headline) message is sent only to that specific resource.<br /> %% If no resource was specified in the JID,<br /> %% and the user is remote or local but offline,<br />-%% the message is sent to the bare JID.<br />+%% the (headline) message is sent to the bare JID.<br /> %% If the user is local and is online in several resources,<br />-%% the message is sent to all its resources.<br />-send_message(FromJIDString, ToJIDString, Subject, Body) -&gt;<br />+%% the (headline) message is sent to all its resources.<br />+send_headline(FromJIDString, ToJIDString, Subject, Body) -&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp; FromJID = jlib:string_to_jid(FromJIDString),<br />&nbsp;&nbsp;&nbsp;&nbsp; ToJID = jlib:string_to_jid(ToJIDString),<br />&nbsp;&nbsp;&nbsp;&nbsp; ToUser = ToJID#jid.user,<br />&nbsp;&nbsp;&nbsp;&nbsp; ToServer = ToJID#jid.server,<br />&nbsp;&nbsp;&nbsp;&nbsp; case ToJID#jid.resource of<br /> &quot;&quot; -&gt;<br />- &nbsp;&nbsp;&nbsp; send_message(FromJID, ToUser, ToServer, Subject, Body);<br />+ &nbsp;&nbsp;&nbsp; send_headline(FromJID, ToUser, ToServer, Subject, Body);<br /> Resource -&gt;<br />- &nbsp;&nbsp;&nbsp; send_message(FromJID, ToUser, ToServer, Resource, Subject, Body)<br />+ &nbsp;&nbsp;&nbsp; send_headline(FromJID, ToUser, ToServer, Resource, Subject, Body)<br />&nbsp;&nbsp;&nbsp;&nbsp; end.<br />-send_message(FromJID, ToUser, ToServer, Subject, Body) -&gt;<br />+send_headline(FromJID, ToUser, ToServer, Subject, Body) -&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp; case ejabberd_sm:get_user_resources(ToUser, ToServer) of<br /> [] -&gt;<br />- &nbsp;&nbsp;&nbsp; send_message(FromJID, ToUser, ToServer, &quot;&quot;, Subject, Body);<br />+ &nbsp;&nbsp;&nbsp; send_headline(FromJID, ToUser, ToServer, &quot;&quot;, Subject, Body);<br /> ToResources -&gt;<br /> &nbsp;&nbsp;&nbsp; lists:foreach(<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; fun(ToResource) -&gt;<br />- &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; send_message(FromJID, ToUser, ToServer, ToResource, Subject, Body)<br />+ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; send_headline(FromJID, ToUser, ToServer, ToResource, Subject, Body)<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; end,<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ToResources)<br />&nbsp;&nbsp;&nbsp;&nbsp; end.<br />-send_message(FromJID, ToU, ToS, ToR, Subject, Body) -&gt;<br />-&nbsp;&nbsp;&nbsp; MPacket = build_send_message(Subject, Body),<br />+send_headline(FromJID, ToU, ToS, ToR, Subject, Body) -&gt;<br />+&nbsp;&nbsp;&nbsp; MPacket = build_send_headline(Subject, Body),<br />&nbsp;&nbsp;&nbsp;&nbsp; ToJID = jlib:make_jid(ToU, ToS, ToR),<br />&nbsp;&nbsp;&nbsp;&nbsp; ejabberd_router:route(FromJID, ToJID, MPacket).<br />-build_send_message(Subject, Body) -&gt;<br />+build_send_headline(Subject, Body) -&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp; {xmlelement, &quot;message&quot;,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; [{&quot;type&quot;, &quot;headline&quot;}],<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; [{xmlelement, &quot;subject&quot;, [], [{xmlcdata, Subject}]},<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {xmlelement, &quot;body&quot;, [], [{xmlcdata, Body}]}<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ]<br />+&nbsp;&nbsp;&nbsp; }.<br />+<br />+%% @doc Send a (chat) message to a Jabber account.<br />+%% If a resource was specified in the JID,<br />+%% the (chat) message is sent only to that specific resource.<br />+%% If no resource was specified in the JID,<br />+%% and the user is remote or local but offline,<br />+%% the (chat) message is sent to the bare JID.<br />+%% If the user is local and is online in several resources,<br />+%% the (chat) message is sent to all its resources.<br />+send_message(FromJIDString, ToJIDString, Body) -&gt;<br />+&nbsp;&nbsp;&nbsp; FromJID = jlib:string_to_jid(FromJIDString),<br />+&nbsp;&nbsp;&nbsp; ToJID = jlib:string_to_jid(ToJIDString),<br />+&nbsp;&nbsp;&nbsp; ToUser = ToJID#jid.user,<br />+&nbsp;&nbsp;&nbsp; ToServer = ToJID#jid.server,<br />+&nbsp;&nbsp;&nbsp; case ToJID#jid.resource of<br />+ &quot;&quot; -&gt;<br />+ &nbsp;&nbsp;&nbsp; send_message(FromJID, ToUser, ToServer, Body);<br />+ Resource -&gt;<br />+ &nbsp;&nbsp;&nbsp; send_message(FromJID, ToUser, ToServer, Resource, Body)<br />+&nbsp;&nbsp;&nbsp; end.<br />+<br />+send_message(FromJID, ToUser, ToServer, Body) -&gt;<br />+&nbsp;&nbsp;&nbsp; case ejabberd_sm:get_user_resources(ToUser, ToServer) of<br />+ [] -&gt;<br />+ &nbsp;&nbsp;&nbsp; send_message(FromJID, ToUser, ToServer, &quot;&quot;, Body);<br />+ ToResources -&gt;<br />+ &nbsp;&nbsp;&nbsp; lists:foreach(<br />+ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; fun(ToResource) -&gt;<br />+ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; send_message(FromJID, ToUser, ToServer, ToResource, Body)<br />+ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; end,<br />+ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ToResources)<br />+&nbsp;&nbsp;&nbsp; end.<br />+<br />+send_message(FromJID, ToU, ToS, ToR, Body) -&gt;<br />+&nbsp;&nbsp;&nbsp; MPacket = build_send_message(Body),<br />+&nbsp;&nbsp;&nbsp; ToJID = jlib:make_jid(ToU, ToS, ToR),<br />+&nbsp;&nbsp;&nbsp; ejabberd_router:route(FromJID, ToJID, MPacket).<br />+<br />+build_send_message(Body) -&gt;<br />+&nbsp;&nbsp;&nbsp; {xmlelement, &quot;message&quot;,<br />+&nbsp;&nbsp;&nbsp;&nbsp; [{&quot;type&quot;, &quot;chat&quot;}],<br />+&nbsp;&nbsp;&nbsp;&nbsp; [{xmlelement, &quot;body&quot;, [], [{xmlcdata, Body}]}]<br />&nbsp;&nbsp;&nbsp;&nbsp; }.</code></div> <p>Then, put the file to <code>[svn]/ejabberd-modules/mod_admin_extra/trunk/src</code>,<br /> run <code>patch -p0 &lt; FILE</code>,<br /> and rebuild module.</p> <p>If <code>mod_admin_extra</code>-developers consider this function corresponds all standards, users' demand and their own ideology, and they suggest to implement it in native code, it would be very nice :-)))</p> <p>Thanks.</p> Thu, 06 Nov 2008 18:40:12 +0000 xyu comment 53721 at https://www.ejabberd.im ejabberd doesn't store "headline"; try change to send "normal" https://www.ejabberd.im/node/3267#comment-53715 <div class="quote-msg"> <div class="quote-author"><em>xyu</em> wrote:</div> <p>the <code>send_message</code> doesn't post messages to offline contacts</p></div> <p>send_message is described: "Send a headline message to a local or remote bare of full JID". So, this command sends a message stanza of type "headline". </p> <p>As explained in <noindex><a href="http://xmpp.org/internet-drafts/draft-saintandre-rfc3921bis-07.html#message-syntax-type" rel="nofollow" >XMPP-IM 5.2.2. Type Attribute</a></noindex>:</p> <div class="quote-msg"> <div class="quote-author">Quote:</div> <p>headline -- The message provides an alert, a notification, or other information to which no reply is expected (e.g., news headlines, sports updates, near-real-time market data, and syndicated content). Because <strong>no reply to the message is expected</strong>, typically a receiving client will present a message of type "headline" in an interface that appropriately differentiates the message from standalone messages, chat messages, or groupchat messages (e.g., by not providing the recipient with the ability to reply). The receiving server SHOULD deliver the message to all of the recipient's available resources. </p></div> <p><noindex><a href="http://xmpp.org/internet-drafts/draft-saintandre-rfc3921bis-07.html#rules-barejid-noresource-message" rel="nofollow" >XMPP-IM 8.3.2.1. Message</a></noindex> explains regarding offline storage:</p> <div class="quote-msg"> <div class="quote-author">Quote:</div> <p>For a message stanza of type "headline", according to local service policies the server MUST either (1) add the message to offline storage or (2) silently discard the message (i.e., neither deliver it to the intended recipient nor return an error to the sender).</p></div> <p>So ejabberd implements (2) and this is compliant with the protocol.</p> <p>You would like it to implement (1), but it doesn't.</p> <p>Another solution is to send a message stanza of type "normal":</p> <div class="quote-msg"> <div class="quote-author">Quote:</div> <p>For a message stanza of type "chat" or "normal", the server SHOULD add the message to offline storage or forward the message to the user via a non-XMPP messaging system (e.g., to the user's email account).</p></div> <p>In this case, if mod_offline is enabled, it will be used.</p> <p>To send a message of type "normal", replace this function with this code:</p> <pre>build_send_message(Subject, Body) -&gt; {xmlelement, "message", [], [{xmlelement, "subject", [], [{xmlcdata, Subject}]}, {xmlelement, "body", [], [{xmlcdata, Body}]} ] }.</pre> Sun, 02 Nov 2008 22:35:09 +0000 mfoss comment 53715 at https://www.ejabberd.im