diff --git a/CHANGELOG.md b/CHANGELOG.md index 7fb2f5b3a..cf88dc4e5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ## [Unreleased] +- Mark Telegram-relayed Lumi messages with their source. - Collapse each break kind in settings and expand it on click. - Keep Linux break reminder text and progress bars in separate rows. - Catalog games can award their own achievements, with the usual top-right notification. diff --git a/apps/lumi/lumi_view.zi b/apps/lumi/lumi_view.zi index 6ff27cb9c..661e8fb60 100644 --- a/apps/lumi/lumi_view.zi +++ b/apps/lumi/lumi_view.zi @@ -843,7 +843,14 @@ LumiView :: (message: LumiMessage, commands: LumiCommands, revision: s64) -> Lum .text = ifx row.developer then LumiViewLocaleHost("lumi_developer") else "Lumi", .font = Scale(12)}) } - text_top := Scale(ifx row.user then 12 else 32) + from_telegram := row.user && row.kind == LUMI_CHAT_TEXT && row.payload == "telegram" + if from_telegram { + Text(frame.session, TextProps.{.key = cast(u64)(300408 + index * 4), + .bounds = Bounds(left + Scale(14), top + Scale(8), + bubble_width - Scale(28), Scale(16)), + .text = LumiViewLocaleHost("lumi_from_telegram"), .font = Scale(11)}) + } + text_top := Scale(ifx row.user then (ifx from_telegram then 30 else 12) else 32) if row.developer && row.quote.count > 0 { FeedbackQuote(row, index, left, top + text_top, bubble_width) text_top += Scale(LUMI_QUOTE_HEIGHT) diff --git a/locales/cs.txt b/locales/cs.txt index ba3950b3c..6f4b8309f 100644 --- a/locales/cs.txt +++ b/locales/cs.txt @@ -2925,6 +2925,9 @@ Odpověď vývojáře: [lumi_developer] Vývojář --- +[lumi_from_telegram] +Z Telegramu +--- [lumi_your_feedback] Vaše zpětná vazba --- diff --git a/locales/de.txt b/locales/de.txt index 17ce36739..efbb915fb 100644 --- a/locales/de.txt +++ b/locales/de.txt @@ -2919,6 +2919,9 @@ Antwort vom Entwickler: [lumi_developer] Entwickler --- +[lumi_from_telegram] +Von Telegram +--- [lumi_your_feedback] Dein Feedback --- diff --git a/locales/en.txt b/locales/en.txt index ff78b3515..e8e3fa64f 100644 --- a/locales/en.txt +++ b/locales/en.txt @@ -2943,6 +2943,9 @@ Developer reply: [lumi_developer] Developer --- +[lumi_from_telegram] +From Telegram +--- [lumi_your_feedback] Your feedback --- diff --git a/locales/es.txt b/locales/es.txt index 681545953..d37b72145 100644 --- a/locales/es.txt +++ b/locales/es.txt @@ -2919,6 +2919,9 @@ Respuesta del desarrollador: [lumi_developer] Desarrollador --- +[lumi_from_telegram] +De Telegram +--- [lumi_your_feedback] Tus comentarios --- diff --git a/locales/fr.txt b/locales/fr.txt index 68a82fe4f..a33263fc7 100644 --- a/locales/fr.txt +++ b/locales/fr.txt @@ -2907,6 +2907,9 @@ Réponse du développeur : [lumi_developer] Développeur --- +[lumi_from_telegram] +De Telegram +--- [lumi_your_feedback] Votre retour --- diff --git a/locales/id.txt b/locales/id.txt index ac7f6865e..5f4e68701 100644 --- a/locales/id.txt +++ b/locales/id.txt @@ -2908,6 +2908,9 @@ Balasan pengembang: [lumi_developer] Pengembang --- +[lumi_from_telegram] +Dari Telegram +--- [lumi_your_feedback] Masukanmu --- diff --git a/locales/it.txt b/locales/it.txt index 4592d876d..50381dfa4 100644 --- a/locales/it.txt +++ b/locales/it.txt @@ -2908,6 +2908,9 @@ Risposta dello sviluppatore: [lumi_developer] Sviluppatore --- +[lumi_from_telegram] +Da Telegram +--- [lumi_your_feedback] Il tuo feedback --- diff --git a/locales/ja.txt b/locales/ja.txt index 20495f09d..43661b3e0 100644 --- a/locales/ja.txt +++ b/locales/ja.txt @@ -2904,6 +2904,9 @@ https:// のアドレス(http はこの端末内のみ)とモデル名を入 [lumi_developer] 開発者 --- +[lumi_from_telegram] +Telegramから +--- [lumi_your_feedback] あなたのフィードバック --- diff --git a/locales/ko.txt b/locales/ko.txt index 8c9228f54..0471172cc 100644 --- a/locales/ko.txt +++ b/locales/ko.txt @@ -2914,6 +2914,9 @@ https:// 주소(http는 이 기기에서만)와 모델 이름을 입력하세요 [lumi_developer] 개발자 --- +[lumi_from_telegram] +Telegram에서 +--- [lumi_your_feedback] 내 피드백 --- diff --git a/locales/pt.txt b/locales/pt.txt index 1983d3856..682b5646b 100644 --- a/locales/pt.txt +++ b/locales/pt.txt @@ -2917,6 +2917,9 @@ Resposta do desenvolvedor: [lumi_developer] Desenvolvedor --- +[lumi_from_telegram] +Do Telegram +--- [lumi_your_feedback] O teu comentário --- diff --git a/locales/ru.txt b/locales/ru.txt index 0d52307d9..dce7b6c03 100644 --- a/locales/ru.txt +++ b/locales/ru.txt @@ -2913,6 +2913,9 @@ Lumi остаётся без сети, пока вы не примете её у [lumi_developer] Разработчик --- +[lumi_from_telegram] +Из Telegram +--- [lumi_your_feedback] Ваш отзыв --- diff --git a/locales/zh.txt b/locales/zh.txt index 053fe831e..40f1542c7 100644 --- a/locales/zh.txt +++ b/locales/zh.txt @@ -2919,6 +2919,9 @@ API 密钥 [lumi_developer] 开发者 --- +[lumi_from_telegram] +来自 Telegram +--- [lumi_your_feedback] 你的反馈 --- diff --git a/src/apps/lumi_store.zi b/src/apps/lumi_store.zi index b92c0a555..6b0b1d44f 100644 --- a/src/apps/lumi_store.zi +++ b/src/apps/lumi_store.zi @@ -255,6 +255,14 @@ LumiStoreLoad :: () { payload = TextFromBytes(payload_bytes[:payload_length]) rich_valid = ifx kind == LUMI_CHAT_PROGRESS then LumiChartRead(payload).valid else payload.count == 32 } + } else if kind == LUMI_CHAT_TEXT && user.value == 1.0 { + source_bytes: [16]u8 + payload_length := ReadStringText(document, FieldAt(document, element, "payload"), source_bytes[:]) + if payload_length > 0 { + source := TextFromBytes(source_bytes[:payload_length]) + rich_valid = source == "telegram" + if rich_valid { payload = "telegram" } + } } rich_valid = rich_valid && (kind == LUMI_CHAT_TEXT || user.value == 0.0) } @@ -355,7 +363,8 @@ LumiStoreSave :: () -> bool { } LumiStoreAppend :: (text: string, user: bool) { - unused LumiStoreAppendCard(text, user, LUMI_CHAT_TEXT, "") + source := LumiTelegramMessageSource(lumi_next_message_id) + unused LumiStoreAppendCard(text, user, LUMI_CHAT_TEXT, source) } LumiStoreAppendCard :: (text: string, user: bool, kind: s32, payload: string) -> bool { @@ -371,11 +380,12 @@ LumiStoreAppendRow :: (message: LumiChatRow) -> bool { if text.count == 0 || text.count >= LUMI_INPUT_MAX { return false } + telegram_source := user && kind == LUMI_CHAT_TEXT && payload == "telegram" if kind < LUMI_CHAT_TEXT || kind > LUMI_CHAT_FEEDBACK || kind == LUMI_CHAT_RETIRED || (kind != LUMI_CHAT_TEXT && user) || (kind == LUMI_CHAT_PROGRESS && !LumiChartRead(payload).valid) || (kind == LUMI_CHAT_FEEDBACK && payload.count != 32) || - (kind != LUMI_CHAT_PROGRESS && kind != LUMI_CHAT_FEEDBACK && payload.count != 0) { + (!telegram_source && kind != LUMI_CHAT_PROGRESS && kind != LUMI_CHAT_FEEDBACK && payload.count != 0) { return false } if (message.developer && (user || kind != LUMI_CHAT_TEXT)) || diff --git a/src/apps/lumi_types.zi b/src/apps/lumi_types.zi index cc5bf5087..0bdfd5978 100644 --- a/src/apps/lumi_types.zi +++ b/src/apps/lumi_types.zi @@ -39,6 +39,14 @@ LUMI_CHAT_MAX :: 64 // as many older ones each time the chat is scrolled to the top. LUMI_HISTORY_PAGE :: 20 +LumiTelegramMessageSource :: (message_id: string) -> string { + prefix := "telegram-" + if message_id.count > prefix.count && message_id[:prefix.count] == prefix { + return "telegram" + } + return "" +} + LumiMessage :: struct { abi: s32 action: s32 diff --git a/src/screens/lumi_screen.zi b/src/screens/lumi_screen.zi index f2f8dfdb1..89aabd95d 100644 --- a/src/screens/lumi_screen.zi +++ b/src/screens/lumi_screen.zi @@ -916,6 +916,9 @@ LumiChatRowAt :: (index: s32, access: LumiRowAccess) -> LumiChatRow { LumiRowKey :: (index: s32, access: LumiRowAccess) -> u64 { row := LumiChatRowAt(index, access) marker := cast(u64)(row.kind * 2 + (ifx row.user then 1 else 0) + 1) + if row.user && row.kind == LUMI_CHAT_TEXT && row.payload == "telegram" { + marker += cast(u64)2 + } if row.developer { marker ^= KeyHash(row.quote) * cast(u64)31 + cast(u64)1 } @@ -935,6 +938,9 @@ LumiMeasuredRow :: (index: s32, access: LumiRowAccess) -> LumiChatRow { cast(float32)(column_width - cast(s32)((ifx row.user then 88.0 else 108.0) * lumi_ui.scale)), 0.0}}, DefaultTextFace()) height := cast(s32)prepared.bounds.height + cast(s32)((ifx row.user then 38.0 else 58.0) * lumi_ui.scale) + if row.user && row.kind == LUMI_CHAT_TEXT && row.payload == "telegram" { + height += AppScale(18) + } if row.kind == LUMI_CHAT_PROGRESS { height += AppScale(242) } else if row.kind == LUMI_CHAT_FEEDBACK { diff --git a/tests/lumi_telegram_input_behavior.zi b/tests/lumi_telegram_input_behavior.zi index 33ad533ba..3ec671932 100644 --- a/tests/lumi_telegram_input_behavior.zi +++ b/tests/lumi_telegram_input_behavior.zi @@ -3,6 +3,7 @@ #import, file "../src/app/text_buffers.zi"; #import, file "../src/app/app_types.zi"; #import, file "../src/apps/inbe_types.zi"; +#import, file "../src/apps/lumi_types.zi"; #import, file "../src/apps/lumi_online.zi"; #import, file "../src/apps/lumi_connection.zi"; #import, file "../src/storage/storage_settings.zi"; @@ -77,6 +78,9 @@ InputTestTransport :: () -> AsyncTransport { Check :: () -> s32 { transport := InputTestTransport() check_true("fixture transport available", transport.start != null) + check_true("telegram update ids choose the Telegram source", + LumiTelegramMessageSource("telegram-17") == "telegram") + check_true("local message ids stay local", LumiTelegramMessageSource("local-17") == "") guard := support_begin("/tmp/inbe-lumi-telegram-input-test/") if guard != 0 { return guard @@ -113,7 +117,11 @@ Check :: () -> s32 { check_int("app history never posts to Telegram", mirrors, 0) check_true("input polling retained", polls > 0) check_true("input acknowledged", acks > 0) - check_true("incoming message archived", contains(storage_get_setting_text("cell.lumi.message.telegram-17"), "/habits")) + incoming_record := storage_get_setting_text("cell.lumi.message.telegram-17") + check_true("incoming message archived", contains(incoming_record, "/habits")) + check_true("incoming message records Telegram as its source", contains(incoming_record, "\"payload\":\"telegram\"")) + check_true("incoming message exposes Telegram in the chat row", LumiStoreRow(142).payload == "telegram") + check_true("local app message stays unlabelled", LumiStoreRow(140).payload == "") check_true("incoming execution claim retained", storage_get_setting_int("telegram.update.17", 0) == 1) check_true("input schedules regular account sync", app.ui.sync_requested) check_int("input and its response appended once", LumiStoreCount(), expected) @@ -129,6 +137,7 @@ Check :: () -> s32 { check_true("oldest history stays visible", LumiStoreRow(0).text == "1") check_true("app conversation stays visible", LumiStoreRow(140).text == "App message" && LumiStoreRow(141).text == "App response") check_true("incoming history stays visible", LumiStoreRow(142).text == "/habits" && LumiStoreRow(143).text == "No habits yet.") + check_true("Telegram source survives reopening", LumiStoreRow(142).payload == "telegram") check_int("complete account outbox survives reopening", read_db_count("SELECT COUNT(*) FROM sync_outbox WHERE entity_type='cell_record' AND entity_id LIKE 'cell.lumi.message.%'"), expected) SecureWipe(*owner.private_key_hex[0], ACCOUNT_PRIVATE_KEY_HEX_SIZE) storage_close()