~ubuntu-branches/ubuntu/trusty/ejabberd/trusty-proposed

« back to all changes in this revision

Viewing changes to src/mod_muc/mod_muc_room.erl

  • Committer: Bazaar Package Importer
  • Author(s): Konstantin Khomoutov, Konstantin Khomoutov
  • Date: 2010-07-26 20:36:14 UTC
  • mfrom: (1.1.15 upstream)
  • Revision ID: james.westby@ubuntu.com-20100726203614-s3asj0k5ym3bxhdw
Tags: 2.1.4-1
[ Konstantin Khomoutov ]
* Do not prevent ejabberd_debug from being installed and used
  as this was implemented upstream as the default behavior.
* Add build dependency on erlang-parsetools.
* Add 'sharedscripts' option to logrotate config.
* Update VCS references in control file to point to git.deb.at.
* Add group sticky bit to permissions on the log directory --
  this should make log files owned by the group "adm".
* Explicitly set umask to 027 before starting erl.
* Add patch with fix for EJAB-953 (closes: #590389).
* Fix call to setup_ejabberd in postinst.
* Fix owner/permissions for log files when upgrading.
* Minor fixes and clarifications in ejabberdctl.8 manual page.
* Refresh reopen-log.patch

Show diffs side-by-side

added added

removed removed

Lines of Context:
593
593
%%          {stop, Reason, Reply, NewStateData}
594
594
%%----------------------------------------------------------------------
595
595
handle_sync_event({get_disco_item, JID, Lang}, _From, StateName, StateData) ->
596
 
    FAffiliation = get_affiliation(JID, StateData),
597
 
    FRole = get_role(JID, StateData),
598
 
    Tail =
599
 
        case ((StateData#state.config)#config.public_list == true) orelse
600
 
            (FRole /= none) orelse
601
 
            (FAffiliation == admin) orelse
602
 
            (FAffiliation == owner) of
603
 
            true ->
604
 
                Desc = case (StateData#state.config)#config.public of
605
 
                           true ->
606
 
                               "";
607
 
                           _ ->
608
 
                               translate:translate(Lang, "private, ")
609
 
                       end,
610
 
                Len = ?DICT:fold(fun(_, _, Acc) -> Acc + 1 end, 0,
611
 
                                 StateData#state.users),
612
 
                " (" ++ Desc ++ integer_to_list(Len) ++ ")";
613
 
            _ ->
614
 
                " (n/a)"
615
 
        end,
616
 
    Reply = case ((StateData#state.config)#config.public == true) orelse
617
 
                (FRole /= none) orelse
618
 
                (FAffiliation == admin) orelse
619
 
                (FAffiliation == owner) of
 
596
    case (StateData#state.config)#config.public_list of
 
597
        true ->
 
598
            Reply = get_roomdesc_reply(StateData,
 
599
                                       get_roomdesc_tail(StateData, Lang)),
 
600
            {reply, Reply, StateName, StateData};
 
601
        _ ->
 
602
            case is_occupant_or_admin(JID, StateData) of
620
603
                true ->
621
 
                    {item, get_title(StateData) ++ Tail};
 
604
                    Reply = get_roomdesc_reply(StateData, get_roomdesc_tail(
 
605
                                                            StateData, Lang)),
 
606
                    {reply, Reply, StateName, StateData};
622
607
                _ ->
623
 
                    false
624
 
            end,
625
 
    {reply, Reply, StateName, StateData};
 
608
                    {reply, false, StateName, StateData}
 
609
            end
 
610
    end;
626
611
handle_sync_event(get_config, _From, StateName, StateData) ->
627
612
    {reply, {ok, StateData#state.config}, StateName, StateData};
628
613
handle_sync_event(get_state, _From, StateName, StateData) ->
1000
985
    LJID = jlib:jid_tolower(JID),
1001
986
    ?DICT:is_key(LJID, StateData#state.users).
1002
987
 
 
988
%% Check if the user is occupant of the room, or at least is an admin or owner.
 
989
is_occupant_or_admin(JID, StateData) ->
 
990
    FAffiliation = get_affiliation(JID, StateData),
 
991
    FRole = get_role(JID, StateData),
 
992
    case (FRole /= none) orelse
 
993
        (FAffiliation == admin) orelse
 
994
        (FAffiliation == owner) of
 
995
        true ->
 
996
            true;
 
997
        _ ->
 
998
            false
 
999
    end.
1003
1000
 
1004
1001
%%%
1005
1002
%%% Handle IQ queries of vCard
3329
3326
    {error, ?ERR_NOT_ALLOWED};
3330
3327
 
3331
3328
process_iq_disco_items(From, get, _Lang, StateData) ->
3332
 
    FAffiliation = get_affiliation(From, StateData),
3333
 
    FRole = get_role(From, StateData),
3334
 
    case ((StateData#state.config)#config.public_list == true) orelse
3335
 
        (FRole /= none) orelse
3336
 
        (FAffiliation == admin) orelse
3337
 
        (FAffiliation == owner) of
 
3329
    case (StateData#state.config)#config.public_list of
3338
3330
        true ->
3339
 
            UList =
3340
 
                lists:map(
3341
 
                  fun({_LJID, Info}) ->
3342
 
                          Nick = Info#user.nick,
3343
 
                          {xmlelement, "item",
3344
 
                           [{"jid", jlib:jid_to_string(
3345
 
                                      {StateData#state.room,
3346
 
                                       StateData#state.host,
3347
 
                                       Nick})},
3348
 
                            {"name", Nick}], []}
3349
 
                  end,
3350
 
                  ?DICT:to_list(StateData#state.users)),
3351
 
            {result, UList, StateData};
 
3331
            {result, get_mucroom_disco_items(StateData), StateData};
3352
3332
        _ ->
3353
 
            {error, ?ERR_FORBIDDEN}
 
3333
            case is_occupant_or_admin(From, StateData) of
 
3334
                true ->
 
3335
                    {result, get_mucroom_disco_items(StateData), StateData};
 
3336
                _ ->
 
3337
                    {error, ?ERR_FORBIDDEN}
 
3338
            end
3354
3339
    end.
3355
3340
 
3356
3341
process_iq_captcha(_From, get, _Lang, _SubEl, _StateData) ->
3372
3357
            Name
3373
3358
    end.
3374
3359
 
 
3360
get_roomdesc_reply(StateData, Tail) ->
 
3361
    case ((StateData#state.config)#config.public == true) of
 
3362
        true ->
 
3363
            {item, get_title(StateData) ++ Tail};
 
3364
        _ ->
 
3365
            false
 
3366
    end.
 
3367
 
 
3368
get_roomdesc_tail(StateData, Lang) ->
 
3369
    Desc = case (StateData#state.config)#config.public of
 
3370
               true ->
 
3371
                   "";
 
3372
               _ ->
 
3373
                   translate:translate(Lang, "private, ")
 
3374
           end,
 
3375
    Len = ?DICT:fold(fun(_, _, Acc) -> Acc + 1 end, 0, StateData#state.users),
 
3376
    " (" ++ Desc ++ integer_to_list(Len) ++ ")".
 
3377
 
 
3378
get_mucroom_disco_items(StateData) ->
 
3379
    lists:map(
 
3380
      fun({_LJID, Info}) ->
 
3381
              Nick = Info#user.nick,
 
3382
              {xmlelement, "item",
 
3383
               [{"jid", jlib:jid_to_string({StateData#state.room,
 
3384
                                            StateData#state.host, Nick})},
 
3385
                {"name", Nick}], []}
 
3386
      end,
 
3387
      ?DICT:to_list(StateData#state.users)).
3375
3388
 
3376
3389
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3377
3390
% Invitation support