Skip to content
This repository has been archived by the owner on Apr 12, 2022. It is now read-only.

Commit

Permalink
Room upgrade: Use the server_name parameter when joining the new ro…
Browse files Browse the repository at this point in the history
…om (Fixes #3204)
  • Loading branch information
bmarty committed Jul 17, 2019
1 parent 2455085 commit 039173e
Show file tree
Hide file tree
Showing 7 changed files with 129 additions and 28 deletions.
2 changes: 1 addition & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Features:
-

Improvements:
-
- Room upgrade: Use the `server_name` parameter when joining the new room (#3204)

Other changes:
- Piwik SDK has been replaced by Matomo SDK (#3163)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,5 +219,9 @@ abstract class MockMessageAdapterActionListener : IMessagesAdapterActionsListene
override fun onSelectedEventChange(currentSelectedEvent: Event?) {
TODO("not implemented")
}

override fun onTombstoneLinkClicked(roomId: String?, senderId: String?) {
TODO("not implemented")
}
}

11 changes: 10 additions & 1 deletion vector/src/main/java/im/vector/activity/VectorRoomActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,9 @@
import org.matrix.androidsdk.rest.model.message.Message;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Timer;
Expand Down Expand Up @@ -2626,7 +2628,14 @@ private void refreshNotificationsArea() {
state = new NotificationAreaView.State.Typing(mLatestTypingMessage);
} else if (mRoom.getState().isVersioned()) {
final RoomTombstoneContent roomTombstoneContent = mRoom.getState().getRoomTombstoneContent();
state = new NotificationAreaView.State.Tombstone(roomTombstoneContent);
final List<Event> events = mRoom.getState().getStateEvents(new HashSet<>(Arrays.asList(Event.EVENT_TYPE_STATE_ROOM_TOMBSTONE)));

String sender = "";
if (events != null && !events.isEmpty()) {
sender = events.get(0).sender;
}

state = new NotificationAreaView.State.Tombstone(roomTombstoneContent, sender);
}
}
mNotificationsArea.render(state);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
import org.matrix.androidsdk.adapters.MessageRow;
import org.matrix.androidsdk.core.JsonUtils;
import org.matrix.androidsdk.core.Log;
import org.matrix.androidsdk.core.MXPatterns;
import org.matrix.androidsdk.core.PermalinkUtils;
import org.matrix.androidsdk.core.callback.ApiCallback;
import org.matrix.androidsdk.core.callback.SimpleApiCallback;
Expand Down Expand Up @@ -771,6 +772,55 @@ public void onSelectedEventChange(@Nullable Event currentSelectedEvent) {
}
}

@Override
public void onTombstoneLinkClicked(String roomId, String senderId) {
// Join the room and open it
showInitLoading();

// Extract the server name
String serverName = MXPatterns.extractServerNameFromId(senderId);

List<String> viaServers = null;

if (serverName != null) {
viaServers = Collections.singletonList(serverName);
}

mSession.joinRoom(roomId, viaServers, new ApiCallback<String>() {
@Override
public void onNetworkError(Exception e) {
hideInitLoading();
Toast.makeText(getActivity(), e.getLocalizedMessage(), Toast.LENGTH_LONG).show();
}

@Override
public void onMatrixError(MatrixError e) {
hideInitLoading();
Toast.makeText(getActivity(), e.getLocalizedMessage(), Toast.LENGTH_LONG).show();
}

@Override
public void onUnexpectedError(Exception e) {
hideInitLoading();
Toast.makeText(getActivity(), e.getLocalizedMessage(), Toast.LENGTH_LONG).show();
}

@Override
public void onSuccess(String info) {
hideInitLoading();

// Open the room
if (isAdded()) {
Intent intent = new Intent(getActivity(), VectorRoomActivity.class);
intent.putExtra(VectorRoomActivity.EXTRA_ROOM_ID, info);
intent.putExtra(VectorRoomActivity.EXTRA_MATRIX_ID, mSession.getCredentials().userId);
getActivity().startActivity(intent);
getActivity().finish();
}
}
});
}

/**
* The user reports a content problem to the server
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,4 +186,12 @@ public interface IMessagesAdapterActionsListener {
* @param currentSelectedEvent the current selected event, or null if no event is selected
*/
void onSelectedEventChange(@Nullable Event currentSelectedEvent);

/**
* Called when the tombstone link is clicked
*
* @param roomId
* @param senderId
*/
void onTombstoneLinkClicked(String roomId, String senderId);
}
77 changes: 54 additions & 23 deletions vector/src/main/java/im/vector/util/MatrixURLSpan.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,18 +56,43 @@ public MatrixURLSpan[] newArray(int size) {
// URL regex
private final Pattern mPattern;

// is a tombstone link
private final boolean isTombstone;

// SenderId for the tombstone link
private final String senderId;

// listener
private final IMessagesAdapterActionsListener mActionsListener;

public MatrixURLSpan(String url, Pattern pattern, IMessagesAdapterActionsListener actionsListener) {
mURL = url;
mPattern = pattern;
isTombstone = false;
senderId = null;
mActionsListener = actionsListener;
}

/**
* Create a URL Span for tombstone
*
* @param roomId
* @param senderId
* @param actionsListener
*/
public MatrixURLSpan(String roomId, String senderId, IMessagesAdapterActionsListener actionsListener) {
mURL = roomId;
mPattern = null;
isTombstone = true;
this.senderId = senderId;
mActionsListener = actionsListener;
}

private MatrixURLSpan(Parcel src) {
mURL = src.readString();
mPattern = null;
isTombstone = false;
senderId = null;
mActionsListener = null;
}

Expand Down Expand Up @@ -110,33 +135,39 @@ private String getURL() {
@Override
public void onClick(View widget) {
try {
if (mPattern == MXPatterns.PATTERN_CONTAIN_MATRIX_USER_IDENTIFIER) {
if (null != mActionsListener) {
mActionsListener.onMatrixUserIdClick(mURL);
}
} else if (mPattern == MXPatterns.PATTERN_CONTAIN_MATRIX_ALIAS) {
if (null != mActionsListener) {
mActionsListener.onRoomAliasClick(mURL);
}
} else if (mPattern == MXPatterns.PATTERN_CONTAIN_MATRIX_ROOM_IDENTIFIER) {
if (isTombstone) {
if (null != mActionsListener) {
mActionsListener.onRoomIdClick(mURL);
}
} else if (mPattern == MXPatterns.PATTERN_CONTAIN_MATRIX_EVENT_IDENTIFIER) {
if (null != mActionsListener) {
mActionsListener.onEventIdClick(mURL);
}
} else if (mPattern == MXPatterns.PATTERN_CONTAIN_MATRIX_GROUP_IDENTIFIER) {
if (null != mActionsListener) {
mActionsListener.onGroupIdClick(mURL);
mActionsListener.onTombstoneLinkClicked(mURL, senderId);
}
} else {
Uri uri = Uri.parse(getURL());

if (null != mActionsListener) {
mActionsListener.onURLClick(uri);
if (mPattern == MXPatterns.PATTERN_CONTAIN_MATRIX_USER_IDENTIFIER) {
if (null != mActionsListener) {
mActionsListener.onMatrixUserIdClick(mURL);
}
} else if (mPattern == MXPatterns.PATTERN_CONTAIN_MATRIX_ALIAS) {
if (null != mActionsListener) {
mActionsListener.onRoomAliasClick(mURL);
}
} else if (mPattern == MXPatterns.PATTERN_CONTAIN_MATRIX_ROOM_IDENTIFIER) {
if (null != mActionsListener) {
mActionsListener.onRoomIdClick(mURL);
}
} else if (mPattern == MXPatterns.PATTERN_CONTAIN_MATRIX_EVENT_IDENTIFIER) {
if (null != mActionsListener) {
mActionsListener.onEventIdClick(mURL);
}
} else if (mPattern == MXPatterns.PATTERN_CONTAIN_MATRIX_GROUP_IDENTIFIER) {
if (null != mActionsListener) {
mActionsListener.onGroupIdClick(mURL);
}
} else {
ExternalApplicationsUtilKt.openUrlInExternalBrowser(widget.getContext(), uri);
Uri uri = Uri.parse(getURL());

if (null != mActionsListener) {
mActionsListener.onURLClick(uri);
} else {
ExternalApplicationsUtilKt.openUrlInExternalBrowser(widget.getContext(), uri);
}
}
}
} catch (Exception e) {
Expand Down
5 changes: 2 additions & 3 deletions vector/src/main/java/im/vector/view/NotificationAreaView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,7 @@ class NotificationAreaView @JvmOverloads constructor(
visibility = View.VISIBLE
imageView.setImageResource(R.drawable.error)
val roomTombstoneContent = state.tombstoneContent
val roomLink = PermalinkUtils.createPermalink(roomTombstoneContent.replacementRoom)
val urlSpan = MatrixURLSpan(roomLink, MXPatterns.PATTERN_CONTAIN_APP_LINK_PERMALINK_ROOM_ID, delegate?.providesMessagesActionListener())
val urlSpan = MatrixURLSpan(roomTombstoneContent.replacementRoom, state.tombstoneEventSenderId, delegate?.providesMessagesActionListener())
val textColorInt = ThemeUtils.getColor(context, R.attr.vctr_message_text_color)
val message = Spanny(resources.getString(R.string.room_tombstone_versioned_description),
StyleSpan(Typeface.BOLD),
Expand Down Expand Up @@ -339,7 +338,7 @@ class NotificationAreaView @JvmOverloads constructor(
object ConnectionError : State()

// The room is dead
data class Tombstone(val tombstoneContent: RoomTombstoneContent) : State()
data class Tombstone(val tombstoneContent: RoomTombstoneContent, val tombstoneEventSenderId: String) : State()

// Somebody is typing
data class Typing(val message: String) : State()
Expand Down

0 comments on commit 039173e

Please sign in to comment.