2016年1月14日星期四

Offline Message Push Notification Module for Ejabberd, Test on ejabberd-15.11

Recently I need a offline push notification on ejabberd server for iOS and Android remote notification, after a sets of google and try I found the following solution, it works fine on jabberd-15.11, hope it helpful for somebody.

You should save the following code to a file and put it into ejabberd source code folder ejabberd-15.11/src/mod_offline_push.erl


%% name of module must match file name
-module(mod_offline_push).

-author("guangmean").

%% Every ejabberd module implements the gen_mod behavior
%% The gen_mod behavior requires two functions: start/2 and stop/1
-behaviour(gen_mod).

%% public methods for this module
-export([start/2, stop/1, message_push/3]).

%% included for writing to ejabberd log file
-include("ejabberd.hrl").
-include("logger.hrl"). 

%% ejabberd functions for JID manipulation called jlib.
-include("jlib.hrl").

start(Host, Opts) -> 
        ?INFO_MSG("Loading offline message push mode", []),
        ejabberd_hooks:add(offline_message_hook, Host, ?MODULE, message_push, 3).   

stop(Host) -> 
        ?INFO_MSG("Stoping offline message push mode", []),
        ejabberd_hooks:delete(offline_message_hook, Host, ?MODULE, message_push, 3).

message_push(From, To, Packet) ->
        MessageType = xml:get_tag_attr_s(<<"type">>, Packet),
        MessageFrom = xml:get_tag_attr_s(<<"from">>, Packet),
        MessageTo = xml:get_tag_attr_s(<<"to">>, Packet),
        curl_request_push(MessageFrom, MessageTo),
    ok.

curl_request_push(From, To) ->
        ?INFO_MSG("Pushing notify From ~p To ~p~n",[From, To]),
    httpc:request(post, {"http://fullstacking.blogspot.com", [], "application/x-www-form-urlencoded", list_to_binary(["from=", From, "&to=", To])}, [], []).



Compile ejabberd:
./configure --prefix=/your/ejabberd/install/path/ejabberd-15.11
make
make install

MySQL存储Emoji表情

Problems with utf8 character set, should use utf8mb4

Apply to whole table:
ALTER TABLE table_name CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_bin

Or apply to a column
ALTER TABLE table_name CHANGE column_name VARCHAR(60) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin