fix client chat
This commit is contained in:
@@ -105,38 +105,22 @@ func fetch_messages(channel_id: String, before_id: String = "") -> void:
|
||||
var payload: Dictionary = { "channelId": channel_id }
|
||||
if not before_id.is_empty():
|
||||
payload["beforeMessageId"] = before_id
|
||||
Network.request("chat.get_messages", payload,
|
||||
func(_t: String, p: Variant) -> void:
|
||||
var msgs: Array = (p as Dictionary).get("messages", [])
|
||||
if channel_id not in messages:
|
||||
messages[channel_id] = []
|
||||
messages[channel_id].append_array(msgs)
|
||||
message_received.emit(channel_id, {})
|
||||
,
|
||||
func(_c: String, _m: String) -> void: pass
|
||||
Network.request(
|
||||
"chat.get_messages",
|
||||
payload,
|
||||
_on_fetch_messages_success.bind(channel_id),
|
||||
_noop_error
|
||||
)
|
||||
|
||||
|
||||
## Open or retrieve the Direct channel with recipient_account_id.
|
||||
## Emits channels_updated on success so the DMs tab can refresh.
|
||||
func open_dm(recipient_account_id: String) -> void:
|
||||
Network.request("chat.dm_open", { "recipientAccountId": recipient_account_id },
|
||||
func(_t: String, p: Variant) -> void:
|
||||
var chan: Dictionary = (p as Dictionary).get("channel", {})
|
||||
if chan.is_empty():
|
||||
return
|
||||
var cid: String = chan.get("id", "")
|
||||
# Add to local list if not already present.
|
||||
var found := false
|
||||
for c: Dictionary in channels:
|
||||
if c.get("id", "") == cid:
|
||||
found = true
|
||||
break
|
||||
if not found:
|
||||
channels.push_front(chan)
|
||||
channels_updated.emit()
|
||||
,
|
||||
func(_c: String, _m: String) -> void: pass
|
||||
Network.request(
|
||||
"chat.dm_open",
|
||||
{ "recipientAccountId": recipient_account_id },
|
||||
_on_open_dm_success,
|
||||
_noop_error
|
||||
)
|
||||
|
||||
|
||||
@@ -183,13 +167,11 @@ func set_presence(status: String) -> void:
|
||||
func fetch_presence(account_ids: Array) -> void:
|
||||
if account_ids.is_empty():
|
||||
return
|
||||
Network.request("chat.presence.get", { "accountIds": account_ids },
|
||||
func(_t: String, p: Variant) -> void:
|
||||
for pr: Dictionary in (p as Dictionary).get("presences", []):
|
||||
presence[pr.get("accountId", "")] = pr
|
||||
presence_updated.emit()
|
||||
,
|
||||
func(_c: String, _m: String) -> void: pass
|
||||
Network.request(
|
||||
"chat.presence.get",
|
||||
{ "accountIds": account_ids },
|
||||
_on_fetch_presence_success,
|
||||
_noop_error
|
||||
)
|
||||
|
||||
|
||||
@@ -230,42 +212,76 @@ func _set_own_presence(status: String) -> void:
|
||||
|
||||
|
||||
func _fetch_social() -> void:
|
||||
Network.request("chat.get_social", {},
|
||||
func(_t: String, p: Variant) -> void:
|
||||
var d := p as Dictionary
|
||||
friends = d.get("friends", [])
|
||||
pending_requests = d.get("pendingRequests", [])
|
||||
blocked_users = d.get("blockedUsers", [])
|
||||
social_updated.emit()
|
||||
# Refresh presence for all friends.
|
||||
var ids: Array = friends.map(func(f: Dictionary) -> String:
|
||||
return f.get("accountId", ""))
|
||||
fetch_presence(ids)
|
||||
,
|
||||
func(_c: String, _m: String) -> void: pass
|
||||
)
|
||||
Network.request("chat.get_social", {}, _on_fetch_social_success, _noop_error)
|
||||
|
||||
|
||||
func _fetch_channels() -> void:
|
||||
Network.request("chat.get_channels", {},
|
||||
func(_t: String, p: Variant) -> void:
|
||||
channels = (p as Dictionary).get("channels", [])
|
||||
channels_updated.emit()
|
||||
,
|
||||
func(_c: String, _m: String) -> void: pass
|
||||
)
|
||||
Network.request("chat.get_channels", {}, _on_fetch_channels_success, _noop_error)
|
||||
|
||||
|
||||
func _fetch_notifications() -> void:
|
||||
Network.request("chat.notifications.get", { "unreadOnly": false },
|
||||
func(_t: String, p: Variant) -> void:
|
||||
notifications = (p as Dictionary).get("notifications", [])
|
||||
notifications_updated.emit()
|
||||
,
|
||||
func(_c: String, _m: String) -> void: pass
|
||||
Network.request(
|
||||
"chat.notifications.get",
|
||||
{ "unreadOnly": false },
|
||||
_on_fetch_notifications_success,
|
||||
_noop_error
|
||||
)
|
||||
|
||||
|
||||
func _on_fetch_messages_success(_t: String, p: Variant, channel_id: String) -> void:
|
||||
var msgs: Array = (p as Dictionary).get("messages", [])
|
||||
if channel_id not in messages:
|
||||
messages[channel_id] = []
|
||||
messages[channel_id].append_array(msgs)
|
||||
message_received.emit(channel_id, {})
|
||||
|
||||
|
||||
func _on_open_dm_success(_t: String, p: Variant) -> void:
|
||||
var chan: Dictionary = (p as Dictionary).get("channel", {})
|
||||
if chan.is_empty():
|
||||
return
|
||||
var cid: String = chan.get("id", "")
|
||||
var found := false
|
||||
for c: Dictionary in channels:
|
||||
if c.get("id", "") == cid:
|
||||
found = true
|
||||
break
|
||||
if not found:
|
||||
channels.push_front(chan)
|
||||
channels_updated.emit()
|
||||
|
||||
|
||||
func _on_fetch_presence_success(_t: String, p: Variant) -> void:
|
||||
for pr: Dictionary in (p as Dictionary).get("presences", []):
|
||||
presence[pr.get("accountId", "")] = pr
|
||||
presence_updated.emit()
|
||||
|
||||
|
||||
func _on_fetch_social_success(_t: String, p: Variant) -> void:
|
||||
var d := p as Dictionary
|
||||
friends = d.get("friends", [])
|
||||
pending_requests = d.get("pendingRequests", [])
|
||||
blocked_users = d.get("blockedUsers", [])
|
||||
social_updated.emit()
|
||||
var ids: Array = friends.map(func(f: Dictionary) -> String:
|
||||
return f.get("accountId", ""))
|
||||
fetch_presence(ids)
|
||||
|
||||
|
||||
func _on_fetch_channels_success(_t: String, p: Variant) -> void:
|
||||
channels = (p as Dictionary).get("channels", [])
|
||||
channels_updated.emit()
|
||||
|
||||
|
||||
func _on_fetch_notifications_success(_t: String, p: Variant) -> void:
|
||||
notifications = (p as Dictionary).get("notifications", [])
|
||||
notifications_updated.emit()
|
||||
|
||||
|
||||
func _noop_error(_c: String, _m: String) -> void:
|
||||
pass
|
||||
|
||||
|
||||
func _on_server_push(type: String, payload: Variant) -> void:
|
||||
match type:
|
||||
"chat.message.push":
|
||||
|
||||
Reference in New Issue
Block a user