mirror of
https://github.com/tulir/gomuks.git
synced 2025-04-20 10:33:41 -05:00
hicli/send: add /unencrypted command
This commit is contained in:
parent
35eb50cf8a
commit
ddd97655b0
1 changed files with 10 additions and 4 deletions
|
@ -71,6 +71,11 @@ func (h *HiClient) SendMessage(
|
|||
relatesTo *event.RelatesTo,
|
||||
mentions *event.Mentions,
|
||||
) (*database.Event, error) {
|
||||
var unencrypted bool
|
||||
if strings.HasPrefix(text, "/unencrypted ") {
|
||||
text = strings.TrimPrefix(text, "/unencrypted ")
|
||||
unencrypted = true
|
||||
}
|
||||
if strings.HasPrefix(text, "/raw ") {
|
||||
parts := strings.SplitN(text, " ", 3)
|
||||
if len(parts) < 2 || len(parts[1]) == 0 {
|
||||
|
@ -85,7 +90,7 @@ func (h *HiClient) SendMessage(
|
|||
if !json.Valid(content) {
|
||||
return nil, fmt.Errorf("invalid JSON in /raw command")
|
||||
}
|
||||
return h.send(ctx, roomID, event.Type{Type: parts[1]}, content, "")
|
||||
return h.send(ctx, roomID, event.Type{Type: parts[1]}, content, "", unencrypted)
|
||||
}
|
||||
var content event.MessageEventContent
|
||||
msgType := event.MsgText
|
||||
|
@ -148,7 +153,7 @@ func (h *HiClient) SendMessage(
|
|||
content.RelatesTo = relatesTo
|
||||
}
|
||||
}
|
||||
return h.send(ctx, roomID, event.EventMessage, &event.Content{Parsed: content, Raw: extra}, origText)
|
||||
return h.send(ctx, roomID, event.EventMessage, &event.Content{Parsed: content, Raw: extra}, origText, unencrypted)
|
||||
}
|
||||
|
||||
func (h *HiClient) MarkRead(ctx context.Context, roomID id.RoomID, eventID id.EventID, receiptType event.ReceiptType) error {
|
||||
|
@ -212,7 +217,7 @@ func (h *HiClient) Send(
|
|||
evtType event.Type,
|
||||
content any,
|
||||
) (*database.Event, error) {
|
||||
return h.send(ctx, roomID, evtType, content, "")
|
||||
return h.send(ctx, roomID, evtType, content, "", false)
|
||||
}
|
||||
|
||||
func (h *HiClient) Resend(ctx context.Context, txnID string) (*database.Event, error) {
|
||||
|
@ -241,6 +246,7 @@ func (h *HiClient) send(
|
|||
evtType event.Type,
|
||||
content any,
|
||||
overrideEditSource string,
|
||||
disableEncryption bool,
|
||||
) (*database.Event, error) {
|
||||
room, err := h.DB.Room.Get(ctx, roomID)
|
||||
if err != nil {
|
||||
|
@ -261,7 +267,7 @@ func (h *HiClient) send(
|
|||
Reactions: map[string]int{},
|
||||
LastEditRowID: ptr.Ptr(database.EventRowID(0)),
|
||||
}
|
||||
if room.EncryptionEvent != nil && evtType != event.EventReaction {
|
||||
if room.EncryptionEvent != nil && evtType != event.EventReaction && !disableEncryption {
|
||||
dbEvt.Type = event.EventEncrypted.Type
|
||||
dbEvt.DecryptedType = evtType.Type
|
||||
dbEvt.Decrypted, err = json.Marshal(content)
|
||||
|
|
Loading…
Add table
Reference in a new issue