server icon indicating copy to clipboard operation
server copied to clipboard

Plugins messages not displayed upon refresh of the message page, nor can they be deleted

Open thomas-maurice opened this issue 9 months ago • 4 comments

Can the issue be reproduced with the latest available release? (y/n) Yes

Which one is the environment gotify server is running in?

  • [x] Docker
  • [ ] Linux machine
  • [ ] Windows machine
Docker startup command or config file here (please mask sensitive information)
Standard config file using sqlite

Do you have an reverse proxy installed in front of gotify server? (Please select None if the problem can be reproduced without the presense of a reverse proxy)

  • [x] None
  • [ ] Nginx
  • [ ] Apache
  • [ ] Caddy

On which client do you experience problems? (Select as many as you can see)

  • [x] WebUI
  • [ ] gotify-cli
  • [ ] Android Client
  • [ ] 3rd-party API call (Please include your code)

What did you do?

Yesterday I was trying to write a simple plugin for Gotify and I noticed a weird behaviour. Take the following plugin code:

The code
package main

import (
	"time"

	"github.com/gin-gonic/gin"
	"github.com/gotify/plugin-api"
)

// GetGotifyPluginInfo returns gotify plugin info.
func GetGotifyPluginInfo() plugin.Info {
	return plugin.Info{
		ModulePath:  "github.com/thomas-maurice/plugin",
		Version:     "0.0.1",
		Author:      "Thomas Maurice",
		Website:     "https://gotify.net/docs/plugin",
		Description: "Plugin",
		License:     "MIT",
		Name:        "thomas-maurice/plugin",
	}
}

// Plugin is the gotify plugin instance.
type Plugin struct {
	msgHandler plugin.MessageHandler
}

// SetMessageHandler implements plugin.Messenger
// Invoked during initialization
func (c *Plugin) SetMessageHandler(h plugin.MessageHandler) {
	c.msgHandler = h
}

func (c *Plugin) Enable() error {
	go func() {
		time.Sleep(5 * time.Second)
		c.msgHandler.SendMessage(plugin.Message{
			Message: "The plugin has been enabled for 5 seconds.",
		})
	}()
	return nil
}

// Disable disables the plugin.
func (c *Plugin) Disable() error {
	return nil
}

// RegisterWebhook implements plugin.Webhooker.
func (c *Plugin) RegisterWebhook(basePath string, g *gin.RouterGroup) {
}

// NewGotifyPluginInstance creates a plugin instance for a user context.
func NewGotifyPluginInstance(ctx plugin.UserContext) plugin.Plugin {
	return &Plugin{}
}

func main() {
	panic("this should be built as go plugin")
}

I compiled it and ran it as per the instructions of the plugin template repo, it compiles and loads properly, so far so good. However when it starts to send messages the messages show up on the web ui, but for instance if I try to delete them it fails, and I see this error in the logs:

2024-05-15T09:31:45Z | 404 |     289.835µs |      172.17.0.1 | DELETE   "/message/49"
Error #01: message does not exist

Reloading the messages page also shows none of the messages sent by the plugin.

I tested with a standard app, and the messages sent via apps do survive a refresh and behave as i would expect.

This is very odd because if I inspect the database itself the messages are there:

sqlite> select * from messages where id=49;
49|0|The plugin has been enabled for 5 seconds.|foo|5||2024-05-15 09:31:42.899755887+00:00

What did you expect to see?

I expect to see the plugin messages show up on the message page even after a refresh

What did you see instead? (Include screenshots, android logcat/request dumps if possible)

The messages disappeared after a page restart, and I cannot seem to delete them from the UI when they show up (immediately after a publish)

thomas-maurice avatar May 15 '24 09:05 thomas-maurice