Compare commits

...

1 Commits
master ... dev

Author SHA1 Message Date
normen
588633cc60 initial work for quoting 2021-07-12 21:37:48 +02:00
4 changed files with 64 additions and 2 deletions

View File

@@ -48,6 +48,7 @@ type Keymap struct {
MessageUrl string
MessageInfo string
MessageRevoke string
MessageQuote string
}
type Ui struct {
@@ -100,6 +101,7 @@ var Config = IniFile{
MessageUrl: "u",
MessageRevoke: "r",
MessageShow: "s",
MessageQuote: "q",
},
&Ui{
ChatSidebarWidth: 30,

19
main.go
View File

@@ -17,7 +17,7 @@ import (
"github.com/zyedidia/clipboard"
)
var VERSION string = "v1.0.10"
var VERSION string = "v1.1.0"
var sndTxt string = ""
var currentReceiver messages.Chat = messages.Chat{}
@@ -202,6 +202,20 @@ func handleCommand(command string) func(ev *tcell.EventKey) *tcell.EventKey {
}
}
func handleQuote(ev *tcell.EventKey) *tcell.EventKey {
if hls := textView.GetHighlights(); len(hls) > 0 {
for _, val := range curRegions {
if val.Id == hls[0] {
cmdPrefix := config.Config.General.CmdPrefix
textInput.SetText(cmdPrefix + "quote " + val.ChatId + " " + val.Id + " ")
}
}
ResetMsgSelection()
app.SetFocus(textInput)
}
return nil
}
func handleCopyUser(ev *tcell.EventKey) *tcell.EventKey {
if hls := textView.GetHighlights(); len(hls) > 0 {
for _, val := range curRegions {
@@ -371,6 +385,9 @@ func LoadShortcuts() {
if err := keysMessages.Set(config.Config.Keymap.MessageRevoke, handleMessageCommand("revoke")); err != nil {
PrintErrorMsg("message_revoke:", err)
}
if err := keysMessages.Set(config.Config.Keymap.MessageQuote, handleQuote); err != nil {
PrintErrorMsg("quote:", err)
}
keysMessages.SetKey(tcell.ModNone, tcell.KeyEscape, handleExitMessages)
keysMessages.SetKey(tcell.ModNone, tcell.KeyUp, handleMessagesMove(-1))
keysMessages.SetKey(tcell.ModNone, tcell.KeyDown, handleMessagesMove(1))

View File

@@ -307,6 +307,14 @@ func (sm *SessionManager) execCommand(command Command) {
} else {
sm.printCommandUsage("send", "[chat-id[] [message text[]")
}
case "quote":
if checkParam(command.Params, 3) {
textParams := command.Params[2:]
text := strings.Join(textParams, " ")
sm.sendQuotedText(command.Params[0], command.Params[1], text)
} else {
sm.printCommandUsage("quote", "[chat-id[] [quoted-message-id[] [message text[]")
}
case "select":
if checkParam(command.Params, 1) {
sm.setCurrentReceiver(command.Params[0])
@@ -829,13 +837,33 @@ func (sm *SessionManager) sendText(wid string, text string) {
},
Text: text,
}
sm.sendMsg(msg, wid)
}
func (sm *SessionManager) sendQuotedText(wid string, qid string, text string) {
sm.db.GetMessageInfo(qid)
msg := whatsapp.TextMessage{
Info: whatsapp.MessageInfo{
RemoteJid: wid,
FromMe: true,
Timestamp: uint64(time.Now().Unix()),
},
Text: text,
ContextInfo: whatsapp.ContextInfo{
QuotedMessageID: qid,
Participant: sm.db.GetMessageSender(qid),
},
}
sm.sendMsg(msg, wid)
}
func (sm *SessionManager) sendMsg(msg whatsapp.TextMessage, wid string) {
sm.lastSent = time.Now()
newid, err := sm.getConnection().Send(msg)
msg.Info.Id = newid
if err != nil {
sm.uiHandler.PrintError(err)
} else {
msg.Info.Id = newid
sm.db.AddTextMessage(&msg)
if sm.currentReceiver == wid {
sm.uiHandler.NewMessage(sm.createMessage(&msg))

View File

@@ -153,6 +153,21 @@ func (db *MessageDatabase) GetMessageInfo(id string) string {
return out
}
func (db *MessageDatabase) GetMessageSender(id string) string {
if _, ok := db.otherMessages[id]; ok {
return ""
}
out := ""
if msg, ok := db.messagesById[id]; ok {
if msg.ContextInfo.Participant != "" {
return msg.ContextInfo.Participant
} else {
return msg.Info.SenderJid
}
}
return out
}
// get a string containing all messages for a chat by chat id
func (db *MessageDatabase) GetMessages(wid string) []whatsapp.TextMessage {
var arr = []whatsapp.TextMessage{}