Skip to content
This repository has been archived by the owner on Jun 7, 2020. It is now read-only.

[NEW] Manage Users in a Room(Add/Remove) #2351

Merged
merged 12 commits into from
Jul 8, 2019

Conversation

Shailesh351
Copy link
Contributor

@RocketChat/android

Closes #1230

Changes:

  • Add API for invite and remove user in Kotlin SDK ([NEW] Add invite and kick endpoints Rocket.Chat.Kotlin.SDK#249)
  • Permission Check for remove user (Show only when user have permission to remove)
  • Add Remove User Feature
  • Permission Check for invite user (Show only when user have permission to invite)
  • Add invite user feature(Using spotlight)

Screenshots or GIF for the change:

Screenshot_20190529-191704
Screenshot_20190530-155126
Screenshot_20190529-191717

@raaparin
Copy link

raaparin commented May 31, 2019

I tried your implementation and I noticed a mistake.
Steps To Reproduce:

  1. Add users
  2. Write something added by the user.
  3. To remove the user
  4. Do not log out of the chat by the deleted user
    Expected result: user is deleted and can not write in the chat, the chat screen is closed
    Actual result: the user can write and read messages, but does not appear in the list of channel members. If you open some other fragment, the chat will disappear from the list of chats.

@philipbrito philipbrito added this to the 3.5.0 milestone May 31, 2019
Copy link
Contributor

@hfeky hfeky left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for this great pull request! 😃 Just a small change I would mention is to add all the newly added strings in all other strings resource files as well, so that it is more clear that they need to be translated and not to be forgotten, and remove TODO Translate from the default file.

import timber.log.Timber
import javax.inject.Inject

class ChatRoomRoleHelper @Inject constructor(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is not acting as a helper class. It is mostly a presenter...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@filipedelimabrito It helps in getting ChatRoles from chatroom id. It is used in PermissionsInterector. Should I move methods in PermissionsInterector? It will make PermissionsInterector long.


try {
for (user in usersList) {
try {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are you using try { ... again here?

Copy link
Contributor Author

@Shailesh351 Shailesh351 Jun 10, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@filipedelimabrito For each user it makes API call to server. And for each user we need to catch exception like user already added in the room or something went wrong

Outer try block is used for hiding loading view and showing msg after API call is made for all the user in the list using finally block.

@CasaPlaysYT

This comment has been minimized.

Copy link
Contributor

@philipbrito philipbrito left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Shailesh351 There are lots of issue here with the code indentation. Could you please make sure to follow our coding style?

@Shailesh351
Copy link
Contributor Author

@filipedelimabrito Updated PR with RocketChat Coding Style. Till now I was using Tab instead of 4 Spaces. Sorry for that.

roomTypeOf(getChatRoomType(chatRoomId)),
user.userId
)
stringBuilder.append("Invited : ${user.username}\n")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hard-coded string. Please remove.

stringBuilder.append("Invited : ${user.username}\n")
} catch (exception: RocketChatException) {
exception.message?.let {
stringBuilder.append("Exception : ${user.username} : $it\n")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hard-coded string. Please remove.

exception.message?.let {
stringBuilder.append("Exception : ${user.username} : $it\n")
}.ifNull {
stringBuilder.append("Error : ${user.username} : Try again later\n")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hard-coded string. Please remove.

private const val BUNDLE_CHAT_ROOM_ID = "chat_room_id"

class InviteUsersFragment : Fragment(), InviteUsersView {

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unneeded blank line.


/**
* Loads all the chat room members for the given room id.
*
* @param roomId The id of the room to get chat room members from.
*/
fun loadChatRoomsMembers(roomId: String) {
fun loadChatRoomsMembers(roomId: String, offset: Long = 0, clearDataset: Boolean = false) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the reason of adding the offset param on the function declaration here?

Copy link
Contributor Author

@Shailesh351 Shailesh351 Jul 8, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually there is one bug in MembersFragment where members are not loaded as recycler view is scrolled using EndlessRecyclerViewListener. And only one page of member is shown.

To fix that I followed same pattern we are using for EndlessRecyclerView in ChatRoomFragment
https://github.com/RocketChat/Rocket.Chat.Android/blob/develop/app/src/main/java/chat/rocket/android/chatroom/presentation/ChatRoomPresenter.kt#L240

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is fixed now - you can test by seeing a channel with a lot of users.

totalItemsCount: Int,
recyclerView: RecyclerView
) {
presenter.loadChatRoomsMembers(chatRoomId, page * 60L)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the reason of passing the offset here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

@philipbrito philipbrito Jul 8, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have simplified it (based on other classes we have too - e.g MentionsPresenter.kt), but I see your point by choosing that approach. But since the offset is used on the presenter, moving it there can keep the scope...there. But I see your point.

<FrameLayout
android:id="@+id/text_invite_users"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Widget isn't a text. So it shouldn't be get such id.

Copy link
Contributor

@philipbrito philipbrito left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for sending this PR @Shailesh351

  • All requested changes here were addressed by my own. Pay attention to them for future reference if you want. Thanks ❤️

@philipbrito philipbrito merged commit a115926 into RocketChat:develop Jul 8, 2019
@Shailesh351 Shailesh351 deleted the sb_add_user branch July 10, 2019 16:15
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[NEW] Create an interface to manage users in a channel/group
5 participants