diff --git a/internal/pwa/components/saltychat.go b/internal/pwa/components/saltychat.go index 4166937..47bdc59 100644 --- a/internal/pwa/components/saltychat.go +++ b/internal/pwa/components/saltychat.go @@ -123,6 +123,7 @@ func (h *SaltyChat) connect(ctx app.Context) { return case msg := <-inboxCh: // passing both the message and the text in case we need the message key at some point + ctx.NewActionWithValue(saltyChatRecvMessageAction, msg, app.T("text", msg.Text)) case msg := <-outboxCh: // passing both the message and the text in case we need the message key at some point @@ -139,7 +140,7 @@ func (h *SaltyChat) incomingMessage(ctx app.Context, action app.Action) { h.dialog.ShowDialog("incoming message error", err.Error()) return } -log.Print("in: ", s) += switch s := s.(type) { case *lextwt.SaltyText: user := s.User.String() @@ -168,19 +169,27 @@ func (h *SaltyChat) outgoingMessage(ctx app.Context, action app.Action) { h.dialog.ShowDialog("outgoing message error", err.Error()) return } -log.Print("out:", s) + + friend := "" switch s := s.(type) { case *lextwt.SaltyText: - friend := s.User.String() + friend = s.User.String() storage.ContactsLocalStorage(ctx).Add(friend) storage.ConversationsLocalStorage(ctx, friend). Append(string(saltyim.PackMessage(client.Me(), s.LiteralText()))) + } + // only update when incoming user's message is the active chat + if h.friend == friend { + h.chatBox.UpdateMessages(ctx) + } else { + // TODO: Creates some initial content of the new chat + // to give the user a change to Accept/Reject the contact. + log.Printf("new incoming chat from %s", friend) } } func (h *SaltyChat) Render() app.UI { - topBar := &bar.TopAppBar{Title: "Salty IM", Navigation: []app.HTMLButton{icon.MIMenu.Button().OnClick(func(ctx app.Context, e app.Event) { h.navigation.drawer.ActionOpen(ctx) @@ -238,9 +247,9 @@ func (h *SaltyChat) handleSendMessage(ctx app.Context, e app.Event) { h.chatBox.User = h.friend ctx.Async(func() { if err := client.Send(h.friend, msg); err == nil { - storage.ConversationsLocalStorage(ctx, h.friend). - Append(string(saltyim.PackMessage(client.Me(), msg))) - h.chatBox.UpdateMessages(ctx) + // storage.ConversationsLocalStorage(ctx, h.friend). + // Append(string(saltyim.PackMessage(client.Me(), msg))) + // h.chatBox.UpdateMessages(ctx) } else { h.dialog.ShowDialog("error sending message", err.Error()) } diff --git a/internal/web/app.wasm b/internal/web/app.wasm index c3c2a40..3618da4 100755 --- a/internal/web/app.wasm +++ b/internal/web/app.wasm @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:2ec05cfce9cd986c818ce909a2b0048f032f71df80c50497f15d3c7aaf1e9ef2 -size 28584522 +oid sha256:dfc1cdc5ff7fd12413b61cea7f7411a75c64b19e861ad4734db46a45b19a0a5e +size 28572009