| 1 |
// gomuks - A terminal Matrix client written in Go. |
| 2 |
// Copyright (C) 2020 Tulir Asokan |
| 3 |
// |
| 4 |
// This program is free software: you can redistribute it and/or modify |
| 5 |
// it under the terms of the GNU Affero General Public License as published by |
| 6 |
// the Free Software Foundation, either version 3 of the License, or |
| 7 |
// (at your option) any later version. |
| 8 |
// |
| 9 |
// This program is distributed in the hope that it will be useful, |
| 10 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 |
// GNU Affero General Public License for more details. |
| 13 |
// |
| 14 |
// You should have received a copy of the GNU Affero General Public License |
| 15 |
// along with this program. If not, see <https://www.gnu.org/licenses/>. |
| 16 |
|
| 17 |
package messages |
| 18 |
|
| 19 |
import ( |
| 20 |
"go.mau.fi/mauview" |
| •21 |
"github.com/gdamore/tcell/v2" |
| 22 |
|
| 23 |
"maunium.net/go/gomuks/matrix/muksevt" |
| 24 |
|
| 25 |
"maunium.net/go/gomuks/config" |
| 26 |
) |
| 27 |
|
| 28 |
type RedactedMessage struct{} |
| 29 |
|
| 30 |
func NewRedactedMessage(evt *muksevt.Event, displayname string) *UIMessage { |
| 31 |
return newUIMessage(evt, displayname, &RedactedMessage{}) |
| 32 |
} |
| 33 |
|
| 34 |
func (msg *RedactedMessage) Clone() MessageRenderer { |
| 35 |
return &RedactedMessage{} |
| 36 |
} |
| 37 |
|
| 38 |
func (msg *RedactedMessage) NotificationContent() string { |
| 39 |
return "" |
| 40 |
} |
| 41 |
|
| 42 |
func (msg *RedactedMessage) PlainText() string { |
| 43 |
return "[redacted]" |
| 44 |
} |
| 45 |
|
| 46 |
func (msg *RedactedMessage) String() string { |
| 47 |
return "&messages.RedactedMessage{}" |
| 48 |
} |
| 49 |
|
| 50 |
func (msg *RedactedMessage) CalculateBuffer(prefs config.UserPreferences, width int, uiMsg *UIMessage) { |
| 51 |
} |
| 52 |
|
| 53 |
func (msg *RedactedMessage) Height() int { |
| 54 |
return 1 |
| 55 |
} |
| 56 |
|
| 57 |
const RedactionChar = '█' |
| 58 |
const RedactionMaxWidth = 40 |
| 59 |
|
| 60 |
var RedactionStyle = tcell.StyleDefault.Foreground(tcell.NewRGBColor(50, 0, 0)) |
| 61 |
|
| 62 |
func (msg *RedactedMessage) Draw(screen mauview.Screen, _ *UIMessage) { |
| 63 |
w, _ := screen.Size() |
| 64 |
for x := 0; x < w && x < RedactionMaxWidth; x++ { |
| 65 |
screen.SetContent(x, 0, RedactionChar, nil, RedactionStyle) |
| 66 |
} |
| 67 |
} |