Skip to content

Commit 9c3ec68

Browse files
committed
Save "No such user" errors in private history
1 parent 5011113 commit 9c3ec68

1 file changed

Lines changed: 12 additions & 4 deletions

File tree

oicb.c

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ void proceed_group_list(char *msg, size_t len);
155155
char *null_completer(const char *text, int cmpl_state);
156156

157157
struct history_file *get_history_file(char *path);
158-
char *get_save_path_for(char type, const char *peer);
158+
char *get_save_path_for(char type, const char *peer, const char *msg);
159159
void save_history(char type, const char *peer, const char *msg,
160160
int incoming);
161161
void proceed_history(void);
@@ -423,12 +423,19 @@ create_dir_for(char *path) {
423423
}
424424

425425
char*
426-
get_save_path_for(char type, const char *peer) {
426+
get_save_path_for(char type, const char *peer, const char *msg) {
427427
int rv;
428428
const char *prefix;
429429
char *path;
430430

431-
if (type != 'c') {
431+
#define NO_SUCH_USER "No such user "
432+
if (type == 'e' &&
433+
strncmp(msg, NO_SUCH_USER, strlen(NO_SUCH_USER)) == 0) {
434+
// Those errors occur happen in private chats,
435+
// so it's logical to save them there.
436+
peer = msg + strlen(NO_SUCH_USER);
437+
prefix = "private-";
438+
} else if (type != 'c') {
432439
peer = room;
433440
prefix = "room-";
434441
} else {
@@ -812,12 +819,13 @@ save_history(char type, const char *peer, const char *msg, int incoming) {
812819
char *path;
813820
const int datelen = 20;
814821

822+
warnx("%s: type='%c' peer='%s' msg='%s' incomint=%d", __func__, type, peer, msg, incoming);
815823
if (!enable_history)
816824
return;
817825

818826
t = time(NULL);
819827
now = localtime(&t);
820-
path = get_save_path_for(type, peer);
828+
path = get_save_path_for(type, peer, msg);
821829
if (path == NULL)
822830
goto fail;
823831
hf = get_history_file(path);

0 commit comments

Comments
 (0)