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 }
|
var payload: Dictionary = { "channelId": channel_id }
|
||||||
if not before_id.is_empty():
|
if not before_id.is_empty():
|
||||||
payload["beforeMessageId"] = before_id
|
payload["beforeMessageId"] = before_id
|
||||||
Network.request("chat.get_messages", payload,
|
Network.request(
|
||||||
func(_t: String, p: Variant) -> void:
|
"chat.get_messages",
|
||||||
var msgs: Array = (p as Dictionary).get("messages", [])
|
payload,
|
||||||
if channel_id not in messages:
|
_on_fetch_messages_success.bind(channel_id),
|
||||||
messages[channel_id] = []
|
_noop_error
|
||||||
messages[channel_id].append_array(msgs)
|
|
||||||
message_received.emit(channel_id, {})
|
|
||||||
,
|
|
||||||
func(_c: String, _m: String) -> void: pass
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
## Open or retrieve the Direct channel with recipient_account_id.
|
## Open or retrieve the Direct channel with recipient_account_id.
|
||||||
## Emits channels_updated on success so the DMs tab can refresh.
|
## Emits channels_updated on success so the DMs tab can refresh.
|
||||||
func open_dm(recipient_account_id: String) -> void:
|
func open_dm(recipient_account_id: String) -> void:
|
||||||
Network.request("chat.dm_open", { "recipientAccountId": recipient_account_id },
|
Network.request(
|
||||||
func(_t: String, p: Variant) -> void:
|
"chat.dm_open",
|
||||||
var chan: Dictionary = (p as Dictionary).get("channel", {})
|
{ "recipientAccountId": recipient_account_id },
|
||||||
if chan.is_empty():
|
_on_open_dm_success,
|
||||||
return
|
_noop_error
|
||||||
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
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@@ -183,13 +167,11 @@ func set_presence(status: String) -> void:
|
|||||||
func fetch_presence(account_ids: Array) -> void:
|
func fetch_presence(account_ids: Array) -> void:
|
||||||
if account_ids.is_empty():
|
if account_ids.is_empty():
|
||||||
return
|
return
|
||||||
Network.request("chat.presence.get", { "accountIds": account_ids },
|
Network.request(
|
||||||
func(_t: String, p: Variant) -> void:
|
"chat.presence.get",
|
||||||
for pr: Dictionary in (p as Dictionary).get("presences", []):
|
{ "accountIds": account_ids },
|
||||||
presence[pr.get("accountId", "")] = pr
|
_on_fetch_presence_success,
|
||||||
presence_updated.emit()
|
_noop_error
|
||||||
,
|
|
||||||
func(_c: String, _m: String) -> void: pass
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@@ -230,40 +212,74 @@ func _set_own_presence(status: String) -> void:
|
|||||||
|
|
||||||
|
|
||||||
func _fetch_social() -> void:
|
func _fetch_social() -> void:
|
||||||
Network.request("chat.get_social", {},
|
Network.request("chat.get_social", {}, _on_fetch_social_success, _noop_error)
|
||||||
func(_t: String, p: Variant) -> void:
|
|
||||||
|
|
||||||
|
func _fetch_channels() -> void:
|
||||||
|
Network.request("chat.get_channels", {}, _on_fetch_channels_success, _noop_error)
|
||||||
|
|
||||||
|
|
||||||
|
func _fetch_notifications() -> void:
|
||||||
|
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
|
var d := p as Dictionary
|
||||||
friends = d.get("friends", [])
|
friends = d.get("friends", [])
|
||||||
pending_requests = d.get("pendingRequests", [])
|
pending_requests = d.get("pendingRequests", [])
|
||||||
blocked_users = d.get("blockedUsers", [])
|
blocked_users = d.get("blockedUsers", [])
|
||||||
social_updated.emit()
|
social_updated.emit()
|
||||||
# Refresh presence for all friends.
|
|
||||||
var ids: Array = friends.map(func(f: Dictionary) -> String:
|
var ids: Array = friends.map(func(f: Dictionary) -> String:
|
||||||
return f.get("accountId", ""))
|
return f.get("accountId", ""))
|
||||||
fetch_presence(ids)
|
fetch_presence(ids)
|
||||||
,
|
|
||||||
func(_c: String, _m: String) -> void: pass
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
func _fetch_channels() -> void:
|
func _on_fetch_channels_success(_t: String, p: Variant) -> void:
|
||||||
Network.request("chat.get_channels", {},
|
|
||||||
func(_t: String, p: Variant) -> void:
|
|
||||||
channels = (p as Dictionary).get("channels", [])
|
channels = (p as Dictionary).get("channels", [])
|
||||||
channels_updated.emit()
|
channels_updated.emit()
|
||||||
,
|
|
||||||
func(_c: String, _m: String) -> void: pass
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
func _fetch_notifications() -> void:
|
func _on_fetch_notifications_success(_t: String, p: Variant) -> void:
|
||||||
Network.request("chat.notifications.get", { "unreadOnly": false },
|
|
||||||
func(_t: String, p: Variant) -> void:
|
|
||||||
notifications = (p as Dictionary).get("notifications", [])
|
notifications = (p as Dictionary).get("notifications", [])
|
||||||
notifications_updated.emit()
|
notifications_updated.emit()
|
||||||
,
|
|
||||||
func(_c: String, _m: String) -> void: pass
|
|
||||||
)
|
func _noop_error(_c: String, _m: String) -> void:
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
func _on_server_push(type: String, payload: Variant) -> void:
|
func _on_server_push(type: String, payload: Variant) -> void:
|
||||||
|
|||||||
Reference in New Issue
Block a user