mirror of
https://github.com/pushbits/server.git
synced 2025-05-03 12:16:20 +02:00
multiple smaller fixes and improvements
This commit is contained in:
parent
a1558f6f63
commit
728c84676c
4 changed files with 9 additions and 21 deletions
|
@ -7,7 +7,7 @@ import (
|
||||||
|
|
||||||
var (
|
var (
|
||||||
tokenCharacters = []byte("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789")
|
tokenCharacters = []byte("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789")
|
||||||
regularTokenLength = 64 // This length includes the prefix (one character).
|
regularTokenLength = 63 // This length includes the prefix (one character).
|
||||||
compatTokenLength = 15 // This length includes the prefix (one character).
|
compatTokenLength = 15 // This length includes the prefix (one character).
|
||||||
applicationTokenPrefix = "A"
|
applicationTokenPrefix = "A"
|
||||||
)
|
)
|
||||||
|
|
|
@ -45,7 +45,7 @@ func (d *Dispatcher) DeregisterApplication(a *model.Application, u *model.User)
|
||||||
|
|
||||||
if _, err := d.mautrixClient.KickUser(mId.RoomID(a.MatrixID), &mautrix.ReqKickUser{
|
if _, err := d.mautrixClient.KickUser(mId.RoomID(a.MatrixID), &mautrix.ReqKickUser{
|
||||||
Reason: "This application was deleted",
|
Reason: "This application was deleted",
|
||||||
UserID: mId.UserID(a.MatrixID),
|
UserID: mId.UserID(u.MatrixID),
|
||||||
}); err != nil {
|
}); err != nil {
|
||||||
log.Print(err)
|
log.Print(err)
|
||||||
return err
|
return err
|
||||||
|
|
|
@ -27,7 +27,7 @@ func Create(homeserver, username, password string, formatting configuration.Form
|
||||||
Type: mautrix.AuthTypePassword,
|
Type: mautrix.AuthTypePassword,
|
||||||
Identifier: mautrix.UserIdentifier{Type: mautrix.IdentifierTypeUser, User: username},
|
Identifier: mautrix.UserIdentifier{Type: mautrix.IdentifierTypeUser, User: username},
|
||||||
Password: password,
|
Password: password,
|
||||||
DeviceID: id.DeviceID("my-device"), // TODO make device ID configurable
|
DeviceID: id.DeviceID("pushbits"),
|
||||||
StoreCredentials: true,
|
StoreCredentials: true,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -259,27 +259,15 @@ func (d *Dispatcher) respondToMessage(a *model.Application, body, formattedBody
|
||||||
|
|
||||||
// Extracts body and formatted body from a matrix message event
|
// Extracts body and formatted body from a matrix message event
|
||||||
func bodiesFromMessage(message *event.Event) (body, formattedBody string, err error) {
|
func bodiesFromMessage(message *event.Event) (body, formattedBody string, err error) {
|
||||||
if val, ok := message.Content.Raw["body"]; ok {
|
msgContent := message.Content.AsMessage()
|
||||||
body, ok := val.(string)
|
if msgContent == nil {
|
||||||
|
|
||||||
if !ok {
|
|
||||||
return "", "", pberrors.ErrorMessageNotFound
|
|
||||||
}
|
|
||||||
|
|
||||||
formattedBody = body
|
|
||||||
|
|
||||||
} else {
|
|
||||||
return "", "", pberrors.ErrorMessageNotFound
|
return "", "", pberrors.ErrorMessageNotFound
|
||||||
}
|
}
|
||||||
|
|
||||||
if val, ok := message.Content.Raw["formatted_body"]; ok {
|
formattedBody = msgContent.FormattedBody
|
||||||
body, ok := val.(string)
|
if formattedBody == "" {
|
||||||
if !ok {
|
formattedBody = msgContent.Body
|
||||||
return "", "", pberrors.ErrorMessageNotFound
|
|
||||||
}
|
|
||||||
|
|
||||||
formattedBody = body
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return body, formattedBody, nil
|
return msgContent.Body, formattedBody, nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue