~phablet-team/messaging-framework/maintain-connection-state

« back to all changes in this revision

Viewing changes to src/messaging/qt/tp/text_channel.cpp

  • Committer: Tarmac
  • Author(s): Roberto Mier Escandon
  • Date: 2016-08-16 15:59:06 UTC
  • mfrom: (50.3.14 group-own-permissions)
  • Revision ID: tarmac-20160816155906-4t6hzw1055mr0450
Added flags generic type
Added permissions flags for groups in group_manager, so that every plugin has to fill them with the ones the current user has as participant in the group

NOTE: this MR should be landed along with https://code.launchpad.net/~ningbo-team/ningbo/group-own-permissions/+merge/302308.

Approved by system-apps-ci-bot, Tiago Salem Herrmann.

Show diffs side-by-side

added added

removed removed

Lines of Context:
214
214
        });
215
215
}
216
216
 
 
217
void mqt::tp::TextChannel::Observer::on_group_permissions_changed(const Flags<GroupPermissions> &permissions)
 
218
{
 
219
    auto thiz = shared_from_this();
 
220
    runtime->enter_with_task([thiz, permissions]() {
 
221
            thiz->tc->on_group_permissions_changed(permissions);
 
222
        });
 
223
}
 
224
 
217
225
void mqt::tp::TextChannel::Observer::on_file_receiving(const std::string& id, uint received_size, uint total_size)
218
226
{
219
227
    // TODO: notify telepathy about the progress of the file being downloaded
339
347
        }
340
348
 
341
349
        room_config_interface->setConfigurationRetrieved(true);
342
 
        room_config_interface->setCanUpdateConfiguration(true);
 
350
        // FIXME (rmescandon): as telepathy does not offer a way to differentiate whether it can be changed one configuration element
 
351
        // or other, let's use the flag to enable/dissable all configuration properties permissions by now
 
352
        room_config_interface->setCanUpdateConfiguration(group_manager->permissions().is_set(GroupPermissions::CanChangeTitle));
343
353
 
344
354
        // FIXME: check what flags we want by default
345
355
        Tp::ChannelGroupFlags groupFlags = Tp::ChannelGroupFlagCanAdd |
697
707
    group_interface->setMembers(handles, local_info_list, remote_handles,  /* details */ QVariantMap());
698
708
}
699
709
 
 
710
/*!
 
711
 * Received the permissions of the group after they have changed, not only the ones changed
 
712
 */
 
713
void mqt::tp::TextChannel::on_group_permissions_changed(const Flags<GroupPermissions> &permissions)
 
714
{
 
715
    LOG(INFO) << __PRETTY_FUNCTION__;
 
716
 
 
717
    // Can update the title?
 
718
    // NOTE: in this case we are giving permissions to modify not only to title but any other property the group has.
 
719
    // See how this can be fine grained, as for now, telepathy does not have a way to differentiate one configuration
 
720
    // property permissions from another
 
721
    if (not room_config_interface.isNull())
 
722
    {
 
723
        room_config_interface->setCanUpdateConfiguration(permissions.is_set(GroupPermissions::CanChangeTitle));
 
724
    }
 
725
 
 
726
    // Can kick other participants?
 
727
    if (not group_interface.isNull())
 
728
    {
 
729
        if (permissions.is_set(GroupPermissions::CanKick))
 
730
        {
 
731
            group_interface->setGroupFlags(group_interface->groupFlags() | Tp::ChannelGroupFlagCanRemove
 
732
                                                                         | Tp::ChannelGroupFlagCanRescind);
 
733
        }
 
734
        else
 
735
        {
 
736
            group_interface->setGroupFlags(group_interface->groupFlags() & ~Tp::ChannelGroupFlagCanRemove
 
737
                                                                         & ~Tp::ChannelGroupFlagCanRescind);
 
738
        }
 
739
    }
 
740
}
 
741
 
700
742
QString mqt::tp::TextChannel::send_message(const Tp::MessagePartList& message, uint flags, Tp::DBusError* error)
701
743
{
702
744
    //TODO TRACE
801
843
            return;
802
844
        }
803
845
 
 
846
        if (not group_manager->permissions().is_set(GroupPermissions::CanKick))
 
847
        {
 
848
            error->set(TP_QT_ERROR_PERMISSION_DENIED, "Remove members not allowed");
 
849
            return;
 
850
        }
 
851
 
804
852
        QStringList ids = tp_connection->inspectHandles(Tp::HandleTypeContact, handles, 0);
805
853
        messaging::Members members;
806
854
        for (QString id : ids)
858
906
            return;
859
907
        }
860
908
 
 
909
        if (not group_manager->permissions().is_set(GroupPermissions::CanChangeTitle)) {
 
910
            error->set(TP_QT_ERROR_PERMISSION_DENIED, "Title property update not allowed");
 
911
            return;
 
912
        }
 
913
 
861
914
        group_manager->change_group_title(properties["Title"].toString().toStdString());
862
915
    }
863
916
    catch (...)
876
929
            return;
877
930
        }
878
931
 
 
932
        if (not group_manager->permissions().is_set(GroupPermissions::CanDissolve))
 
933
        {
 
934
            error->set(TP_QT_ERROR_PERMISSION_DENIED, "Destroy channel not allowed");
 
935
            return;
 
936
        }
 
937
 
879
938
        group_manager->dissolve_group();
880
939
    }
881
940
    catch (const std::exception& e)