Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .github/scripts/d1-migration-manifest.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -119,4 +119,9 @@ export const D1_MIGRATIONS = [
"table:message_event_compaction",
],
},
{
id: "2026-08-30-pinned-messages",
file: "worker/migrations/2026-08-30-pinned-messages.sql",
artifacts: ["table:channel_pins", "trigger:clear_pin_after_message_soft_delete"],
},
];
3 changes: 2 additions & 1 deletion .github/workflows/android-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@ jobs:
apksigner_path="$(find "$ANDROID_HOME/build-tools" -type f -name apksigner | sort -V | tail -n 1)"
test -n "$apksigner_path"
"$apksigner_path" verify --verbose --print-certs android/release-artifacts/*.apk
jarsigner -verify -strict android/release-artifacts/*.aab
# AAB 是 JAR 签名格式;JDK 17 的 strict 模式会把 App Bundle 合法的 ZIP 结构警告误判为失败。
jarsigner -verify -verbose -certs android/release-artifacts/*.aab
- name: Publish GitHub Release
shell: bash
env:
Expand Down
2 changes: 1 addition & 1 deletion README.en.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ GitHub Actions deployment is recommended first — it suits long-term maintenanc

### Native Android Client

The repository's `android/` directory is an independent Kotlin + Jetpack Compose client for Android 8 / API 26 and newer. It depends only on the stable `/api/v1` contract and never packages Vue components or CSS. On first launch, paste a valid HTTPS server origin or open `edgechat://connect?server=https%3A%2F%2Fchat.example.com`; the app validates server capabilities before sign-in.
The repository's `android/` directory is an independent Kotlin + Jetpack Compose client for Android 8 / API 26 and newer. It depends only on the stable `/api/v1` contract and never packages Vue components or CSS. When signed out, enter the HTTPS server origin, username, and password on one screen, or use `edgechat://connect?server=https%3A%2F%2Fchat.example.com` to prefill the server. The app validates server capabilities before completing sign-in.

- Installation: download `edgechat-*.apk` from GitHub Releases and verify `SHA256SUMS.txt`
- CI: `.github/workflows/android-ci.yml` runs unit tests, Lint, and a Debug APK build
Expand Down
2 changes: 1 addition & 1 deletion README.ja.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ GitHub Actions でのデプロイを優先的に推奨します。長期的な

### ネイティブ Android クライアント

リポジトリの `android/` は Android 8 / API 26 以降向けの独立した Kotlin + Jetpack Compose クライアントです。安定した `/api/v1` 契約だけを共有し、Vue コンポーネントや CSS は APK に含めません。初回起動時に有効な HTTPS サーバー URL を入力するか、`edgechat://connect?server=https%3A%2F%2Fchat.example.com` を開くと、ログイン前にサーバー機能を確認します。
リポジトリの `android/` は Android 8 / API 26 以降向けの独立した Kotlin + Jetpack Compose クライアントです。安定した `/api/v1` 契約だけを共有し、Vue コンポーネントや CSS は APK に含めません。未ログイン時は 1 つの画面で HTTPS サーバー URL、ユーザー名、パスワードを入力できます。`edgechat://connect?server=https%3A%2F%2Fchat.example.com` でサーバーを事前入力することもでき、送信後にサーバー機能を確認してからログインします。

- インストール:GitHub Releases から `edgechat-*.apk` を取得し、`SHA256SUMS.txt` を確認
- CI:`.github/workflows/android-ci.yml` が単体テスト、Lint、Debug APK ビルドを実行
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ EdgeChat 是一个部署在 Cloudflare 上的团队聊天系统:账号体系

### 原生 Android 客户端

仓库内的 `android/` 是独立的 Kotlin + Jetpack Compose 客户端(Android 8 / API 26 起),只依赖稳定的 `/api/v1` 协议,不复用网页组件或 CSS。首次启动粘贴有效 HTTPS 服务器地址,或打开 `edgechat://connect?server=https%3A%2F%2Fchat.example.com`,客户端会先校验服务器能力再登录。
仓库内的 `android/` 是独立的 Kotlin + Jetpack Compose 客户端(Android 8 / API 26 起),只依赖稳定的 `/api/v1` 协议,不复用网页组件或 CSS。未登录时可在同一页输入 HTTPS 服务器地址、用户名和密码;也可以通过 `edgechat://connect?server=https%3A%2F%2Fchat.example.com` 预填服务器。提交后客户端会先校验服务器能力,再完成登录。

- 安装包:从 GitHub Releases 下载 `edgechat-*.apk` 并核对 `SHA256SUMS.txt`
- CI:`.github/workflows/android-ci.yml` 运行单元测试、Lint 和 Debug APK 构建
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,62 @@
package com.aozorae.edgechat.feature.auth

import androidx.compose.ui.test.assertIsDisplayed
import androidx.compose.ui.test.assertIsNotEnabled
import androidx.compose.ui.test.assertTextContains
import androidx.compose.ui.test.junit4.createComposeRule
import androidx.compose.ui.test.onNodeWithText
import androidx.compose.ui.test.junit4.StateRestorationTester
import androidx.compose.ui.test.onNodeWithTag
import androidx.compose.ui.test.performClick
import org.junit.Assert.assertTrue
import androidx.compose.ui.test.performTextInput
import androidx.compose.ui.test.performTextReplacement
import org.junit.Assert.assertEquals
import org.junit.Rule
import org.junit.Test

class WelcomeScreenTest {
@get:Rule val compose = createComposeRule()

@Test
fun connectServerOpensSetupFlow() {
var continued = false
fun loginStartsDisabledUntilAllFieldsAreFilled() {
compose.setContent {
WelcomeScreen(language = "en-US", onContinue = { continued = true })
WelcomeScreen(null, false, "en-US") { _, _, _ -> }
}

compose.onNodeWithText("EdgeChat").assertIsDisplayed()
compose.onNodeWithText("Connect server").assertIsDisplayed().performClick()
assertTrue(continued)
compose.onNodeWithTag("serverField").assertIsDisplayed()
compose.onNodeWithTag("usernameField").assertIsDisplayed()
compose.onNodeWithTag("passwordField").assertIsDisplayed()
compose.onNodeWithTag("loginButton").assertIsNotEnabled()
}

@Test
fun loginSubmitsServerAndCredentials() {
var submitted: Triple<String, String, String>? = null
compose.setContent {
WelcomeScreen(null, false, "en-US") { server, username, password ->
submitted = Triple(server, username, password)
}
}

compose.onNodeWithTag("serverField").performTextInput("https://chat.example.com")
compose.onNodeWithTag("usernameField").performTextInput("alice")
compose.onNodeWithTag("passwordField").performTextInput("secret")
compose.onNodeWithTag("loginButton").performClick()

assertEquals(Triple("https://chat.example.com", "alice", "secret"), submitted)
}

@Test
fun serverAndUsernameSurviveStateRestoration() {
val restoration = StateRestorationTester(compose)
restoration.setContent {
WelcomeScreen("https://old.example.com", false, "en-US") { _, _, _ -> }
}

compose.onNodeWithTag("serverField").performTextReplacement("https://chat.example.com")
compose.onNodeWithTag("usernameField").performTextInput("alice")
restoration.emulateSavedInstanceStateRestore()

compose.onNodeWithTag("serverField").assertTextContains("https://chat.example.com")
compose.onNodeWithTag("usernameField").assertTextContains("alice")
}
}
Original file line number Diff line number Diff line change
@@ -1,20 +1,26 @@
package com.aozorae.edgechat.feature.chat

import android.graphics.Bitmap
import android.graphics.Color
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.lazy.rememberLazyListState
import androidx.compose.ui.Modifier
import androidx.compose.ui.test.junit4.createComposeRule
import androidx.compose.ui.test.onNodeWithTag
import androidx.compose.ui.test.performClick
import androidx.compose.ui.unit.dp
import androidx.test.platform.app.InstrumentationRegistry
import com.aozorae.edgechat.core.database.MessageEntity
import com.aozorae.edgechat.core.database.OutboxEntity
import com.aozorae.edgechat.core.network.dto.SessionDto
import com.aozorae.edgechat.ui.theme.EdgeChatTheme
import org.junit.Assert.assertEquals
import org.junit.Assert.assertTrue
import org.junit.Rule
import org.junit.Test
import java.io.File

class ChatMessagesLayoutTest {
@get:Rule val compose = createComposeRule()
Expand Down Expand Up @@ -59,13 +65,115 @@ class ChatMessagesLayoutTest {
assertTrue(pendingCenter > listCenter)
}

@Test
fun imageAttachmentsUseInlinePreviewAndRemainOpenable() {
var opened: Triple<String, String, String>? = null
compose.setContent {
EdgeChatTheme {
Box(Modifier.width(360.dp).height(640.dp)) {
ChatMessages(
messages = listOf(
message(
id = 3,
senderId = "2",
content = "",
attachmentName = "photo.jpg",
attachmentType = "image/jpeg",
attachmentUrl = "https://images.invalid/photo.jpg",
),
message(
id = 4,
senderId = "2",
content = "",
attachmentName = "report.pdf",
attachmentType = "application/pdf",
attachmentUrl = "/files/report.pdf",
),
),
outbox = emptyList(),
currentUser = currentUser(),
serverBaseUrl = "https://example.com",
language = "en-US",
scrollState = rememberLazyListState(),
onLoadOlder = {},
onRetry = {},
onCancel = {},
onDeleteMessage = {},
onOpenAttachment = { url, name, type -> opened = Triple(url, name, type) },
)
}
}
}

compose.onNodeWithTag("message_image:3").performClick()
compose.onNodeWithTag("message_attachment:4").assertExists()
assertEquals(
Triple("https://images.invalid/photo.jpg", "photo.jpg", "image/jpeg"),
opened,
)
}

@Test
fun portraitPendingImageUsesItsOwnAspectRatioAndStaysCompact() {
val context = InstrumentationRegistry.getInstrumentation().targetContext
val portrait = File(context.cacheDir, "portrait-preview.png")
Bitmap.createBitmap(90, 180, Bitmap.Config.ARGB_8888).run {
eraseColor(Color.RED)
portrait.outputStream().use { compress(Bitmap.CompressFormat.PNG, 100, it) }
recycle()
}
compose.setContent {
EdgeChatTheme {
Box(Modifier.width(360.dp).height(640.dp)) {
ChatMessages(
messages = emptyList(),
outbox = listOf(
pendingMessage(
localAttachmentPath = portrait.absolutePath,
attachmentName = "portrait-preview.png",
attachmentType = "image/png",
),
),
currentUser = currentUser(),
serverBaseUrl = "https://example.com",
language = "en-US",
scrollState = rememberLazyListState(),
onLoadOlder = {},
onRetry = {},
onCancel = {},
onDeleteMessage = {},
onOpenAttachment = { _, _, _ -> },
)
}
}
}

compose.waitUntil(5_000) {
val bounds = compose.onNodeWithTag("pending_message_image:pending-1")
.fetchSemanticsNode().boundsInRoot
bounds.height > bounds.width
}
val bounds = compose.onNodeWithTag("pending_message_image:pending-1")
.fetchSemanticsNode().boundsInRoot
assertTrue(bounds.height > bounds.width * 1.9f)
assertTrue(bounds.height <= 240f * context.resources.displayMetrics.density + 1f)
portrait.delete()
}

private fun currentUser() = SessionDto(
userId = 1,
username = "me",
displayName = "Me",
)

private fun message(id: Long, senderId: String, content: String) = MessageEntity(
private fun message(
id: Long,
senderId: String,
content: String,
attachmentName: String? = null,
attachmentType: String? = null,
attachmentUrl: String? = null,
) = MessageEntity(
id = id,
roomKind = "public",
roomId = 1,
Expand All @@ -79,20 +187,24 @@ class ChatMessagesLayoutTest {
senderDisplayName = "User $senderId",
senderAvatarUrl = "",
attachmentKey = null,
attachmentName = null,
attachmentType = null,
attachmentName = attachmentName,
attachmentType = attachmentType,
attachmentSize = null,
attachmentUrl = null,
attachmentUrl = attachmentUrl,
)

private fun pendingMessage() = OutboxEntity(
private fun pendingMessage(
localAttachmentPath: String? = null,
attachmentName: String? = null,
attachmentType: String? = null,
) = OutboxEntity(
clientMessageId = "pending-1",
roomKind = "public",
roomId = 1,
content = "Pending",
localAttachmentPath = null,
attachmentName = null,
attachmentType = null,
localAttachmentPath = localAttachmentPath,
attachmentName = attachmentName,
attachmentType = attachmentType,
attachmentSize = null,
clientUploadId = null,
uploadedKey = null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,19 @@ import coil.ImageLoader
import coil.ImageLoaderFactory
import dagger.hilt.android.HiltAndroidApp
import javax.inject.Inject
import okhttp3.OkHttpClient

@HiltAndroidApp
class EdgeChatApplication : Application(), Configuration.Provider, ImageLoaderFactory {
@Inject lateinit var workerFactory: HiltWorkerFactory
@Inject lateinit var okHttpClient: OkHttpClient

override val workManagerConfiguration: Configuration
get() = Configuration.Builder().setWorkerFactory(workerFactory).build()

override fun newImageLoader(): ImageLoader = ImageLoader.Builder(this).crossfade(true).build()
override fun newImageLoader(): ImageLoader = ImageLoader.Builder(this)
// 消息图片受移动端会话保护,复用网络层客户端才能统一附加令牌并完成过期刷新。
.okHttpClient(okHttpClient)
.crossfade(true)
.build()
}
Loading
Loading