Skip to content

Commit

Permalink
Fixes for setting/displaying idleness
Browse files Browse the repository at this point in the history
  • Loading branch information
EionRobb committed Feb 7, 2024
1 parent ebb08d4 commit c83c217
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 14 deletions.
6 changes: 6 additions & 0 deletions libteams.c
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,12 @@ teams_status_types(PurpleAccount *account)
// types = g_list_append(types, status);
status = purple_status_type_new_with_attrs(PURPLE_STATUS_OFFLINE, "Offline", _("Offline"), TRUE, TRUE, FALSE, "message", "Mood", purple_value_new(PURPLE_TYPE_STRING), NULL);
types = g_list_append(types, status);

status = purple_status_type_new_with_attrs(PURPLE_STATUS_AVAILABLE, "AvailableIdle", _("Available (Idle)"), FALSE, FALSE, FALSE, "message", "Mood", purple_value_new(PURPLE_TYPE_STRING), NULL);
types = g_list_append(types, status);
status = purple_status_type_new_with_attrs(PURPLE_STATUS_OFFLINE, "PresenceUnknown", _("Unknown"), FALSE, FALSE, FALSE, "message", "Mood", purple_value_new(PURPLE_TYPE_STRING), NULL);
types = g_list_append(types, status);


return types;
}
Expand Down
1 change: 1 addition & 0 deletions teams_connection.c
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ TeamsConnection *teams_post_or_get(TeamsAccount *sa, TeamsMethod method,
purple_http_request_header_set(request, "x-ms-client-user-agent", "Teams-Desktop");
purple_http_request_header_set(request, "x-ms-correlation-id", "1");
purple_http_request_header_set(request, "x-ms-client-version", "27/1.0.0.2023052414");
purple_http_request_header_set(request, "x-ms-endpoint-id", sa->endpoint);

} else if (g_str_equal(host, "substrate.office.com")) {
purple_http_request_header_set_printf(request, "Authorization", "Bearer %s", sa->substrate_access_token);
Expand Down
32 changes: 19 additions & 13 deletions teams_messages.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "teams_connection.h"
#include "teams_contacts.h"
#include "teams_login.h"
#include "teams_trouter.h"

static GString* make_last_timestamp_setting(const gchar *convname) {
GString *rv = g_string_new(NULL);
Expand Down Expand Up @@ -63,19 +64,11 @@ process_userpresence_resource(TeamsAccount *sa, JsonObject *resource)

purple_blist_add_buddy(purple_buddy_new(sa->account, from, NULL), NULL, group, NULL);
}

// if (g_str_equal(capabilities, "IsMobile")) { //"Seamless | IsMobile"
// purple_protocol_got_user_status(sa->account, from, "mobile", NULL);
// }

// is_idle = purple_strequal(status, TEAMS_STATUS_IDLE);
// if (!is_idle) {
purple_protocol_got_user_status(sa->account, from, status, NULL);
// } else {
// purple_protocol_got_user_status(sa->account, from, "Available", NULL);
// }

// purple_protocol_got_user_idle(sa->account, from, is_idle, 0);

purple_protocol_got_user_status(sa->account, from, status, NULL);

gboolean is_idle = purple_strequal(status, "AvailableIdle");
purple_prpl_got_user_idle(sa->account, from, is_idle, 0);
}

// static gboolean
Expand Down Expand Up @@ -1698,6 +1691,9 @@ teams_got_contact_statuses(TeamsAccount *sa, JsonNode *node, gpointer user_data)
*/

purple_protocol_got_user_status(sa->account, from, availability, NULL);

gboolean is_idle = purple_strequal(availability, "AvailableIdle");
purple_prpl_got_user_idle(sa->account, from, is_idle, 0);
}
}
}
Expand Down Expand Up @@ -1902,6 +1898,13 @@ teams_subscribe(TeamsAccount *sa)
subscriptions = json_array_new();
json_array_add_object_element(subscriptions, sub);
json_object_set_array_member(obj, "subscriptions", subscriptions);

if (sa->trouter_surl != NULL) {
JsonObject *trouter_sub = json_object_new();
json_object_set_string_member(trouter_sub, "channelType", "TrouterPush");
json_object_set_array_member(trouter_sub, "interestedResources", json_array_ref(interested));
json_array_add_object_element(subscriptions, trouter_sub);
}

post = teams_jsonobj_to_string(obj);

Expand Down Expand Up @@ -2086,6 +2089,9 @@ teams_set_idle(PurpleConnection *pc, int time)
post = g_strdup_printf("{\"endpointId\":\"%s\",\"isActive\":%s}", sa->endpoint, is_active ? "true" : "false");
teams_post_or_get(sa, TEAMS_METHOD_POST | TEAMS_METHOD_SSL, TEAMS_PRESENCE_HOST, "/v1/me/reportmyactivity/", post, NULL, NULL, TRUE);
g_free(post);

// send isactive on trouter if it's connected
teams_trouter_send_active(sa, is_active);
}


Expand Down
17 changes: 16 additions & 1 deletion teams_trouter.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,21 @@ teams_trouter_stop(TeamsAccount *sa)

}

void
teams_trouter_send_active(TeamsAccount *sa, gboolean active)
{
gchar *message;
gchar *cv;

cv = purple_uuid_random();
message = g_strdup_printf("{\"name\":\"user.activity\",\"args\":[{\"state\":\"%s\",\"cv\":\"%s\"}]}", active ? "active" : "inactive", cv);

teams_trouter_send_message(sa, message);

g_free(cv);
g_free(message);
}

static void
teams_trouter_websocket_cb(PurpleWebsocket *ws, gpointer user_data, PurpleWebsocketOp op, const guchar *msg, size_t len)
{
Expand All @@ -49,7 +64,7 @@ teams_trouter_websocket_cb(PurpleWebsocket *ws, gpointer user_data, PurpleWebsoc
if (op == PURPLE_WEBSOCKET_OPEN) {
purple_debug_info("teams", "Trouter WS: Opened\n");

teams_trouter_send_message(sa, "{\"name\":\"user.activity\",\"args\":[{\"state\":\"active\"}]}");
teams_trouter_send_active(sa, TRUE);

return;
} else if (op == PURPLE_WEBSOCKET_CLOSE) {
Expand Down
1 change: 1 addition & 0 deletions teams_trouter.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,6 @@
void teams_trouter_begin(TeamsAccount *sa);
void teams_trouter_stop(TeamsAccount *sa);
gboolean teams_trouter_send_message(TeamsAccount *sa, const gchar *message);
void teams_trouter_send_active(TeamsAccount *sa, gboolean active);

#endif /*TEAMS_TROUTER_H*/

0 comments on commit c83c217

Please sign in to comment.