From e6feccaf7900668e2614cbe5c73238ca4a996877 Mon Sep 17 00:00:00 2001 From: bqv Date: Mon, 28 Mar 2022 22:57:58 +0100 Subject: [PATCH] fix idle string --- channel.cpp | 2 +- connection.cpp | 4 ++-- user.cpp | 10 ++-------- user.hh | 5 ++++- 4 files changed, 9 insertions(+), 12 deletions(-) diff --git a/channel.cpp b/channel.cpp index 008d70c..eb2a058 100644 --- a/channel.cpp +++ b/channel.cpp @@ -979,7 +979,7 @@ struct t_channel_member *channel__add_member(struct t_account *account, user->profile.status ? user->profile.status : (user->profile.idle ? "idle" : "entered"), weechat_color("reset"), user->profile.idle ? "since " : "", - user->profile.idle ? user->profile.idle : "", + user->profile.idle ? user->profile.idle->data() : "", user->profile.status_text ? " [" : "", user->profile.status_text ? user->profile.status_text : "", user->profile.status_text ? "]" : "", diff --git a/connection.cpp b/connection.cpp index 7b99cd8..e8d6db8 100644 --- a/connection.cpp +++ b/connection.cpp @@ -209,7 +209,7 @@ int connection__presence_handler(xmpp_conn_t *conn, xmpp_stanza_t *stanza, void auto idle = binding.idle_since(); user->profile.status_text = status ? strdup(status->data()) : NULL; user->profile.status = show ? strdup(show->data()) : NULL; - user->profile.idle = idle ? strdup("2000-01-01T00:00:00.000z") : NULL; + user->profile.idle = idle ? fmt::format("{}", *idle) : std::string(); user->is_away = show ? *show == "away" : false; user->profile.role = role.size() ? strdup(role.data()) : NULL; user->profile.affiliation = affiliation.size() && affiliation == "none" @@ -243,7 +243,7 @@ int connection__presence_handler(xmpp_conn_t *conn, xmpp_stanza_t *stanza, void auto idle = binding.idle_since(); user->profile.status_text = status ? strdup(status->data()) : NULL; user->profile.status = show ? strdup(show->data()) : NULL; - user->profile.idle = idle ? strdup("2000-01-01T00:00:00.000z") : NULL; + user->profile.idle = idle ? fmt::format("{}", *idle) : std::string(); user->is_away = show ? *show == "away" : false; user->profile.role = NULL; user->profile.affiliation = NULL; diff --git a/user.cpp b/user.cpp index 97b1cb5..eeb7737 100644 --- a/user.cpp +++ b/user.cpp @@ -166,10 +166,7 @@ struct t_user *user__new(struct t_account *account, return ptr_user; } - if ((new_user = (struct t_user*)malloc(sizeof(*new_user))) == NULL) - { - return NULL; - } + new_user = new struct t_user; new_user->prev_user = account->last_user; new_user->next_user = NULL; @@ -185,7 +182,6 @@ struct t_user *user__new(struct t_account *account, new_user->profile.avatar_hash = NULL; new_user->profile.status_text = NULL; new_user->profile.status = NULL; - new_user->profile.idle = NULL; new_user->profile.display_name = display_name ? strdup(display_name) : strdup(""); new_user->profile.affiliation = NULL; @@ -234,8 +230,6 @@ void user__free(struct t_account *account, free(user->profile.status_text); if (user->profile.status) free(user->profile.status); - if (user->profile.idle) - free(user->profile.idle); if (user->profile.display_name) free(user->profile.display_name); if (user->profile.affiliation) @@ -245,7 +239,7 @@ void user__free(struct t_account *account, if (user->profile.role) free(user->profile.role); - free(user); + delete user; account->users = new_users; } diff --git a/user.hh b/user.hh index 02afaee..c0b2d65 100644 --- a/user.hh +++ b/user.hh @@ -4,12 +4,15 @@ #pragma once +#include +#include + struct t_user_profile { char *avatar_hash; char *status_text; char *status; - char *idle; + std::optional idle; char *display_name; char *email; char *role;