}
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;
}
/* 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)) {
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;
/* 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;
!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);
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 */
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 */