Skip to content

Commit 59b45c3

Browse files
committed
merge conflicts + refactor
Signed-off-by: sowjanyakch <sowjanya.kch@gmail.com>
1 parent 59748ed commit 59b45c3

12 files changed

Lines changed: 1614 additions & 919 deletions

File tree

app/schemas/com.nextcloud.talk.data.source.local.TalkDatabase/21.json

Lines changed: 757 additions & 762 deletions
Large diffs are not rendered by default.

app/schemas/com.nextcloud.talk.data.source.local.TalkDatabase/23.json

Lines changed: 801 additions & 0 deletions
Large diffs are not rendered by default.

app/src/main/java/com/nextcloud/talk/api/NcApiCoroutines.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,7 @@ interface NcApiCoroutines {
340340

341341
@FormUrlEncoded
342342
@POST
343+
@Suppress("LongParameterList")
343344
suspend fun sendScheduleChatMessage(
344345
@Header("Authorization") authorization: String,
345346
@Url url: String,
@@ -355,6 +356,7 @@ interface NcApiCoroutines {
355356

356357
@FormUrlEncoded
357358
@POST
359+
@Suppress("LongParameterList")
358360
suspend fun updateScheduledMessage(
359361
@Header("Authorization") authorization: String,
360362
@Url url: String,

app/src/main/java/com/nextcloud/talk/chat/ScheduleMessageCompose.kt

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,7 @@ class ScheduleMessageCompose(
249249
}
250250

251251
@OptIn(ExperimentalMaterial3Api::class)
252+
@Suppress("LongMethod")
252253
@Composable
253254
private fun CollapsableDateTime(shouldDismiss: MutableState<Boolean>, isCollapsed: MutableState<Boolean>) {
254255
GeneralIconButton(icon = Icons.Filled.DateRange, label = stringResource(R.string.custom)) {
@@ -264,10 +265,8 @@ class ScheduleMessageCompose(
264265
val currentYear = LocalDate.now().year
265266
val selectableDates = object : SelectableDates {
266267
override fun isSelectableDate(utcTimeMillis: Long): Boolean = utcTimeMillis >= todayMillis
267-
268268
override fun isSelectableYear(year: Int): Boolean = year >= currentYear
269269
}
270-
271270
val datePickerState = rememberDatePickerState(
272271
selectableDates = selectableDates
273272
)
@@ -277,13 +276,11 @@ class ScheduleMessageCompose(
277276
initialMinute = now.minute,
278277
is24Hour = DateFormat.is24HourFormat(LocalContext.current)
279278
)
280-
281279
BoxWithConstraints(
282280
modifier = Modifier
283281
.requiredSizeIn(minWidth = 360.dp)
284282
) {
285283
val scale = remember(maxWidth) { if (maxWidth < 360.dp) maxWidth / 360.dp else 1f }
286-
287284
DatePicker(
288285
state = datePickerState,
289286
modifier = Modifier
@@ -293,13 +290,10 @@ class ScheduleMessageCompose(
293290
)
294291
)
295292
}
296-
297293
Spacer(modifier = Modifier.height(16.dp))
298-
299294
TimePicker(
300295
state = timePickerState
301296
)
302-
303297
val date = datePickerState.selectedDateMillis?.let {
304298
val instant = Instant.ofEpochMilli(it)
305299
LocalDateTime.ofInstant(instant, ZoneOffset.UTC) // Google sends time in UTC

app/src/main/java/com/nextcloud/talk/chat/ScheduledMessagesActivity.kt

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ class ScheduledMessagesActivity : BaseActivity() {
211211
}
212212

213213
@OptIn(ExperimentalMaterial3Api::class)
214-
@Suppress("LongMethod")
214+
@Suppress("LongParameterList", "LongMethod")
215215
@Composable
216216
private fun ScheduledMessagesScreen(
217217
conversationName: String,
@@ -296,8 +296,13 @@ class ScheduledMessagesActivity : BaseActivity() {
296296
TopAppBar(
297297
title = { Text(text = conversationName, style = MaterialTheme.typography.titleMedium) },
298298
navigationIcon = {
299-
IconButton(onClick = onBack) { Icon(Icons.AutoMirrored.Outlined.ArrowBack, contentDescription =
300-
null) }
299+
IconButton(onClick = onBack) {
300+
Icon(
301+
Icons.AutoMirrored.Outlined.ArrowBack,
302+
contentDescription =
303+
null
304+
)
305+
}
301306
}
302307
)
303308
},
@@ -469,7 +474,7 @@ class ScheduledMessagesActivity : BaseActivity() {
469474
shape = MaterialTheme.shapes.medium,
470475
tonalElevation = 1.dp,
471476
modifier = Modifier.width(IntrinsicSize.Max)
472-
.combinedClickable(onClick = {}, onLongClick = onLongPress)
477+
.combinedClickable(onClick = {}, onLongClick = onLongPress)
473478
) {
474479
Column(modifier = Modifier.padding(12.dp)) {
475480
Text(text = text, style = MaterialTheme.typography.bodyMedium)
@@ -488,6 +493,7 @@ class ScheduledMessagesActivity : BaseActivity() {
488493
}
489494

490495
@OptIn(ExperimentalMaterial3Api::class)
496+
@Suppress("LongMethod")
491497
@Composable
492498
private fun ScheduledMessageEditRow(
493499
editValue: TextFieldValue,

app/src/main/java/com/nextcloud/talk/chat/data/network/OfflineFirstChatRepository.kt

Lines changed: 24 additions & 141 deletions
Original file line numberDiff line numberDiff line change
@@ -484,93 +484,6 @@ class OfflineFirstChatRepository @Inject constructor(
484484
return fieldMap
485485
}
486486

487-
@Suppress("LongParameterList")
488-
override suspend fun sendScheduledChatMessage(
489-
credentials: String,
490-
url: String,
491-
message: String,
492-
displayName: String,
493-
referenceId: String,
494-
replyTo: Int?,
495-
sendWithoutNotification: Boolean,
496-
threadTitle: String?,
497-
threadId: Long?,
498-
sendAt: Int?
499-
): Flow<Result<ChatOverallSingleMessage>> {
500-
return flow {
501-
val response = network.sendScheduledChatMessage(
502-
credentials,
503-
url,
504-
message,
505-
displayName,
506-
referenceId,
507-
replyTo,
508-
sendWithoutNotification,
509-
threadTitle,
510-
threadId,
511-
sendAt
512-
)
513-
emit(Result.success(response))
514-
}.catch { e ->
515-
Log.e(TAG, "Error when scheduling message", e)
516-
emit(Result.failure(e))
517-
}
518-
}
519-
520-
@Suppress("LongParameterList")
521-
override suspend fun updateScheduledChatMessage(
522-
credentials: String,
523-
url: String,
524-
message: String,
525-
sendAt: Int?,
526-
replyTo: Int?,
527-
sendWithoutNotification: Boolean,
528-
threadTitle: String?,
529-
threadId: Long?
530-
): Flow<Result<ChatOverallSingleMessage>> {
531-
return flow {
532-
val response = network.updateScheduledMessage(
533-
credentials,
534-
url,
535-
message,
536-
sendAt,
537-
replyTo,
538-
sendWithoutNotification,
539-
threadTitle,
540-
threadId
541-
)
542-
emit(Result.success(response))
543-
}.catch { e ->
544-
Log.e(TAG, "Error when updating scheduled message", e)
545-
emit(Result.failure(e))
546-
}
547-
}
548-
549-
override suspend fun deleteScheduledChatMessage(credentials: String, url: String): Flow<Result<GenericOverall>> {
550-
return flow {
551-
val response = network.deleteScheduledMessage(credentials, url)
552-
emit(Result.success(response))
553-
}.catch { e ->
554-
Log.e(TAG, "Error when deleting scheduled message", e)
555-
emit(Result.failure(e))
556-
}
557-
}
558-
559-
override suspend fun getScheduledChatMessages(credentials: String, url: String): Flow<Result<List<ChatMessage>>> {
560-
return flow {
561-
val response = network.getScheduledMessages(credentials, url)
562-
val messages = response.ocs?.data.orEmpty().map { messageJson ->
563-
messageJson.asModel().copy(
564-
token = messageJson.id.toString()
565-
)
566-
}
567-
emit(Result.success(messages))
568-
}.catch { e ->
569-
Log.e(TAG, "Error when fetching scheduled messages", e)
570-
emit(Result.failure(e))
571-
}
572-
}
573-
574487
override suspend fun getNumberOfThreadReplies(threadId: Long): Int =
575488
chatDao.getNumberOfThreadReplies(internalConversationId, threadId)
576489

@@ -1185,54 +1098,22 @@ class OfflineFirstChatRepository @Inject constructor(
11851098
}
11861099
}
11871100

1188-
@Suppress("Detekt.TooGenericExceptionCaught")
1189-
override suspend fun addTemporaryMessage(
1190-
message: CharSequence,
1191-
displayName: String,
1192-
replyTo: Int,
1193-
sendWithoutNotification: Boolean,
1194-
referenceId: String
1195-
): Flow<Result<ChatMessage?>> =
1196-
flow {
1197-
try {
1198-
val tempChatMessageEntity = createChatMessageEntity(
1199-
internalConversationId,
1200-
message.toString(),
1201-
replyTo,
1202-
sendWithoutNotification,
1203-
referenceId
1204-
)
1205-
1206-
chatDao.upsertChatMessage(tempChatMessageEntity)
1207-
1208-
val tempChatMessageModel = tempChatMessageEntity.asModel()
1209-
1210-
emit(Result.success(tempChatMessageModel))
1211-
1212-
val triple = Triple(true, false, listOf(tempChatMessageModel))
1213-
_messageFlow.emit(triple)
1214-
} catch (e: Exception) {
1215-
Log.e(TAG, "Something went wrong when adding temporary message", e)
1216-
emit(Result.failure(e))
1217-
}
1218-
}
1219-
12201101
@Suppress("LongParameterList")
12211102
override suspend fun sendScheduledChatMessage(
12221103
credentials: String,
12231104
url: String,
12241105
message: String,
12251106
displayName: String,
12261107
referenceId: String,
1227-
replyTo: Int,
1108+
replyTo: Int?,
12281109
sendWithoutNotification: Boolean,
1229-
threadTitle: String,
1230-
threadId: Int,
1231-
sendAt: Int
1110+
threadTitle: String?,
1111+
threadId: Long?,
1112+
sendAt: Int?
12321113
): Flow<Result<ChatOverallSingleMessage>> {
12331114
if (!networkMonitor.isOnline.value) {
12341115
return flow {
1235-
emit(Result.failure(IOException("Skipped to send scheduled message as device is offline")))
1116+
emit(Result.failure(IOException("Skipped to schedule message as device is offline")))
12361117
}
12371118
}
12381119

@@ -1251,20 +1132,21 @@ class OfflineFirstChatRepository @Inject constructor(
12511132
)
12521133
emit(Result.success(response))
12531134
}.catch { e ->
1135+
Log.e(TAG, "Error when scheduling message", e)
12541136
emit(Result.failure(e))
12551137
}
12561138
}
12571139

12581140
@Suppress("LongParameterList")
1259-
override suspend fun updateScheduledMessage(
1141+
override suspend fun updateScheduledChatMessage(
12601142
credentials: String,
12611143
url: String,
12621144
message: String,
1263-
sendAt: Int,
1264-
replyTo: Int,
1145+
sendAt: Int?,
1146+
replyTo: Int?,
12651147
sendWithoutNotification: Boolean,
1266-
threadTitle: String,
1267-
threadId: Int
1148+
threadTitle: String?,
1149+
threadId: Long?
12681150
): Flow<Result<ChatOverallSingleMessage>> {
12691151
if (!networkMonitor.isOnline.value) {
12701152
return flow {
@@ -1285,47 +1167,48 @@ class OfflineFirstChatRepository @Inject constructor(
12851167
)
12861168
emit(Result.success(response))
12871169
}.catch { e ->
1170+
Log.e(TAG, "Error when updating scheduled message", e)
12881171
emit(Result.failure(e))
12891172
}
12901173
}
12911174

1292-
override suspend fun deleteScheduledMessage(
1293-
credentials: String,
1294-
url: String
1295-
): Flow<Result<GenericOverall>> {
1175+
override suspend fun deleteScheduledChatMessage(credentials: String, url: String): Flow<Result<GenericOverall>> {
12961176
if (!networkMonitor.isOnline.value) {
12971177
return flow {
1298-
emit(Result.failure(IOException("Skip delete scheduled message as dvice is offline")))
1178+
emit(Result.failure(IOException("Skipped to delete scheduled message as device is offline")))
12991179
}
13001180
}
13011181

13021182
return flow {
13031183
val response = network.deleteScheduledMessage(credentials, url)
13041184
emit(Result.success(response))
13051185
}.catch { e ->
1186+
Log.e(TAG, "Error when deleting scheduled message", e)
13061187
emit(Result.failure(e))
13071188
}
13081189
}
13091190

1310-
override suspend fun getScheduledMessages(
1311-
credentials: String,
1312-
url: String
1313-
): Flow<Result<ChatOverall>> {
1191+
override suspend fun getScheduledChatMessages(credentials: String, url: String): Flow<Result<List<ChatMessage>>> {
13141192
if (!networkMonitor.isOnline.value) {
13151193
return flow {
1316-
emit(Result.failure(IOException("Skip fetch scheduled messages as dvice is offline")))
1194+
emit(Result.failure(IOException("Skipped to fetch scheduled messages as device is offline")))
13171195
}
13181196
}
13191197

13201198
return flow {
13211199
val response = network.getScheduledMessages(credentials, url)
1322-
emit(Result.success(response))
1200+
val messages = response.ocs?.data.orEmpty().map { messageJson ->
1201+
messageJson.asModel().copy(
1202+
token = messageJson.id.toString()
1203+
)
1204+
}
1205+
emit(Result.success(messages))
13231206
}.catch { e ->
1207+
Log.e(TAG, "Error when fetching scheduled messages", e)
13241208
emit(Result.failure(e))
13251209
}
13261210
}
13271211

1328-
13291212
private fun createChatMessageEntity(
13301213
internalConversationId: String,
13311214
message: String,

app/src/main/java/com/nextcloud/talk/chat/data/network/RetrofitChatNetwork.kt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,4 +275,13 @@ class RetrofitChatNetwork(private val ncApi: NcApi, private val ncApiCoroutines:
275275

276276
override suspend fun getScheduledMessages(credentials: String, url: String): ChatOverall =
277277
ncApiCoroutines.getScheduledMessage(credentials, url)
278+
279+
override suspend fun pinMessage(credentials: String, url: String, pinUntil: Int): ChatOverallSingleMessage =
280+
ncApiCoroutines.pinMessage(credentials, url, pinUntil)
281+
282+
override suspend fun unPinMessage(credentials: String, url: String): ChatOverallSingleMessage =
283+
ncApiCoroutines.unPinMessage(credentials, url)
284+
285+
override suspend fun hidePinnedMessage(credentials: String, url: String): GenericOverall =
286+
ncApiCoroutines.hidePinnedMessage(credentials, url)
278287
}

app/src/main/java/com/nextcloud/talk/chat/viewmodels/ScheduledMessagesViewModel.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ class ScheduledMessagesViewModel @Inject constructor(private val chatRepository:
7979
}
8080
}
8181

82+
@Suppress("LongParameterList")
8283
fun sendNow(
8384
credentials: String,
8485
sendUrl: String,

app/src/main/java/com/nextcloud/talk/data/database/model/ChatMessageEntity.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,10 @@ data class ChatMessageEntity(
7171
@ColumnInfo(name = "threadTitle") var threadTitle: String? = null,
7272
@ColumnInfo(name = "threadReplies") var threadReplies: Int? = 0,
7373
@ColumnInfo(name = "timestamp") var timestamp: Long = 0,
74-
@ColumnInfo(name = "sendAt") var sendAt: Int? = 0,
7574
@ColumnInfo(name = "pinnedActorType") var pinnedActorType: String? = null,
7675
@ColumnInfo(name = "pinnedActorId") var pinnedActorId: String? = null,
7776
@ColumnInfo(name = "pinnedActorDisplayName") var pinnedActorDisplayName: String? = null,
7877
@ColumnInfo(name = "pinnedAt") var pinnedAt: Long? = null,
79-
@ColumnInfo(name = "pinnedUntil") var pinnedUntil: Long? = null
78+
@ColumnInfo(name = "pinnedUntil") var pinnedUntil: Long? = null,
79+
@ColumnInfo(name = "sendAt") var sendAt: Int? = 0
8080
)

app/src/main/java/com/nextcloud/talk/data/source/local/Migrations.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ object Migrations {
2222
@DeleteColumn(tableName = "ChatMessages", columnName = "sendingFailed")
2323
class AutoMigration16To17 : AutoMigrationSpec
2424

25+
@DeleteColumn(tableName = "ChatMessages", columnName = "sendAt")
26+
class AutoMigration22To23 : AutoMigrationSpec
27+
2528
//endregion
2629

2730
//region Manual migrations

0 commit comments

Comments
 (0)