Merge pull request #738 from vector-im/feature/ban_reason
Displaay ban and other membership events reason
This commit is contained in:
commit
8b1701e537
@ -8,7 +8,7 @@ Improvements 🙌:
|
|||||||
- Support entering a RiotWeb client URL instead of the homeserver URL during connection (#744)
|
- Support entering a RiotWeb client URL instead of the homeserver URL during connection (#744)
|
||||||
|
|
||||||
Other changes:
|
Other changes:
|
||||||
-
|
- Add reason for all membership events (https://github.com/matrix-org/matrix-doc/pull/2367)
|
||||||
|
|
||||||
Bugfix 🐛:
|
Bugfix 🐛:
|
||||||
- When automardown is ON, pills are sent as MD in body (#739)
|
- When automardown is ON, pills are sent as MD in body (#739)
|
||||||
@ -17,7 +17,7 @@ Translations 🗣:
|
|||||||
-
|
-
|
||||||
|
|
||||||
Build 🧱:
|
Build 🧱:
|
||||||
-
|
- "ban" event are not rendered correctly (#716)
|
||||||
|
|
||||||
Changes in RiotX 0.9.1 (2019-12-05)
|
Changes in RiotX 0.9.1 (2019-12-05)
|
||||||
===================================================
|
===================================================
|
||||||
|
@ -57,8 +57,9 @@ class RxRoom(private val room: Room) {
|
|||||||
room.loadRoomMembersIfNeeded(MatrixCallbackSingle(it)).toSingle(it)
|
room.loadRoomMembersIfNeeded(MatrixCallbackSingle(it)).toSingle(it)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun joinRoom(viaServers: List<String> = emptyList()): Single<Unit> = Single.create {
|
fun joinRoom(reason: String? = null,
|
||||||
room.join(viaServers, MatrixCallbackSingle(it)).toSingle(it)
|
viaServers: List<String> = emptyList()): Single<Unit> = Single.create {
|
||||||
|
room.join(reason, viaServers, MatrixCallbackSingle(it)).toSingle(it)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun liveEventReadReceipts(eventId: String): Observable<List<ReadReceipt>> {
|
fun liveEventReadReceipts(eventId: String): Observable<List<ReadReceipt>> {
|
||||||
|
@ -76,8 +76,10 @@ class RxSession(private val session: Session) {
|
|||||||
session.searchUsersDirectory(search, limit, excludedUserIds, MatrixCallbackSingle(it)).toSingle(it)
|
session.searchUsersDirectory(search, limit, excludedUserIds, MatrixCallbackSingle(it)).toSingle(it)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun joinRoom(roomId: String, viaServers: List<String> = emptyList()): Single<Unit> = Single.create {
|
fun joinRoom(roomId: String,
|
||||||
session.joinRoom(roomId, viaServers, MatrixCallbackSingle(it)).toSingle(it)
|
reason: String? = null,
|
||||||
|
viaServers: List<String> = emptyList()): Single<Unit> = Single.create {
|
||||||
|
session.joinRoom(roomId, reason, viaServers, MatrixCallbackSingle(it)).toSingle(it)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -30,12 +30,16 @@ interface RoomDirectoryService {
|
|||||||
/**
|
/**
|
||||||
* Get rooms from directory
|
* Get rooms from directory
|
||||||
*/
|
*/
|
||||||
fun getPublicRooms(server: String?, publicRoomsParams: PublicRoomsParams, callback: MatrixCallback<PublicRoomsResponse>): Cancelable
|
fun getPublicRooms(server: String?,
|
||||||
|
publicRoomsParams: PublicRoomsParams,
|
||||||
|
callback: MatrixCallback<PublicRoomsResponse>): Cancelable
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Join a room by id
|
* Join a room by id
|
||||||
*/
|
*/
|
||||||
fun joinRoom(roomId: String, callback: MatrixCallback<Unit>): Cancelable
|
fun joinRoom(roomId: String,
|
||||||
|
reason: String? = null,
|
||||||
|
callback: MatrixCallback<Unit>): Cancelable
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fetches the overall metadata about protocols supported by the homeserver.
|
* Fetches the overall metadata about protocols supported by the homeserver.
|
||||||
|
@ -30,14 +30,17 @@ interface RoomService {
|
|||||||
/**
|
/**
|
||||||
* Create a room asynchronously
|
* Create a room asynchronously
|
||||||
*/
|
*/
|
||||||
fun createRoom(createRoomParams: CreateRoomParams, callback: MatrixCallback<String>): Cancelable
|
fun createRoom(createRoomParams: CreateRoomParams,
|
||||||
|
callback: MatrixCallback<String>): Cancelable
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Join a room by id
|
* Join a room by id
|
||||||
* @param roomId the roomId of the room to join
|
* @param roomId the roomId of the room to join
|
||||||
|
* @param reason optional reason for joining the room
|
||||||
* @param viaServers the servers to attempt to join the room through. One of the servers must be participating in the room.
|
* @param viaServers the servers to attempt to join the room through. One of the servers must be participating in the room.
|
||||||
*/
|
*/
|
||||||
fun joinRoom(roomId: String,
|
fun joinRoom(roomId: String,
|
||||||
|
reason: String? = null,
|
||||||
viaServers: List<String> = emptyList(),
|
viaServers: List<String> = emptyList(),
|
||||||
callback: MatrixCallback<Unit>): Cancelable
|
callback: MatrixCallback<Unit>): Cancelable
|
||||||
|
|
||||||
@ -69,5 +72,6 @@ interface RoomService {
|
|||||||
/**
|
/**
|
||||||
* Mark all rooms as read
|
* Mark all rooms as read
|
||||||
*/
|
*/
|
||||||
fun markAllAsRead(roomIds: List<String>, callback: MatrixCallback<Unit>): Cancelable
|
fun markAllAsRead(roomIds: List<String>,
|
||||||
|
callback: MatrixCallback<Unit>): Cancelable
|
||||||
}
|
}
|
||||||
|
@ -52,16 +52,21 @@ interface MembershipService {
|
|||||||
/**
|
/**
|
||||||
* Invite a user in the room
|
* Invite a user in the room
|
||||||
*/
|
*/
|
||||||
fun invite(userId: String, callback: MatrixCallback<Unit>): Cancelable
|
fun invite(userId: String,
|
||||||
|
reason: String? = null,
|
||||||
|
callback: MatrixCallback<Unit>): Cancelable
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Join the room, or accept an invitation.
|
* Join the room, or accept an invitation.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
fun join(viaServers: List<String> = emptyList(), callback: MatrixCallback<Unit>): Cancelable
|
fun join(reason: String? = null,
|
||||||
|
viaServers: List<String> = emptyList(),
|
||||||
|
callback: MatrixCallback<Unit>): Cancelable
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Leave the room, or reject an invitation.
|
* Leave the room, or reject an invitation.
|
||||||
*/
|
*/
|
||||||
fun leave(callback: MatrixCallback<Unit>): Cancelable
|
fun leave(reason: String? = null,
|
||||||
|
callback: MatrixCallback<Unit>): Cancelable
|
||||||
}
|
}
|
||||||
|
@ -26,9 +26,13 @@ import im.vector.matrix.android.api.session.events.model.UnsignedData
|
|||||||
@JsonClass(generateAdapter = true)
|
@JsonClass(generateAdapter = true)
|
||||||
data class RoomMember(
|
data class RoomMember(
|
||||||
@Json(name = "membership") val membership: Membership,
|
@Json(name = "membership") val membership: Membership,
|
||||||
|
@Json(name = "reason") val reason: String? = null,
|
||||||
@Json(name = "displayname") val displayName: String? = null,
|
@Json(name = "displayname") val displayName: String? = null,
|
||||||
@Json(name = "avatar_url") val avatarUrl: String? = null,
|
@Json(name = "avatar_url") val avatarUrl: String? = null,
|
||||||
@Json(name = "is_direct") val isDirect: Boolean = false,
|
@Json(name = "is_direct") val isDirect: Boolean = false,
|
||||||
@Json(name = "third_party_invite") val thirdPartyInvite: Invite? = null,
|
@Json(name = "third_party_invite") val thirdPartyInvite: Invite? = null,
|
||||||
@Json(name = "unsigned") val unsignedData: UnsignedData? = null
|
@Json(name = "unsigned") val unsignedData: UnsignedData? = null
|
||||||
)
|
) {
|
||||||
|
val safeReason
|
||||||
|
get() = reason?.takeIf { it.isNotBlank() }
|
||||||
|
}
|
||||||
|
@ -44,9 +44,9 @@ internal class DefaultRoomDirectoryService @Inject constructor(private val getPu
|
|||||||
.executeBy(taskExecutor)
|
.executeBy(taskExecutor)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun joinRoom(roomId: String, callback: MatrixCallback<Unit>): Cancelable {
|
override fun joinRoom(roomId: String, reason: String?, callback: MatrixCallback<Unit>): Cancelable {
|
||||||
return joinRoomTask
|
return joinRoomTask
|
||||||
.configureWith(JoinRoomTask.Params(roomId)) {
|
.configureWith(JoinRoomTask.Params(roomId, reason)) {
|
||||||
this.callback = callback
|
this.callback = callback
|
||||||
}
|
}
|
||||||
.executeBy(taskExecutor)
|
.executeBy(taskExecutor)
|
||||||
|
@ -96,9 +96,9 @@ internal class DefaultRoomService @Inject constructor(private val monarchy: Mona
|
|||||||
.executeBy(taskExecutor)
|
.executeBy(taskExecutor)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun joinRoom(roomId: String, viaServers: List<String>, callback: MatrixCallback<Unit>): Cancelable {
|
override fun joinRoom(roomId: String, reason: String?, viaServers: List<String>, callback: MatrixCallback<Unit>): Cancelable {
|
||||||
return joinRoomTask
|
return joinRoomTask
|
||||||
.configureWith(JoinRoomTask.Params(roomId, viaServers)) {
|
.configureWith(JoinRoomTask.Params(roomId, reason, viaServers)) {
|
||||||
this.callback = callback
|
this.callback = callback
|
||||||
}
|
}
|
||||||
.executeBy(taskExecutor)
|
.executeBy(taskExecutor)
|
||||||
|
@ -217,7 +217,7 @@ internal interface RoomAPI {
|
|||||||
@POST(NetworkConstants.URI_API_PREFIX_PATH_R0 + "rooms/{roomId}/join")
|
@POST(NetworkConstants.URI_API_PREFIX_PATH_R0 + "rooms/{roomId}/join")
|
||||||
fun join(@Path("roomId") roomId: String,
|
fun join(@Path("roomId") roomId: String,
|
||||||
@Query("server_name") viaServers: List<String>,
|
@Query("server_name") viaServers: List<String>,
|
||||||
@Body params: Map<String, String>): Call<Unit>
|
@Body params: Map<String, String?>): Call<Unit>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Leave the given room.
|
* Leave the given room.
|
||||||
@ -227,7 +227,7 @@ internal interface RoomAPI {
|
|||||||
*/
|
*/
|
||||||
@POST(NetworkConstants.URI_API_PREFIX_PATH_R0 + "rooms/{roomId}/leave")
|
@POST(NetworkConstants.URI_API_PREFIX_PATH_R0 + "rooms/{roomId}/leave")
|
||||||
fun leave(@Path("roomId") roomId: String,
|
fun leave(@Path("roomId") roomId: String,
|
||||||
@Body params: Map<String, String>): Call<Unit>
|
@Body params: Map<String, String?>): Call<Unit>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Strips all information out of an event which isn't critical to the integrity of the server-side representation of the room.
|
* Strips all information out of an event which isn't critical to the integrity of the server-side representation of the room.
|
||||||
|
@ -83,8 +83,8 @@ internal class DefaultMembershipService @AssistedInject constructor(@Assisted pr
|
|||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun invite(userId: String, callback: MatrixCallback<Unit>): Cancelable {
|
override fun invite(userId: String, reason: String?, callback: MatrixCallback<Unit>): Cancelable {
|
||||||
val params = InviteTask.Params(roomId, userId)
|
val params = InviteTask.Params(roomId, userId, reason)
|
||||||
return inviteTask
|
return inviteTask
|
||||||
.configureWith(params) {
|
.configureWith(params) {
|
||||||
this.callback = callback
|
this.callback = callback
|
||||||
@ -92,8 +92,8 @@ internal class DefaultMembershipService @AssistedInject constructor(@Assisted pr
|
|||||||
.executeBy(taskExecutor)
|
.executeBy(taskExecutor)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun join(viaServers: List<String>, callback: MatrixCallback<Unit>): Cancelable {
|
override fun join(reason: String?, viaServers: List<String>, callback: MatrixCallback<Unit>): Cancelable {
|
||||||
val params = JoinRoomTask.Params(roomId, viaServers)
|
val params = JoinRoomTask.Params(roomId, reason, viaServers)
|
||||||
return joinTask
|
return joinTask
|
||||||
.configureWith(params) {
|
.configureWith(params) {
|
||||||
this.callback = callback
|
this.callback = callback
|
||||||
@ -101,8 +101,8 @@ internal class DefaultMembershipService @AssistedInject constructor(@Assisted pr
|
|||||||
.executeBy(taskExecutor)
|
.executeBy(taskExecutor)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun leave(callback: MatrixCallback<Unit>): Cancelable {
|
override fun leave(reason: String?, callback: MatrixCallback<Unit>): Cancelable {
|
||||||
val params = LeaveRoomTask.Params(roomId)
|
val params = LeaveRoomTask.Params(roomId, reason)
|
||||||
return leaveRoomTask
|
return leaveRoomTask
|
||||||
.configureWith(params) {
|
.configureWith(params) {
|
||||||
this.callback = callback
|
this.callback = callback
|
||||||
|
@ -21,5 +21,6 @@ import com.squareup.moshi.JsonClass
|
|||||||
|
|
||||||
@JsonClass(generateAdapter = true)
|
@JsonClass(generateAdapter = true)
|
||||||
data class InviteBody(
|
data class InviteBody(
|
||||||
@Json(name = "user_id") val userId: String
|
@Json(name = "user_id") val userId: String,
|
||||||
|
@Json(name = "reason") val reason: String?
|
||||||
)
|
)
|
||||||
|
@ -24,7 +24,8 @@ import javax.inject.Inject
|
|||||||
internal interface InviteTask : Task<InviteTask.Params, Unit> {
|
internal interface InviteTask : Task<InviteTask.Params, Unit> {
|
||||||
data class Params(
|
data class Params(
|
||||||
val roomId: String,
|
val roomId: String,
|
||||||
val userId: String
|
val userId: String,
|
||||||
|
val reason: String?
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -32,7 +33,7 @@ internal class DefaultInviteTask @Inject constructor(private val roomAPI: RoomAP
|
|||||||
|
|
||||||
override suspend fun execute(params: InviteTask.Params) {
|
override suspend fun execute(params: InviteTask.Params) {
|
||||||
return executeRequest {
|
return executeRequest {
|
||||||
val body = InviteBody(params.userId)
|
val body = InviteBody(params.userId, params.reason)
|
||||||
apiCall = roomAPI.invite(params.roomId, body)
|
apiCall = roomAPI.invite(params.roomId, body)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -32,6 +32,7 @@ import javax.inject.Inject
|
|||||||
internal interface JoinRoomTask : Task<JoinRoomTask.Params, Unit> {
|
internal interface JoinRoomTask : Task<JoinRoomTask.Params, Unit> {
|
||||||
data class Params(
|
data class Params(
|
||||||
val roomId: String,
|
val roomId: String,
|
||||||
|
val reason: String?,
|
||||||
val viaServers: List<String> = emptyList()
|
val viaServers: List<String> = emptyList()
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@ -43,7 +44,7 @@ internal class DefaultJoinRoomTask @Inject constructor(private val roomAPI: Room
|
|||||||
|
|
||||||
override suspend fun execute(params: JoinRoomTask.Params) {
|
override suspend fun execute(params: JoinRoomTask.Params) {
|
||||||
executeRequest<Unit> {
|
executeRequest<Unit> {
|
||||||
apiCall = roomAPI.join(params.roomId, params.viaServers, HashMap())
|
apiCall = roomAPI.join(params.roomId, params.viaServers, mapOf("reason" to params.reason))
|
||||||
}
|
}
|
||||||
val roomId = params.roomId
|
val roomId = params.roomId
|
||||||
// Wait for room to come back from the sync (but it can maybe be in the DB is the sync response is received before)
|
// Wait for room to come back from the sync (but it can maybe be in the DB is the sync response is received before)
|
||||||
|
@ -23,7 +23,8 @@ import javax.inject.Inject
|
|||||||
|
|
||||||
internal interface LeaveRoomTask : Task<LeaveRoomTask.Params, Unit> {
|
internal interface LeaveRoomTask : Task<LeaveRoomTask.Params, Unit> {
|
||||||
data class Params(
|
data class Params(
|
||||||
val roomId: String
|
val roomId: String,
|
||||||
|
val reason: String?
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -31,7 +32,7 @@ internal class DefaultLeaveRoomTask @Inject constructor(private val roomAPI: Roo
|
|||||||
|
|
||||||
override suspend fun execute(params: LeaveRoomTask.Params) {
|
override suspend fun execute(params: LeaveRoomTask.Params) {
|
||||||
return executeRequest {
|
return executeRequest {
|
||||||
apiCall = roomAPI.leave(params.roomId, HashMap())
|
apiCall = roomAPI.leave(params.roomId, mapOf("reason" to params.reason))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,8 +2,19 @@
|
|||||||
<resources>
|
<resources>
|
||||||
|
|
||||||
|
|
||||||
|
<string name="notice_room_invite_no_invitee_with_reason">%1$s\'s invitation. Reason: %2$s</string>
|
||||||
|
<string name="notice_room_invite_with_reason">%1$s invited %2$s. Reason: %3$s</string>
|
||||||
|
<string name="notice_room_invite_you_with_reason">%1$s invited you. Reason: %2$s</string>
|
||||||
|
<string name="notice_room_join_with_reason">%1$s joined. Reason: %2$s</string>
|
||||||
|
<string name="notice_room_leave_with_reason">%1$s left. Reason: %2$s</string>
|
||||||
|
<string name="notice_room_reject_with_reason">%1$s rejected the invitation. Reason: %2$s</string>
|
||||||
|
<string name="notice_room_kick_with_reason">%1$s kicked %2$s. Reason: %3$s</string>
|
||||||
|
<string name="notice_room_unban_with_reason">%1$s unbanned %2$s. Reason: %3$s</string>
|
||||||
|
<string name="notice_room_ban_with_reason">%1$s banned %2$s. Reason: %3$s</string>
|
||||||
|
<string name="notice_room_third_party_invite_with_reason">%1$s sent an invitation to %2$s to join the room. Reason: %3$s</string>
|
||||||
|
<string name="notice_room_third_party_revoked_invite_with_reason">%1$s revoked the invitation for %2$s to join the room. Reason: %3$s</string>
|
||||||
|
<string name="notice_room_third_party_registered_invite_with_reason">%1$s accepted the invitation for %2$s. Reason: %3$s</string>
|
||||||
|
<string name="notice_room_withdraw_with_reason">%1$s withdrew %2$s\'s invitation. Reason: %3$s</string>
|
||||||
|
|
||||||
<string name="no_network_indicator">There is no network connection right now</string>
|
<string name="no_network_indicator">There is no network connection right now</string>
|
||||||
</resources>
|
</resources>
|
@ -27,16 +27,19 @@ import im.vector.riotx.R
|
|||||||
enum class Command(val command: String, val parameters: String, @StringRes val description: Int) {
|
enum class Command(val command: String, val parameters: String, @StringRes val description: Int) {
|
||||||
EMOTE("/me", "<message>", R.string.command_description_emote),
|
EMOTE("/me", "<message>", R.string.command_description_emote),
|
||||||
BAN_USER("/ban", "<user-id> [reason]", R.string.command_description_ban_user),
|
BAN_USER("/ban", "<user-id> [reason]", R.string.command_description_ban_user),
|
||||||
UNBAN_USER("/unban", "<user-id>", R.string.command_description_unban_user),
|
UNBAN_USER("/unban", "<user-id> [reason]", R.string.command_description_unban_user),
|
||||||
SET_USER_POWER_LEVEL("/op", "<user-id> [<power-level>]", R.string.command_description_op_user),
|
SET_USER_POWER_LEVEL("/op", "<user-id> [<power-level>]", R.string.command_description_op_user),
|
||||||
RESET_USER_POWER_LEVEL("/deop", "<user-id>", R.string.command_description_deop_user),
|
RESET_USER_POWER_LEVEL("/deop", "<user-id>", R.string.command_description_deop_user),
|
||||||
INVITE("/invite", "<user-id>", R.string.command_description_invite_user),
|
INVITE("/invite", "<user-id> [reason]", R.string.command_description_invite_user),
|
||||||
JOIN_ROOM("/join", "<room-alias>", R.string.command_description_join_room),
|
JOIN_ROOM("/join", "<room-alias> [reason]", R.string.command_description_join_room),
|
||||||
PART("/part", "<room-alias>", R.string.command_description_part_room),
|
PART("/part", "<room-alias> [reason]", R.string.command_description_part_room),
|
||||||
TOPIC("/topic", "<topic>", R.string.command_description_topic),
|
TOPIC("/topic", "<topic>", R.string.command_description_topic),
|
||||||
KICK_USER("/kick", "<user-id> [reason]", R.string.command_description_kick_user),
|
KICK_USER("/kick", "<user-id> [reason]", R.string.command_description_kick_user),
|
||||||
CHANGE_DISPLAY_NAME("/nick", "<display-name>", R.string.command_description_nick),
|
CHANGE_DISPLAY_NAME("/nick", "<display-name>", R.string.command_description_nick),
|
||||||
MARKDOWN("/markdown", "<on|off>", R.string.command_description_markdown),
|
MARKDOWN("/markdown", "<on|off>", R.string.command_description_markdown),
|
||||||
CLEAR_SCALAR_TOKEN("/clear_scalar_token", "", R.string.command_description_clear_scalar_token),
|
CLEAR_SCALAR_TOKEN("/clear_scalar_token", "", R.string.command_description_clear_scalar_token),
|
||||||
SPOILER("/spoiler", "<message>", R.string.command_description_spoiler);
|
SPOILER("/spoiler", "<message>", R.string.command_description_spoiler);
|
||||||
|
|
||||||
|
val length
|
||||||
|
get() = command.length + 1
|
||||||
}
|
}
|
||||||
|
@ -81,29 +81,52 @@ object CommandParser {
|
|||||||
ParsedCommand.SendEmote(message)
|
ParsedCommand.SendEmote(message)
|
||||||
}
|
}
|
||||||
Command.JOIN_ROOM.command -> {
|
Command.JOIN_ROOM.command -> {
|
||||||
val roomAlias = textMessage.substring(Command.JOIN_ROOM.command.length).trim()
|
if (messageParts.size >= 2) {
|
||||||
|
val roomAlias = messageParts[1]
|
||||||
|
|
||||||
if (roomAlias.isNotEmpty()) {
|
if (roomAlias.isNotEmpty()) {
|
||||||
ParsedCommand.JoinRoom(roomAlias)
|
ParsedCommand.JoinRoom(
|
||||||
|
roomAlias,
|
||||||
|
textMessage.substring(Command.JOIN_ROOM.length + roomAlias.length)
|
||||||
|
.trim()
|
||||||
|
.takeIf { it.isNotBlank() }
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
ParsedCommand.ErrorSyntax(Command.JOIN_ROOM)
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
ParsedCommand.ErrorSyntax(Command.JOIN_ROOM)
|
ParsedCommand.ErrorSyntax(Command.JOIN_ROOM)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Command.PART.command -> {
|
Command.PART.command -> {
|
||||||
val roomAlias = textMessage.substring(Command.PART.command.length).trim()
|
if (messageParts.size >= 2) {
|
||||||
|
val roomAlias = messageParts[1]
|
||||||
|
|
||||||
if (roomAlias.isNotEmpty()) {
|
if (roomAlias.isNotEmpty()) {
|
||||||
ParsedCommand.PartRoom(roomAlias)
|
ParsedCommand.PartRoom(
|
||||||
|
roomAlias,
|
||||||
|
textMessage.substring(Command.PART.length + roomAlias.length)
|
||||||
|
.trim()
|
||||||
|
.takeIf { it.isNotBlank() }
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
ParsedCommand.ErrorSyntax(Command.PART)
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
ParsedCommand.ErrorSyntax(Command.PART)
|
ParsedCommand.ErrorSyntax(Command.PART)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Command.INVITE.command -> {
|
Command.INVITE.command -> {
|
||||||
if (messageParts.size == 2) {
|
if (messageParts.size >= 2) {
|
||||||
val userId = messageParts[1]
|
val userId = messageParts[1]
|
||||||
|
|
||||||
if (MatrixPatterns.isUserId(userId)) {
|
if (MatrixPatterns.isUserId(userId)) {
|
||||||
ParsedCommand.Invite(userId)
|
ParsedCommand.Invite(
|
||||||
|
userId,
|
||||||
|
textMessage.substring(Command.INVITE.length + userId.length)
|
||||||
|
.trim()
|
||||||
|
.takeIf { it.isNotBlank() }
|
||||||
|
)
|
||||||
} else {
|
} else {
|
||||||
ParsedCommand.ErrorSyntax(Command.INVITE)
|
ParsedCommand.ErrorSyntax(Command.INVITE)
|
||||||
}
|
}
|
||||||
@ -114,12 +137,14 @@ object CommandParser {
|
|||||||
Command.KICK_USER.command -> {
|
Command.KICK_USER.command -> {
|
||||||
if (messageParts.size >= 2) {
|
if (messageParts.size >= 2) {
|
||||||
val userId = messageParts[1]
|
val userId = messageParts[1]
|
||||||
if (MatrixPatterns.isUserId(userId)) {
|
|
||||||
val reason = textMessage.substring(Command.KICK_USER.command.length
|
|
||||||
+ 1
|
|
||||||
+ userId.length).trim()
|
|
||||||
|
|
||||||
ParsedCommand.KickUser(userId, reason)
|
if (MatrixPatterns.isUserId(userId)) {
|
||||||
|
ParsedCommand.KickUser(
|
||||||
|
userId,
|
||||||
|
textMessage.substring(Command.KICK_USER.length + userId.length)
|
||||||
|
.trim()
|
||||||
|
.takeIf { it.isNotBlank() }
|
||||||
|
)
|
||||||
} else {
|
} else {
|
||||||
ParsedCommand.ErrorSyntax(Command.KICK_USER)
|
ParsedCommand.ErrorSyntax(Command.KICK_USER)
|
||||||
}
|
}
|
||||||
@ -130,12 +155,14 @@ object CommandParser {
|
|||||||
Command.BAN_USER.command -> {
|
Command.BAN_USER.command -> {
|
||||||
if (messageParts.size >= 2) {
|
if (messageParts.size >= 2) {
|
||||||
val userId = messageParts[1]
|
val userId = messageParts[1]
|
||||||
if (MatrixPatterns.isUserId(userId)) {
|
|
||||||
val reason = textMessage.substring(Command.BAN_USER.command.length
|
|
||||||
+ 1
|
|
||||||
+ userId.length).trim()
|
|
||||||
|
|
||||||
ParsedCommand.BanUser(userId, reason)
|
if (MatrixPatterns.isUserId(userId)) {
|
||||||
|
ParsedCommand.BanUser(
|
||||||
|
userId,
|
||||||
|
textMessage.substring(Command.BAN_USER.length + userId.length)
|
||||||
|
.trim()
|
||||||
|
.takeIf { it.isNotBlank() }
|
||||||
|
)
|
||||||
} else {
|
} else {
|
||||||
ParsedCommand.ErrorSyntax(Command.BAN_USER)
|
ParsedCommand.ErrorSyntax(Command.BAN_USER)
|
||||||
}
|
}
|
||||||
@ -144,11 +171,16 @@ object CommandParser {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
Command.UNBAN_USER.command -> {
|
Command.UNBAN_USER.command -> {
|
||||||
if (messageParts.size == 2) {
|
if (messageParts.size >= 2) {
|
||||||
val userId = messageParts[1]
|
val userId = messageParts[1]
|
||||||
|
|
||||||
if (MatrixPatterns.isUserId(userId)) {
|
if (MatrixPatterns.isUserId(userId)) {
|
||||||
ParsedCommand.UnbanUser(userId)
|
ParsedCommand.UnbanUser(
|
||||||
|
userId,
|
||||||
|
textMessage.substring(Command.UNBAN_USER.length + userId.length)
|
||||||
|
.trim()
|
||||||
|
.takeIf { it.isNotBlank() }
|
||||||
|
)
|
||||||
} else {
|
} else {
|
||||||
ParsedCommand.ErrorSyntax(Command.UNBAN_USER)
|
ParsedCommand.ErrorSyntax(Command.UNBAN_USER)
|
||||||
}
|
}
|
||||||
|
@ -34,14 +34,14 @@ sealed class ParsedCommand {
|
|||||||
// Valid commands:
|
// Valid commands:
|
||||||
|
|
||||||
class SendEmote(val message: CharSequence) : ParsedCommand()
|
class SendEmote(val message: CharSequence) : ParsedCommand()
|
||||||
class BanUser(val userId: String, val reason: String) : ParsedCommand()
|
class BanUser(val userId: String, val reason: String?) : ParsedCommand()
|
||||||
class UnbanUser(val userId: String) : ParsedCommand()
|
class UnbanUser(val userId: String, val reason: String?) : ParsedCommand()
|
||||||
class SetUserPowerLevel(val userId: String, val powerLevel: Int) : ParsedCommand()
|
class SetUserPowerLevel(val userId: String, val powerLevel: Int) : ParsedCommand()
|
||||||
class Invite(val userId: String) : ParsedCommand()
|
class Invite(val userId: String, val reason: String?) : ParsedCommand()
|
||||||
class JoinRoom(val roomAlias: String) : ParsedCommand()
|
class JoinRoom(val roomAlias: String, val reason: String?) : ParsedCommand()
|
||||||
class PartRoom(val roomAlias: String) : ParsedCommand()
|
class PartRoom(val roomAlias: String, val reason: String?) : ParsedCommand()
|
||||||
class ChangeTopic(val topic: String) : ParsedCommand()
|
class ChangeTopic(val topic: String) : ParsedCommand()
|
||||||
class KickUser(val userId: String, val reason: String) : ParsedCommand()
|
class KickUser(val userId: String, val reason: String?) : ParsedCommand()
|
||||||
class ChangeDisplayName(val displayName: String) : ParsedCommand()
|
class ChangeDisplayName(val displayName: String) : ParsedCommand()
|
||||||
class SetMarkdown(val enable: Boolean) : ParsedCommand()
|
class SetMarkdown(val enable: Boolean) : ParsedCommand()
|
||||||
object ClearScalarToken : ParsedCommand()
|
object ClearScalarToken : ParsedCommand()
|
||||||
|
@ -1181,7 +1181,7 @@ class RoomDetailFragment @Inject constructor(
|
|||||||
&& userId == session.myUserId) {
|
&& userId == session.myUserId) {
|
||||||
// Empty composer, current user: start an emote
|
// Empty composer, current user: start an emote
|
||||||
composerLayout.composerEditText.setText(Command.EMOTE.command + " ")
|
composerLayout.composerEditText.setText(Command.EMOTE.command + " ")
|
||||||
composerLayout.composerEditText.setSelection(Command.EMOTE.command.length + 1)
|
composerLayout.composerEditText.setSelection(Command.EMOTE.length)
|
||||||
} else {
|
} else {
|
||||||
val roomMember = roomDetailViewModel.getMember(userId)
|
val roomMember = roomDetailViewModel.getMember(userId)
|
||||||
// TODO move logic outside of fragment
|
// TODO move logic outside of fragment
|
||||||
|
@ -200,9 +200,10 @@ class RoomDetailViewModel @AssistedInject constructor(@Assisted initialState: Ro
|
|||||||
invisibleEventsObservable.accept(action)
|
invisibleEventsObservable.accept(action)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getMember(userId: String) : RoomMember? {
|
fun getMember(userId: String): RoomMember? {
|
||||||
return room.getRoomMember(userId)
|
return room.getRoomMember(userId)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convert a send mode to a draft and save the draft
|
* Convert a send mode to a draft and save the draft
|
||||||
*/
|
*/
|
||||||
@ -266,7 +267,7 @@ class RoomDetailViewModel @AssistedInject constructor(@Assisted initialState: Ro
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
session.rx()
|
session.rx()
|
||||||
.joinRoom(roomId, viaServer)
|
.joinRoom(roomId, viaServers = viaServer)
|
||||||
.map { roomId }
|
.map { roomId }
|
||||||
.execute {
|
.execute {
|
||||||
copy(tombstoneEventHandling = it)
|
copy(tombstoneEventHandling = it)
|
||||||
@ -487,7 +488,7 @@ class RoomDetailViewModel @AssistedInject constructor(@Assisted initialState: Ro
|
|||||||
private fun handleInviteSlashCommand(invite: ParsedCommand.Invite) {
|
private fun handleInviteSlashCommand(invite: ParsedCommand.Invite) {
|
||||||
_sendMessageResultLiveData.postLiveEvent(SendMessageResult.SlashCommandHandled())
|
_sendMessageResultLiveData.postLiveEvent(SendMessageResult.SlashCommandHandled())
|
||||||
|
|
||||||
room.invite(invite.userId, object : MatrixCallback<Unit> {
|
room.invite(invite.userId, invite.reason, object : MatrixCallback<Unit> {
|
||||||
override fun onSuccess(data: Unit) {
|
override fun onSuccess(data: Unit) {
|
||||||
_sendMessageResultLiveData.postLiveEvent(SendMessageResult.SlashCommandResultOk)
|
_sendMessageResultLiveData.postLiveEvent(SendMessageResult.SlashCommandResultOk)
|
||||||
}
|
}
|
||||||
@ -553,7 +554,7 @@ class RoomDetailViewModel @AssistedInject constructor(@Assisted initialState: Ro
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun handleRejectInvite() {
|
private fun handleRejectInvite() {
|
||||||
room.leave(object : MatrixCallback<Unit> {})
|
room.leave(null, object : MatrixCallback<Unit> {})
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun handleAcceptInvite() {
|
private fun handleAcceptInvite() {
|
||||||
|
@ -19,14 +19,7 @@ package im.vector.riotx.features.home.room.detail.timeline.format
|
|||||||
import im.vector.matrix.android.api.session.events.model.Event
|
import im.vector.matrix.android.api.session.events.model.Event
|
||||||
import im.vector.matrix.android.api.session.events.model.EventType
|
import im.vector.matrix.android.api.session.events.model.EventType
|
||||||
import im.vector.matrix.android.api.session.events.model.toModel
|
import im.vector.matrix.android.api.session.events.model.toModel
|
||||||
import im.vector.matrix.android.api.session.room.model.Membership
|
import im.vector.matrix.android.api.session.room.model.*
|
||||||
import im.vector.matrix.android.api.session.room.model.RoomHistoryVisibility
|
|
||||||
import im.vector.matrix.android.api.session.room.model.RoomHistoryVisibilityContent
|
|
||||||
import im.vector.matrix.android.api.session.room.model.RoomJoinRules
|
|
||||||
import im.vector.matrix.android.api.session.room.model.RoomJoinRulesContent
|
|
||||||
import im.vector.matrix.android.api.session.room.model.RoomMember
|
|
||||||
import im.vector.matrix.android.api.session.room.model.RoomNameContent
|
|
||||||
import im.vector.matrix.android.api.session.room.model.RoomTopicContent
|
|
||||||
import im.vector.matrix.android.api.session.room.model.call.CallInviteContent
|
import im.vector.matrix.android.api.session.room.model.call.CallInviteContent
|
||||||
import im.vector.matrix.android.api.session.room.timeline.TimelineEvent
|
import im.vector.matrix.android.api.session.room.timeline.TimelineEvent
|
||||||
import im.vector.riotx.R
|
import im.vector.riotx.R
|
||||||
@ -36,7 +29,7 @@ import timber.log.Timber
|
|||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
class NoticeEventFormatter @Inject constructor(private val sessionHolder: ActiveSessionHolder,
|
class NoticeEventFormatter @Inject constructor(private val sessionHolder: ActiveSessionHolder,
|
||||||
private val stringProvider: StringProvider) {
|
private val sp: StringProvider) {
|
||||||
|
|
||||||
fun format(timelineEvent: TimelineEvent): CharSequence? {
|
fun format(timelineEvent: TimelineEvent): CharSequence? {
|
||||||
return when (val type = timelineEvent.root.getClearType()) {
|
return when (val type = timelineEvent.root.getClearType()) {
|
||||||
@ -84,36 +77,35 @@ class NoticeEventFormatter @Inject constructor(private val sessionHolder: Active
|
|||||||
private fun formatRoomNameEvent(event: Event, senderName: String?): CharSequence? {
|
private fun formatRoomNameEvent(event: Event, senderName: String?): CharSequence? {
|
||||||
val content = event.getClearContent().toModel<RoomNameContent>() ?: return null
|
val content = event.getClearContent().toModel<RoomNameContent>() ?: return null
|
||||||
return if (content.name.isNullOrBlank()) {
|
return if (content.name.isNullOrBlank()) {
|
||||||
stringProvider.getString(R.string.notice_room_name_removed, senderName)
|
sp.getString(R.string.notice_room_name_removed, senderName)
|
||||||
} else {
|
} else {
|
||||||
stringProvider.getString(R.string.notice_room_name_changed, senderName, content.name)
|
sp.getString(R.string.notice_room_name_changed, senderName, content.name)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun formatRoomTombstoneEvent(senderName: String?): CharSequence? {
|
private fun formatRoomTombstoneEvent(senderName: String?): CharSequence? {
|
||||||
return stringProvider.getString(R.string.notice_room_update, senderName)
|
return sp.getString(R.string.notice_room_update, senderName)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun formatRoomTopicEvent(event: Event, senderName: String?): CharSequence? {
|
private fun formatRoomTopicEvent(event: Event, senderName: String?): CharSequence? {
|
||||||
val content = event.getClearContent().toModel<RoomTopicContent>() ?: return null
|
val content = event.getClearContent().toModel<RoomTopicContent>() ?: return null
|
||||||
return if (content.topic.isNullOrEmpty()) {
|
return if (content.topic.isNullOrEmpty()) {
|
||||||
stringProvider.getString(R.string.notice_room_topic_removed, senderName)
|
sp.getString(R.string.notice_room_topic_removed, senderName)
|
||||||
} else {
|
} else {
|
||||||
stringProvider.getString(R.string.notice_room_topic_changed, senderName, content.topic)
|
sp.getString(R.string.notice_room_topic_changed, senderName, content.topic)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun formatRoomHistoryVisibilityEvent(event: Event, senderName: String?): CharSequence? {
|
private fun formatRoomHistoryVisibilityEvent(event: Event, senderName: String?): CharSequence? {
|
||||||
val historyVisibility = event.getClearContent().toModel<RoomHistoryVisibilityContent>()?.historyVisibility
|
val historyVisibility = event.getClearContent().toModel<RoomHistoryVisibilityContent>()?.historyVisibility ?: return null
|
||||||
?: return null
|
|
||||||
|
|
||||||
val formattedVisibility = when (historyVisibility) {
|
val formattedVisibility = when (historyVisibility) {
|
||||||
RoomHistoryVisibility.SHARED -> stringProvider.getString(R.string.notice_room_visibility_shared)
|
RoomHistoryVisibility.SHARED -> sp.getString(R.string.notice_room_visibility_shared)
|
||||||
RoomHistoryVisibility.INVITED -> stringProvider.getString(R.string.notice_room_visibility_invited)
|
RoomHistoryVisibility.INVITED -> sp.getString(R.string.notice_room_visibility_invited)
|
||||||
RoomHistoryVisibility.JOINED -> stringProvider.getString(R.string.notice_room_visibility_joined)
|
RoomHistoryVisibility.JOINED -> sp.getString(R.string.notice_room_visibility_joined)
|
||||||
RoomHistoryVisibility.WORLD_READABLE -> stringProvider.getString(R.string.notice_room_visibility_world_readable)
|
RoomHistoryVisibility.WORLD_READABLE -> sp.getString(R.string.notice_room_visibility_world_readable)
|
||||||
}
|
}
|
||||||
return stringProvider.getString(R.string.notice_made_future_room_visibility, senderName, formattedVisibility)
|
return sp.getString(R.string.notice_made_future_room_visibility, senderName, formattedVisibility)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun formatCallEvent(event: Event, senderName: String?): CharSequence? {
|
private fun formatCallEvent(event: Event, senderName: String?): CharSequence? {
|
||||||
@ -122,13 +114,13 @@ class NoticeEventFormatter @Inject constructor(private val sessionHolder: Active
|
|||||||
val content = event.getClearContent().toModel<CallInviteContent>() ?: return null
|
val content = event.getClearContent().toModel<CallInviteContent>() ?: return null
|
||||||
val isVideoCall = content.offer.sdp == CallInviteContent.Offer.SDP_VIDEO
|
val isVideoCall = content.offer.sdp == CallInviteContent.Offer.SDP_VIDEO
|
||||||
return if (isVideoCall) {
|
return if (isVideoCall) {
|
||||||
stringProvider.getString(R.string.notice_placed_video_call, senderName)
|
sp.getString(R.string.notice_placed_video_call, senderName)
|
||||||
} else {
|
} else {
|
||||||
stringProvider.getString(R.string.notice_placed_voice_call, senderName)
|
sp.getString(R.string.notice_placed_voice_call, senderName)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
EventType.CALL_ANSWER == event.type -> stringProvider.getString(R.string.notice_answered_call, senderName)
|
EventType.CALL_ANSWER == event.type -> sp.getString(R.string.notice_answered_call, senderName)
|
||||||
EventType.CALL_HANGUP == event.type -> stringProvider.getString(R.string.notice_ended_call, senderName)
|
EventType.CALL_HANGUP == event.type -> sp.getString(R.string.notice_ended_call, senderName)
|
||||||
else -> null
|
else -> null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -150,12 +142,11 @@ class NoticeEventFormatter @Inject constructor(private val sessionHolder: Active
|
|||||||
if (eventContent?.displayName != prevEventContent?.displayName) {
|
if (eventContent?.displayName != prevEventContent?.displayName) {
|
||||||
val displayNameText = when {
|
val displayNameText = when {
|
||||||
prevEventContent?.displayName.isNullOrEmpty() ->
|
prevEventContent?.displayName.isNullOrEmpty() ->
|
||||||
stringProvider.getString(R.string.notice_display_name_set, event.senderId, eventContent?.displayName)
|
sp.getString(R.string.notice_display_name_set, event.senderId, eventContent?.displayName)
|
||||||
eventContent?.displayName.isNullOrEmpty() ->
|
eventContent?.displayName.isNullOrEmpty() ->
|
||||||
stringProvider.getString(R.string.notice_display_name_removed, event.senderId, prevEventContent?.displayName)
|
sp.getString(R.string.notice_display_name_removed, event.senderId, prevEventContent?.displayName)
|
||||||
else ->
|
else ->
|
||||||
stringProvider.getString(R.string.notice_display_name_changed_from,
|
sp.getString(R.string.notice_display_name_changed_from, event.senderId, prevEventContent?.displayName, eventContent?.displayName)
|
||||||
event.senderId, prevEventContent?.displayName, eventContent?.displayName)
|
|
||||||
}
|
}
|
||||||
displayText.append(displayNameText)
|
displayText.append(displayNameText)
|
||||||
}
|
}
|
||||||
@ -163,73 +154,96 @@ class NoticeEventFormatter @Inject constructor(private val sessionHolder: Active
|
|||||||
if (eventContent?.avatarUrl != prevEventContent?.avatarUrl) {
|
if (eventContent?.avatarUrl != prevEventContent?.avatarUrl) {
|
||||||
val displayAvatarText = if (displayText.isNotEmpty()) {
|
val displayAvatarText = if (displayText.isNotEmpty()) {
|
||||||
displayText.append(" ")
|
displayText.append(" ")
|
||||||
stringProvider.getString(R.string.notice_avatar_changed_too)
|
sp.getString(R.string.notice_avatar_changed_too)
|
||||||
} else {
|
} else {
|
||||||
stringProvider.getString(R.string.notice_avatar_url_changed, senderName)
|
sp.getString(R.string.notice_avatar_url_changed, senderName)
|
||||||
}
|
}
|
||||||
displayText.append(displayAvatarText)
|
displayText.append(displayAvatarText)
|
||||||
}
|
}
|
||||||
if (displayText.isEmpty()) {
|
if (displayText.isEmpty()) {
|
||||||
displayText.append(
|
displayText.append(
|
||||||
stringProvider.getString(R.string.notice_member_no_changes, senderName)
|
sp.getString(R.string.notice_member_no_changes, senderName)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
return displayText.toString()
|
return displayText.toString()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun buildMembershipNotice(event: Event, senderName: String?, eventContent: RoomMember?, prevEventContent: RoomMember?): String? {
|
private fun buildMembershipNotice(event: Event, senderName: String?, eventContent: RoomMember?, prevEventContent: RoomMember?): String? {
|
||||||
val senderDisplayName = senderName ?: event.senderId
|
val senderDisplayName = senderName ?: event.senderId ?: ""
|
||||||
val targetDisplayName = eventContent?.displayName ?: prevEventContent?.displayName ?: ""
|
val targetDisplayName = eventContent?.displayName ?: prevEventContent?.displayName ?: event.stateKey ?: ""
|
||||||
return when {
|
return when (eventContent?.membership) {
|
||||||
Membership.INVITE == eventContent?.membership -> {
|
Membership.INVITE -> {
|
||||||
val selfUserId = sessionHolder.getSafeActiveSession()?.myUserId
|
val selfUserId = sessionHolder.getSafeActiveSession()?.myUserId
|
||||||
when {
|
when {
|
||||||
eventContent.thirdPartyInvite != null -> {
|
eventContent.thirdPartyInvite != null -> {
|
||||||
val userWhoHasAccepted = eventContent.thirdPartyInvite?.signed?.mxid
|
val userWhoHasAccepted = eventContent.thirdPartyInvite?.signed?.mxid ?: event.stateKey
|
||||||
?: event.stateKey
|
val threePidDisplayName = eventContent.thirdPartyInvite?.displayName ?: ""
|
||||||
stringProvider.getString(R.string.notice_room_third_party_registered_invite,
|
eventContent.safeReason?.let { reason ->
|
||||||
userWhoHasAccepted, eventContent.thirdPartyInvite?.displayName)
|
sp.getString(R.string.notice_room_third_party_registered_invite_with_reason, userWhoHasAccepted, threePidDisplayName, reason)
|
||||||
|
} ?: sp.getString(R.string.notice_room_third_party_registered_invite, userWhoHasAccepted, threePidDisplayName)
|
||||||
}
|
}
|
||||||
event.stateKey == selfUserId ->
|
event.stateKey == selfUserId ->
|
||||||
stringProvider.getString(R.string.notice_room_invite_you, senderDisplayName)
|
eventContent.safeReason?.let { reason ->
|
||||||
|
sp.getString(R.string.notice_room_invite_you_with_reason, senderDisplayName, reason)
|
||||||
|
} ?: sp.getString(R.string.notice_room_invite_you, senderDisplayName)
|
||||||
event.stateKey.isNullOrEmpty() ->
|
event.stateKey.isNullOrEmpty() ->
|
||||||
stringProvider.getString(R.string.notice_room_invite_no_invitee, senderDisplayName)
|
eventContent.safeReason?.let { reason ->
|
||||||
|
sp.getString(R.string.notice_room_invite_no_invitee_with_reason, senderDisplayName, reason)
|
||||||
|
} ?: sp.getString(R.string.notice_room_invite_no_invitee, senderDisplayName)
|
||||||
else ->
|
else ->
|
||||||
stringProvider.getString(R.string.notice_room_invite, senderDisplayName, targetDisplayName)
|
eventContent.safeReason?.let { reason ->
|
||||||
|
sp.getString(R.string.notice_room_invite_with_reason, senderDisplayName, targetDisplayName, reason)
|
||||||
|
} ?: sp.getString(R.string.notice_room_invite, senderDisplayName, targetDisplayName)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Membership.JOIN == eventContent?.membership ->
|
Membership.JOIN ->
|
||||||
stringProvider.getString(R.string.notice_room_join, senderDisplayName)
|
eventContent.safeReason?.let { reason ->
|
||||||
Membership.LEAVE == eventContent?.membership ->
|
sp.getString(R.string.notice_room_join_with_reason, senderDisplayName, reason)
|
||||||
|
} ?: sp.getString(R.string.notice_room_join, senderDisplayName)
|
||||||
|
Membership.LEAVE ->
|
||||||
// 2 cases here: this member may have left voluntarily or they may have been "left" by someone else ie. kicked
|
// 2 cases here: this member may have left voluntarily or they may have been "left" by someone else ie. kicked
|
||||||
return if (event.senderId == event.stateKey) {
|
if (event.senderId == event.stateKey) {
|
||||||
if (prevEventContent?.membership == Membership.INVITE) {
|
if (prevEventContent?.membership == Membership.INVITE) {
|
||||||
stringProvider.getString(R.string.notice_room_reject, senderDisplayName)
|
eventContent.safeReason?.let { reason ->
|
||||||
|
sp.getString(R.string.notice_room_reject_with_reason, senderDisplayName, reason)
|
||||||
|
} ?: sp.getString(R.string.notice_room_reject, senderDisplayName)
|
||||||
} else {
|
} else {
|
||||||
stringProvider.getString(R.string.notice_room_leave, senderDisplayName)
|
eventContent.safeReason?.let { reason ->
|
||||||
|
sp.getString(R.string.notice_room_leave_with_reason, senderDisplayName, reason)
|
||||||
|
} ?: sp.getString(R.string.notice_room_leave, senderDisplayName)
|
||||||
}
|
}
|
||||||
} else if (prevEventContent?.membership == Membership.INVITE) {
|
} else if (prevEventContent?.membership == Membership.INVITE) {
|
||||||
stringProvider.getString(R.string.notice_room_withdraw, senderDisplayName, targetDisplayName)
|
eventContent.safeReason?.let { reason ->
|
||||||
|
sp.getString(R.string.notice_room_withdraw_with_reason, senderDisplayName, targetDisplayName, reason)
|
||||||
|
} ?: sp.getString(R.string.notice_room_withdraw, senderDisplayName, targetDisplayName)
|
||||||
} else if (prevEventContent?.membership == Membership.JOIN) {
|
} else if (prevEventContent?.membership == Membership.JOIN) {
|
||||||
stringProvider.getString(R.string.notice_room_kick, senderDisplayName, targetDisplayName)
|
eventContent.safeReason?.let { reason ->
|
||||||
|
sp.getString(R.string.notice_room_kick_with_reason, senderDisplayName, targetDisplayName, reason)
|
||||||
|
} ?: sp.getString(R.string.notice_room_kick, senderDisplayName, targetDisplayName)
|
||||||
} else if (prevEventContent?.membership == Membership.BAN) {
|
} else if (prevEventContent?.membership == Membership.BAN) {
|
||||||
stringProvider.getString(R.string.notice_room_unban, senderDisplayName, targetDisplayName)
|
eventContent.safeReason?.let { reason ->
|
||||||
|
sp.getString(R.string.notice_room_unban_with_reason, senderDisplayName, targetDisplayName, reason)
|
||||||
|
} ?: sp.getString(R.string.notice_room_unban, senderDisplayName, targetDisplayName)
|
||||||
} else {
|
} else {
|
||||||
null
|
null
|
||||||
}
|
}
|
||||||
Membership.BAN == eventContent?.membership ->
|
Membership.BAN ->
|
||||||
stringProvider.getString(R.string.notice_room_ban, senderDisplayName, targetDisplayName)
|
eventContent.safeReason?.let {
|
||||||
Membership.KNOCK == eventContent?.membership ->
|
sp.getString(R.string.notice_room_ban_with_reason, senderDisplayName, targetDisplayName, it)
|
||||||
stringProvider.getString(R.string.notice_room_kick, senderDisplayName, targetDisplayName)
|
} ?: sp.getString(R.string.notice_room_ban, senderDisplayName, targetDisplayName)
|
||||||
else -> null
|
Membership.KNOCK ->
|
||||||
|
eventContent.safeReason?.let { reason ->
|
||||||
|
sp.getString(R.string.notice_room_kick_with_reason, senderDisplayName, targetDisplayName, reason)
|
||||||
|
} ?: sp.getString(R.string.notice_room_kick, senderDisplayName, targetDisplayName)
|
||||||
|
else -> null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun formatJoinRulesEvent(event: Event, senderName: String?): CharSequence? {
|
private fun formatJoinRulesEvent(event: Event, senderName: String?): CharSequence? {
|
||||||
val content = event.getClearContent().toModel<RoomJoinRulesContent>() ?: return null
|
val content = event.getClearContent().toModel<RoomJoinRulesContent>() ?: return null
|
||||||
return when (content.joinRules) {
|
return when (content.joinRules) {
|
||||||
RoomJoinRules.INVITE -> stringProvider.getString(R.string.room_join_rules_invite, senderName)
|
RoomJoinRules.INVITE -> sp.getString(R.string.room_join_rules_invite, senderName)
|
||||||
RoomJoinRules.PUBLIC -> stringProvider.getString(R.string.room_join_rules_public, senderName)
|
RoomJoinRules.PUBLIC -> sp.getString(R.string.room_join_rules_public, senderName)
|
||||||
else -> null
|
else -> null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -123,7 +123,7 @@ class RoomListViewModel @Inject constructor(initialState: RoomListViewState,
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
session.getRoom(roomId)?.join(emptyList(), object : MatrixCallback<Unit> {
|
session.getRoom(roomId)?.join(callback = object : MatrixCallback<Unit> {
|
||||||
override fun onSuccess(data: Unit) {
|
override fun onSuccess(data: Unit) {
|
||||||
// We do not update the joiningRoomsIds here, because, the room is not joined yet regarding the sync data.
|
// We do not update the joiningRoomsIds here, because, the room is not joined yet regarding the sync data.
|
||||||
// Instead, we wait for the room to be joined
|
// Instead, we wait for the room to be joined
|
||||||
@ -158,7 +158,7 @@ class RoomListViewModel @Inject constructor(initialState: RoomListViewState,
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
session.getRoom(roomId)?.leave(object : MatrixCallback<Unit> {
|
session.getRoom(roomId)?.leave(null, object : MatrixCallback<Unit> {
|
||||||
override fun onSuccess(data: Unit) {
|
override fun onSuccess(data: Unit) {
|
||||||
// We do not update the rejectingRoomsIds here, because, the room is not rejected yet regarding the sync data.
|
// We do not update the rejectingRoomsIds here, because, the room is not rejected yet regarding the sync data.
|
||||||
// Instead, we wait for the room to be rejected
|
// Instead, we wait for the room to be rejected
|
||||||
@ -197,7 +197,7 @@ class RoomListViewModel @Inject constructor(initialState: RoomListViewState,
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun handleLeaveRoom(action: RoomListAction.LeaveRoom) {
|
private fun handleLeaveRoom(action: RoomListAction.LeaveRoom) {
|
||||||
session.getRoom(action.roomId)?.leave(object : MatrixCallback<Unit> {
|
session.getRoom(action.roomId)?.leave(null, object : MatrixCallback<Unit> {
|
||||||
override fun onFailure(failure: Throwable) {
|
override fun onFailure(failure: Throwable) {
|
||||||
_viewEvents.post(RoomListViewEvents.Failure(failure))
|
_viewEvents.post(RoomListViewEvents.Failure(failure))
|
||||||
}
|
}
|
||||||
|
@ -74,14 +74,14 @@ class NotificationBroadcastReceiver : BroadcastReceiver() {
|
|||||||
private fun handleJoinRoom(roomId: String) {
|
private fun handleJoinRoom(roomId: String) {
|
||||||
activeSessionHolder.getSafeActiveSession()?.let { session ->
|
activeSessionHolder.getSafeActiveSession()?.let { session ->
|
||||||
session.getRoom(roomId)
|
session.getRoom(roomId)
|
||||||
?.join(emptyList(), object : MatrixCallback<Unit> {})
|
?.join(callback = object : MatrixCallback<Unit> {})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun handleRejectRoom(roomId: String) {
|
private fun handleRejectRoom(roomId: String) {
|
||||||
activeSessionHolder.getSafeActiveSession()?.let { session ->
|
activeSessionHolder.getSafeActiveSession()?.let { session ->
|
||||||
session.getRoom(roomId)
|
session.getRoom(roomId)
|
||||||
?.leave(object : MatrixCallback<Unit> {})
|
?.leave(callback = object : MatrixCallback<Unit> {})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -214,7 +214,7 @@ class RoomDirectoryViewModel @AssistedInject constructor(@Assisted initialState:
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
session.joinRoom(action.roomId, emptyList(), object : MatrixCallback<Unit> {
|
session.joinRoom(action.roomId, callback = object : MatrixCallback<Unit> {
|
||||||
override fun onSuccess(data: Unit) {
|
override fun onSuccess(data: Unit) {
|
||||||
// We do not update the joiningRoomsIds here, because, the room is not joined yet regarding the sync data.
|
// We do not update the joiningRoomsIds here, because, the room is not joined yet regarding the sync data.
|
||||||
// Instead, we wait for the room to be joined
|
// Instead, we wait for the room to be joined
|
||||||
|
@ -97,7 +97,7 @@ class RoomPreviewViewModel @AssistedInject constructor(@Assisted initialState: R
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
session.joinRoom(state.roomId, emptyList(), object : MatrixCallback<Unit> {
|
session.joinRoom(state.roomId, callback = object : MatrixCallback<Unit> {
|
||||||
override fun onSuccess(data: Unit) {
|
override fun onSuccess(data: Unit) {
|
||||||
// We do not update the joiningRoomsIds here, because, the room is not joined yet regarding the sync data.
|
// We do not update the joiningRoomsIds here, because, the room is not joined yet regarding the sync data.
|
||||||
// Instead, we wait for the room to be joined
|
// Instead, we wait for the room to be joined
|
||||||
|
Loading…
x
Reference in New Issue
Block a user