mirror of
https://github.com/nextcloud/talk-android
synced 2025-06-20 20:19:42 +01:00
Fix "own message" detection with guests
Signed-off-by: Joas Schilling <coding@schilljs.com>
This commit is contained in:
parent
97117eb90c
commit
213d11358a
@ -454,8 +454,17 @@ class ChatController(args: Bundle) :
|
|||||||
R.layout.item_date_header, this
|
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(
|
adapter = TalkMessagesListAdapter(
|
||||||
conversationUser?.userId,
|
senderId,
|
||||||
messageHolders,
|
messageHolders,
|
||||||
ImageLoader { imageView, url, payload ->
|
ImageLoader { imageView, url, payload ->
|
||||||
val draweeController = Fresco.newDraweeControllerBuilder()
|
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() {
|
private fun submitMessage() {
|
||||||
if (messageInput != null) {
|
if (messageInput != null) {
|
||||||
val editable = messageInput!!.editableText
|
val editable = messageInput!!.editableText
|
||||||
@ -1351,14 +1348,6 @@ class ChatController(args: Bundle) :
|
|||||||
chatMessage.activeUser = conversationUser
|
chatMessage.activeUser = conversationUser
|
||||||
chatMessage.isLinkPreviewAllowed = isLinkPreviewAllowed
|
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 =
|
val shouldScroll =
|
||||||
!isThereANewNotice && !shouldAddNewMessagesNotice && layoutManager?.findFirstVisibleItemPosition() == 0 || adapter != null && adapter?.itemCount == 0
|
!isThereANewNotice && !shouldAddNewMessagesNotice && layoutManager?.findFirstVisibleItemPosition() == 0 || adapter != null && adapter?.itemCount == 0
|
||||||
|
|
||||||
|
@ -347,6 +347,35 @@ public class OperationsMenuController extends BaseController {
|
|||||||
getRouter().pushController(RouterTransaction.with(new EntryMenuController(bundle))
|
getRouter().pushController(RouterTransaction.with(new EntryMenuController(bundle))
|
||||||
.pushChangeHandler(new HorizontalChangeHandler())
|
.pushChangeHandler(new HorizontalChangeHandler())
|
||||||
.popChangeHandler(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<RoomOverall>() {
|
||||||
|
@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 {
|
} else {
|
||||||
initiateConversation(false);
|
initiateConversation(false);
|
||||||
}
|
}
|
||||||
@ -668,6 +697,8 @@ public class OperationsMenuController extends BaseController {
|
|||||||
@Override
|
@Override
|
||||||
public void onNext(Object o) {
|
public void onNext(Object o) {
|
||||||
if (operationCode != 99) {
|
if (operationCode != 99) {
|
||||||
|
RoomOverall roomOverall = (RoomOverall) o;
|
||||||
|
conversation = roomOverall.getOcs().getData();
|
||||||
showResultImage(true, false);
|
showResultImage(true, false);
|
||||||
} else {
|
} else {
|
||||||
RoomOverall roomOverall = (RoomOverall) o;
|
RoomOverall roomOverall = (RoomOverall) o;
|
||||||
|
@ -214,14 +214,18 @@ public class ChatMessage implements IMessage, MessageContentType, MessageContent
|
|||||||
return new IUser() {
|
return new IUser() {
|
||||||
@Override
|
@Override
|
||||||
public String getId() {
|
public String getId() {
|
||||||
return actorId;
|
return actorType + "/" + actorId;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getName() {
|
public String getName() {
|
||||||
|
if (!TextUtils.isEmpty(actorDisplayName)) {
|
||||||
return actorDisplayName;
|
return actorDisplayName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return NextcloudTalkApplication.Companion.getSharedApplication().getString(R.string.nc_guest);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getAvatar() {
|
public String getAvatar() {
|
||||||
if (getActorType().equals("users")) {
|
if (getActorType().equals("users")) {
|
||||||
|
@ -61,6 +61,10 @@ public class Conversation {
|
|||||||
public boolean hasPassword;
|
public boolean hasPassword;
|
||||||
@JsonField(name = "sessionId")
|
@JsonField(name = "sessionId")
|
||||||
public String sessionId;
|
public String sessionId;
|
||||||
|
@JsonField(name = "actorId")
|
||||||
|
public String actorId;
|
||||||
|
@JsonField(name = "actorType")
|
||||||
|
public String actorType;
|
||||||
public String password;
|
public String password;
|
||||||
@JsonField(name = "isFavorite")
|
@JsonField(name = "isFavorite")
|
||||||
public boolean isFavorite;
|
public boolean isFavorite;
|
||||||
@ -180,6 +184,14 @@ public class Conversation {
|
|||||||
return this.participantType;
|
return this.participantType;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getActorId() {
|
||||||
|
return actorId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getActorType() {
|
||||||
|
return actorType;
|
||||||
|
}
|
||||||
|
|
||||||
public boolean isHasPassword() {
|
public boolean isHasPassword() {
|
||||||
return this.hasPassword;
|
return this.hasPassword;
|
||||||
}
|
}
|
||||||
@ -277,6 +289,14 @@ public class Conversation {
|
|||||||
this.participantType = participantType;
|
this.participantType = participantType;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setActorId(String actorId) {
|
||||||
|
this.actorId = actorId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setActorType(String actorType) {
|
||||||
|
this.actorType = actorType;
|
||||||
|
}
|
||||||
|
|
||||||
public void setHasPassword(boolean hasPassword) {
|
public void setHasPassword(boolean hasPassword) {
|
||||||
this.hasPassword = hasPassword;
|
this.hasPassword = hasPassword;
|
||||||
}
|
}
|
||||||
@ -399,6 +419,12 @@ public class Conversation {
|
|||||||
if (sessionId != null ? !sessionId.equals(that.sessionId) : that.sessionId != null) {
|
if (sessionId != null ? !sessionId.equals(that.sessionId) : that.sessionId != null) {
|
||||||
return false;
|
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) {
|
if (password != null ? !password.equals(that.password) : that.password != null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -441,6 +467,8 @@ public class Conversation {
|
|||||||
result = 31 * result + (int) (lastPing ^ (lastPing >>> 32));
|
result = 31 * result + (int) (lastPing ^ (lastPing >>> 32));
|
||||||
result = 31 * result + (participants != null ? participants.hashCode() : 0);
|
result = 31 * result + (participants != null ? participants.hashCode() : 0);
|
||||||
result = 31 * result + (participantType != null ? participantType.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 + (hasPassword ? 1 : 0);
|
||||||
result = 31 * result + (sessionId != null ? sessionId.hashCode() : 0);
|
result = 31 * result + (sessionId != null ? sessionId.hashCode() : 0);
|
||||||
result = 31 * result + (password != null ? password.hashCode() : 0);
|
result = 31 * result + (password != null ? password.hashCode() : 0);
|
||||||
@ -473,6 +501,8 @@ public class Conversation {
|
|||||||
", lastPing=" + lastPing +
|
", lastPing=" + lastPing +
|
||||||
", participants=" + participants +
|
", participants=" + participants +
|
||||||
", participantType=" + participantType +
|
", participantType=" + participantType +
|
||||||
|
", actorId=" + actorId +
|
||||||
|
", actorType=" + actorType +
|
||||||
", hasPassword=" + hasPassword +
|
", hasPassword=" + hasPassword +
|
||||||
", sessionId='" + sessionId + '\'' +
|
", sessionId='" + sessionId + '\'' +
|
||||||
", password='" + password + '\'' +
|
", password='" + password + '\'' +
|
||||||
|
Loading…
Reference in New Issue
Block a user