Skip to content

Commit 4e86373

Browse files
authored
Teams shared channels (#218)
* shared channel support * add custom prefer: header for all teams calls * don't use result of async op
1 parent 898c6ea commit 4e86373

File tree

8 files changed

+31
-9
lines changed

8 files changed

+31
-9
lines changed

NEWS.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@
1010

1111
- Enable deleting of chat messages, now that this functionality is exposed in the underlying Graph API (#166).
1212

13+
## Teams
14+
15+
- Add the ability to create shared channels (#174).
16+
1317
## Planner
1418

1519
- Fix a bug in the `ms_plan$get_details()` method.

R/ms_channel.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@
9393
#' }
9494
#' @format An R6 object of class `ms_channel`, inheriting from `ms_object`.
9595
#' @export
96-
ms_channel <- R6::R6Class("ms_channel", inherit=ms_object,
96+
ms_channel <- R6::R6Class("ms_channel", inherit=ms_teams_object,
9797

9898
public=list(
9999

R/ms_chat.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@
7474
#' }
7575
#' @format An R6 object of class `ms_chat`, inheriting from `ms_object`.
7676
#' @export
77-
ms_chat <- R6::R6Class("ms_chat", inherit=ms_object,
77+
ms_chat <- R6::R6Class("ms_chat", inherit=ms_teams_object,
7878

7979
public=list(
8080

R/ms_chat_message.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
#' }
5858
#' @format An R6 object of class `ms_chat_message`, inheriting from `ms_object`.
5959
#' @export
60-
ms_chat_message <- R6::R6Class("ms_chat_message", inherit=ms_object,
60+
ms_chat_message <- R6::R6Class("ms_chat_message", inherit=ms_teams_object,
6161

6262
public=list(
6363

R/ms_team.R

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
#' - `sync_fields()`: Synchronise the R object with the team metadata in Microsoft Graph.
1717
#' - `list_channels(filter=NULL, n=Inf)`: List the channels for this team.
1818
#' - `get_channel(channel_name, channel_id)`: Retrieve a channel. If the name and ID are not specified, returns the primary channel.
19-
#' - `create_channel(channel_name, description, membership)`: Create a new channel. Optionally, you can specify a short text description of the channel, and the type of membership: either standard or private (invitation-only).
19+
#' - `create_channel(channel_name, description, membership)`: Create a new channel. Optionally, you can specify a short text description of the channel, and the type of membership: either standard, shared or private (invitation-only). Note that creating a shared channel is an _asynchronous_ operation; the call returns before the creation is finished. You can retrieve the channel with the `get_channel` method after waiting for a short while.
2020
#' - `delete_channel(channel_name, channel_id, confirm=TRUE)`: Delete a channel; by default, ask for confirmation first. You cannot delete the primary channel of a team. Note that Teams keeps track of all channels ever created, even if you delete them (you can see the deleted channels by going to the "Manage team" pane for a team, then the "Channels" tab, and expanding the "Deleted" entry); therefore, try not to create and delete channels unnecessarily.
2121
#' - `list_drives(filter=NULL, n=Inf)`: List the drives (shared document libraries) associated with this team.
2222
#' - `get_drive(drive_name, drive_id)`: Retrieve a shared document library for this team. If the name and ID are not specified, this returns the default document library.
@@ -57,7 +57,7 @@
5757
#' }
5858
#' @format An R6 object of class `ms_team`, inheriting from `ms_object`.
5959
#' @export
60-
ms_team <- R6::R6Class("ms_team", inherit=ms_object,
60+
ms_team <- R6::R6Class("ms_team", inherit=ms_teams_object,
6161

6262
public=list(
6363

@@ -88,18 +88,25 @@ public=list(
8888
else if(is.null(channel_name) && !is.null(channel_id))
8989
file.path("channels", channel_id)
9090
else stop("Do not supply both the channel name and ID", call.=FALSE)
91+
9192
ms_channel$new(self$token, self$tenant, self$do_operation(op), team_id=self$properties$id)
9293
},
9394

94-
create_channel=function(channel_name, description="", membership=c("standard", "private"))
95+
create_channel=function(channel_name, description="", membership=c("standard", "private", "shared"))
9596
{
9697
membership <- match.arg(membership)
9798
body <- list(
9899
displayName=channel_name,
99100
description=description,
100101
membershipType=membership
101102
)
102-
ms_channel$new(self$token, self$tenant, self$do_operation("channels", body=body, http_verb="POST"),
103+
obj <- self$do_operation("channels", body=body, http_verb="POST")
104+
if(membership == "shared")
105+
{
106+
cat("Shared channel creation started in the background. Use the 'get_channel' method to retrieve it.\n")
107+
return(NULL)
108+
}
109+
ms_channel$new(self$token, self$tenant, ,
103110
team_id=self$properties$id)
104111
},
105112

R/ms_team_member.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
#' [Microsoft Teams API reference](https://learn.microsoft.com/en-us/graph/api/resources/teams-api-overview?view=graph-rest-1.0)
2727
#' @format An R6 object of class `ms_team_member`, inheriting from `ms_object`.
2828
#' @export
29-
ms_team_member <- R6::R6Class("ms_team_member", inherit=ms_object,
29+
ms_team_member <- R6::R6Class("ms_team_member", inherit=ms_teams_object,
3030

3131
public=list(
3232

R/ms_teams_object.R

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Prefer header needed to work with shared channels
2+
ms_teams_object <- R6::R6Class("ms_teams_object", inherit=ms_object,
3+
4+
public=list(
5+
6+
do_operation=function(op="", ...)
7+
{
8+
outlook_headers <- httr::add_headers(Prefer="include-unknown-enum-members")
9+
super$do_operation(op, ..., outlook_headers)
10+
}
11+
))

man/ms_team.Rd

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)