Skip to content

Commit c9bf4fe

Browse files
committed
chore(fc): mark messages deleted upon room join; add link image preview generation behind hidden beta flag for now
Signed-off-by: Brandon McAnsh <[email protected]>
1 parent d094dd3 commit c9bf4fe

File tree

28 files changed

+671
-154
lines changed

28 files changed

+671
-154
lines changed

flipchatApp/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ dependencies {
128128
implementation(project(":libs:messaging"))
129129
implementation(project(":libs:network:exchange"))
130130
implementation(project(":libs:network:connectivity"))
131+
implementation(project(":libs:opengraph"))
131132
implementation(project(":libs:permissions"))
132133
implementation(project(":libs:quickresponse"))
133134
implementation(project(":libs:requests"))

flipchatApp/src/main/kotlin/xyz/flipchat/app/MainActivity.kt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import androidx.activity.compose.setContent
99
import androidx.activity.enableEdgeToEdge
1010
import androidx.compose.runtime.CompositionLocalProvider
1111
import androidx.fragment.app.FragmentActivity
12+
import com.getcode.libs.opengraph.LocalOpenGraphParser
13+
import com.getcode.libs.opengraph.OpenGraphParser
1214
import com.getcode.network.client.Client
1315
import com.getcode.network.exchange.ExchangeNull
1416
import com.getcode.network.exchange.LocalExchange
@@ -68,6 +70,9 @@ class MainActivity : FragmentActivity() {
6870
@Inject
6971
lateinit var iapController: BillingClient
7072

73+
@Inject
74+
lateinit var openGraphParser: OpenGraphParser
75+
7176
override fun onCreate(savedInstanceState: Bundle?) {
7277
super.onCreate(savedInstanceState)
7378
handleUncaughtException()
@@ -83,7 +88,8 @@ class MainActivity : FragmentActivity() {
8388
LocalUserManager provides userManager,
8489
LocalPaymentController provides paymentController,
8590
LocalLabs provides betaFeatures,
86-
LocalBillingClient provides iapController
91+
LocalBillingClient provides iapController,
92+
LocalOpenGraphParser provides openGraphParser,
8793
) {
8894
Rinku {
8995
App(tipsEngine = tipsEngine)

flipchatApp/src/main/kotlin/xyz/flipchat/app/beta/LabsController.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,12 @@ sealed interface Lab {
6767
override val launched: Boolean = false
6868
}
6969

70+
data object LinkImages : Lab {
71+
override val key: String = "link_image_preview_enabled"
72+
override val default: Boolean = false
73+
override val launched: Boolean = false
74+
}
75+
7076
companion object {
7177
val entries = listOf(
7278
ReplyToMessage,

flipchatApp/src/main/kotlin/xyz/flipchat/app/features/beta/BetaFlagsScreen.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ private val Lab.title: String
106106
Lab.DeleteMessage -> "Delete Message Support"
107107
Lab.OpenCloseRoom -> "Open/Close Rooms"
108108
Lab.Tipping -> "Tipping"
109+
Lab.LinkImages -> "Show Previews for Links"
109110
}
110111

111112
private val Lab.message: String
@@ -117,4 +118,5 @@ private val Lab.message: String
117118
Lab.DeleteMessage -> "When enabled, hosts will gain the ability to delete messages"
118119
Lab.OpenCloseRoom -> "When enabled, hosts will gain the ability to temporarily close (and reopen) their rooms"
119120
Lab.Tipping -> "When enabled, you'll gain the ability to double tap messages to tip the author"
121+
Lab.LinkImages -> "When enabled, links shared in chat will show a preview image for the link"
120122
}

flipchatApp/src/main/kotlin/xyz/flipchat/app/features/chat/conversation/ConversationChatInput.kt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -202,9 +202,7 @@ private fun RoomOpenControlBar(
202202
)
203203

204204
CodeButton(
205-
text = stringResource(
206-
if (isOpen) R.string.action_close else R.string.action_reopen
207-
),
205+
text = stringResource(R.string.action_change),
208206
shape = CircleShape,
209207
buttonState = ButtonState.Filled,
210208
overrideContentPadding = true,

flipchatApp/src/main/kotlin/xyz/flipchat/app/features/chat/conversation/ConversationMessages.kt

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,10 @@ internal fun ConversationMessages(
163163
navigator.show(MessageTipsSheet(event.tips))
164164
}
165165
}
166+
167+
is MessageListEvent.UnreadStateHandled -> {
168+
dispatchEvent(ConversationViewModel.Event.OnUnreadStateHandled)
169+
}
166170
}
167171
}
168172
)
@@ -203,7 +207,7 @@ internal fun ConversationMessages(
203207
}
204208
}
205209

206-
HandleMessageChanges(listState = lazyListState, items = messages) { message ->
207-
dispatchEvent(ConversationViewModel.Event.MarkDelivered(message.chatMessageId))
208-
}
210+
// HandleMessageChanges(listState = lazyListState, items = messages) { message ->
211+
// dispatchEvent(ConversationViewModel.Event.MarkDelivered(message.chatMessageId))
212+
// }
209213
}

flipchatApp/src/main/kotlin/xyz/flipchat/app/features/chat/conversation/ConversationViewModel.kt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ class ConversationViewModel @Inject constructor(
115115
val replyEnabled: Boolean,
116116
val replyMessage: MessageReplyAnchor?,
117117
val startAtUnread: Boolean,
118+
val unreadStateHandled: Boolean,
118119
val title: String,
119120
val imageUri: String?,
120121
val lastSeen: Instant?,
@@ -126,6 +127,7 @@ class ConversationViewModel @Inject constructor(
126127
val isRoomOpen: Boolean,
127128
val isOpenCloseEnabled: Boolean,
128129
val isTippingEnabled: Boolean,
130+
val isLinkImagePreviewsEnabled: Boolean,
129131
val roomInfoArgs: RoomInfoArgs,
130132
val lastReadMessage: UUID?
131133
) {
@@ -140,6 +142,7 @@ class ConversationViewModel @Inject constructor(
140142
imageUri = null,
141143
conversationId = null,
142144
unreadCount = null,
145+
unreadStateHandled = false,
143146
chattableState = null,
144147
lastReadMessage = null,
145148
textFieldState = TextFieldState(),
@@ -156,6 +159,7 @@ class ConversationViewModel @Inject constructor(
156159
isRoomOpen = true,
157160
isOpenCloseEnabled = false,
158161
isTippingEnabled = false,
162+
isLinkImagePreviewsEnabled = false,
159163
roomInfoArgs = RoomInfoArgs(),
160164
)
161165
}
@@ -169,6 +173,7 @@ class ConversationViewModel @Inject constructor(
169173
Event
170174

171175
data class OnInitialUnreadCountDetermined(val count: Int) : Event
176+
data object OnUnreadStateHandled: Event
172177
data class OnTitlesChanged(val title: String, val roomCardTitle: String) : Event
173178
data class OnUserActivity(val activity: Instant) : Event
174179
data object SendCash : Event
@@ -183,6 +188,7 @@ class ConversationViewModel @Inject constructor(
183188
data class OnReplyEnabled(val enabled: Boolean) : Event
184189
data class OnOpenCloseEnabled(val enabled: Boolean) : Event
185190
data class OnTippingEnabled(val enabled: Boolean) : Event
191+
data class OnLinkImagePreviewsEnabled(val enabled: Boolean) : Event
186192
data class ReplyTo(val anchor: MessageReplyAnchor) : Event {
187193
constructor(chatItem: ChatItem.Message) : this(
188194
MessageReplyAnchor(
@@ -259,6 +265,10 @@ class ConversationViewModel @Inject constructor(
259265
.onEach { dispatchEvent(Event.OnTippingEnabled(it)) }
260266
.launchIn(viewModelScope)
261267

268+
betaFeatures.observe(Lab.LinkImages)
269+
.onEach { dispatchEvent(Event.OnLinkImagePreviewsEnabled(it)) }
270+
.launchIn(viewModelScope)
271+
262272
eventFlow
263273
.filterIsInstance<Event.OnChatIdChanged>()
264274
.map { it.chatId }
@@ -827,6 +837,8 @@ class ConversationViewModel @Inject constructor(
827837
val enableReply =
828838
currentState.replyEnabled && currentState.chattableState is ChattableState.Enabled
829839

840+
val enableLinkImages = currentState.isLinkImagePreviewsEnabled
841+
830842
page.map { indice ->
831843
val (message, member, contents, reply, tipInfo) = indice
832844

@@ -904,6 +916,7 @@ class ConversationViewModel @Inject constructor(
904916
enableReply = enableReply && !message.isDeleted,
905917
showTimestamp = false,
906918
enableTipping = tippingEnabled,
919+
enableLinkImagePreview = enableLinkImages,
907920
sender = Sender(
908921
id = message.senderId,
909922
profileImage = member?.imageUri.takeIf { it.orEmpty().isNotEmpty() },
@@ -1345,6 +1358,8 @@ class ConversationViewModel @Inject constructor(
13451358
is Event.CancelReply -> { state -> state.copy(replyMessage = null) }
13461359
is Event.OnOpenCloseEnabled -> { state -> state.copy(isOpenCloseEnabled = event.enabled) }
13471360
is Event.OnTippingEnabled -> { state -> state.copy(isTippingEnabled = event.enabled) }
1361+
is Event.OnLinkImagePreviewsEnabled -> { state -> state.copy(isLinkImagePreviewsEnabled = event.enabled) }
1362+
Event.OnUnreadStateHandled -> { state -> state.copy(unreadStateHandled = true) }
13481363
}
13491364
}
13501365
}

flipchatApp/src/main/kotlin/xyz/flipchat/app/inject/AppModule.kt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ import android.os.Build
99
import android.os.VibratorManager
1010
import android.telephony.TelephonyManager
1111
import androidx.core.app.NotificationManagerCompat
12+
import com.getcode.libs.opengraph.OpenGraphCacheProvider
13+
import com.getcode.libs.opengraph.OpenGraphParser
14+
import com.getcode.libs.opengraph.cache.CacheProvider
1215
import com.getcode.services.analytics.AnalyticsService
1316
import com.getcode.services.analytics.AnalyticsServiceNull
1417
import com.getcode.util.locale.LocaleHelper
@@ -167,4 +170,16 @@ object AppModule {
167170
} else {
168171
GooglePlayBillingClient(context, userManager, purchaseRepository)
169172
}
173+
174+
@Singleton
175+
@Provides
176+
fun providesOpenGraphCache(
177+
@ApplicationContext context: Context,
178+
): CacheProvider = OpenGraphCacheProvider(context)
179+
180+
@Singleton
181+
@Provides
182+
fun providesOpenGraphParser(
183+
cache: CacheProvider
184+
): OpenGraphParser = OpenGraphParser(cacheProvider = cache)
170185
}

libs/opengraph/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
build/
2+
.gradle/

libs/opengraph/build.gradle.kts

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
plugins {
2+
id(Plugins.android_library)
3+
id(Plugins.kotlin_android)
4+
id(Plugins.kotlin_kapt)
5+
id(Plugins.kotlin_serialization)
6+
}
7+
8+
android {
9+
namespace = "${Android.codeNamespace}.libs.opengraph"
10+
compileSdk = Android.compileSdkVersion
11+
defaultConfig {
12+
minSdk = Android.minSdkVersion
13+
targetSdk = Android.targetSdkVersion
14+
buildToolsVersion = Android.buildToolsVersion
15+
testInstrumentationRunner = Android.testInstrumentationRunner
16+
}
17+
18+
compileOptions {
19+
sourceCompatibility(Versions.java)
20+
targetCompatibility(Versions.java)
21+
}
22+
23+
java {
24+
toolchain {
25+
languageVersion.set(JavaLanguageVersion.of(Versions.java))
26+
}
27+
}
28+
29+
kotlinOptions {
30+
jvmTarget = Versions.java
31+
freeCompilerArgs += listOf(
32+
"-opt-in=kotlin.ExperimentalUnsignedTypes",
33+
"-opt-in=kotlin.RequiresOptIn"
34+
)
35+
}
36+
37+
buildFeatures {
38+
compose = true
39+
}
40+
41+
composeOptions {
42+
kotlinCompilerExtensionVersion = Versions.compose_compiler
43+
}
44+
}
45+
46+
dependencies {
47+
//Jetpack compose
48+
implementation(platform(Libs.compose_bom))
49+
implementation(Libs.compose_ui)
50+
51+
implementation("org.jsoup:jsoup:1.16.1")
52+
implementation(project(":libs:encryption:utils"))
53+
54+
implementation(Libs.kotlinx_coroutines_core)
55+
implementation(Libs.kotlinx_serialization_json)
56+
implementation(Libs.inject)
57+
58+
implementation(Libs.androidx_datastore)
59+
60+
implementation(Libs.hilt)
61+
62+
implementation(Libs.timber)
63+
implementation(Libs.bugsnag)
64+
}

0 commit comments

Comments
 (0)