anchor.diff:  
   %% TODO: Define some kind of a shaper to prevent floods and the GCM API to burn out :/
   %% Or this could be the limits, like 10 messages/user, 10 messages/hour, etc
  -%% TODO: Check subscription of the source
   message(From, To, Packet) ->
   	Type = xml:get_tag_attr_s(<<"type">>, Packet),
  +	?INFO_MSG("Offline message ~s", [From]),
   	case catch Type of 
   		"normal" -> ok;
   		_ ->
  -			%% strings
  +			%% Strings
   			JFrom = jlib:jid_to_string(From#jid{user = From#jid.user, server = From#jid.server, resource = <<"">>}),
   			JTo = jlib:jid_to_string(To#jid{user = To#jid.user, server = To#jid.server, resource = <<"">>}),
  +			ToUser = To#jid.user,
  +			ToServer = To#jid.server,
   
  -			%% Could be an error here when there's no body
  -			Msg = xml:get_tag_cdata(xml:get_subtag(Packet, <<"body">>)),
  -			Result = mnesia:dirty_read(gcm_users, {To#jid.user, To#jid.server}),
  -			case catch Result of 
  -				[] -> ?DEBUG("mod_gcm: No such record found for ~s", [JTo]);
  -				[#gcm_users{gcm_key = API_KEY}] ->
  -					Args = [{"registration_id", binary_to_list(API_KEY)}, {"data.message", Msg}, {"data.source", binary_to_list(JFrom)}, {"data.destination", binary_to_list(JTo)}],
  -					send(Args, binary_to_list(ejabberd_config:get_global_option(gcm_api_key, fun(V) -> V end)))
  -				end
  -			end.
  +			Body = xml:get_path_s(Packet, [{elem, <<"body">>}, cdata]),
  +
  +			%% Checking subscription
  +			{Subscription, _Groups} = 
  +				ejabberd_hooks:run_fold(roster_get_jid_info, ToServer, {none, []}, [ToUser, ToServer, From]),
  +			case Subscription of
  +				both ->
  +					case catch Body of
  +						<<>> -> ok; %% There is no body
  +						_ ->
  +							Result = mnesia:dirty_read(gcm_users, {ToUser, ToServer}),
  +							case catch Result of 
  +								[] -> ?DEBUG("mod_gcm: No such record found for ~s", [JTo]);
  +								[#gcm_users{gcm_key = API_KEY}] ->
  +									Args = [{"registration_id", API_KEY}, {"data.message", Body}, {"data.source", JFrom}, {"data.destination", JTo}],
  +									send(Args, ejabberd_config:get_global_option(gcm_api_key, fun(V) -> V end))
  +							end
  +						end;
  +					_ -> ok
  +			end
  +	end.
   
   
   iq(#jid{user = User, server = Server} = From, To, #iq{type = Type, sub_el = SubEl} = IQ) ->
  
positive.code: 
  -export([start/2, stop/1, message/3, iq/3]).
  
  
  %% 114196@stackoverflow
  escape_uri(S) when is_list(S) ->
      escape_uri(unicode:characters_to_binary(S));
  escape_uri(<<C:8, Cs/binary>>) when C >= $a, C =< $z ->
  
negative.code: hex_octet(N) ->
      [N - 10 + $a].
  
  
  url_encode(Data) ->
      url_encode(Data,"").
  
  