Skip to content

Commit

Permalink
basic support for sending message states fixes #110 #91
Browse files Browse the repository at this point in the history
  • Loading branch information
nanu-c committed Apr 15, 2020
1 parent 31db25d commit 2c5f6ab
Show file tree
Hide file tree
Showing 46 changed files with 330 additions and 225 deletions.
18 changes: 18 additions & 0 deletions app/handler/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ func TypingMessageHandler(msg *textsecure.Message) {
webserver.UpdateChatList()
}
func ReceiptHandler(source string, devID uint32, timestamp uint64) {
log.Println("[axolotl] receiptMessageHandler2 ")
webserver.UpdateChatList()

s := store.SessionsModel.Get(source)
Expand All @@ -159,15 +160,32 @@ func ReceiptHandler(source string, devID uint32, timestamp uint64) {
m.Receipt = true
//qml.Changed(m, &m.IsRead)
store.UpdateMessageRead(m)
webserver.UpdateActiveChat()
return
}
}
webserver.UpdateChatList()
log.Printf("[axolotl] receipt: Message with timestamp %d not found\n", timestamp)
}

func ReceiptMessageHandler(msg *textsecure.Message) {
log.Println("[axolotl] receiptMessageHandler: Message ", msg)

webserver.UpdateChatList()
s := store.SessionsModel.Get(msg.Source())
for i := len(s.Messages) - 1; i >= 0; i-- {
m := s.Messages[i]
if m.SentAt == msg.Timestamp() {
m.Receipt = true
//qml.Changed(m, &m.IsRead)
store.UpdateMessageRead(m)
webserver.UpdateChatList()

return
}
}
webserver.UpdateChatList()
log.Printf("[axolotl] receipt: Message with timestamp %d not found\n", msg.Timestamp())
log.Println("[axolotl] receiptMessageHandler: Message ", msg)
}

Expand Down
11 changes: 9 additions & 2 deletions app/sender/messageSender.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,11 @@ func SendMessage(s *store.Session, m *store.Message) {
s.Timestamp = m.SentAt
m.IsSent = true
if ts == 0 {
log.Debugln("SendMessageLoop", ts)
m.SendingError = true
m.IsSent = false
m.SentAt = uint64(time.Now().UnixNano() / 1000000)
m.ExpireTimer = 0
}
m.HTime = helpers.HumanizeTimestamp(m.SentAt)
s.When = m.HTime
Expand Down Expand Up @@ -95,12 +98,16 @@ func SendMessageLoop(to, message string, group bool, att io.Reader, flags int, t
log.Debugln("[axolotl] send to group ")
} else {
ts, err = textsecure.SendMessage(to, message, timer)
if err != nil {
log.Debugln("blub", err.Error(), ts)
}

}
} else {
if group {
ts, err = textsecure.SendGroupAttachment(to, message, att, timer)
} else {
log.Printf("SendMessageLoop sendAttachment")
log.Printf("[axolotl] SendMessageLoop sendAttachment")
// buf := new(bytes.Buffer)
// buf.ReadFrom(att)
// s := buf.String()
Expand All @@ -112,7 +119,7 @@ func SendMessageLoop(to, message string, group bool, att io.Reader, flags int, t
if err == nil {
break
}
log.Println(err)
log.Println("[axolotl]", err)
//If sending failed, try again after a while
time.Sleep(3 * time.Second)
count++
Expand Down
10 changes: 5 additions & 5 deletions app/store/message.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
package store

import (
"log"

"github.com/nanu-c/axolotl/app/helpers"
log "github.com/sirupsen/logrus"
)

type Message struct {
ID int64
ID int64 `db:"id"`
SID int64
ChatID string
Source string
Expand Down Expand Up @@ -44,15 +43,16 @@ func SaveMessage(m *Message) (error, *Message) {
}

func UpdateMessageSent(m *Message) error {
_, err := DS.Dbx.NamedExec("UPDATE messages SET issent = :issent, sentat = :sentat WHERE id = :id", m)
log.Debugln("SendingError", m.SendingError)
_, err := DS.Dbx.NamedExec("UPDATE messages SET issent = :issent, sentat = :sentat, sendingError = :sendingError, expireTimer = :expireTimer WHERE id = :id", m)
if err != nil {
return err
}
return err
}

func UpdateMessageRead(m *Message) error {
_, err := DS.Dbx.NamedExec("UPDATE messages SET isread = :isread WHERE id = :id", m)
_, err := DS.Dbx.NamedExec("UPDATE messages SET isread = :isread, receipt = :receipt WHERE id = :id", m)
if err != nil {
return err
}
Expand Down
43 changes: 42 additions & 1 deletion app/webserver/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,39 @@ func sendCurrentChat(client *websocket.Conn, s *store.Session) {
RemoveClientFromList(client)
return
}

}
func updateCurrentChat(client *websocket.Conn, s *store.Session) {
var (
err error
gr *textsecure.Group
c *textsecure.Contact
)
if s.IsGroup {
gr, err = textsecure.GetGroupById(s.Tel)
} else {
c = store.GetContactForTel(s.Tel)
}
updateCurrentChatEnvelope := &UpdateCurrentChatEnvelope{
UpdateCurrentChat: &UpdateCurrentChat{
CurrentChat: s,
Contact: c,
Group: gr,
},
}
message := &[]byte{}
*message, err = json.Marshal(updateCurrentChatEnvelope)
if err != nil {
fmt.Println(err)
return
}
// mu.Lock()
// defer mu.Unlock()
err = client.WriteMessage(websocket.TextMessage, *message)
if err != nil {
log.Println("[axolotl] send error update current chat ", err)
RemoveClientFromList(client)
return
}
}
func refreshContacts(client *websocket.Conn, path string) {
var err error
Expand Down Expand Up @@ -262,6 +294,15 @@ func UpdateContactList() {
}
}
}
func UpdateActiveChat() {
log.Debugln("[axolotl] update active chat")
if activeChat != "" {
s := store.SessionsModel.Get(activeChat)
for client := range clients {
updateCurrentChat(client, s)
}
}
}

type SendGui struct {
Gui string
Expand Down
8 changes: 8 additions & 0 deletions app/webserver/messages.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@ type OpenChat struct {
type CurrentChatEnvelope struct {
OpenChat *OpenChat
}
type UpdateCurrentChat struct {
CurrentChat *store.Session
Contact *textsecure.Contact
Group *textsecure.Group
}
type UpdateCurrentChatEnvelope struct {
UpdateCurrentChat *UpdateCurrentChat
}
type IdentityEnvelope struct {
Identity string
TheirId string
Expand Down
2 changes: 2 additions & 0 deletions app/webserver/webserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ func syncClients() {
// if registered {
UpdateChatList()
UpdateContactList()
UpdateActiveChat()
// }
}
}
Expand Down Expand Up @@ -136,6 +137,7 @@ func wsReader(conn *websocket.Conn) {
json.Unmarshal([]byte(p), &openChatMessage)
log.Println("[axolotl] Open chat for ", openChatMessage.Id)
s := store.SessionsModel.Get(openChatMessage.Id)
activeChat = openChatMessage.Id
sendCurrentChat(conn, s)
case "leaveChat":
activeChat = ""
Expand Down
4 changes: 3 additions & 1 deletion axolotl-web/src/assets/dark.scss
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ $chat-entry-border-color: #333;

$message-color: #fff;
$received-message-bg: #2880b0;
$sent-message-bg: #29b786;
$sent-message-bg: #ab54d3;
$sending-message-bg: #92c4ec;
$recieved-message-bg: #29b786;
$sent-message-link: #004090;
$sent-message-link-visited: #003060;

Expand Down
2 changes: 2 additions & 0 deletions axolotl-web/src/assets/light.scss
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ $chat-entry-border-color: #ddd;

$message-color: #000;
$received-message-bg: #dfdfdf;
$sending-message-bg: #92c4ec;
$recieved-message-bg: #68db9a;

This comment has been minimized.

Copy link
@Flaburgan

Flaburgan Apr 15, 2020

Collaborator

You have a small typo here ;)

$sent-message-bg: #d3f2d7;
$sent-message-link: $primary;

Expand Down
6 changes: 6 additions & 0 deletions axolotl-web/src/assets/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ $link-color: $primary;
.sent .message {
background-color: $sent-message-bg;
}
.sending .message {
background-color: $sending-message-bg;
}
.receipt .message {
background-color: $recieved-message-bg;
}

#messageInput {
border: 1px solid $message-input-border;
Expand Down
13 changes: 9 additions & 4 deletions axolotl-web/src/pages/MessageList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@
</video>
<button class="btn btn-secondary close" @click="showFullscreenVideoSrc=''">X</button>
</div>
<div v-for="(message,i) in messages.slice().reverse()"
<div v-for="(message) in messageList.Messages.slice().reverse()"
:class="{'col-12':true,
'sent':message.Outgoing,
'reply':!message.Outgoing,
'status':message.Flags>0||message.StatusMessage||message.Attachment.includes('null')&&message.Message=='',
'error':message.SentAt==0||message.SendingError}"
v-bind:key="i"
'error':message.SentAt==0||message.SendingError,
'sending':!message.IsSent&&message.Outgoing,
'receipt':message.Receipt}"
v-bind:key="message.ID"
>
<div class="row w-100" v-if="verifySelfDestruction(message)">
<div class="col-12 data">
Expand Down Expand Up @@ -432,7 +434,7 @@ export default {
isGroup () {
return this.$store.state.messageList.Session.IsGroup
},
... mapState(['contacts','config']),
... mapState(['contacts','config','messageList']),
}
}
</script>
Expand Down Expand Up @@ -549,6 +551,9 @@ video,
.error .message{
background-color:#f7663a;
}
.error .meta{
color:#f7663a;
}
.messageInputBox {
bottom: 0px;
width: 100vw;
Expand Down
11 changes: 11 additions & 0 deletions axolotl-web/src/store/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,14 @@ export default new Vuex.Store({
state.currentGroup = data.Group;
state.currentContact = data.Contact;
},
UPDATE_CURRENT_CHAT(state, data){
state.currentChat = data.CurrentChat;
var prepare = state.messageList.Messages.map(function(e) { return e.ID; })
data.CurrentChat.Messages.forEach(m => {
state.messageList.Messages[prepare.indexOf(m.ID)] = m;
});
// state.MessageList.Messages
},
SET_CONFIG(state, config){
state.config = config;
},
Expand Down Expand Up @@ -259,6 +267,9 @@ export default new Vuex.Store({
else if(Object.keys(messageData)[0]=="OpenChat"){
this.commit("OPEN_CHAT",messageData["OpenChat"]);
}
else if(Object.keys(messageData)[0]=="UpdateCurrentChat"){
this.commit("UPDATE_CURRENT_CHAT",messageData["UpdateCurrentChat"]);
}
else{
// console.log("unkown message ", Object.keys(messageData)[0]);
}
Expand Down
12 changes: 6 additions & 6 deletions po/ar.po
Original file line number Diff line number Diff line change
Expand Up @@ -183,11 +183,11 @@ msgstr ""
msgid "No devices available"
msgstr ""

#: src/pages/MessageList.vue:121
#: src/pages/MessageList.vue:123
msgid "No Messages available."
msgstr ""

#: src/pages/MessageList.vue:57 src/pages/MessageList.vue:83
#: src/pages/MessageList.vue:59 src/pages/MessageList.vue:85
msgid "Not supported mime type:"
msgstr ""

Expand Down Expand Up @@ -266,7 +266,7 @@ msgstr "إعادة ضبط جلسة آمنة"
msgid "Set password"
msgstr ""

#: src/pages/MessageList.vue:89
#: src/pages/MessageList.vue:91
msgid "Set timer for self-destructing messages"
msgstr ""

Expand Down Expand Up @@ -331,12 +331,12 @@ msgstr "فيديو"
msgid "Wrong code entered. Restart for another try."
msgstr ""

#: src/pages/MessageList.vue:11 src/pages/MessageList.vue:44
#: src/pages/MessageList.vue:53 src/pages/MessageList.vue:68
#: src/pages/MessageList.vue:11 src/pages/MessageList.vue:46
#: src/pages/MessageList.vue:55 src/pages/MessageList.vue:70
msgid "Your browser does not support the audio element."
msgstr ""

#: src/pages/MessageList.vue:78
#: src/pages/MessageList.vue:80
msgid "Your browser does not support the video element."
msgstr ""

Expand Down
12 changes: 6 additions & 6 deletions po/be.po
Original file line number Diff line number Diff line change
Expand Up @@ -182,11 +182,11 @@ msgstr ""
msgid "No devices available"
msgstr ""

#: src/pages/MessageList.vue:121
#: src/pages/MessageList.vue:123
msgid "No Messages available."
msgstr ""

#: src/pages/MessageList.vue:57 src/pages/MessageList.vue:83
#: src/pages/MessageList.vue:59 src/pages/MessageList.vue:85
msgid "Not supported mime type:"
msgstr ""

Expand Down Expand Up @@ -263,7 +263,7 @@ msgstr ""
msgid "Set password"
msgstr ""

#: src/pages/MessageList.vue:89
#: src/pages/MessageList.vue:91
msgid "Set timer for self-destructing messages"
msgstr ""

Expand Down Expand Up @@ -328,12 +328,12 @@ msgstr ""
msgid "Wrong code entered. Restart for another try."
msgstr ""

#: src/pages/MessageList.vue:11 src/pages/MessageList.vue:44
#: src/pages/MessageList.vue:53 src/pages/MessageList.vue:68
#: src/pages/MessageList.vue:11 src/pages/MessageList.vue:46
#: src/pages/MessageList.vue:55 src/pages/MessageList.vue:70
msgid "Your browser does not support the audio element."
msgstr ""

#: src/pages/MessageList.vue:78
#: src/pages/MessageList.vue:80
msgid "Your browser does not support the video element."
msgstr ""

Expand Down
Loading

0 comments on commit 2c5f6ab

Please sign in to comment.