From e47a54d1898802eaf95e48e55d202315403e00dc Mon Sep 17 00:00:00 2001 From: "Rich O." Date: Thu, 5 Nov 2026 15:02:22 -0500 Subject: [PATCH] palm-client: in a conversation, tap a #hashtag to open that channel, or join it after asking (lowercased, as MeshCore One joins them). Typing @ (or Options > Insert Mention) lists recent senders here and then the companions in the contacts, and inserts @[Name] --- palm-client/src/convo_extra.c | 109 ++++++++++++++++++++++++++++++++++ palm-client/src/convo_extra.h | 21 +++++++ palm-client/src/convo_form.c | 22 ++++++- 3 files changed, 150 insertions(+), 2 deletions(-) create mode 100644 palm-client/src/convo_extra.c create mode 100644 palm-client/src/convo_extra.h diff --git a/palm-client/src/convo_extra.c b/palm-client/src/convo_extra.c new file mode 100644 index 0000000..e4ee3f7 --- /dev/null +++ b/palm-client/src/convo_extra.c @@ -0,0 +1,109 @@ +#include +#include "resources.h" +#include "app.h" +#include "session.h" +#include "channels.h" +#include "channel_form.h" +#include "contacts.h" +#include "messages.h" +#include "sha256.h" +#include "ui/text.h" +#include "convo_extra.h" + +static Boolean Have(Char (*names)[VM_NAME_SIZE], UInt16 n, const Char *name) VM_SECT5; + +#define PICK_MAX 40 +#define PICK_RECENT 20 /* senders from the conversation, newest first, before the contacts */ + +void ConvoOpenHashtag(const Char *tag) +{ + UInt8 utf8[VM_NAME_SIZE], hash[32]; + UInt16 n = TxtPalmToUtf8(tag, StrLen(tag), utf8, VM_NAME_SIZE - 1), i; + UInt8 maxChannels = SessionDevice()->maxChannels; + VmChannel c; + VmConv conv; + + /* joined already (by its key, whatever it's called here): just open it */ + if (n) { + VmSha256(utf8, n, hash); + ChannelsOpen(); + for (i = 0; i < (maxChannels ? maxChannels : 8); i++) { + if (ChannelsFindSlot((UInt8)i, &c) && MemCmp(c.secret, hash, VM_CHANNEL_SECRET_SIZE) == 0) { + MemSet(&conv, sizeof(conv), 0); + conv.type = VM_CONV_CHANNEL; + conv.channel = (UInt8)i; + AppOpenConversation(&conv); + return; + } + } + } + if (FrmCustomAlert(HashtagAlert, tag, "", "") == 0) + ChannelJoin(tag, NULL); +} + +static Boolean Have(Char (*names)[VM_NAME_SIZE], UInt16 n, const Char *name) +{ + UInt16 i; + + for (i = 0; i < n; i++) + if (StrCompare(names[i], name) == 0) + return true; + return false; +} + +Boolean ConvoMentionPick(UInt16 listId, UInt16 fieldId, Boolean typedAt) +{ + FormType *form = FrmGetActiveForm(); + ListType *list = FrmGetObjectPtr(form, FrmGetObjectIndex(form, listId)); + FieldType *field = FrmGetObjectPtr(form, FrmGetObjectIndex(form, fieldId)); + Char (*names)[VM_NAME_SIZE]; + Char **items; + const VmMsgHeader *h; + UInt16 n = 0, i, count; + VmContact c; + Char buf[VM_NAME_SIZE + 5]; + Int16 pick; + + names = MemPtrNew(PICK_MAX * VM_NAME_SIZE); + items = MemPtrNew(PICK_MAX * sizeof(Char *)); + if (!names || !items) { + if (names) + MemPtrFree(names); + if (items) + MemPtrFree(items); + return false; + } + /* who spoke here lately, then the companions in the contacts */ + count = MessagesCount(); + for (i = count; i > 0 && n < PICK_RECENT; i--) { + h = MessagesLock(i - 1); + if (!h) + continue; + if (h->dir == VM_DIR_IN && h->sender[0] && ConvEqual(&h->conv, &gAppConv) && !Have(names, n, h->sender)) + StrCopy(names[n++], h->sender); + MessagesRelease(i - 1); + } + count = ContactsCount(); + for (i = 0; i < count && n < PICK_MAX; i++) + if (ContactsGet(i, &c) && c.type == VM_ADV_TYPE_CHAT && c.name[0] && !Have(names, n, c.name)) + StrCopy(names[n++], c.name); + for (i = 0; i < n; i++) + items[i] = names[i]; + pick = -1; + if (n) { + LstSetListChoices(list, items, n); + LstSetHeight(list, n < 8 ? n : 8); + pick = LstPopupList(list); + LstSetListChoices(list, NULL, 0); + } + FrmSetFocus(form, FrmGetObjectIndex(form, fieldId)); + if (pick >= 0) { + StrPrintF(buf, "@[%s] ", names[pick]); + FldInsert(field, buf, StrLen(buf)); + } else if (typedAt) { + FldInsert(field, "@", 1); + } + MemPtrFree(items); + MemPtrFree(names); + return pick >= 0 || typedAt; +} diff --git a/palm-client/src/convo_extra.h b/palm-client/src/convo_extra.h new file mode 100644 index 0000000..7c00628 --- /dev/null +++ b/palm-client/src/convo_extra.h @@ -0,0 +1,21 @@ +/* + * Conversation extras, kept out of the second segment: a tap on a #hashtag + * joins (or opens) that channel, and the @mention picker ("@" in the compose + * field, or Options > Insert Mention) lists recent senders and contacts. + */ +#ifndef VM_CONVO_EXTRA_H +#define VM_CONVO_EXTRA_H + +#include +#include "sections.h" /* this module is in the fifth code segment */ + +/* tag is a #hashtag (protocol2.h VmHashtagAt): opens it if joined, else asks to join. */ +void ConvoOpenHashtag(const Char *tag) VM_SECT5; +/* + * The picker (listId on the active form) for the field: picking inserts + * "@[Name] ". typedAt: the user typed '@', which goes in if they cancel. + * Returns true if the field changed. + */ +Boolean ConvoMentionPick(UInt16 listId, UInt16 fieldId, Boolean typedAt) VM_SECT5; + +#endif diff --git a/palm-client/src/convo_form.c b/palm-client/src/convo_form.c index ade0ce2..5aed325 100644 --- a/palm-client/src/convo_form.c +++ b/palm-client/src/convo_form.c @@ -17,6 +17,8 @@ #include "ui/rowlist.h" #include "ui/emoji.h" #include "msg_menu.h" +#include "convo_extra.h" +#include "protocol2.h" #include "convo_form.h" /* In the second code segment: see sections.h for the rules. */ @@ -453,7 +455,7 @@ static void InsertMention(const Char *sender) DrawCounter(); } -/* An emoji (or its neighbour, they're narrow) under the pen: show it enlarged. */ +/* An emoji (or its neighbour, they're narrow) under the pen: show it enlarged; a #hashtag: join or open it. */ static Boolean TappedEmoji(UInt16 row, Coord penX) { FormType *form = FrmGetActiveForm(); @@ -463,8 +465,9 @@ static Boolean TappedEmoji(UInt16 row, Coord penX) RectangleType b; FontID old; Int16 k; - Char c[3]; + Char c[3], tag[VM_NAME_SIZE]; UInt16 n = 0, i; + Boolean isTag = false; if (l->kind != L_TEXT) return false; @@ -482,8 +485,13 @@ static Boolean TappedEmoji(UInt16 row, Coord penX) c[n++] = text[k - 1]; if (k + 1 < (Int16)l->len) c[n++] = text[k + 1]; + isTag = VmHashtagAt(text, l->len, (UInt16)k, tag, sizeof(tag)); } MessagesRelease(l->msg); + if (isTag) { + ConvoOpenHashtag(tag); + return true; + } for (i = 0; i < n; i++) if (EmojiShow(c[i])) return true; @@ -649,6 +657,11 @@ Boolean ConvoFormHandleEvent(EventType *event) break; case menuEvent: + if (event->data.menu.itemID == MainMenuMention) { + if (ConvoMentionPick(ConvoMentionList, ConvoField, false)) + DrawCounter(); + return true; + } if (event->data.menu.itemID == MainMenuMessage) { UInt16 msg; @@ -663,6 +676,11 @@ Boolean ConvoFormHandleEvent(EventType *event) Send(form); return true; } + if (event->data.keyDown.chr == '@' && FrmGetFocus(form) == FrmGetObjectIndex(form, ConvoField)) { + if (ConvoMentionPick(ConvoMentionList, ConvoField, true)) + DrawCounter(); + return true; + } break; default: