diff --git a/app/src/main/java/com/nextcloud/talk/controllers/ChatController.kt b/app/src/main/java/com/nextcloud/talk/controllers/ChatController.kt index edd46c7c7..c759f64f9 100644 --- a/app/src/main/java/com/nextcloud/talk/controllers/ChatController.kt +++ b/app/src/main/java/com/nextcloud/talk/controllers/ChatController.kt @@ -454,8 +454,17 @@ class ChatController(args: Bundle) : R.layout.item_date_header, this ) + var senderId = "" + if (!conversationUser?.userId.equals("?")) { + senderId = "users/" + conversationUser?.userId + } else { + senderId = currentConversation?.getActorType() + "/" + currentConversation?.getActorId() + } + + Log.d(TAG, "Initialize TalkMessagesListAdapter with senderId: " + senderId) + adapter = TalkMessagesListAdapter( - conversationUser?.userId, + senderId, messageHolders, ImageLoader { imageView, url, payload -> val draweeController = Fresco.newDraweeControllerBuilder() @@ -1050,18 +1059,6 @@ class ChatController(args: Bundle) : }) } - private fun setSenderId() { - try { - val senderId = adapter?.javaClass?.getDeclaredField("senderId") - senderId?.isAccessible = true - senderId?.set(adapter, conversationUser?.userId) - } catch (e: NoSuchFieldException) { - Log.w(TAG, "Failed to set sender id") - } catch (e: IllegalAccessException) { - Log.w(TAG, "Failed to access and set field") - } - } - private fun submitMessage() { if (messageInput != null) { val editable = messageInput!!.editableText @@ -1351,14 +1348,6 @@ class ChatController(args: Bundle) : chatMessage.activeUser = conversationUser chatMessage.isLinkPreviewAllowed = isLinkPreviewAllowed - // if credentials are empty, we're acting as a guest - if (TextUtils.isEmpty(credentials) && myFirstMessage != null && !TextUtils.isEmpty(myFirstMessage?.toString())) { - if (chatMessage.actorType == "guests") { - conversationUser?.userId = chatMessage.actorId - setSenderId() - } - } - val shouldScroll = !isThereANewNotice && !shouldAddNewMessagesNotice && layoutManager?.findFirstVisibleItemPosition() == 0 || adapter != null && adapter?.itemCount == 0 diff --git a/app/src/main/java/com/nextcloud/talk/controllers/bottomsheet/OperationsMenuController.java b/app/src/main/java/com/nextcloud/talk/controllers/bottomsheet/OperationsMenuController.java index d2a978a32..eae132ecd 100644 --- a/app/src/main/java/com/nextcloud/talk/controllers/bottomsheet/OperationsMenuController.java +++ b/app/src/main/java/com/nextcloud/talk/controllers/bottomsheet/OperationsMenuController.java @@ -347,6 +347,35 @@ public class OperationsMenuController extends BaseController { getRouter().pushController(RouterTransaction.with(new EntryMenuController(bundle)) .pushChangeHandler(new HorizontalChangeHandler()) .popChangeHandler(new HorizontalChangeHandler())); + } else if (conversation.isGuest()) { + ncApi.joinRoom(credentials, ApiUtils.getUrlForParticipantsActive(apiVersion, + baseUrl, + conversationToken), null) + .subscribeOn(Schedulers.io()) + .observeOn(AndroidSchedulers.mainThread()) + .subscribe(new Observer() { + @Override + public void onSubscribe(Disposable d) { + + } + + @Override + public void onNext(RoomOverall roomOverall) { + conversation = roomOverall.getOcs().getData(); + initiateConversation(false); + } + + @Override + public void onError(Throwable e) { + showResultImage(false, false); + dispose(); + } + + @Override + public void onComplete() { + + } + }); } else { initiateConversation(false); } @@ -668,6 +697,8 @@ public class OperationsMenuController extends BaseController { @Override public void onNext(Object o) { if (operationCode != 99) { + RoomOverall roomOverall = (RoomOverall) o; + conversation = roomOverall.getOcs().getData(); showResultImage(true, false); } else { RoomOverall roomOverall = (RoomOverall) o; diff --git a/app/src/main/java/com/nextcloud/talk/models/json/chat/ChatMessage.java b/app/src/main/java/com/nextcloud/talk/models/json/chat/ChatMessage.java index 8e4dba56d..b13ff44cd 100644 --- a/app/src/main/java/com/nextcloud/talk/models/json/chat/ChatMessage.java +++ b/app/src/main/java/com/nextcloud/talk/models/json/chat/ChatMessage.java @@ -214,12 +214,16 @@ public class ChatMessage implements IMessage, MessageContentType, MessageContent return new IUser() { @Override public String getId() { - return actorId; + return actorType + "/" + actorId; } @Override public String getName() { - return actorDisplayName; + if (!TextUtils.isEmpty(actorDisplayName)) { + return actorDisplayName; + } + + return NextcloudTalkApplication.Companion.getSharedApplication().getString(R.string.nc_guest); } @Override diff --git a/app/src/main/java/com/nextcloud/talk/models/json/conversations/Conversation.java b/app/src/main/java/com/nextcloud/talk/models/json/conversations/Conversation.java index bc81ef087..d068c2750 100644 --- a/app/src/main/java/com/nextcloud/talk/models/json/conversations/Conversation.java +++ b/app/src/main/java/com/nextcloud/talk/models/json/conversations/Conversation.java @@ -61,6 +61,10 @@ public class Conversation { public boolean hasPassword; @JsonField(name = "sessionId") public String sessionId; + @JsonField(name = "actorId") + public String actorId; + @JsonField(name = "actorType") + public String actorType; public String password; @JsonField(name = "isFavorite") public boolean isFavorite; @@ -180,6 +184,14 @@ public class Conversation { return this.participantType; } + public String getActorId() { + return actorId; + } + + public String getActorType() { + return actorType; + } + public boolean isHasPassword() { return this.hasPassword; } @@ -277,6 +289,14 @@ public class Conversation { this.participantType = participantType; } + public void setActorId(String actorId) { + this.actorId = actorId; + } + + public void setActorType(String actorType) { + this.actorType = actorType; + } + public void setHasPassword(boolean hasPassword) { this.hasPassword = hasPassword; } @@ -399,6 +419,12 @@ public class Conversation { if (sessionId != null ? !sessionId.equals(that.sessionId) : that.sessionId != null) { return false; } + if (actorId != null ? !actorId.equals(that.actorId) : that.actorId != null) { + return false; + } + if (actorType != null ? !actorType.equals(that.actorType) : that.actorType != null) { + return false; + } if (password != null ? !password.equals(that.password) : that.password != null) { return false; } @@ -441,6 +467,8 @@ public class Conversation { result = 31 * result + (int) (lastPing ^ (lastPing >>> 32)); result = 31 * result + (participants != null ? participants.hashCode() : 0); result = 31 * result + (participantType != null ? participantType.hashCode() : 0); + result = 31 * result + (actorId != null ? actorId.hashCode() : 0); + result = 31 * result + (actorType != null ? actorType.hashCode() : 0); result = 31 * result + (hasPassword ? 1 : 0); result = 31 * result + (sessionId != null ? sessionId.hashCode() : 0); result = 31 * result + (password != null ? password.hashCode() : 0); @@ -473,6 +501,8 @@ public class Conversation { ", lastPing=" + lastPing + ", participants=" + participants + ", participantType=" + participantType + + ", actorId=" + actorId + + ", actorType=" + actorType + ", hasPassword=" + hasPassword + ", sessionId='" + sessionId + '\'' + ", password='" + password + '\'' +