Skip to content

Commit 7014792

Browse files
authored
Merge pull request #858 from safatshahin/MDL-79961
Docs for communication API and updates for provider plugin type - MDL-79961
2 parents 30af0cb + e0ff079 commit 7014792

File tree

5 files changed

+569
-50
lines changed

5 files changed

+569
-50
lines changed

docs/apis.md

+4
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,10 @@ The [Check API](./apis/subsystems/check/index.md) allows you to add security, pe
9292

9393
The [Comment API](https://docs.moodle.org/dev/Comment_API) allows you to save and retrieve user comments, so that you can easily add commenting to any of your code.
9494

95+
### Communication API (communication)
96+
97+
The [Communication API](./apis/subsystems/communication/index.md) provides access to the messaging system and other communication providers (such as Matrix).
98+
9599
### Competency API (competency)
96100

97101
The [Competency API](https://docs.moodle.org/dev/Competency_API) allows you to list and add evidence of competencies to learning plans, learning plan templates, frameworks, courses and activities.

docs/apis/plugintypes/communication/index.md

+36-33
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
---
2-
title: Communication
2+
title: Communication plugin
33
tags:
4-
- communication
5-
- provider
6-
- Communication provider
7-
- Communication room
8-
- Communication service
9-
- Chat
4+
- communication
5+
- provider
6+
- Communication provider
7+
- Communication room
8+
- Communication service
9+
- Chat
1010
documentationDraft: true
1111
---
1212

@@ -58,30 +58,15 @@ you like. These are feature classes which will be defined from the communication
5858

5959
:::
6060

61-
## Creating a new plugin
62-
63-
:::info
64-
65-
TBA after implementing MDL-76796
66-
67-
:::
68-
69-
### Generating the plugin skeleton
70-
71-
:::info
72-
73-
TBA after implementing MDL-76796
74-
75-
:::
76-
7761
## Key files
7862

7963
There are a number of key files within the plugin, described below.
8064

8165
### communication_feature.php
8266

83-
Each plugin must implement this class and should have the exact class name. This part is important for the core communication api.
84-
The core communication api will pick the features and actions from this class. This class should implement the interfaces it supports.
67+
Each plugin must implement this class and should have the exact class name. The core communication api will pick the features and actions from this class. There is no strict rule
68+
on which interfaces should be implemented, plugins can choose which features they support and implement accordingly. Exception is the `communication_provider` interface which
69+
is mandatory for all the plugins. Check below for more details on the interfaces.
8570

8671
```php
8772
class communication_feature implements
@@ -100,24 +85,26 @@ class communication_feature implements
10085
### communication_provider
10186

10287
This is the base communication provider interface. This interface should be used to declare the support for the instantiation method for communication providers.
103-
Every provider plugin must implement this interface. This interface will have the following methods.
88+
Every provider plugin must implement this interface as a bare minimum. This interface will have the following methods.
10489

10590
#### load_for_instance()
10691

107-
This method will have the base communication processor object which will allow loading the communication provider for the communication api.
92+
This method will have the base communication processor(core_communication\processor) object which will allow loading the communication provider for the communication api.
10893

10994
### user_provider
11095

111-
This is the base user provider interface. This interface should be used to declare the support for the for user provider creation and management.
112-
Every provider plugin must implement this interface if user creation is required. This interface will have the following methods.
96+
This is the user provider interface. This interface should be used to declare the support for the for user creation for a provider. For example, Matrix allows creation of users
97+
via API and the `communication_matrix` plugin can support the creation of users in Matrix, in that case, `communication_matrix` plugin should implement this interface. Some APIs might
98+
not need to create user as they might have been created in a different way, in that case this interface can be excluded. This interface will have the following methods.
11399

114100
#### create_members()
115101

116-
All the necessary actions to create members for the room should live here. Some APIs might not need to create user as they might have been created in a different way.
102+
All the necessary code and API calls to create members for the communication room should live here.
117103

118104
### room_chat_provider
119105

120-
This interface will define the features for creating a room. Let's look at the methods of this interface to get a better idea.
106+
This interface will define the features for creating a room. For example, if a communication provider allows creating a room via API, this interface should be implemented.
107+
Let's look at the methods of this interface to get a better idea.
121108

122109
#### create_chat_room()
123110

@@ -134,20 +121,36 @@ value should be returned to indicate if the room is deleted or something went wr
134121

135122
#### generate_room_url()
136123

137-
Generate a room url according to the room information, web client url or any other required information.
124+
Generate a room url according to the room information, web client url or any other required information. This is an important one to allow users access the room from the UI.
125+
Course has an icon to access the room if a room is created for the course, this method will be used to generate the url for the room.
138126

139127
### room_user_provider
140128

141-
This interface will define the features for adding members to the room or removing members from the room. Let's look at the methods of this class to get a better idea.
129+
This interface will define the features for adding/removing/updating members to the room. Room members should be added when a user is enrolled or a role changes. If a provider
130+
allows addition of users to a room via API, this interface should be implemented. Let's look at the methods of this class to get a better idea.
142131

143132
#### add_members_to_room()
144133

145134
All the necessary actions to add members to a room should live here. The array of user ids must be passed here.
146135

136+
#### update_room_membership()
137+
138+
Updating the membership might be necessary in some cases where a user is capability changed, this method will come into play in those cases.
139+
147140
#### remove_members_from_room()
148141

149142
All the necessary actions to remove members from a room should live here. The array of user ids must be passed here.
150143

144+
### synchronise_provider
145+
146+
Communication API has a scheduled task `core_communication\task\synchronise_providers_task` which will synchronise the data from the communication provider to the current Moodle
147+
instance. For example, it can compare the users in the communication room and users enrolled in a course and add/remove users accordingly. The scheduled task runs and adds an
148+
ad-hoc task for each instance where the provider implements this interface. This feature will help keep the data on-sync between the provider and Moodle.
149+
150+
#### synchronise_room_members()
151+
152+
All the necessary code to synchronise the room members should live here.
153+
151154
:::info
152155

153156
For a real plugin example, please look at the [Matrix plugin](https://github.com/moodle/moodle/tree/master/communication/provider/matrix).

0 commit comments

Comments
 (0)