cryoflamer

Untitled

Jun 15th, 2018
727
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. info(#'Message'{id = Id, feed_id = Feed, from = From, to = To,
  2.     files = [#'Desc'{id = ID, payload = Payload, filename = Lang, mime = DMime} = ND | _], status = update}, Req,
  3.     #cx{params = ClientId, client_pid = C} = State) ->
  4.     PhoneId = case ClientId of
  5.                   <<"sys_bpe">> -> From;
  6.                   <<"emqttd_", _/binary>> -> roster:phone_id(ClientId);
  7.                   _ -> <<>>
  8.               end,
  9.     roster:info(?MODULE, "~p:~p:Message/update:", [PhoneId, To]),
  10.     roster:info(?MODULE, ":~P ~n", [Payload, 30]),
  11.     NMsg = case kvs:get('Message', Id) of
  12.                {ok, #'Message'{feed_id = Feed, files = Descs, seenby = Seen} = Msg} when Lang == [], ID /= [] ->
  13.                    NewDescs = case lists:keytake(ID, #'Desc'.id, Descs) of
  14.                                   false -> Descs;
  15.                                   {value, #'Desc'{info = RIds} = T, NDescs} ->
  16.                                       NDescs ++ [T#'Desc'{info = binary_delpart(RIds, PhoneId)}] end,
  17.                    Msg#'Message'{files = NewDescs};
  18.                {ok, #'Message'{feed_id = Feed, files = Descs, seenby = Seen} = Msg} when Seen /= [-1] ->
  19.                    Descs2 = lists:flatten(lists:foldr(
  20.                        fun(#'Desc'{info = I, mime = TMime, filename = <<_/integer, _/binary>> = TLang} = D, [Acc, ND2])
  21.                            when TMime =:= DMime ->
  22.                            case binary_delpart(I, PhoneId) of
  23.                                [] when I == [] -> [Acc, []];
  24.                                [] -> [Acc, ND2];
  25.                                I2 when TLang == Lang ->
  26.                                    [[D#'Desc'{info = <<I2/binary, ",", PhoneId/binary>>, payload = Payload} | Acc], []];
  27.                                I2 ->
  28.                                    [[D#'Desc'{info = I2, payload = Payload} | Acc], ND2] end;
  29.                            (D, [Acc, ND2]) -> [[D | Acc], ND2] end,
  30.                        {[], [ND#'Desc'{info = PhoneId}]}, Descs)),
  31.                    Msg#'Message'{files = Descs2};
  32.                _ -> {io, {error, message_not_found}, <<>>} end,
  33.     {reply, {bert, case NMsg of
  34.                        #'Message'{id = MID, feed_id = Feed0} = NM ->
  35.                            case kvs_stream:load_writer(Feed0) of
  36.                                #writer{cache = #'Message'{id = MID}} = W -> kvs_stream:save(W#writer{cache = NM});
  37.                                _ -> skip
  38.                            end,
  39.                            kvs:put(NM),
  40.                            n2o_vnode:send(C, case Feed0 of #muc{name = Name} -> _ =
  41.                                roster:room_topic(Name); #p2p{} = P2P -> roster:p2p_topic(P2P); _ ->
  42.                                <<>> end, term_to_binary(NM#'Message'{status = update})),
  43.                            <<>>;
  44.                        E -> E
  45.                    end}, Req, State};
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×