MM-52804 - Implement SendPushNotification plugin api method (#24273)
* add SendPushNotification plugin api method * lint; add testing.Short bc of the sleep * add interface and generated layers * add fields to PluginPushNotification; generate mocks * SendPushNotification -> SendPluginPushNotification; improved comments * more comments; fix test * send api.ctx
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
f13a531bca
Коммит
8418eefb75
@@ -1180,6 +1180,15 @@ type API interface {
|
||||
// @tag Upload
|
||||
// Minimum server version: 7.6
|
||||
GetUploadSession(uploadID string) (*model.UploadSession, error)
|
||||
|
||||
// SendPluginPushNotification will attempt to send a push notification to `notification.User`, using
|
||||
// `notification.Post` as the source of the notification. The server will use the PluginPushNotification
|
||||
// data to construct the final push notification according to the server's configuration and license. Refer
|
||||
// to `App.BuildPushNotificationMessage` for the logic used to construct the push notification.
|
||||
// Note: the NotificationWillBePushed hook will be run after SendPluginPushNotification is called.
|
||||
//
|
||||
// Minimum server version: 9.0
|
||||
SendPluginPushNotification(notification *model.PluginPushNotification) error
|
||||
}
|
||||
|
||||
var handshake = plugin.HandshakeConfig{
|
||||
|
||||
@@ -1266,3 +1266,10 @@ func (api *apiTimerLayer) GetUploadSession(uploadID string) (*model.UploadSessio
|
||||
api.recordTime(startTime, "GetUploadSession", _returnsB == nil)
|
||||
return _returnsA, _returnsB
|
||||
}
|
||||
|
||||
func (api *apiTimerLayer) SendPluginPushNotification(notification *model.PluginPushNotification) error {
|
||||
startTime := timePkg.Now()
|
||||
_returnsA := api.apiImpl.SendPluginPushNotification(notification)
|
||||
api.recordTime(startTime, "SendPluginPushNotification", _returnsA == nil)
|
||||
return _returnsA
|
||||
}
|
||||
|
||||
@@ -5868,3 +5868,32 @@ func (s *apiRPCServer) GetUploadSession(args *Z_GetUploadSessionArgs, returns *Z
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type Z_SendPluginPushNotificationArgs struct {
|
||||
A *model.PluginPushNotification
|
||||
}
|
||||
|
||||
type Z_SendPluginPushNotificationReturns struct {
|
||||
A error
|
||||
}
|
||||
|
||||
func (g *apiRPCClient) SendPluginPushNotification(notification *model.PluginPushNotification) error {
|
||||
_args := &Z_SendPluginPushNotificationArgs{notification}
|
||||
_returns := &Z_SendPluginPushNotificationReturns{}
|
||||
if err := g.client.Call("Plugin.SendPluginPushNotification", _args, _returns); err != nil {
|
||||
log.Printf("RPC call to SendPluginPushNotification API failed: %s", err.Error())
|
||||
}
|
||||
return _returns.A
|
||||
}
|
||||
|
||||
func (s *apiRPCServer) SendPluginPushNotification(args *Z_SendPluginPushNotificationArgs, returns *Z_SendPluginPushNotificationReturns) error {
|
||||
if hook, ok := s.impl.(interface {
|
||||
SendPluginPushNotification(notification *model.PluginPushNotification) error
|
||||
}); ok {
|
||||
returns.A = hook.SendPluginPushNotification(args.A)
|
||||
returns.A = encodableError(returns.A)
|
||||
} else {
|
||||
return encodableError(fmt.Errorf("API SendPluginPushNotification called but not implemented."))
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -291,6 +291,9 @@ type Hooks interface {
|
||||
//
|
||||
// To cancel a push notification, return true.
|
||||
//
|
||||
// Note that this method will be called for push notification sent by plugins, including
|
||||
// the plugin that created the push notification.
|
||||
//
|
||||
// Minimum server version: 9.0
|
||||
NotificationWillBePushed(pushNotification *model.PluginPushNotification) (cancel bool)
|
||||
}
|
||||
|
||||
@@ -3639,6 +3639,20 @@ func (_m *API) SendMail(to string, subject string, htmlBody string) *model.AppEr
|
||||
return r0
|
||||
}
|
||||
|
||||
// SendPluginPushNotification provides a mock function with given fields: notification
|
||||
func (_m *API) SendPluginPushNotification(notification *model.PluginPushNotification) error {
|
||||
ret := _m.Called(notification)
|
||||
|
||||
var r0 error
|
||||
if rf, ok := ret.Get(0).(func(*model.PluginPushNotification) error); ok {
|
||||
r0 = rf(notification)
|
||||
} else {
|
||||
r0 = ret.Error(0)
|
||||
}
|
||||
|
||||
return r0
|
||||
}
|
||||
|
||||
// SetProfileImage provides a mock function with given fields: userID, data
|
||||
func (_m *API) SetProfileImage(userID string, data []byte) *model.AppError {
|
||||
ret := _m.Called(userID, data)
|
||||
|
||||
Ссылка в новой задаче
Block a user