]> www.infradead.org Git - pidgin-chime.git/commitdiff
Refine criteria for setting PURPLE_MESSAGE_DELAYED flag
authorDavid Woodhouse <dwmw@amazon.co.uk>
Wed, 1 Apr 2020 13:49:40 +0000 (14:49 +0100)
committerDavid Woodhouse <dwmw@amazon.co.uk>
Wed, 1 Apr 2020 13:49:40 +0000 (14:49 +0100)
Not for *all* messages in the last day, but only for the *last* message, if
it's less than a day old.

prpl/chat.c
prpl/chime.h
prpl/conversations.c
prpl/messages.c

index da9fb9d700d880307827accd811564cb12dbec94..73786a233cf16a886806687a68a63480343a3aa8 100644 (file)
@@ -138,7 +138,7 @@ static gchar *parse_outbound_mentions(ChimeRoom *room, const gchar *message)
 }
 
 static void do_chat_deliver_msg(ChimeConnection *cxn, struct chime_msgs *msgs,
-                               JsonNode *node, time_t msg_time)
+                               JsonNode *node, time_t msg_time, gboolean new_msg)
 {
        struct chime_chat *chat = (struct chime_chat *)msgs;
        PurpleConnection *conn = chat->conv->account->gc;
@@ -175,7 +175,7 @@ static void do_chat_deliver_msg(ChimeConnection *cxn, struct chime_msgs *msgs,
        }
 
        /* If the message is over a day old, don't beep for it. */
-       if (msg_time + 86400 < time(NULL))
+       if (!new_msg)
                msg_flags |= PURPLE_MESSAGE_DELAYED;
 
        if (parse_string(node, "Content", &content)) {
index d1173c383c08df61937c1ac54ac1013bdf145e76..e86e8ed63f1546c49efe72fd36433204f4b9dcb4 100644 (file)
@@ -124,7 +124,7 @@ extern PurpleDBusBinding chime_purple_dbus_bindings[];
 struct chime_msgs;
 
 typedef void (*chime_msg_cb)(ChimeConnection *cxn, struct chime_msgs *msgs,
-                            JsonNode *node, time_t tm);
+                            JsonNode *node, time_t tm, gboolean new_msg);
 struct chime_msgs {
        PurpleConnection *conn;
        ChimeObject *obj;
index 1bebb9d109decb37673ccafaf51872964f222317..60b5a96839cae8d52d520d03ead4f02d416cbdd7 100644 (file)
@@ -35,7 +35,7 @@ struct chime_im {
 
 /* Called for all deliveries of incoming conversation messages, at startup and later */
 static gboolean do_conv_deliver_msg(ChimeConnection *cxn, struct chime_im *im,
-                                   JsonNode *record, time_t msg_time)
+                                   JsonNode *record, time_t msg_time, gboolean new_msg)
 {
        const gchar *sender, *message;
        gint64 sys;
@@ -43,12 +43,10 @@ static gboolean do_conv_deliver_msg(ChimeConnection *cxn, struct chime_im *im,
            !parse_int(record, "IsSystemMessage", &sys))
                return FALSE;
 
-
        PurpleMessageFlags flags = 0;
        if (sys)
                flags |= PURPLE_MESSAGE_SYSTEM;
-       /* If the message is over a day old, don't beep for it. */
-       if (msg_time + 86400 < time(NULL))
+       if (!new_msg)
                flags |= PURPLE_MESSAGE_DELAYED;
 
        const gchar *email = chime_contact_get_email(im->peer);
index b9a46ea6a3da018ea7956f22ac1b7a70020a0cc9..f87848994ad7ac82724960c5ec84218a4fd80b5f 100644 (file)
@@ -96,11 +96,18 @@ void chime_complete_messages(ChimeConnection *cxn, struct chime_msgs *msgs)
                JsonNode *node = ms->node;
                gboolean seen_one = FALSE;
 
+               l = g_list_remove(l, ms);
+
                if (is_msg_unseen(msgs->seen_msgs, id)) {
+                       gboolean new_msg = FALSE;
+                       /* Only treat it as a new message if it is the last one,
+                        * and it was sent within the last day */
+                       if (!l && !msgs->fetch_until && ms->tm.tv_sec + 86400 < time(NULL))
+                               new_msg = TRUE;
+
                        seen_one = TRUE;
-                       msgs->cb(cxn, msgs, node, ms->tm.tv_sec);
+                       msgs->cb(cxn, msgs, node, ms->tm.tv_sec, new_msg);
                }
-               l = g_list_remove(l, ms);
                g_free(ms);
 
                /* Last message, note down the received time */
@@ -179,7 +186,7 @@ static void on_message_received(ChimeObject *obj, JsonNode *node, struct chime_m
                chime_update_last_msg(cxn, msgs, created, id);
 
        if (is_msg_unseen(msgs->seen_msgs, id))
-               msgs->cb(cxn, msgs, node, tv.tv_sec);
+               msgs->cb(cxn, msgs, node, tv.tv_sec, TRUE);
 }
 
 /* Once the message fetching is complete, we can play the fetched messages in order */