switched implementation to multi-account mode

* instead of starting signal-cli in json-rpc mode with the '-u',
  we start signal-cli without the '-u' parameter (also known as
  multi-account mode). This makes it possible to register a number in
  json-rpc mode.
This commit is contained in:
Bernhard B
2023-10-30 14:49:11 +01:00
parent 0cab12c49d
commit a06a9f873b
5 changed files with 131 additions and 158 deletions

View File

@@ -384,7 +384,7 @@ func (a *Api) SendV2(c *gin.Context) {
}
func (a *Api) handleSignalReceive(ws *websocket.Conn, number string, stop chan struct{}) {
receiveChannel, err := a.signalClient.GetReceiveChannel(number)
receiveChannel, err := a.signalClient.GetReceiveChannel()
if err != nil {
log.Error("Couldn't get receive channel: ", err.Error())
return
@@ -404,12 +404,24 @@ func (a *Api) handleSignalReceive(ws *websocket.Conn, number string, stop chan s
if err == nil {
if data != "" {
err = ws.WriteMessage(websocket.TextMessage, []byte(data))
type Response struct {
Account string `json:"account"`
}
var response Response
err = json.Unmarshal([]byte(data), &response)
if err != nil {
if websocket.IsUnexpectedCloseError(err, websocket.CloseGoingAway, websocket.CloseAbnormalClosure) {
log.Error("Couldn't write message: " + err.Error())
log.Error("Couldn't parse message ", data, ":", err.Error())
continue
}
if response.Account == number {
err = ws.WriteMessage(websocket.TextMessage, []byte(data)) //TODO split up data in different channels
if err != nil {
if websocket.IsUnexpectedCloseError(err, websocket.CloseGoingAway, websocket.CloseAbnormalClosure) {
log.Error("Couldn't write message: " + err.Error())
}
return
}
return
}
}
} else {