palm-client: pin DMs to the top of Home's Direct list (tap and hold: Pin/Unpin)
Pins are kept by key prefix (pins.c, segment 4, up to 8), so they work for senders who aren't contacts; those get a Pin-only popup. Pinned DMs sort first, most recent first among themselves; the rest keep their order.
This commit is contained in:
1 parent
9cca51a8dd
commit
3fd932da4f
9 files changed
+135
-26
No files matched your search
@@ -10,7 +10,7 @@ APP = visormesh
|
||||
NAME = VisorMesh
|
||||
CREATOR = VMsh
|
||||
|
||||
SRCS = src/main.c src/app.c src/home_form.c src/convo_form.c src/node_form.c src/channel_form.c src/convos.c src/protocol.c src/sha256.c src/transport_srm.c src/transport_sb.c src/sb_spi.c src/session.c src/settings.c src/presets.c src/contacts.c src/contacts_form.c src/contact_form.c src/heard.c src/remote_fmt.c src/remote.c src/remote_form.c src/messages.c src/channels.c src/preview_form.c src/ui/draw.c src/ui/text.c src/ui/rowlist.c src/ui/fontmetrics.c src/ports.c src/sounds.c src/mutes.c src/scopes.c src/scope_proto.c src/map_geo.c src/map_form.c src/ui/emoji.c src/bgcheck.c
|
||||
SRCS = src/main.c src/app.c src/home_form.c src/convo_form.c src/node_form.c src/channel_form.c src/convos.c src/protocol.c src/sha256.c src/transport_srm.c src/transport_sb.c src/sb_spi.c src/session.c src/settings.c src/presets.c src/contacts.c src/contacts_form.c src/contact_form.c src/heard.c src/remote_fmt.c src/remote.c src/remote_form.c src/messages.c src/channels.c src/preview_form.c src/ui/draw.c src/ui/text.c src/ui/rowlist.c src/ui/fontmetrics.c src/ports.c src/sounds.c src/mutes.c src/scopes.c src/scope_proto.c src/map_geo.c src/map_form.c src/ui/emoji.c src/bgcheck.c src/pins.c
|
||||
OBJS = $(SRCS:src/%.c=build/%.o)
|
||||
|
||||
CC = m68k-palmos-gcc
|
||||
|
||||
@@ -97,7 +97,7 @@ BEGIN
|
||||
SCROLLBAR ID HomeScroll AT (153 16 7 128) VALUE 0 MIN 0 MAX 0 PAGESIZE 1
|
||||
BUTTON "Contacts" ID HomeContactsButton AT (1 147 AUTO AUTO)
|
||||
BUTTON "Node" ID HomeNodeButton AT (PREVRIGHT+5 PREVTOP AUTO AUTO)
|
||||
LIST "" ID HomeActionList AT (28 16 80 AUTO) NONUSABLE VISIBLEITEMS 3
|
||||
LIST "" ID HomeActionList AT (28 16 80 AUTO) NONUSABLE VISIBLEITEMS 4
|
||||
END
|
||||
|
||||
/* One conversation: transcript, compose field, send */
|
||||
@@ -416,6 +416,14 @@ BEGIN
|
||||
BUTTONS "Open" "Later"
|
||||
END
|
||||
|
||||
ALERT ID PinAlert
|
||||
INFORMATION
|
||||
BEGIN
|
||||
TITLE "Pin Conversation"
|
||||
MESSAGE "^1"
|
||||
BUTTONS "OK"
|
||||
END
|
||||
|
||||
ALERT ID MuteAlert
|
||||
INFORMATION
|
||||
BEGIN
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
#include "sounds.h"
|
||||
#include "mutes.h"
|
||||
#include "scopes.h"
|
||||
#include "pins.h"
|
||||
|
||||
VmConv gAppConv;
|
||||
Boolean gAppAutoConnectTried = false;
|
||||
@@ -31,6 +32,7 @@ void AppLoadPrefs(void)
|
||||
SoundsLoad();
|
||||
MutesLoad();
|
||||
ScopesLoad();
|
||||
PinsLoad();
|
||||
if (PrefGetAppPreferences(VM_CREATOR, VM_PREFS_ID, &prefs, &size, true) != noPreferenceFound &&
|
||||
size == sizeof(prefs) && prefs.version == VM_PREFS_VERSION) {
|
||||
/*
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#include "messages.h"
|
||||
#include "convos.h"
|
||||
#include "mutes.h"
|
||||
#include "pins.h"
|
||||
|
||||
/* In the second code segment: see sections.h for the rules. */
|
||||
static void HexPrefix(const UInt8 *p, Char *out) VM_SECT2;
|
||||
@@ -198,10 +199,16 @@ UInt16 ConvosBuild(VmConvRow *rows, UInt16 max)
|
||||
MessagesRelease(i);
|
||||
}
|
||||
|
||||
/* direct: most recent first; those without messages keep their (alphabetical) order */
|
||||
for (i = directStart; i < n; i++)
|
||||
rows[i].pinned = DirectPinned(rows[i].conv.key);
|
||||
/*
|
||||
* direct: pinned first, then most recent first; those without messages
|
||||
* keep their (alphabetical) order
|
||||
*/
|
||||
for (i = directStart + 1; i < n; i++) {
|
||||
tmp = rows[i];
|
||||
for (j = i; j > directStart && rows[j - 1].last < tmp.last; j--)
|
||||
for (j = i; j > directStart && (rows[j - 1].pinned < tmp.pinned ||
|
||||
(rows[j - 1].pinned == tmp.pinned && rows[j - 1].last < tmp.last)); j--)
|
||||
rows[j] = rows[j - 1];
|
||||
rows[j] = tmp;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* The conversation list: channels (slot order) then direct conversations
|
||||
* (most recent first), with unread counts, last activity and a preview,
|
||||
* (pinned first, then most recent first), with unread counts, last activity and a preview,
|
||||
* built from the channel cache, the contacts and one pass over the messages.
|
||||
*/
|
||||
#ifndef VM_CONVOS_H
|
||||
@@ -24,6 +24,7 @@ typedef struct {
|
||||
Boolean failed; /* the newest outgoing message here wasn't delivered */
|
||||
UInt32 lastOut; /* when that message was stored (Unix seconds) */
|
||||
Boolean muted; /* a muted channel (mutes.h) */
|
||||
Boolean pinned; /* a pinned direct conversation (pins.h) */
|
||||
Char preview[VM_PREVIEW_LEN];
|
||||
} VmConvRow;
|
||||
|
||||
|
||||
+26
-21
@@ -2,7 +2,7 @@
|
||||
* Home: the conversation list, MeshTerm's chat picker. Channels in slot
|
||||
* order, then direct conversations (most recent first). Each row: marker,
|
||||
* name, unread badge or failed mark, age, preview. Tap to open; tap and hold
|
||||
* for a channel's actions (mute, scope, leave) or a contact's (info, reset
|
||||
* for a channel's actions (mute, scope, leave) or a DM's (pin, info, reset
|
||||
* path, remove).
|
||||
*/
|
||||
#include <PalmOS.h>
|
||||
@@ -19,6 +19,7 @@
|
||||
#include "channel_form.h"
|
||||
#include "contacts.h"
|
||||
#include "contact_form.h"
|
||||
#include "pins.h"
|
||||
|
||||
/* In the second code segment: see sections.h for the rules. */
|
||||
static void DrawRow(UInt16 row, const RectangleType *b, void *ctx) VM_SECT2;
|
||||
@@ -27,7 +28,7 @@ static void DrawTitleStatus(void) VM_SECT2;
|
||||
static void ShowStatus(const Char *text) VM_SECT2;
|
||||
static void TitleRight(const Char *text) VM_SECT2;
|
||||
static void Rebuild(Boolean draw) VM_SECT2;
|
||||
static Int16 PopupActions(const RectangleType *b, Char **items) VM_SECT2;
|
||||
static Int16 PopupActions(const RectangleType *b, Char **items, UInt16 n) VM_SECT2;
|
||||
static Boolean HoldChannel(const VmConvRow *r, const RectangleType *b) VM_SECT2;
|
||||
static Boolean HoldDirect(const VmConvRow *r, const RectangleType *b) VM_SECT2;
|
||||
static Boolean Hold(UInt16 row, const RectangleType *b, void *ctx) VM_SECT2;
|
||||
@@ -76,12 +77,12 @@ static void DrawRow(UInt16 row, const RectangleType *b, void *ctx)
|
||||
FntSetFont(old);
|
||||
}
|
||||
|
||||
#define HOLD_ITEMS 3
|
||||
#define HOLD_MAX 4
|
||||
#define HOLD_LIST_X 28
|
||||
#define HOLD_LIST_H (HOLD_ITEMS * 11 + 2) /* stdFont rows and the frame */
|
||||
#define HOLD_LIST_H(n) ((n) * 11 + 2) /* stdFont rows and the frame */
|
||||
|
||||
/* Shows the popup beside the row (below it, or above near the bottom of the list); returns the pick. */
|
||||
static Int16 PopupActions(const RectangleType *b, Char **items)
|
||||
static Int16 PopupActions(const RectangleType *b, Char **items, UInt16 n)
|
||||
{
|
||||
FormType *form = FrmGetActiveForm();
|
||||
ListType *list = FrmGetObjectPtr(form, FrmGetObjectIndex(form, HomeActionList));
|
||||
@@ -89,10 +90,10 @@ static Int16 PopupActions(const RectangleType *b, Char **items)
|
||||
Coord y = b->topLeft.y + b->extent.y;
|
||||
|
||||
FrmGetObjectBounds(form, FrmGetObjectIndex(form, HomeGadget), &area);
|
||||
if (y + HOLD_LIST_H > area.topLeft.y + area.extent.y)
|
||||
y = b->topLeft.y - HOLD_LIST_H;
|
||||
LstSetListChoices(list, items, HOLD_ITEMS);
|
||||
LstSetHeight(list, HOLD_ITEMS);
|
||||
if (y + HOLD_LIST_H(n) > area.topLeft.y + area.extent.y)
|
||||
y = b->topLeft.y - HOLD_LIST_H(n);
|
||||
LstSetListChoices(list, items, n);
|
||||
LstSetHeight(list, n);
|
||||
LstSetPosition(list, HOLD_LIST_X, y);
|
||||
LstSetSelection(list, noListSelection);
|
||||
return LstPopupList(list);
|
||||
@@ -100,13 +101,13 @@ static Int16 PopupActions(const RectangleType *b, Char **items)
|
||||
|
||||
static Boolean HoldChannel(const VmConvRow *r, const RectangleType *b)
|
||||
{
|
||||
Char *items[HOLD_ITEMS];
|
||||
Char *items[HOLD_MAX];
|
||||
UInt8 slot = r->conv.channel;
|
||||
|
||||
items[0] = r->muted ? "Unmute" : "Mute";
|
||||
items[1] = "Channel Scope...";
|
||||
items[2] = "Leave Channel";
|
||||
switch (PopupActions(b, items)) {
|
||||
switch (PopupActions(b, items, 3)) {
|
||||
case 0:
|
||||
ChannelMuteToggle(slot);
|
||||
Rebuild(true);
|
||||
@@ -121,25 +122,29 @@ static Boolean HoldChannel(const VmConvRow *r, const RectangleType *b)
|
||||
return true;
|
||||
}
|
||||
|
||||
/* A sender we have no contact for has nothing to act on: that hold is a tap. */
|
||||
/* A sender we have no contact for only gets Pin. */
|
||||
static Boolean HoldDirect(const VmConvRow *r, const RectangleType *b)
|
||||
{
|
||||
Char *items[HOLD_ITEMS];
|
||||
Char *items[HOLD_MAX];
|
||||
VmContact c;
|
||||
Boolean known = ContactsFindByPrefix(r->conv.key, &c);
|
||||
|
||||
if (!ContactsFindByPrefix(r->conv.key, &c))
|
||||
return false;
|
||||
items[0] = "Contact Info";
|
||||
items[1] = "Reset Path";
|
||||
items[2] = "Remove Contact";
|
||||
switch (PopupActions(b, items)) {
|
||||
items[0] = r->pinned ? "Unpin" : "Pin";
|
||||
items[1] = "Contact Info";
|
||||
items[2] = "Reset Path";
|
||||
items[3] = "Remove Contact";
|
||||
switch (PopupActions(b, items, known ? 4 : 1)) {
|
||||
case 0:
|
||||
ContactFormOpen(&c);
|
||||
if (DirectPinToggle(r->conv.key))
|
||||
Rebuild(true);
|
||||
break;
|
||||
case 1:
|
||||
ContactResetPath(&c);
|
||||
ContactFormOpen(&c);
|
||||
break;
|
||||
case 2:
|
||||
ContactResetPath(&c);
|
||||
break;
|
||||
case 3:
|
||||
if (ContactRemove(&c))
|
||||
Rebuild(true);
|
||||
break;
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
#include <PalmOS.h>
|
||||
#include "resources.h"
|
||||
#include "app.h"
|
||||
#include "pins.h"
|
||||
|
||||
static Int16 FindPin(const UInt8 *key6) VM_SECT4;
|
||||
static void SavePrefs(void) VM_SECT4;
|
||||
|
||||
#define VM_PINS_PREFS_ID 8
|
||||
#define VM_PINS_PREFS_VERSION 1
|
||||
#define VM_PINS_MAX 8
|
||||
#define VM_PIN_ID_SIZE 6 /* the key prefix DMs are known by */
|
||||
|
||||
typedef struct {
|
||||
UInt16 version;
|
||||
UInt16 count;
|
||||
UInt8 ids[VM_PINS_MAX][VM_PIN_ID_SIZE];
|
||||
} PinsPrefs;
|
||||
|
||||
static PinsPrefs gPins;
|
||||
|
||||
void PinsLoad(void)
|
||||
{
|
||||
UInt16 size = sizeof(gPins);
|
||||
|
||||
if (PrefGetAppPreferences(VM_CREATOR, VM_PINS_PREFS_ID, &gPins, &size, true) == noPreferenceFound ||
|
||||
size != sizeof(gPins) || gPins.version != VM_PINS_PREFS_VERSION || gPins.count > VM_PINS_MAX)
|
||||
gPins.count = 0;
|
||||
gPins.version = VM_PINS_PREFS_VERSION;
|
||||
}
|
||||
|
||||
static void SavePrefs(void)
|
||||
{
|
||||
PrefSetAppPreferences(VM_CREATOR, VM_PINS_PREFS_ID, VM_PINS_PREFS_VERSION, &gPins, sizeof(gPins), true);
|
||||
}
|
||||
|
||||
static Int16 FindPin(const UInt8 *key6)
|
||||
{
|
||||
UInt16 i;
|
||||
|
||||
for (i = 0; i < gPins.count; i++)
|
||||
if (MemCmp(gPins.ids[i], key6, VM_PIN_ID_SIZE) == 0)
|
||||
return (Int16)i;
|
||||
return -1;
|
||||
}
|
||||
|
||||
Boolean DirectPinned(const UInt8 *key6)
|
||||
{
|
||||
return FindPin(key6) >= 0;
|
||||
}
|
||||
|
||||
Boolean DirectPinToggle(const UInt8 *key6)
|
||||
{
|
||||
Int16 i = FindPin(key6);
|
||||
|
||||
if (i >= 0) {
|
||||
MemMove(gPins.ids[i], gPins.ids[i + 1], (gPins.count - i - 1) * VM_PIN_ID_SIZE);
|
||||
gPins.count--;
|
||||
} else if (gPins.count >= VM_PINS_MAX) {
|
||||
FrmCustomAlert(PinAlert, "Too many pinned conversations: unpin one first.", "", "");
|
||||
return false;
|
||||
} else {
|
||||
MemMove(gPins.ids[gPins.count++], key6, VM_PIN_ID_SIZE);
|
||||
}
|
||||
SavePrefs();
|
||||
return true;
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
/*
|
||||
* Pinned direct conversations: they stay at the top of Home's Direct list
|
||||
* (most recent first among themselves), above the unpinned ones. Kept by the
|
||||
* contact's key prefix, so a pin survives the contact list refresh and works
|
||||
* for senders who aren't contacts.
|
||||
*/
|
||||
#ifndef VM_PINS_H
|
||||
#define VM_PINS_H
|
||||
|
||||
#include <PalmOS.h>
|
||||
#include "sections.h"
|
||||
|
||||
void PinsLoad(void) VM_SECT4;
|
||||
Boolean DirectPinned(const UInt8 *key6) VM_SECT4;
|
||||
/* Pins or unpins; false (with an alert) if the list of pins is full. */
|
||||
Boolean DirectPinToggle(const UInt8 *key6) VM_SECT4;
|
||||
|
||||
#endif
|
||||
@@ -99,6 +99,7 @@
|
||||
#define HomeContactsButton 1503
|
||||
#define HomeNodeButton 1504
|
||||
#define HomeActionList 1505 /* tap-and-hold popup (home_form.c) */
|
||||
#define PinAlert 1506
|
||||
|
||||
#define ConvoForm 1600
|
||||
#define ConvoGadget 1601
|
||||
|
||||
Reference in new issue
Block a user