palm-client: block a sender (a contact's More, or hold their message > Block Sender): their new messages and reactions are dropped as they sync, also in the closed-app check. A contact is blocked by key and by name (channels name senders only by name). Contacts > Blocked Senders lists them to unblock

This commit is contained in:
rich committed 2026-11-05 15:02:22 -05:00
1 parent 80f2d2781b
commit 34c99d8b0a
5 files changed
+259 -3

No files matched your search

+2 -2
View File
@@ -750,7 +750,7 @@ CONFIRMATION
DEFAULTBUTTON 1
BEGIN
TITLE "Block"
MESSAGE "Hide messages and reactions from ^1? Unblock under Contacts > Blocked Senders."
MESSAGE "Drop new messages and reactions from ^1? Ones already here stay. Unblock under Contacts > Blocked Senders."
BUTTONS "Block" "Cancel"
END
@@ -759,7 +759,7 @@ CONFIRMATION
DEFAULTBUTTON 1
BEGIN
TITLE "Unblock"
MESSAGE "Show messages from ^1 again?"
MESSAGE "Take new messages from ^1 again?"
BUTTONS "Unblock" "Cancel"
END
+209
View File
@@ -0,0 +1,209 @@
#include <PalmOS.h>
#include "resources.h"
#include "app.h"
#include "ui/text.h"
#include "blocks.h"
static void Load(void) VM_SECT5;
static void Save(void) VM_SECT5;
static Int16 FindKey(const UInt8 *key) VM_SECT5;
static Int16 FindName(const Char *name) VM_SECT5;
static void Remove(UInt16 i) VM_SECT5;
#define VM_BLOCKS_PREFS_ID 9
#define VM_BLOCKS_PREFS_VERSION 1
typedef struct {
UInt8 hasKey;
UInt8 key[VM_BLOCK_KEY_SIZE];
Char name[VM_NAME_SIZE];
} Block;
typedef struct {
UInt16 version;
UInt16 count;
Block list[VM_BLOCKS_MAX];
} BlocksPrefs;
static BlocksPrefs gBlocks;
static Boolean gLoaded = false; /* loaded on first use: the closed-app check has fresh globals */
static void Load(void)
{
UInt16 size = sizeof(gBlocks);
if (gLoaded)
return;
gLoaded = true;
if (PrefGetAppPreferences(VM_CREATOR, VM_BLOCKS_PREFS_ID, &gBlocks, &size, true) == noPreferenceFound ||
size != sizeof(gBlocks) || gBlocks.version != VM_BLOCKS_PREFS_VERSION || gBlocks.count > VM_BLOCKS_MAX)
gBlocks.count = 0;
gBlocks.version = VM_BLOCKS_PREFS_VERSION;
}
static void Save(void)
{
PrefSetAppPreferences(VM_CREATOR, VM_BLOCKS_PREFS_ID, VM_BLOCKS_PREFS_VERSION, &gBlocks, sizeof(gBlocks), true);
}
static Int16 FindKey(const UInt8 *key)
{
UInt16 i;
for (i = 0; i < gBlocks.count; i++)
if (gBlocks.list[i].hasKey && MemCmp(gBlocks.list[i].key, key, VM_BLOCK_KEY_SIZE) == 0)
return (Int16)i;
return -1;
}
static Int16 FindName(const Char *name)
{
UInt16 i;
for (i = 0; i < gBlocks.count; i++)
if (gBlocks.list[i].name[0] && StrCompare(gBlocks.list[i].name, name) == 0)
return (Int16)i;
return -1;
}
static void Remove(UInt16 i)
{
if (i >= gBlocks.count)
return;
MemMove(&gBlocks.list[i], &gBlocks.list[i + 1], (gBlocks.count - i - 1) * sizeof(Block));
gBlocks.count--;
Save();
}
Boolean BlocksMessage(const VmMessage *m)
{
Char name[VM_NAME_SIZE];
UInt16 n;
Load();
if (gBlocks.count == 0)
return false;
if (m->isChannel) {
/* a channel names its sender only as "Name: " */
for (n = 0; n < m->textLen && m->text[n] != ':'; n++)
;
if (n == m->textLen)
return false;
n = TxtUtf8ToPalm(m->text, n, name, sizeof(name) - 1);
name[n] = 0;
return n > 0 && FindName(name) >= 0;
}
if (m->hasSigner) {
UInt16 i;
/* a room post: its author by the first 4 bytes of their key */
for (i = 0; i < gBlocks.count; i++)
if (gBlocks.list[i].hasKey && MemCmp(gBlocks.list[i].key, m->signer, 4) == 0)
return true;
return false;
}
return FindKey(m->senderPrefix) >= 0;
}
Boolean BlocksIsContact(const VmContact *c)
{
Load();
return FindKey(c->pubKey) >= 0;
}
Boolean BlocksIsName(const Char *name)
{
Load();
return FindName(name) >= 0;
}
/* Asks, then blocks c (its key, and its name for channels) or unblocks it. */
void BlocksToggleContact(const VmContact *c)
{
Int16 i;
Block *b;
Load();
i = FindKey(c->pubKey);
if (i < 0)
i = FindName(c->name);
if (i >= 0) {
if (FrmCustomAlert(UnblockAlert, c->name, "", "") == 0)
Remove((UInt16)i);
return;
}
if (FrmCustomAlert(BlockAlert, c->name, "", "") != 0)
return;
if (gBlocks.count >= VM_BLOCKS_MAX) {
FrmCustomAlert(SettingsErrorAlert, "The block list is full. Unblock someone first (Contacts > Blocked Senders).", "", "");
return;
}
b = &gBlocks.list[gBlocks.count++];
MemSet(b, sizeof(*b), 0);
b->hasKey = 1;
MemMove(b->key, c->pubKey, VM_BLOCK_KEY_SIZE);
StrNCopy(b->name, c->name, VM_NAME_SIZE - 1);
Save();
}
Boolean BlocksAskName(const Char *name)
{
Block *b;
Load();
if (FindName(name) >= 0)
return false;
if (FrmCustomAlert(BlockAlert, name, "", "") != 0)
return false;
if (gBlocks.count >= VM_BLOCKS_MAX) {
FrmCustomAlert(SettingsErrorAlert, "The block list is full. Unblock someone first (Contacts > Blocked Senders).", "", "");
return false;
}
b = &gBlocks.list[gBlocks.count++];
MemSet(b, sizeof(*b), 0);
StrNCopy(b->name, name, VM_NAME_SIZE - 1);
Save();
return true;
}
void BlocksManage(UInt16 listId)
{
FormType *form = FrmGetActiveForm();
ListType *list = FrmGetObjectPtr(form, FrmGetObjectIndex(form, listId));
Char **names, (*keyed)[VM_NAME_SIZE + 14];
UInt16 i;
Int16 pick;
Load();
if (gBlocks.count == 0) {
FrmCustomAlert(NoteAlert, "No one is blocked. Block someone from their contact (More) or by holding their message.", "", "");
return;
}
/* on the heap: the stack is small */
names = MemPtrNew(gBlocks.count * sizeof(Char *));
keyed = MemPtrNew(gBlocks.count * sizeof(*keyed));
if (!names || !keyed) {
if (names)
MemPtrFree(names);
if (keyed)
MemPtrFree(keyed);
return;
}
for (i = 0; i < gBlocks.count; i++) {
names[i] = keyed[i];
if (gBlocks.list[i].name[0]) {
StrCopy(keyed[i], gBlocks.list[i].name);
} else {
StrCopy(keyed[i], "key ");
TxtHex(gBlocks.list[i].key, VM_BLOCK_KEY_SIZE, keyed[i] + 4);
}
}
LstSetListChoices(list, names, gBlocks.count);
LstSetHeight(list, gBlocks.count < 8 ? gBlocks.count : 8);
pick = LstPopupList(list);
LstSetListChoices(list, NULL, 0);
if (pick >= 0 && FrmCustomAlert(UnblockAlert, keyed[pick], "", "") == 0)
Remove((UInt16)pick);
MemPtrFree(keyed);
MemPtrFree(names);
}
+28
View File
@@ -0,0 +1,28 @@
/*
* Blocked senders: their new messages and reactions are dropped as they
* sync (what's already stored stays). A contact is blocked by its key and
* its name, since channels name senders only by name; a channel sender with
* no contact by name alone. Kept in a saved preference.
*/
#ifndef VM_BLOCKS_H
#define VM_BLOCKS_H
#include <PalmOS.h>
#include "sections.h" /* this module is in the fifth code segment */
#include "protocol.h"
#define VM_BLOCKS_MAX 32
#define VM_BLOCK_KEY_SIZE 6
/* True if a synced message is from someone blocked. */
Boolean BlocksMessage(const VmMessage *m) VM_SECT5;
Boolean BlocksIsContact(const VmContact *c) VM_SECT5;
Boolean BlocksIsName(const Char *name) VM_SECT5;
/* Asks, then blocks or unblocks c. */
void BlocksToggleContact(const VmContact *c) VM_SECT5;
/* Asks, then blocks a channel sender by name; true if blocked. */
Boolean BlocksAskName(const Char *name) VM_SECT5;
/* Contacts > Blocked Senders: the list in a popup (listId on the active form); picking one unblocks it. */
void BlocksManage(UInt16 listId) VM_SECT5;
#endif
+17 -1
View File
@@ -9,6 +9,7 @@
#include "ui/text.h"
#include "ui/emoji.h"
#include "info_fmt.h"
#include "blocks.h"
#include "msg_menu.h"
static Int16 Popup(const RectangleType *b, UInt16 listId, UInt16 areaId, Char **items, UInt16 n) VM_SECT3;
@@ -24,7 +25,8 @@ static Boolean Matches(const VmReact *r, const UInt8 *hash, const Char *name, Bo
#define ACT_DM 2
#define ACT_PATH 3
#define ACT_RETRY 4
#define ACT_MAX 5
#define ACT_BLOCK 5
#define ACT_MAX 6
#define LIST_X 28
#define LIST_H(n) ((n) * 11 + 2) /* stdFont rows and the frame */
#define QUOTE_CHARS 10
@@ -75,6 +77,8 @@ UInt16 MsgMenuOpen(UInt16 msg, const RectangleType *b, UInt16 listId, UInt16 are
Int16 pick;
Boolean mine, channel, room, failed;
Char name[VM_NAME_SIZE];
UInt8 key[6];
VmContact c;
if (!h)
return MSG_MENU_NONE;
@@ -83,6 +87,7 @@ UInt16 MsgMenuOpen(UInt16 msg, const RectangleType *b, UInt16 listId, UInt16 are
room = !channel && !mine && h->sender[0]; /* a room post: rooms have no reactions */
failed = mine && h->status == VM_ST_FAILED;
NameOf(h, name);
MemMove(key, h->conv.key, sizeof(key));
MessagesRelease(msg);
if (!mine && !room) {
@@ -103,6 +108,10 @@ UInt16 MsgMenuOpen(UInt16 msg, const RectangleType *b, UInt16 listId, UInt16 are
items[n] = "Retry";
acts[n++] = ACT_RETRY;
}
if (!mine && !room && (!channel || name[0])) {
items[n] = "Block Sender";
acts[n++] = ACT_BLOCK;
}
pick = Popup(b, listId, areaId, items, n);
if (pick < 0 || pick >= (Int16)n)
return MSG_MENU_NONE;
@@ -114,6 +123,13 @@ UInt16 MsgMenuOpen(UInt16 msg, const RectangleType *b, UInt16 listId, UInt16 are
case ACT_RETRY:
SessionRetry(msg);
return MSG_MENU_REFRESH;
case ACT_BLOCK:
/* a channel sender by name; a DM's by its contact */
if (channel)
BlocksAskName(name);
else if (ContactsFindByPrefix(key, &c))
BlocksToggleContact(&c);
break;
}
return MSG_MENU_NONE;
}
+3
View File
@@ -21,6 +21,7 @@
#include "reaction_fmt.h"
#include "protocol2.h"
#include "packets_form.h"
#include "blocks.h"
#define VM_APP_NAME "VisorMesh"
#define VM_REPLY_TIMEOUT (2 * SysTicksPerSecond())
@@ -654,6 +655,8 @@ Err SessionSyncMessages(void)
gChanged |= VM_CHANGED_REMOTE;
continue;
}
if (BlocksMessage(&m))
continue; /* blocked (blocks.h): dropped, reactions too */
if (ReactionsTake(&m, SessionNow())) {
gChanged |= VM_CHANGED_MESSAGES;
continue;