aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorache <ache@ache.one>2019-02-10 23:31:44 +0100
committerache <ache@ache.one>2019-02-10 23:31:44 +0100
commit10959bf8d4b034173b818e86ca2ed3530e29df78 (patch)
tree0a33a85ca27be90191814a4273c3f46d9c8dd855
parentRefesh from inotify (fuck yeah !) (diff)
Manage new message
-rw-r--r--contactWind.c6
-rw-r--r--main.c15
-rw-r--r--messageWind.c1
-rw-r--r--sms.c16
-rw-r--r--sms.h2
-rw-r--r--sms.obin0 -> 10144 bytes
6 files changed, 17 insertions, 23 deletions
diff --git a/contactWind.c b/contactWind.c
index fee0ffd..d353a43 100644
--- a/contactWind.c
+++ b/contactWind.c
@@ -20,7 +20,6 @@ int showName = 1;
contact* getContactSelected(void) {
return contactListSelection+contactList;
}
-
void selectNextContact(void) {
if( contactListSelection < nbContacts - 1)
contactListSelection++;
@@ -34,7 +33,6 @@ void selectPreviousContact(void) {
if( contactListSelection > 0)
contactListSelection--;
}
-
void clearContactListW(void) {
for(int i = firstConctactShow; i < h_menuContact && i < nbContacts; i++) {
move(y_menuContact+i,x_menuContact);
@@ -56,7 +54,7 @@ void showLineContactW(contact* c, int x, int y, int i, char* tmp) {
sms* lastSMS = &c->conversation->listSMS[c->conversation->nbSMS-1];
struct tm* dateOut = localtime(&lastSMS->outDate);
- hasNewMessage = lastSMS->state;
+ hasNewMessage = lastSMS->state == SMS_UNREAD;
isLastToRespond = !lastSMS->in_out;
nbMessage = c->conversation->nbSMS;
@@ -108,8 +106,6 @@ void showLineContactW(contact* c, int x, int y, int i, char* tmp) {
move(y,x + w_menuContact - 8 - r );
printw("✉️");
}
-
-
y++;
attrset(0 | A_NORMAL);
}
diff --git a/main.c b/main.c
index 77981eb..810ff65 100644
--- a/main.c
+++ b/main.c
@@ -217,9 +217,6 @@ int main(int argc, char* argv[]){
int ret = read( fd, buffer, EVENT_BUF_LEN );
int i = 0;
while( ret > 0 ) {
-#ifdef DEBUG
- fprintf(stderr, "%d\n", ret);
-#endif
struct inotify_event *event = (struct inotify_event*) (buffer+i);
ret -= EVENT_SIZE + event->len;
i += EVENT_SIZE + event->len;
@@ -229,15 +226,16 @@ int main(int argc, char* argv[]){
#endif
if( strncmp(event->name, "IN", 2) == 0 ) {
sprintf(sms_filename, "%s%s", config.SMS_INBOX, event->name);
- fprintf(stderr, "%s\n", sms_filename);
- readSMS(sms_filename, 0);
+ readSMS(sms_filename, SMS_IN, SMS_UNREAD);
} else {
sprintf(sms_filename, "%s%s", config.SMS_SENTBOX, event->name);
- fprintf(stderr, "%s\n", sms_filename);
- readSMS(sms_filename, 1);
+ readSMS(sms_filename, SMS_OUT, SMS_UNREAD);
}
}
}
+ if( i > 0 ) {
+ showContactListW();
+ }
if (c == KEY_RESIZE) {
resize();
@@ -422,8 +420,7 @@ edit:
}
}
-
- }
+ }
// inotify stuff
if( wd_in >= 0 ) {
diff --git a/messageWind.c b/messageWind.c
index ca9d3a1..73d1182 100644
--- a/messageWind.c
+++ b/messageWind.c
@@ -89,6 +89,7 @@ int show1SMS(sms* S, int y_base, int* hasFinish) {
move(y+y_base, x_base);
printw("%s", line);
}
+ S->state = SMS_READ;
move(y+y_base+1, x_base);
attrset( COLOR_PAIR( 0 ) | A_NORMAL);
diff --git a/sms.c b/sms.c
index df48780..b7f49cb 100644
--- a/sms.c
+++ b/sms.c
@@ -26,7 +26,7 @@ int insertSMS(sms* S) {
return 1;
}
int indexSMS = -1;
-
+
for(int i = 0 ; i < listConv[index].nbSMS; i++) {
if( listConv[index].listSMS[i].outDate > S->outDate ) {
indexSMS = i;
@@ -78,7 +78,7 @@ void showConv(const char* number) {
}
}
-int readSMS(char* filename, int inbox_outbox) {
+int readSMS(char* filename, int inbox_outbox, char state) {
FILE* file = fopen(filename,"r");
if( file ) {
@@ -95,7 +95,7 @@ int readSMS(char* filename, int inbox_outbox) {
loop:
// On cherche [SMSBackup]
while( fgets(line, 1024, file) != NULL) {
-
+
if( strstr(line, "[SMSBackup") ) {
char SMSBackup[30] = "";
sprintf(SMSBackup, "[SMSBackup%.03d]\n", sms_number);
@@ -152,9 +152,13 @@ int readSMS(char* filename, int inbox_outbox) {
}
if( !feof(file) )
goto loop;
+
sms_text[++sms_len] = lastChar;
getSms.text = sms_text;
getSms.len = sms_len;
+ if( state == SMS_UNREAD && getSms.in_out == SMS_IN ) {
+ getSms.state = state;
+ }
int r = insertSMS(&getSms);
if( r ) {
@@ -180,7 +184,7 @@ int listSMS(char* smsInboxDir, int inorout) {
char filename[1024] ="";
sprintf(filename, "%s/%s", smsInboxDir, dir->d_name);
- int r = readSMS(filename, inorout);
+ int r = readSMS(filename, inorout, SMS_READ);
if( r ) {
return 2;
}
@@ -194,9 +198,6 @@ int listSMS(char* smsInboxDir, int inorout) {
return 0;
}
-
-
-
int loadConv(void) {
int r = 0;
@@ -227,4 +228,3 @@ int loadConv(void) {
return 0;
}
-
diff --git a/sms.h b/sms.h
index 7ab9281..798bfe6 100644
--- a/sms.h
+++ b/sms.h
@@ -38,7 +38,7 @@ typedef struct conversation {
size_t nbSMS;
} conversation;
-int readSMS(char*, int);
+int readSMS(char*, int, char);
int listSMS(char*,int);
int loadConv(void);
diff --git a/sms.o b/sms.o
new file mode 100644
index 0000000..7f12f77
--- /dev/null
+++ b/sms.o
Binary files differ