Skip to content

Commit

Permalink
Tutorial: Fix notification showing up when user logs in
Browse files Browse the repository at this point in the history
  • Loading branch information
NathanLovato committed Jul 1, 2020
1 parent a391824 commit 4d8e947
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 15 deletions.
21 changes: 13 additions & 8 deletions tutorial/godot/src/Main/Demo.gd
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ onready var debug_panel := $CanvasLayer/DebugPanel
onready var chat_box := $CanvasLayer/ChatBox
onready var notification_list := $CanvasLayer/NotificationList

var email := "[email protected]"
var password := "password"


func _ready() -> void:
var email := "[email protected]"
var password := "password"

var result: int = yield(request_authentication(email, password), "completed")
if result != OK:
Expand Down Expand Up @@ -65,13 +66,17 @@ func _on_ChatBox_text_sent(text) -> void:
yield(server_connection.send_text_async(text), "completed")


func _on_ServerConnection_chat_message_received(sender_id, text) -> void:
chat_box.add_reply(text, "User", user_color)
func _on_ServerConnection_chat_message_received(username, text) -> void:
chat_box.add_reply(text, username, user_color)


func _on_ServerConnection_user_joined(user) -> void:
notification_list.add_notification(user.username, Color.white, false)
func _on_ServerConnection_user_joined(username) -> void:
if email == username:
return
notification_list.add_notification(username, Color.white, false)


func _on_ServerConnection_user_left(user) -> void:
notification_list.add_notification(user.username, Color.white, true)
func _on_ServerConnection_user_left(username) -> void:
if email == username:
return
notification_list.add_notification(username, Color.white, true)
12 changes: 6 additions & 6 deletions tutorial/godot/src/Main/ServerConnection.gd
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
extends Node

signal chat_message_received(sender_id, text)
signal user_joined(user)
signal user_left(user)
signal chat_message_received(username, text)
signal user_joined(username)
signal user_left(username)

# Nakama read permissions
enum ReadPermissions { NO_READ, OWNER_READ, PUBLIC_READ }
Expand Down Expand Up @@ -148,16 +148,16 @@ func _on_NamakaSocket_received_channel_message(message: NakamaAPI.ApiChannelMess
return

var content: Dictionary = JSON.parse(message.content).result
emit_signal("chat_message_received", message.sender_id, content.msg)
emit_signal("chat_message_received", message.username, content.msg)


func _on_NakamaSocket_received_match_presence(new_presences: NakamaRTAPI.MatchPresenceEvent) -> void:
for user in new_presences.leaves:
#warning-ignore: return_value_discarded
_presences.erase(user.user_id)
emit_signal("user_left", user)
emit_signal("user_left", user.username)

for user in new_presences.joins:
_presences[user.user_id] = user
emit_signal("user_joined", user)
emit_signal("user_joined", user.username)

1 change: 0 additions & 1 deletion tutorial/godot/src/UI/ChatBox.gd
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,3 @@ func _on_LineEdit_focus_exited() -> void:

func _on_ToggleChatButton_toggled(button_pressed: bool) -> void:
visible = button_pressed

0 comments on commit 4d8e947

Please sign in to comment.